Skip to content

Commit

Permalink
datamodel: use dict for identifiers field
Browse files Browse the repository at this point in the history
  • Loading branch information
fenekku committed Mar 16, 2020
1 parent f113b09 commit f799282
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 118 deletions.
25 changes: 10 additions & 15 deletions invenio_rdm_records/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@ def create_fake_record():
"type": "image",
"subtype": "photo"
},
"identifiers": [{
"identifier": "10.9999/rdm.9999999",
"scheme": "DOI"
}, {
"identifier": "9999.99999",
"scheme": "arXiv"
}],
"identifiers": {
"DOI": "10.9999/rdm.9999999",
"arXiv": "9999.99999",
},
"creators": [{
"name": fake.name(),
"type": "Personal",
"identifiers": [{
"identifier": "9999-9999-9999-9999",
"scheme": "Orcid"
}],
"identifiers": {
"Orcid": "9999-9999-9999-9999",
},
"affiliations": [{
"name": fake.company(),
"identifier": "entity-one",
Expand All @@ -81,10 +77,9 @@ def create_fake_record():
"contributors": [{
"name": fake.name(),
"type": "Personal",
"identifiers": [{
"identifier": "9999-9999-9999-9998",
"scheme": "Orcid"
}],
"identifiers": {
"Orcid": "9999-9999-9999-9998",
},
"affiliations": [{
"name": fake.company(),
"identifier": "entity-one",
Expand Down
34 changes: 27 additions & 7 deletions invenio_rdm_records/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,32 @@ class CommunitySchemaV1(BaseSchema):
secondary = fields.List(SanitizedUnicode())


class IdentifierSchemaV1(BaseSchema):
"""Extra/Alternate identifiers of the record."""
# 'Fake' Identifiers Field
def _not_blank(error_msg):
"""Returns a non-blank validation rule with custom error message."""
return validate.Length(min=1, error=error_msg)

identifier = SanitizedUnicode(required=True)
scheme = SanitizedUnicode(required=True)

def Identifiers():
"""Returns a "fake" Identifiers field.
Field expects:
"<scheme1>": "<identifier1>",
...
"<schemeN>": "<identifierN>"
"""
return fields.Dict(
# scheme
keys=SanitizedUnicode(
required=True, validate=_not_blank(_('Scheme cannot be blank.'))
),
# identifier
values=SanitizedUnicode(
required=True,
validate=_not_blank(_('Identifier cannot be blank.'))
)
)


class AffiliationSchemaV1(BaseSchema):
Expand Down Expand Up @@ -61,7 +82,7 @@ class CreatorSchemaV1(BaseSchema):
))
given_name = SanitizedUnicode()
family_name = SanitizedUnicode()
identifiers = fields.List(fields.Nested(IdentifierSchemaV1))
identifiers = Identifiers()
affiliations = fields.List(fields.Nested(AffiliationSchemaV1))


Expand Down Expand Up @@ -379,8 +400,7 @@ class MetadataSchemaV1(BaseSchema):
_contact = SanitizedUnicode(data_key="contact", attribute="contact")

# Metadata fields
identifiers = fields.List(fields.Nested(IdentifierSchemaV1),
required=True) # TODO: not required
identifiers = Identifiers()
creators = fields.List(Nested(CreatorSchemaV1), required=True)
titles = fields.List(fields.Nested(TitleSchemaV1), required=True)
resource_type = fields.Nested(ResourceTypeSchemaV1, required=True)
Expand Down
39 changes: 13 additions & 26 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,19 @@ def full_record():
"type": "image",
"subtype": "photo"
},
"identifiers": [{
"identifier": "10.5281/zenodo.9999999",
"scheme": "DOI"
}, {
"identifier": "9999.99999",
"scheme": "arXiv"
}],
"identifiers": {
"DOI": "10.5281/zenodo.9999999",
"arXiv": "9999.99999"
},
"creators": [
{
"name": "Julio Cesar",
"type": "Personal",
"given_name": "Julio",
"family_name": "Cesar",
"identifiers": [{
"identifier": "9999-9999-9999-9999",
"scheme": "Orcid"
}],
"identifiers": {
"Orcid": "9999-9999-9999-9999"
},
"affiliations": [{
"name": "Entity One",
"identifier": "entity-one",
Expand All @@ -121,10 +117,9 @@ def full_record():
{
"name": "California Digital Library",
"type": "Organizational",
"identifiers": [{
"identifier": "03yrm5c26",
"scheme": "ROR"
}]
"identifiers": {
"ROR": "03yrm5c26",
}
}
],
"titles": [{
Expand All @@ -143,10 +138,9 @@ def full_record():
"type": "Personal",
"given_name": "Maximo",
"family_name": "Decimo Meridio",
"identifiers": [{
"identifier": "9999-9999-9999-9998",
"scheme": "Orcid"
}],
"identifiers": {
"Orcid": "9999-9999-9999-9998",
},
"affiliations": [{
"name": "Entity One",
"identifier": "entity-one",
Expand Down Expand Up @@ -218,13 +212,6 @@ def minimal_record():
"type": "image",
"subtype": "photo"
},
"identifiers": [{
"identifier": "10.5281/zenodo.9999999",
"scheme": "DOI"
}, {
"identifier": "9999.99999",
"scheme": "arXiv"
}],
# Technically not required
"creators": [],
"titles": [{
Expand Down
Loading

0 comments on commit f799282

Please sign in to comment.