def test_datacite43_identifiers(running_app, minimal_record):
    """Test serialization of records with DOI alternate identifiers"""
    # Mimic user putting DOI in alternate identifier field
    minimal_record["metadata"]["identifiers"] = [{
        "identifier": "10.5281/inveniordm.1234",
        "scheme": "doi"
    }]

    serializer = DataCite43JSONSerializer()
    serialized_record = serializer.dump_one(minimal_record)

    assert 'identifiers' not in serialized_record

    minimal_record["pids"] = {
        "doi": {
            "identifier": "10.5281/inveniordm.1234",
            "provider": "datacite",
            "client": "inveniordm"
        },
    }

    serialized_record = serializer.dump_one(minimal_record)
    assert len(serialized_record['identifiers']) == 1
    identifier = serialized_record['identifiers'][0]['identifier']
    assert identifier == "10.5281/inveniordm.1234"
Ejemplo n.º 2
0
    def update(self, pid, record, url, **kwargs):
        """Update metadata associated with a DOI.

        This can be called before/after a DOI is registered.
        :param pid: the PID to register.
        :param record: the record metadata for the DOI.
        :returns: `True` if is updated successfully.
        """
        # PIDS-FIXME: Do we want to log when reactivate the DOI
        # if pid.is_deleted():
        if self.is_api_client_setup:
            try:
                # PIDS-FIXME: move to async task, exception handling included
                # Set metadata
                doc = DataCite43JSONSerializer().dump_one(record)
                self.api_client.update_doi(metadata=doc,
                                           doi=pid.pid_value,
                                           url=url)
            except DataCiteError as e:
                current_app.logger.warning("DataCite provider error when "
                                           f"updating DOI for {pid.pid_value}")
                self._log_errors(e)

                return False
        else:
            current_app.logger.warning("DataCite client not configured. Cannot"
                                       f" update DOI for {pid.pid_value}")

        if pid.is_deleted():
            return pid.sync_status(PIDStatus.REGISTERED)

        return True
Ejemplo n.º 3
0
    def register(self, pid, record, **kwargs):
        """Register a DOI via the DataCite API.

        :param pid: the PID to register.
        :param record: the record metadata for the DOI.
        :returns: `True` if is registered successfully.
        """
        local_success = super().register(pid, record)
        if not local_success:
            return False

        if self.is_api_client_setup:
            # PIDS-FIXME: move to async task, exception handling included
            try:
                doc = DataCite43JSONSerializer().dump_one(record)
                url = kwargs["url"]
                self.api_client.public_doi(metadata=doc,
                                           url=url,
                                           doi=pid.pid_value)
            except DataCiteError as e:
                current_app.logger.warning("DataCite provider error when "
                                           f"updating DOI for {pid.pid_value}")
                self._log_errors(e)

                return False
        else:
            current_app.logger.warning("DataCite client not configured. Cannot"
                                       f" register DOI for {pid.pid_value}")

        return True
Ejemplo n.º 4
0
 def __init__(self,
              id_,
              client=None,
              serializer=None,
              pid_type="doi",
              default_status=PIDStatus.NEW,
              **kwargs):
     """Constructor."""
     super().__init__(
         id_,
         client=(client
                 or DataCiteClient("datacite", config_prefix="DATACITE")),
         pid_type=pid_type,
         default_status=default_status)
     self.serializer = serializer or DataCite43JSONSerializer()
def test_datacite43_serializer_with_unknown_id_schemes(running_app,
                                                       full_modified_record):
    """Test if the DataCite 4.3 JSON serializer can handle unknown schemes."""
    # this test is there to ensure that there are no KeyErrors during the
    # lookup of unknown PID schemes during DataCite 4.3 serialization
    # if the behaviour of the datacite serializer is changed, the asserts
    # below should probably be adjusted accordingly

    expected_pid_id = {
        "identifier": "unknown-1234",
        "identifierType": "unknown-scheme",
    }
    expected_pid_id_2 = {
        "identifier": "unknown-1234-a",
        "identifierType": "unknown-scheme",
    }
    expected_related_id = {
        "relatedIdentifier": "unknown-1234-b",
        "relatedIdentifierType": "unknown-scheme",
        "relationType": "IsCitedBy",
    }
    expected_creator_id = {
        "nameIdentifier": "unknown-2345",
        "nameIdentifierScheme": "unknown-scheme"
    }

    serializer = DataCite43JSONSerializer()
    serialized_record = serializer.dump_one(full_modified_record)

    assert expected_pid_id in serialized_record["identifiers"]
    assert expected_pid_id_2 in serialized_record["identifiers"]
    assert len(serialized_record["identifiers"]) == 3

    assert expected_related_id in serialized_record["relatedIdentifiers"]
    assert len(serialized_record["relatedIdentifiers"]) == 1

    creator_ids = serialized_record["creators"][0]["nameIdentifiers"]
    assert expected_creator_id in creator_ids
    assert len(creator_ids) == 1
def test_datacite43_serializer(running_app, full_record, vocabulary_clear):
    """Test serializer to DataCite 4.3 JSON"""
    expected_data = {
        "types": {
            "resourceTypeGeneral": "Image",
            "resourceType": "Photo"
        },
        "creators": [{
            "name":
            "Nielsen, Lars Holm",
            "nameType":
            "Personal",
            "givenName":
            "Lars Holm",
            "familyName":
            "Nielsen",
            "nameIdentifiers": [{
                "nameIdentifier": "http://orcid.org/0000-0001-8135-3489",
                "nameIdentifierScheme": "ORCID",
                'schemeURI': 'http://orcid.org/'
            }],
            "affiliations": [{
                "name": "CERN",
                "affiliationIdentifier": "https://ror.org/01ggx4157",
                "affiliationIdentifierScheme": "ROR",
            }, {
                'name': 'free-text'
            }],
        }],
        "titles": [
            {
                "title": "InvenioRDM"
            },
            {
                "title": "a research data management platform",
                "titleType": "Subtitle",
                "lang": "eng",
            },
        ],
        "publisher":
        "InvenioRDM",
        "publicationYear":
        "2018",
        "subjects": [{
            "subject": "Abdominal Injuries",
            "subjectScheme": "MeSH",
        }],
        "contributors": [{
            "name":
            "Nielsen, Lars Holm",
            "nameType":
            "Personal",
            "contributorType":
            "Other",
            "givenName":
            "Lars Holm",
            "familyName":
            "Nielsen",
            "nameIdentifiers": [{
                "nameIdentifier": "http://orcid.org/0000-0001-8135-3489",
                "nameIdentifierScheme": "ORCID",
                'schemeURI': 'http://orcid.org/'
            }],
            "affiliations": [{
                "name": "CERN",
                "affiliationIdentifier": "https://ror.org/01ggx4157",
                "affiliationIdentifierScheme": "ROR",
            }],
        }],
        "dates": [
            {
                "date": "2018/2020-09",
                "dateType": "Issued"
            },
            {
                "date": "1939/1945",
                "dateType": "Other",
                "dateInformation": "A date"
            },
        ],
        "language":
        "dan",
        "identifiers": [
            {
                "identifier": "1924MNRAS..84..308E",
                "identifierType": "bibcode"
            },
            {
                "identifier": "10.5281/inveniordm.1234",
                "identifierType": "DOI"
            },
        ],
        "relatedIdentifiers": [{
            "relatedIdentifier": "10.1234/foo.bar",
            "relatedIdentifierType": "DOI",
            "relationType": "Cites",
            "resourceTypeGeneral": "Dataset",
        }],
        "sizes": ["11 pages"],
        "formats": ["application/pdf"],
        "version":
        "v1.0",
        "rightsList": [{
            "rights":
            "Creative Commons Attribution 4.0 International",
            "rightsIdentifierScheme":
            "spdx",
            "rightsIdentifier":
            "cc-by-4.0",
            "rightsUri":
            "https://creativecommons.org/licenses/by/4.0/",
        }],
        "descriptions": [
            {
                "description": "Test",
                "descriptionType": "Abstract"
            },
            {
                "description": "Bla bla bla",
                "descriptionType": "Methods",
                "lang": "eng"
            },
        ],
        "geoLocations": [{
            "geoLocationPoint": {
                'pointLatitude': -32.94682,
                'pointLongitude': -60.63932
            },
            "geoLocationPlace": "test location place",
        }],
        "fundingReferences": [{
            "funderName": "European Commission",
            "funderIdentifier": "1234",
            "funderIdentifierType": "ROR",
            "awardTitle": "OpenAIRE",
            "awardNumber": "246686",
            "awardURI": ".../246686",
        }],
        "schemaVersion":
        "http://datacite.org/schema/kernel-4",
    }

    serializer = DataCite43JSONSerializer()
    serialized_record = serializer.dump_one(full_record)

    assert serialized_record == expected_data