示例#1
0
    def process_release_row(self, file_model, file_item_model, release_row):
        package = self.database.get_package_data(release_row.package_data_id)
        package['releases'] = [self.database.get_data(release_row.data_id)]
        upgrade_10_11(package)

        def add_status(database, connection):
            connection.execute(
                database.transform_upgrade_1_0_to_1_1_status_release_table.
                insert(), {
                    'source_release_id': release_row.id,
                })

        package_data = {}
        for key, value in package.items():
            if key != 'releases':
                package_data[key] = value

        with DatabaseStore(
                database=self.database,
                collection_id=self.destination_collection.database_id,
                file_name=file_model.filename,
                number=file_item_model.number,
                url=file_model.url,
                before_db_transaction_ends_callback=add_status,
                allow_existing_collection_file_item_table_row=True) as store:

            store.insert_release(package['releases'][0], package_data)
    def process_record_id(self, file_model, file_item_model, record_id):
        with self.database.get_engine().begin() as connection:
            s = sa.sql.select([self.database.record_table]) \
                .where(self.database.record_table.c.id == record_id)
            result = connection.execute(s)
            record_row = result.fetchone()

        package = self.database.get_package_data(record_row.package_data_id)
        package['records'] = [self.database.get_data(record_row.data_id)]
        package = upgrade_10_11(package)

        def add_status(database, connection):
            connection.execute(database.transform_upgrade_1_0_to_1_1_status_record_table.insert(), {
                'source_record_id': record_row.id,
            })

        package_data = {}
        for key, value in package.items():
            if key != 'records':
                package_data[key] = value

        with DatabaseStore(database=self.database, collection_id=self.destination_collection.database_id,
                           file_name=file_model.filename, number=file_item_model.number,
                           url=file_model.url, before_db_transaction_ends_callback=add_status,
                           allow_existing_collection_file_item_table_row=True) as store:

            store.insert_record(package['records'][0], package_data)
def clean_and_convert_to_1_1(row):
    rowjson = json.dumps(row)
    rowjson = json.loads(rowjson)

    # Fix OCDS errors

    rowjson = fix_cf_supplier_ids(rowjson)

    # Convert to 1.1 OCDS
    json_1_1 = upgrade_10_11(json.loads(json.dumps(rowjson), object_pairs_hook=OrderedDict))
    # json_1_1 = json.dumps(json_1_1)
    return json_1_1
def get_and_insert_1_1_json(row):
    try:
        # Fixing json format
        rowjson = json.dumps(row[0])
        rowjson = json.loads(rowjson)

        # Fixing OCDS errors
        rowjson = fix_cf_supplier_ids(rowjson)

        json_1_1 = upgrade_10_11(
            json.loads(json.dumps(rowjson), object_pairs_hook=OrderedDict))
        json_1_1 = json.dumps(json_1_1)

        insert_1_1_json(json_1_1, row[1], row[2], local_connection)
    except:
        logging.debug('Failed to get 1.1 OCDS', exc_info=True)
示例#5
0
def perform_upgrade(request):
    return _json_response(
        (file.name_with_suffix('upgraded'), upgrade_10_11(file.json()))
        for file in _get_files_from_session(request))
示例#6
0
def perform_upgrade(request):
    return json_response((file.name_with_suffix('upgraded'), upgrade_10_11(file.json(object_pairs_hook=OrderedDict)))
                         for file in get_files_from_session(request))