def import_vendors_from_json(dump_file, rectype="provider"): """Imports vendors from JSON data files.""" dump_file = dump_file[0] click.echo("Importing vendors ..") with click.progressbar(json.load(dump_file)) as input_data: ils_records = [] for record in input_data: record["type"] = "VENDOR" # Legacy_ids in the .json file can be an array of strings or just # an integer, but we only accept an array of strings in the schema if not isinstance(record["legacy_ids"], list): record["legacy_ids"] = [str(record["legacy_ids"])] vocabulary_validator.validate(VOCABULARIES_FIELDS, record) ils_record = import_record( record, rectype=rectype, legacy_id=record["legacy_ids"], mint_legacy_pid=False, ) ils_records.append(ils_record) db.session.commit() bulk_index_records(ils_records)
def import_document_requests_from_json(dump_file, rectype="document-request"): """Imports document requests from JSON data files.""" click.echo("Importing document requests ..") with click.progressbar(json.load(dump_file)) as input_data: ils_records = [] for record in input_data: ils_record = import_record(migrate_document_request(record), rectype=rectype, legacy_id=record["legacy_id"], mint_legacy_pid=False) ils_records.append(ils_record) db.session.commit() bulk_index_records(ils_records)
def import_internal_locations_from_json( dump_file, include, rectype="internal_location" ): """Load parent records from file.""" dump_file = dump_file[0] model, provider = model_provider_by_rectype(rectype) library_model, library_provider = model_provider_by_rectype("library") include_ids = None if include is None else include.split(",") ( location_pid_value, _, ) = current_app_ils.get_default_location_pid with click.progressbar(json.load(dump_file)) as bar: records = [] for record in bar: click.echo( 'Importing internal location "{0}({1})"...'.format( record["legacy_ids"], rectype ) ) if include_ids is None or record["legacy_id"] in include_ids: # remove the library type as it is not a part of the data model library_type = record.pop("type", None) if not isinstance(record["legacy_ids"], list): record["legacy_ids"] = [str(record["legacy_ids"])] if library_type == "external": # if the type is external => ILL Library record = import_record( record, library_model, library_provider, legacy_id_key="legacy_ids", ) records.append(record) else: record["location_pid"] = location_pid_value record = import_record( record, model, provider, legacy_id_key="legacy_ids" ) records.append(record) # Index all new internal location and libraries records bulk_index_records(records)
def import_ill_borrowing_requests_from_json(dump_file): """Imports borrowing requests from JSON data files.""" dump_file = dump_file[0] model, provider = model_provider_by_rectype("borrowing-request") click.echo("Importing borrowing requests ..") with click.progressbar(json.load(dump_file)) as input_data: ils_records = [] for record in input_data: ils_record = import_record( clean_record_json(record), model, provider, legacy_id_key="legacy_id", ) ils_records.append(ils_record) db.session.commit() bulk_index_records(ils_records)
def import_document_requests_from_json(dump_file): """Imports document requests from JSON data files.""" dump_file = dump_file[0] click.echo("Importing document requests ..") with click.progressbar(json.load(dump_file)) as input_data: ils_records = [] for record in input_data: model, provider = model_provider_by_rectype("document-request") ils_record = import_record( migrate_document_request(record), model, provider, legacy_id_key="legacy_id", ) ils_records.append(ils_record) db.session.commit() bulk_index_records(ils_records)
def import_internal_locations_from_json(dump_file, include, rectype="internal_location"): """Load parent records from file.""" dump_file = dump_file[0] include_ids = None if include is None else include.split(",") location_pid_value, _ = current_app_ils.get_default_location_pid with click.progressbar(json.load(dump_file)) as bar: records = [] for record in bar: click.echo('Importing internal location "{0}({1})"...'.format( record["legacy_ids"], rectype)) if include_ids is None or record["legacy_ids"] in include_ids: # remove the library type as it is not a part of the data model library_type = record.pop("type", None) if not isinstance(record["legacy_ids"], list): record["legacy_ids"] = [str(record["legacy_ids"])] if library_type == "external": # if the type is external => ILL Library record["type"] = "LIBRARY" vocabulary_validator.validate(VOCABULARIES_FIELDS, record) record = import_record( record, rectype="provider", legacy_id=record["legacy_ids"], mint_legacy_pid=False, ) records.append(record) else: record["location_pid"] = location_pid_value record = import_record( record, rectype="internal_location", legacy_id=record["legacy_ids"], mint_legacy_pid=False, ) records.append(record) # Index all new internal location and libraries records bulk_index_records(records)
def import_vendors_from_json(dump_file): """Imports vendors from JSON data files.""" dump_file = dump_file[0] model, provider = model_provider_by_rectype("vendor") click.echo("Importing vendors ..") with click.progressbar(json.load(dump_file)) as input_data: ils_records = [] for record in input_data: # Legacy_ids in the .json file can be an array of strings or just # an integer, but we only accept an array of strings in the schema if not isinstance(record["legacy_ids"], list): record["legacy_ids"] = [str(record["legacy_ids"])] ils_record = import_record( record, model, provider, legacy_id_key="legacy_id", ) ils_records.append(ils_record) db.session.commit() bulk_index_records(ils_records)
def import_orders_from_json(dump_file, include=None): """Imports orders from JSON data files.""" dump_file = dump_file[0] click.echo("Importing acquisition orders ..") with click.progressbar(json.load(dump_file)) as input_data: ils_records = [] for record in input_data: model, provider = model_provider_by_rectype("acq-order") try: ils_record = import_record( migrate_order(record), model, provider, legacy_id_key="legacy_id", ) ils_records.append(ils_record) except Exception as e: error_logger.error("ORDER: {0} ERROR: {1}".format( record["legacy_id"], str(e))) db.session.rollback() db.session.commit() bulk_index_records(ils_records)