def create_record(cls, dump, rectype): """Create a new record from dump.""" series_cls = current_app_ils.series_record_cls record_uuid = uuid.uuid4() try: with db.session.begin_nested(): provider = SeriesIdProvider.create( object_type="rec", object_uuid=record_uuid, ) timestamp, json_data = dump.revisions[-1] json_data["pid"] = provider.pid.pid_value json_data = clean_created_by_field(json_data) if rectype == "journal": legacy_recid_minter(json_data["legacy_recid"], record_uuid) add_cover_metadata(json_data) series = series_cls.create(json_data, record_uuid) series.model.created = dump.created.replace(tzinfo=None) series.model.updated = timestamp.replace(tzinfo=None) series.commit() db.session.commit() return series except IlsValidationError as e: click.secho("Field: {}".format(e.errors[0].res["field"]), fg="red") click.secho(e.original_exception.message, fg="red") raise e
def create_record(cls, dump): """Create a new record from dump.""" record_uuid = uuid.uuid4() try: # with db.session.begin_nested(): provider = DocumentIdProvider.create( object_type="rec", object_uuid=record_uuid, ) timestamp, json_data = dump.revisions[-1] json_data["pid"] = provider.pid.pid_value json_data = clean_created_by_field(json_data) document = Document.create(json_data, record_uuid) document.model.created = dump.created.replace(tzinfo=None) document.model.updated = timestamp.replace(tzinfo=None) document.commit() db.session.commit() return document except IlsValidationError as e: click.secho("Field: {}".format(e.errors[0].res["field"]), fg="red") click.secho(e.original_exception.message, fg="red") db.session.rollback() raise e
def create_record(cls, dump): """Create a new record from dump.""" document_cls = current_app_ils.document_record_cls record_uuid = uuid.uuid4() timestamp, json_data = dump.revisions[-1] json_data = clean_created_by_field(json_data) add_cover_metadata(json_data) try: with db.session.begin_nested(): # checks if the document with this legacy_recid already exists legacy_recid_minter(json_data["legacy_recid"], record_uuid) provider = DocumentIdProvider.create( object_type="rec", object_uuid=record_uuid, ) json_data["pid"] = provider.pid.pid_value document = document_cls.create(json_data, record_uuid) document.model.created = dump.created.replace(tzinfo=None) document.model.updated = timestamp.replace(tzinfo=None) document.commit() db.session.commit() return document except IlsValidationError as e: click.secho("Field: {}".format(e.errors[0].res["field"]), fg="red") click.secho(e.original_exception.message, fg="red") raise e except PIDAlreadyExists as e: allow_updates = \ current_app.config.get("CDS_ILS_MIGRATION_ALLOW_UPDATES") if not allow_updates: raise e # update document if already exists with legacy_recid document = get_record_by_legacy_recid(document_cls, json_data["legacy_recid"]) document.update(json_data) document.model.updated = timestamp.replace(tzinfo=None) document.commit() db.session.commit() return document
def create_record(cls, dump, rectype): """Create a new record from dump.""" timestamp, json_data = dump.revisions[-1] json_data = clean_created_by_field(json_data) vocabulary_validator.validate(VOCABULARIES_FIELDS, json_data) add_cover_metadata(json_data) is_multivolume_record = json_data["_migration"].get( "multivolume_record", False) if is_multivolume_record: click.echo("Multivolume record.") record = import_multivolume(json_data) else: click.echo("Multipart record.") record = import_multipart(json_data) # wait for the previous multipart to be indexed click.echo("Indexing.") time.sleep(2) return record
def create_record(cls, dump, rectype): """Create a new record from dump.""" try: timestamp, json_data = dump.revisions[-1] json_data = clean_created_by_field(json_data) add_cover_metadata(json_data) is_multivolume_record = json_data["_migration"].get( "multivolume_record", False) if is_multivolume_record: click.echo("Multivolume record.") record = import_multivolume(json_data) else: click.echo("Multipart record.") record = import_multipart(json_data) # wait for the previous multipart to be indexed click.echo("Indexing.") time.sleep(2) return record except IlsValidationError as e: click.secho("Field: {}".format(e.errors[0].res["field"]), fg="red") click.secho(e.original_exception.message, fg="red") raise e
def create_record(cls, dump): """Create a new record from dump.""" document_cls = current_app_ils.document_record_cls record_uuid = uuid.uuid4() timestamp, json_data = dump.revisions[-1] json_data = clean_created_by_field(json_data) vocabulary_validator.validate(VOCABULARIES_FIELDS, json_data) add_cover_metadata(json_data) add_title_from_conference_info(json_data) add_cds_url(json_data) try: with db.session.begin_nested(): # checks if the document with this legacy_recid already exists legacy_pid_type = current_app.config[ "CDS_ILS_RECORD_LEGACY_PID_TYPE" ] # First mint the legacy_recid before assigning the pid. In case # it fails while importing an existing record we will update it # and don't want the new pid, since there is already one there legacy_recid_minter( json_data["legacy_recid"], legacy_pid_type, record_uuid ) provider = DocumentIdProvider.create( object_type="rec", object_uuid=record_uuid, ) # requirement from the library if ( json_data["_migration"]["has_journal"] and json_data["document_type"] != "PROCEEDINGS" ): json_data["document_type"] = "SERIAL_ISSUE" json_data["pid"] = provider.pid.pid_value document = document_cls.create(json_data, record_uuid) created_date = json_data.get( "_created", CDS_ILS_FALLBACK_CREATION_DATE ) document.model.created = parser.parse(created_date) document.model.updated = timestamp.replace(tzinfo=None) document.commit() db.session.commit() documents_logger.info( "CREATED", extra=dict( legacy_id=json_data["legacy_recid"], new_pid=document["pid"], status="SUCCESS", ), ) return document except IlsValidationError as e: click.secho("Field: {}".format(e.errors[0].res["field"]), fg="red") click.secho(e.original_exception.message, fg="red") raise e except PIDAlreadyExists as e: allow_updates = current_app.config.get( "CDS_ILS_MIGRATION_ALLOW_UPDATES" ) if not allow_updates: raise e # update document if already exists with legacy_recid legacy_pid_type = current_app.config[ "CDS_ILS_RECORD_LEGACY_PID_TYPE" ] # When updating we don't want to change the pid if "pid" in json_data: del json_data["pid"] document = get_record_by_legacy_recid( document_cls, legacy_pid_type, json_data["legacy_recid"] ) document.update(json_data) document.model.updated = timestamp.replace(tzinfo=None) document.commit() db.session.commit() documents_logger.info( "UPDATED", extra=dict( legacy_id=json_data["legacy_recid"], new_pid=document["pid"], status="SUCCESS", ), ) return document
def create_record(cls, dump, rectype): """Create a new record from dump.""" records_logger = logging.getLogger(f"{rectype}s_logger") series_cls = current_app_ils.series_record_cls record_uuid = uuid.uuid4() try: with db.session.begin_nested(): timestamp, json_data = dump.revisions[-1] if rectype == 'serial'\ and serial_already_exists(json_data["title"]): return json_data = clean_created_by_field(json_data) vocabulary_validator.validate(VOCABULARIES_FIELDS, json_data) provider = SeriesIdProvider.create( object_type="rec", object_uuid=record_uuid, ) add_cds_url(json_data) json_data["pid"] = provider.pid.pid_value if rectype == "journal": legacy_pid_type = current_app.config[ "CDS_ILS_SERIES_LEGACY_PID_TYPE"] legacy_recid_minter(json_data["legacy_recid"], legacy_pid_type, record_uuid) add_cover_metadata(json_data) series = series_cls.create(json_data, record_uuid) created_date = json_data.get("_created", CDS_ILS_FALLBACK_CREATION_DATE) series.model.created = parser.parse(created_date) series.model.updated = timestamp.replace(tzinfo=None) series.commit() db.session.commit() records_logger.info( "CREATED", extra=dict( new_pid=series["pid"], status="SUCCESS", legacy_id=json_data["legacy_recid"], ), ) return series except PIDAlreadyExists as e: allow_updates = current_app.config.get( "CDS_ILS_MIGRATION_ALLOW_UPDATES") if not allow_updates: raise e # update document if already exists with legacy_recid legacy_pid_type = current_app.config[ "CDS_ILS_SERIES_LEGACY_PID_TYPE"] # When updating we don't want to change the pid if "pid" in json_data: del json_data["pid"] series = get_record_by_legacy_recid(series_cls, legacy_pid_type, json_data["legacy_recid"]) series.update(json_data) series.model.updated = timestamp.replace(tzinfo=None) series.commit() db.session.commit() records_logger.info( "UPDATED", extra=dict( legacy_id=json_data["legacy_recid"], new_pid=series["pid"], status="SUCCESS", ), ) return series