Beispiel #1
0
def migration_task():
    for config in ILSGatewayConfig.get_all_steady_sync_configs():
        if config.enabled:
            endpoint = ILSGatewayEndpoint.from_config(config)
            ils_bootstrap_domain(ILSGatewayAPI(config.domain, endpoint))
            apis = get_ilsgateway_data_migrations()
            stock_data_task.delay(config.domain, endpoint, apis, config, ILS_FACILITIES)
Beispiel #2
0
def migration_task():
    from custom.ilsgateway.stock_data import ILSStockDataSynchronization
    for config in ILSGatewayConfig.get_all_steady_sync_configs():
        if config.enabled:
            endpoint = ILSGatewayEndpoint.from_config(config)
            ils_bootstrap_domain(ILSGatewayAPI(config.domain, endpoint))
            stock_data_task.delay(ILSStockDataSynchronization(config.domain, endpoint))
Beispiel #3
0
def ils_sync_stock_data(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    domain = config.domain
    endpoint = ILSGatewayEndpoint.from_config(config)
    apis = get_ilsgateway_data_migrations()
    stock_data_task.delay(domain, endpoint, apis, config, ILS_FACILITIES)
    return HttpResponse('OK')
Beispiel #4
0
def fix_stock_data(domain):
    start_date = '2015-07-01'
    end_date = StockDataCheckpoint.objects.get(domain=domain).date.strftime('%Y-%m-%d')
    with connection.cursor() as c:
        c.execute(
            'DELETE FROM ilsgateway_supplypointstatus WHERE location_id IN '
            '(SELECT location_id FROM locations_sqllocation WHERE domain=%s) AND status_date BETWEEN %s AND %s',
            [domain, start_date, end_date]
        )

        c.execute(
            'DELETE FROM ilsgateway_deliverygroupreport WHERE location_id IN '
            '(SELECT location_id FROM locations_sqllocation WHERE domain=%s) AND report_date BETWEEN %s AND %s',
            [domain, start_date, end_date]
        )

        c.execute(
            "DELETE FROM ilsgateway_groupsummary WHERE org_summary_id IN "
            "(SELECT id FROM ilsgateway_organizationsummary WHERE location_id IN "
            "(SELECT location_id FROM locations_sqllocation WHERE domain=%s) AND date BETWEEN %s AND %s)",
            [domain, start_date, end_date]
        )

        c.execute(
            "DELETE FROM ilsgateway_organizationsummary WHERE location_id IN "
            "(SELECT location_id FROM locations_sqllocation WHERE domain=%s AND date BETWEEN %s AND %s)",
            [domain, start_date, end_date]
        )

    config = ILSGatewayConfig.for_domain(domain)
    endpoint = ILSGatewayEndpoint.from_config(config)

    filters = {'status_date__gte': start_date, 'status_date__lte': end_date}

    offset = 0
    _, statuses = endpoint.get_supplypointstatuses(domain, filters=filters, limit=1000, offset=offset)
    while statuses:
        for status in statuses:
            try:
                SupplyPointStatus.objects.get(external_id=status.external_id, location_id=status.location_id)
            except SupplyPointStatus.DoesNotExist:
                status.save()
        offset += 1000
        _, statuses = endpoint.get_supplypointstatuses(domain, filters=filters, limit=1000, offset=offset)

    filters = {'report_date__gte': start_date, 'report_date__lte': end_date}

    offset = 0
    _, reports = endpoint.get_deliverygroupreports(domain, filters=filters, limit=1000, offset=offset)
    while reports:
        for report in reports:
            try:
                DeliveryGroupReport.objects.get(external_id=report.external_id, location_id=report.location_id)
            except DeliveryGroupReport.DoesNotExist:
                report.save()
        offset += 1000
        _, reports = endpoint.get_deliverygroupreports(domain, filters=filters, limit=1000, offset=offset)
Beispiel #5
0
def stock_data_task(domain):
    ilsgateway_config = ILSGatewayConfig.for_domain(domain)
    domain = ilsgateway_config.domain
    endpoint = ILSGatewayEndpoint.from_config(ilsgateway_config)
    commtrack_settings_sync(domain)
    for product in endpoint.get_products():
        sync_ilsgateway_product(domain, product)
    get_locations(domain, endpoint)
    get_product_stock(domain, endpoint)
    get_stock_transaction(domain, endpoint)
    get_supply_point_statuses(domain, endpoint)
    get_delivery_group_reports(domain, endpoint)
Beispiel #6
0
def ils_sync_stock_data(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    domain = config.domain
    endpoint = ILSGatewayEndpoint.from_config(config)
    apis = (
        ('product_stock', get_product_stock),
        ('stock_transaction', get_stock_transaction),
        ('supply_point_status', get_supply_point_statuses),
        ('delivery_group', get_delivery_group_reports)
    )
    stock_data_task.delay(domain, endpoint, apis, ILS_FACILITIES)
    return HttpResponse('OK')
    def handle(self, domain, *args, **options):
        if len(args) == 1:
            ilsgateway_id = args[0]
        else:
            ilsgateway_id = 1166  # defaults to bondenzi: http://ilsgateway.com/tz/facility/1166/

        # cleanup
        _cleanup_existing_data(domain, ilsgateway_id)

        # migrate
        config = ILSGatewayConfig.for_domain(domain)
        assert config.enabled, 'ilsgateway sync must be configured for this domain'
        endpoint = ILSGatewayEndpoint.from_config(config)
        stock_data_task(domain, endpoint, get_ilsgateway_data_migrations(), config,
                        test_facilities=[ilsgateway_id])
    def handle(self, domain, *args, **options):
        if len(args) == 1:
            ilsgateway_id = args[0]
        else:
            ilsgateway_id = 1166  # defaults to bondenzi: http://ilsgateway.com/tz/facility/1166/

        # cleanup
        _cleanup_existing_data(domain, ilsgateway_id)

        # migrate
        config = ILSGatewayConfig.for_domain(domain)
        assert config.enabled, 'ilsgateway sync must be configured for this domain'
        endpoint = ILSGatewayEndpoint.from_config(config)
        stock_data_task(domain, endpoint, get_ilsgateway_data_migrations(), config,
                        test_facilities=[ilsgateway_id])
Beispiel #9
0
def bootstrap_domain(ilsgateway_config):
    domain = ilsgateway_config.domain
    start_date = datetime.today()
    endpoint = ILSGatewayEndpoint.from_config(ilsgateway_config)
    try:
        checkpoint = ILSMigrationCheckpoint.objects.get(domain=domain)
        api = checkpoint.api
        date = checkpoint.date
        limit = checkpoint.limit
        offset = checkpoint.offset
    except ILSMigrationCheckpoint.DoesNotExist:
        checkpoint = ILSMigrationCheckpoint()
        checkpoint.domain = domain
        api = 'product'
        date = None
        limit = 1000
        offset = 0
        commtrack_settings_sync(domain)

    apis = [
        ('product', partial(products_sync, domain, endpoint, checkpoint)),
        ('location_facility', partial(locations_sync, domain, endpoint, checkpoint, date=date,
                                      filters=dict(date_updated__gte=date, type='facility'))),
        ('location_district', partial(locations_sync, domain, endpoint, checkpoint, date=date,
                                      filters=dict(date_updated__gte=date, type='district'))),
        ('location_region', partial(locations_sync, domain, endpoint, checkpoint, date=date,
                                    filters=dict(date_updated__gte=date, type='region'))),
        ('webuser', partial(webusers_sync, domain, endpoint, checkpoint, date=date,
                            filters=dict(user__date_joined__gte=date))),
        ('smsuser', partial(smsusers_sync, domain, endpoint, checkpoint, date=date,
                            filters=dict(date_updated__gte=date)))
    ]

    try:
        i = 0
        while apis[i][0] != api:
            i += 1
        for api in apis[i:]:
            api[1](limit=limit, offset=offset)
            limit = 1000
            offset = 0

        save_checkpoint(checkpoint, 'product', 1000, 0, start_date)
    except ConnectionError as e:
        logging.error(e)
Beispiel #10
0
def bootstrap_domain(ilsgateway_config):
    domain = ilsgateway_config.domain
    start_date = datetime.today()
    endpoint = ILSGatewayEndpoint.from_config(ilsgateway_config)
    try:
        checkpoint = MigrationCheckpoint.objects.get(domain=domain)
        date = checkpoint.date
    except MigrationCheckpoint.DoesNotExist:
        checkpoint = MigrationCheckpoint()
        checkpoint.domain = domain
        date = None
        commtrack_settings_sync(domain)
    try:
        products_sync(domain, endpoint, date=date)
        locations_sync(domain, endpoint, date=date)
        webusers_sync(domain, endpoint, date=date)
        smsusers_sync(domain, endpoint, date=date)
        
        checkpoint.date = start_date
        checkpoint.save()
    except ConnectionError as e:
        logging.error(e)
Beispiel #11
0
def ils_sms_users_fix(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    endpoint = ILSGatewayEndpoint.from_config(config)
    sms_users_fix.delay(ILSGatewayAPI(domain=domain, endpoint=endpoint))
    return HttpResponse('OK')
Beispiel #12
0
def ils_resync_passwords(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    endpoint = ILSGatewayEndpoint.from_config(config)
    resync_webusers_passwords_task.delay(config, endpoint)
    return HttpResponse('OK')
 def endpoint(self):
     return ILSGatewayEndpoint.from_config(ILSGatewayConfig.for_domain(self.domain))
Beispiel #14
0
def ils_sync_stock_data(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    domain = config.domain
    endpoint = ILSGatewayEndpoint.from_config(config)
    stock_data_task.delay(ILSStockDataSynchronization(domain, endpoint))
    return HttpResponse('OK')
Beispiel #15
0
def ils_resync_web_users(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    endpoint = ILSGatewayEndpoint.from_config(config)
    resync_web_users.delay(ILSGatewayAPI(domain=domain, endpoint=endpoint))
    return HttpResponse('OK')
Beispiel #16
0
def ils_bootstrap_domain_task(domain):
    ils_config = ILSGatewayConfig.for_domain(domain)
    return ils_bootstrap_domain(ILSGatewayAPI(domain, ILSGatewayEndpoint.from_config(ils_config)))
Beispiel #17
0
 def endpoint(self):
     return ILSGatewayEndpoint.from_config(
         ILSGatewayConfig.for_domain(self.domain))
Beispiel #18
0
def ils_sync_stock_data(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    domain = config.domain
    endpoint = ILSGatewayEndpoint.from_config(config)
    stock_data_task.delay(ILSStockDataSynchronization(domain, endpoint))
    return HttpResponse('OK')
Beispiel #19
0
def ils_resync_web_users(request, domain):
    config = ILSGatewayConfig.for_domain(domain)
    endpoint = ILSGatewayEndpoint.from_config(config)
    resync_web_users.delay(ILSGatewayAPI(domain=domain, endpoint=endpoint))
    return HttpResponse('OK')
Beispiel #20
0
def migration_task():
    configs = ILSGatewayConfig.get_all_configs()
    for config in configs:
        if config.enabled:
            ils_bootstrap_domain(ILSGatewayAPI(config.domain, ILSGatewayEndpoint.from_config(config)))