Esempio n. 1
0
def create_doi(metadata, url):

    password = os.environ['DATACITE']
    prefix = '10.33569'

    # Initialize the MDS client.
    d = DataCiteMDSClient(username='******',
                          password=password,
                          prefix=prefix,
                          url='https://mds.test.datacite.org'
                          #test_mode=True
                          )

    result = schema40.validate(metadata)
    #Debugging if this fails
    if result == False:
        v = schema40.validator.validate(metadata)
        errors = sorted(v.iter_errors(instance), key=lambda e: e.path)
        for error in errors:
            print(error.message)
        exit()

    #Provide only prefix in identifier field to let DataCite generate DOI
    metadata['identifier'] = {'identifier': prefix, 'identifierType': 'DOI'}

    xml = schema40.tostring(metadata)

    response = d.metadata_post(xml)
    print(response)
    identifier = response.split('(')[1].split(')')[0]
    response = d.doi_post(identifier, url)
    print(response)
Esempio n. 2
0
def update(recid):
    """Update metadata for record with given recid in DataCite."""
    uuid = PersistentIdentifier.get('recid', recid).object_uuid
    record = Record.get_record(uuid)
    doi = record['doi']

    try:
        provider = DataCiteProviderWrapper.get(pid_value=doi,
                                               pid_type='doi')
    except PIDDoesNotExistError:
        raise ClickException('Record with DOI {} not registered in DataCite.'
                             .format(doi))

    # serialize record to schema40
    doc = DataCiteSerializer().dump(record).data
    schema40.validate(doc)
    doc = schema40.tostring(doc)
    landing_page = os.path.join(
        current_app.config.get('PIDSTORE_LANDING_BASE_URL'),
        recid)

    provider.update(url=landing_page,
                    doc=doc)
    db.session.commit()

    click.echo('Record with DOI {} updated in DataCite'.format(doi))
Esempio n. 3
0
def register(recid):
    """Register record with given recid in DataCite."""
    uuid = PersistentIdentifier.get('recid', recid).object_uuid
    record = Record.get_record(uuid)
    experiment = record.get('experiment', None)
    doi = record['doi']

    try:
        provider = DataCiteProviderWrapper.get(pid_value=doi,
                                               pid_type='doi')
    except PIDDoesNotExistError:
        provider = DataCiteProviderWrapper.create(pid_value=doi,
                                                  experiment=experiment)

    # serialize record to schema40
    doc = DataCiteSerializer().dump(record).data
    schema40.validate(doc)
    doc = schema40.tostring(doc)
    landing_page = os.path.join(
        current_app.config.get('PIDSTORE_LANDING_BASE_URL'),
        recid)

    provider.register(url=landing_page,
                      doc=doc)
    db.session.commit()

    click.echo('Record registered with DOI {}'.format(doi))
Esempio n. 4
0
def register(uuid):
    """Register record with given uuid in DataCite."""
    record = Record.get_record(uuid)
    experiment = record.get('experiment', None)
    doi = record['doi']

    try:
        provider = DataCiteProviderWrapper.get(pid_value=doi,
                                               pid_type='doi')
    except PIDDoesNotExistError:
        provider = DataCiteProviderWrapper.create(pid_value=doi,
                                                  experiment=experiment)

    # serialize record to schema40
    doc = DataCiteSerializer().dump(record).data
    schema40.validate(doc)
    doc = schema40.tostring(doc)
    landing_page = '{}/{}'.format(
        current_app.config.get('PIDSTORE_LANDING_BASE_URL'),
        doi)
    provider.register(url=landing_page,
                      doc=doc)
    db.session.commit()

    click.echo('Record registered with DOI {}'.format(doi))
Esempio n. 5
0
def test_minimal_xsd(xsd40):
    """Test that example XML converts to example JSON."""
    xsd40.assertValid(
        etree.XML(
            tostring({
                'identifier': {
                    'identifierType': 'DOI',
                    'identifier': '10.1234/foo.bar',
                },
                'creators': [{
                    'creatorName': 'Nielsen, Lars Holm',
                }, {
                    'creatorName': 'Nielsen, Lars Holm',
                    'nameIdentifier': {
                        'nameIdentifier': '1234',
                        'schemeURI': 'http://orcid.org',
                        'nameIdentifierScheme': 'ORCID',
                    }
                }],
                'titles': [{
                    'title': 'Minimal Test Case',
                }],
                'publisher':
                'Invenio Software',
                'publicationYear':
                '2016',
                'resourceType': {
                    'resourceTypeGeneral': 'Dataset'
                }
            }).encode('utf8')))
def update_record(idv, username, password, datacite_password):
    url = 'https://' + username + ':' + password + '@authors.library.caltech.edu/rest/eprint/'
    record_url = url + str(idv) + '.xml'
    record = subprocess.check_output(["eputil", record_url],
                                     universal_newlines=True)
    eprint = xmltodict.parse(record)['eprints']['eprint']
    metadata = caltech_thesis.epxml_to_datacite(eprint)

    assert schema40.validate(metadata)
    #Debugging if this fails
    #v = schema40.validator.validate(metadata)
    #errors = sorted(v.iter_errors(instance), key=lambda e: e.path)
    #for error in errors:
    #        print(error.message)

    # Initialize the MDS client.
    d = DataCiteMDSClient(
        username='******',
        password=datacite_password,
        prefix='10.7907',
    )

    xml = schema40.tostring(metadata)
    result = d.metadata_post(xml)
    print(result)
Esempio n. 7
0
def update_doi(doi,metadata,url=''):

    password = os.environ['DATACITE']
    prefix = doi.split('/')[0]
    #Ensure metadata identifier matches that given in function
    metadata['identifier'] = {'identifier':doi,'identifierType':'DOI'}

    # Initialize the MDS client.
    d = DataCiteMDSClient(
        username='******',
        password=password,
        prefix=prefix,
        url='https://mds.datacite.org'
        #test_mode=True
        )

    result =  schema40.validate(metadata)
    #Debugging if this fails
    if result == False:
        v = schema40.validator.validate(metadata)
        errors = sorted(v.iter_errors(instance), key=lambda e: e.path)
        for error in errors:
            print(error.message)
        exit()

    xml = schema40.tostring(metadata)

    response = d.metadata_post(xml)
    print(response)
    if url != '':
        response = d.doi_post(doi,url)
        print(response)
Esempio n. 8
0
def update_datacite_metadata(collection, token, access):
    """Access contains username, password, and prefix for DataCite"""
    keys = dataset.keys(collection)
    for a in access:

        username = a["username"]
        password = a["password"]
        prefix = a["prefix"]

        # Initialize the MDS client.
        d = DataCiteMDSClient(
            username=username,
            password=password,
            prefix=prefix,
            url="https://mds.datacite.org",
        )

        for k in keys:
            print(k)
            metadata, err = dataset.read(collection, k)
            if err != "":
                print(err)
                exit()
            # Get rid of Key from dataset
            metadata.pop("_Key")

            if "identifier" in metadata:
                record_doi = metadata["identifier"]["identifier"]

                # Handle records with 4.3 metadata elements
                if "schemaVersion" in metadata:
                    metadata.pop("schemaVersion")
                if "types" in metadata:
                    metadata.pop("types")

                if record_doi.split("/")[0] == prefix:
                    result = schema40.validate(metadata)
                    # Debugging if this fails
                    if result == False:
                        print(metadata)
                        v = schema40.validator.validate(metadata)
                        errors = sorted(v.iter_errors(instance),
                                        key=lambda e: e.path)
                        for error in errors:
                            print(error.message)
                        exit()

                    xml = schema40.tostring(metadata)

                    response = d.metadata_post(xml)
                    print(response)
    def build_metadata(self, node):
        """Return the formatted datacite metadata XML as a string.
         """

        data = {
            'identifier': {
                'identifier': self.build_doi(node),
                'identifierType': 'DOI',
            },
            'creators': [{
                'creatorName': user.fullname,
                'givenName': user.given_name,
                'familyName': user.family_name
            } for user in node.visible_contributors],
            'titles': [{
                'title': node.title
            }],
            'publisher':
            'Open Science Framework',
            'publicationYear':
            str(datetime.datetime.now().year),
            'resourceType': {
                'resourceType': 'Project',
                'resourceTypeGeneral': 'Text'
            }
        }

        if node.description:
            data['descriptions'] = [{
                'descriptionType': 'Abstract',
                'description': node.description
            }]

        if node.node_license:
            data['rightsList'] = [{
                'rights': node.node_license.name,
                'rightsURI': node.node_license.url
            }]

        # Validate dictionary
        assert schema40.validate(data)

        # Generate DataCite XML from dictionary.
        return schema40.tostring(data)
Esempio n. 10
0
    def build_metadata(self, node):
        """Return the formatted datacite metadata XML as a string.
         """

        data = {
            'identifier': {
                'identifier': self.build_doi(node),
                'identifierType': 'DOI',
            },
            'creators': [
                {'creatorName': user.fullname,
                 'givenName': user.given_name,
                 'familyName': user.family_name} for user in node.visible_contributors
            ],
            'titles': [
                {'title': node.title}
            ],
            'publisher': 'Open Science Framework',
            'publicationYear': str(datetime.datetime.now().year),
            'resourceType': {
                'resourceType': 'Project',
                'resourceTypeGeneral': 'Text'
            }
        }

        if node.description:
            data['descriptions'] = [{
                'descriptionType': 'Abstract',
                'description': node.description
            }]

        if node.node_license:
            data['rightsList'] = [{
                'rights': node.node_license.name,
                'rightsURI': node.node_license.url
            }]

        # Validate dictionary
        assert schema40.validate(data)

        # Generate DataCite XML from dictionary.
        return schema40.tostring(data)
 def serialize_xml(cls, record):
     data = json.loads(cls.serialize_json(record))
     return schema40.tostring(data)
Esempio n. 12
0
def test_json_to_xml(example_xml_file40, example_json40, xsd40):
    """Test that example XML converts to example JSON."""
    xsd40.assertValid(etree.XML(example_xml_file40.encode('utf8')))
    xsd40.assertValid(etree.XML(tostring(example_json40).encode('utf8')))
    files = glob.glob("*.xml")
    for f in files:
        if "datacite" not in f:

            print(f)

            with open(f, encoding="utf8") as fd:
                eprint = xmltodict.parse(fd.read())["eprints"]["eprint"]
            print(eprint["title"])

            metadata = epxml_to_datacite(eprint)

            # Validation fails on Windows
            valid = schema40.validate(metadata)
            # Debugging if this fails
            if valid == False:
                v = schema40.validator.validate(metadata)
                errors = sorted(v.iter_errors(instance), key=lambda e: e.path)
                for error in errors:
                    print(error.message)

            xml = schema40.tostring(metadata)

            outname = f.split(".xml")[0] + "_datacite.xml"
            outfile = open(outname, "w", encoding="utf8")
            outfile.write(xml)

            outname = f.split(".xml")[0] + "_datacite.json"
            outfile = open(outname, "w", encoding="utf8")
            json.dump(metadata, outfile)
Esempio n. 14
0
 def serialize_xml(cls, record):
     data = json.loads(cls.serialize_json(record))
     return schema40.tostring(data)
Esempio n. 15
0
    }],
    'titles': [{
        'title': 'DataCite PyPI Package'
    }],
    'publisher': 'CERN',
    'publicationYear': '2015',
    'resourceType': {
        'resourceTypeGeneral': 'Dataset'
    }
}

# Validate dictionary
assert schema40.validate(data)

# Generate DataCite XML from dictionary.
doc = schema40.tostring(data)

# Initialize the MDS client.
d = DataCiteMDSClient(username='******',
                      password='******',
                      prefix='10.5072',
                      test_mode=True)

# Set metadata for DOI
d.metadata_post(doc)

# Mint new DOI
d.doi_post('10.5072/test-doi', 'http://example.org/test-doi')

# Get DOI location
location = d.doi_get("10.5072/test-doi")
Esempio n. 16
0
    def build_metadata(self, node):
        """Return the formatted datacite metadata XML as a string.
         """

        data = {
            'identifier': {
                'identifier': self.build_doi(node),
                'identifierType': 'DOI',
            },
            'creators':
            datacite_format_creators([node.creator]),
            'contributors':
            datacite_format_contributors(node.visible_contributors),
            'titles': [{
                'title': node.title
            }],
            'publisher':
            'Open Science Framework',
            'publicationYear':
            str(datetime.datetime.now().year),
            'resourceType': {
                'resourceType':
                'Pre-registration'
                if node.type == 'osf.registration' else 'Project',
                'resourceTypeGeneral':
                'Text'
            },
            'dates': [
                {
                    'date': node.created.isoformat(),
                    'dateType': 'Created'
                },
                {
                    'date': node.modified.isoformat(),
                    'dateType': 'Updated'
                },
            ]
        }

        article_doi = node.article_doi
        if article_doi:
            data['relatedIdentifiers'] = [{
                'relatedIdentifier': article_doi,
                'relatedIdentifierType': 'DOI',
                'relationType': 'IsSupplementTo'
            }]

        if node.description:
            data['descriptions'] = [{
                'descriptionType': 'Abstract',
                'description': node.description
            }]

        if node.node_license:
            data['rightsList'] = [{
                'rights': node.node_license.name,
                'rightsURI': node.node_license.url
            }]

        data['subjects'] = datacite_format_subjects(node)

        # Validate dictionary
        assert schema40.validate(data)

        # Generate DataCite XML from dictionary.
        return schema40.tostring(data)