예제 #1
0
파일: base.py 프로젝트: MJedr/inspirehep
    def _get_linked_pids_from_field(cls, data, path):
        """Return a list of (pid_type, pid_value) tuples for all records referenced
        in the field at the given path

        Args:
            data (dict): data from which records should be extracted
            path (str): the path of the linked records (where $ref is located).
        Returns:
            list: tuples containing (pid_type, pid_value) of the linked records

        Examples:
            >>> data = {
                'references': [
                    {
                        'record': {
                            '$ref': 'http://localhost/literature/1'
                        }
                    }
                ]
            }
            >>>  record = InspireRecord(data)
            >>>  records = record.get_linked_pids_from_field("references.record")
            ('lit', 1)
        """
        full_path = ".".join([path, "$ref"])
        pids = [
            PidStoreBase.get_pid_from_record_uri(rec)
            for rec in flatten_list(get_value(data, full_path, []))
        ]
        return pids
예제 #2
0
def update_references_pointing_to_merged_record(refs_to_schema,
                                                merged_record_uri,
                                                new_record_uri):
    for index, path in refs_to_schema:
        query = get_query_for_given_path(index, path, merged_record_uri)
        es_index_name = f"records-{index}"
        matched_records = InspireSearch(
            index=es_index_name).query(query).scan()
        for matched_record in matched_records:
            pid_type = current_app.config["SCHEMA_TO_PID_TYPES"][index]
            record_class = InspireRecord.get_subclasses()[pid_type]
            matched_inspire_record_data = (
                db.session.query(RecordMetadata).with_for_update().filter_by(
                    id=matched_record.meta.id).first())
            matched_inspire_record = record_class(
                matched_inspire_record_data.json,
                model=matched_inspire_record_data)
            referenced_records_in_path = flatten_list(
                get_value(matched_inspire_record, path[:-len(".$ref")], []))
            for referenced_record in referenced_records_in_path:
                update_reference_if_reference_uri_matches(
                    referenced_record, merged_record_uri, new_record_uri)
            matched_inspire_record.update(dict(matched_inspire_record))
            LOGGER.info("Updated reference for record",
                        uuid=str(matched_inspire_record.id))
    db.session.commit()
예제 #3
0
def update_references_pointing_to_merged_record(refs_to_schema,
                                                merged_record_uri,
                                                new_record_uri):
    for index, path in refs_to_schema:
        config = get_config_for_given_path(index, path)
        matched_records = match({"$ref": merged_record_uri}, config)
        for matched_record in matched_records:
            matched_inspire_record = InspireRecord.get_record(
                matched_record["_id"], with_deleted=True)
            referenced_records_in_path = flatten_list(
                get_value(matched_inspire_record, path[:-len(".$ref")], []))
            for referenced_record in referenced_records_in_path:
                update_reference_if_reference_uri_matches(
                    referenced_record, merged_record_uri, new_record_uri)
            matched_inspire_record.update(dict(matched_inspire_record))
            LOGGER.info("Updated reference for record",
                        uuid=str(matched_inspire_record.id))
    db.session.commit()
예제 #4
0
 def check(record, logger, state):
     state["quant-ph"] = False
     state["cond-mat"] = False
     for cat in flatten_list(record.get_value("arxiv_eprints.categories", [])):
         if cat.startswith("cond-mat"):
             state["cond-mat"] = True
             continue
         if cat == "quant-ph":
             state["quant-ph"] = True
             continue
     for cat in record.get_value("inspire_categories.term", []):
         if cat == "Quantum Physics":
             state["quant-ph"] = False
             continue
         if cat == "Condensed Matter":
             state["cond-mat"] = False
             continue
     if state["quant-ph"] or state["cond-mat"]:
         return True
예제 #5
0
def test_bai_minter_many_pids(inspire_app):
    data = {
        "ids": [
            {
                "schema": "INSPIRE BAI",
                "value": "K.Janeway.1"
            },
            {
                "schema": "INSPIRE BAI",
                "value": "K.Janeway.2"
            },
        ]
    }
    expected_bais = ["K.Janeway.1", "K.Janeway.2"]
    rec = create_record("aut", data=data)
    bais = flatten_list(
        PersistentIdentifier.query.with_entities(
            PersistentIdentifier.pid_value).filter_by(
                pid_type="bai",
                status=PIDStatus.REGISTERED,
                object_uuid=rec.id).all())
    assert sorted(bais) == sorted(expected_bais)
예제 #6
0
 def get_authors_bais(self):
     return get_values_for_schema(
         flatten_list(self.get_value("authors.ids", [])), "INSPIRE BAI")