Skip to content

Commit

Permalink
Merge 9bb6f19 into 454eed8
Browse files Browse the repository at this point in the history
  • Loading branch information
tmorrell committed Oct 21, 2020
2 parents 454eed8 + 9bb6f19 commit 6b3c3a4
Show file tree
Hide file tree
Showing 35 changed files with 1,960 additions and 1,529 deletions.
14 changes: 14 additions & 0 deletions CHANGES.rst
@@ -1,5 +1,19 @@
Changes
=======
Version v1.1.0 (TBD):

- Adds full support for DataCite Metadata Schema v4.2 XML generation.
- Uses Official DataCite JSON Schema, which has the following notable changes
from the previous schema:

- Uses "identifiers" which is a combination of the XML "identifier" and
"alternativeIdentifiers" elements
- "creatorName" is now "name"
- "contributorName" is now "name"
- "affiliations" is now "affiliation" (is still an array)
- There is no longer a funder identifier object (the identifier and type are just
elements)

Version v1.0.1 (released 2018-03-08):

- Fixes schema location url for DataCite v4.1
Expand Down
1 change: 0 additions & 1 deletion datacite/jsonutils.py
Expand Up @@ -11,7 +11,6 @@
"""JSON utilities."""

import json

from jsonschema import RefResolver, validate
from jsonschema.validators import validator_for

Expand Down
2 changes: 0 additions & 2 deletions datacite/schema41.py
Expand Up @@ -10,8 +10,6 @@

"""DataCite v4.1 JSON to XML transformations."""

from __future__ import absolute_import, print_function

import pkg_resources
from lxml import etree
from lxml.builder import E
Expand Down
61 changes: 35 additions & 26 deletions datacite/schema42.py
Expand Up @@ -11,8 +11,6 @@

"""DataCite v4.2 JSON to XML transformations."""

from __future__ import absolute_import, print_function

import pkg_resources
from lxml import etree
from lxml.builder import E
Expand Down Expand Up @@ -56,13 +54,39 @@ def validate(data):
return validator.is_valid(data)


@rules.rule('identifier')
def identifier(path, value):
"""Transform identifier."""
return E.identifier(
value['identifier'],
identifierType=value['identifierType']
)
@rules.rule('identifiers')
def identifiers(path, values):
"""Transform identifiers to alternateIdentifiers and identifier."""
"""
We assume there will only be 1 DOI identifier for the record.
Any other identifiers are alternative identifiers.
"""
alt = ''
doi = ''
for value in values:
if value['identifierType'] == 'DOI':
if doi != '':
# Don't know what to do with two DOIs
# Which is the actual identifier?
raise TypeError
doi = E.identifier(
value['identifier'],
identifierType='DOI'
)
else:
if alt == '':
alt = E.alternateIdentifiers()
elem = E.alternateIdentifier(value['identifier'])
elem.set('alternateIdentifierType', value['identifierType'])
alt.append(elem)
if alt == '':
# If we only have the DOI
return doi
elif doi == '':
# If we only have alt IDs
return alt
else:
return doi, alt


def affiliations(root, values):
Expand All @@ -87,7 +111,7 @@ def givenname(root, value):
root.append(E.givenName(val))


def person_or_org_name(root, value, xml_tagname,json_tagname):
def person_or_org_name(root, value, xml_tagname, json_tagname):
"""Extract creator/contributor name and it's 'nameType' attribute."""
elem = E(xml_tagname, value[json_tagname])
set_elem_attr(elem, 'nameType', value)
Expand Down Expand Up @@ -231,21 +255,6 @@ def resource_type(path, value):
return elem


@rules.rule('alternateIdentifiers')
def alternate_identifiers(path, values):
"""Transform alternateIdenftifiers."""
if not values:
return

root = E.alternateIdentifiers()
for value in values:
elem = E.alternateIdentifier(value['alternateIdentifier'])
elem.set('alternateIdentifierType', value['alternateIdentifierType'])
root.append(elem)

return root


@rules.rule('relatedIdentifiers')
def related_identifiers(path, values):
"""Transform relatedIdentifiers."""
Expand Down Expand Up @@ -306,7 +315,7 @@ def rights(path, values):
for value in values:
if 'rights' in value:
elem = E.rights(value['rights'])
#Handle the odd case where no rights text present
# Handle the odd case where no rights text present
else:
elem = E.rights()
set_elem_attr(elem, 'rightsURI', value)
Expand Down

0 comments on commit 6b3c3a4

Please sign in to comment.