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 17, 2020
1 parent f113b09 commit a17089a
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 204 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
39 changes: 7 additions & 32 deletions invenio_rdm_records/jsonschemas/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,8 @@
]
},
"identifiers": {
"type": "array",
"minItems": 0,
"uniqueItems": true,
"items":{
"type": "object",
"properties": {
"identifier": {"type": "string"},
"scheme": {"type": "string"}
},
"required": ["identifier", "scheme"]
}
"type": "object",
"additionalProperties": { "type": "string" }
},
"creators": {
"description": "Creators in order of importance.",
Expand All @@ -210,16 +201,8 @@
"given_name": {"type": "string"},
"family_name": {"type": "string"},
"identifiers": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"identifier": {"type": "string"},
"scheme": {"type": "string"}
},
"required": ["identifier", "scheme"]
}
"type": "object",
"additionalProperties": { "type": "string" }
},
"affiliations": {
"type": "array",
Expand Down Expand Up @@ -295,16 +278,8 @@
"given_name": {"type": "string"},
"family_name": {"type": "string"},
"identifiers": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"identifier": {"type": "string"},
"scheme": {"type": "string"}
},
"required": ["identifier", "scheme"]
}
"type": "object",
"additionalProperties": { "type": "string" }
},
"affiliations": {
"type": "array",
Expand Down Expand Up @@ -483,4 +458,4 @@
}
}
}
}
}
30 changes: 3 additions & 27 deletions invenio_rdm_records/mappings/v6/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,7 @@
}
},
"identifiers": {
"type": "object",
"properties": {
"identifier": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
}
}
"type": "object"
},
"creators": {
"type": "object",
Expand All @@ -147,15 +139,7 @@
"type": "text"
},
"identifiers": {
"type": "object",
"properties": {
"identifier": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
}
}
"type": "object"
},
"affiliations": {
"type": "object",
Expand Down Expand Up @@ -224,15 +208,7 @@
"type": "text"
},
"identifiers": {
"type": "object",
"properties": {
"identifier": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
}
}
"type": "object"
},
"affiliations": {
"type": "object",
Expand Down
30 changes: 3 additions & 27 deletions invenio_rdm_records/mappings/v7/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,7 @@
}
},
"identifiers": {
"type": "object",
"properties": {
"identifier": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
}
}
"type": "object"
},
"creators": {
"type": "object",
Expand All @@ -146,15 +138,7 @@
"type": "text"
},
"identifiers": {
"type": "object",
"properties": {
"identifier": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
}
}
"type": "object"
},
"affiliations": {
"type": "object",
Expand Down Expand Up @@ -223,15 +207,7 @@
"type": "text"
},
"identifiers": {
"type": "object",
"properties": {
"identifier": {
"type": "keyword"
},
"scheme": {
"type": "keyword"
}
}
"type": "object"
},
"affiliations": {
"type": "object",
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 a17089a

Please sign in to comment.