def link_signature_to_author(signature_data, author_control_number): """Adds record/$ref of the given author to the given signature. Args: author_control_number (int): The control number of the author to which we want to link. signature_data (list): List containing 2 elements: the publication_id and the signature uuid. Returns: dict: The signature data from the publication with the linked author. """ record = LiteratureRecord.get_record_by_pid_value( signature_data["publication_id"]) signature = next( (author for author in record.get("authors") if author.get("uuid") == signature_data["signature_uuid"]), None, ) if not signature or ("record" in signature and signature.get("curated_relation")): return None if signature.get("curated_relation") and "record" not in signature: signature["curated_relation"] = False new_author_record = get_record_ref(author_control_number, "authors") if new_author_record == signature.get("record"): # no changes, avoid creating a new useless version of the record return None signature["record"] = new_author_record record.update(dict(record)) return signature
def build_seminar(self, data) -> dict: builder = SeminarBuilder() builder.set_title(title=data.get("name")) builder.add_inspire_categories(data.get("field_of_interest", [])) builder.add_public_note(value=data.get("additional_info", "")) builder.add_series( name=data.get("series_name"), number=data.get("series_number") ) timezone = data.get("timezone") builder.set_timezone(timezone) start_datetime = get_value(data, "dates[0]") start_datetime_utc = local_form_datetime_to_iso_utc(start_datetime, timezone) builder.set_start_datetime(start_datetime_utc) end_datetime = get_value(data, "dates[1]") end_datetime_utc = local_form_datetime_to_iso_utc(end_datetime, timezone) builder.set_end_datetime(end_datetime_utc) address = data.get("address") if address: builder.set_address( cities=[address.get("city")], state=address.get("state"), place_name=address.get("venue"), country_code=country_name_to_code(address.get("country")), ) abstract = data.get("abstract") if abstract: builder.set_abstract(value=abstract) captioned = data.get("captioned") if captioned: builder.set_captioned(captioned) for contact in data.get("contacts", []): builder.add_contact(**contact) for speaker in data.get("speakers", []): name = speaker.get("name") record = speaker.get("record") affiliation_value = speaker.get("affiliation") affiliation_record = speaker.get("affiliation_record") affiliation = {} if affiliation_value: affiliation["value"] = affiliation_value if affiliation_record: affiliation["record"] = affiliation_record affiliations = [affiliation] if affiliation else None builder.add_speaker(name=name, record=record, affiliations=affiliations) for url in data.get("material_urls", []): builder.add_material_url(**url) for url in data.get("join_urls", []): builder.add_join_url(**url) for website in data.get("websites", []): builder.add_url(website) for keyword in data.get("keywords", []): builder.add_keyword(value=keyword) for literature_record_pid in data.get("literature_records", []): try: LiteratureRecord.get_record_by_pid_value(literature_record_pid) except PIDDoesNotExistError: raise InvalidDataError( f"{literature_record_pid} is not a valid literature record." ) record = { "$ref": f"{get_inspirehep_url()}/api/literature/{literature_record_pid}" } builder.add_literature_record(record=record) builder.record["$schema"] = url_for( "invenio_jsonschemas.get_schema", schema_path="records/seminars.json", _external=True, ) return builder.record