Skip to content

Commit

Permalink
datamodel: add title and alternative title fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Panero committed Oct 25, 2019
1 parent 1db6be2 commit 3cb2349
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
34 changes: 34 additions & 0 deletions invenio_rdm_records/jsonschemas/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "http://localhost/schemas/records/record-v1.0.0.json",
"title": "Invenio Datacite based Record Schema v1.0.0",
"definitions": {
"title_type": {
"description": "Alternative titles types.",
"type": "string",
"enum": [
"AlternativeTitle",
"Subtitle",
"TranslatedTitle",
"Other"
]
}
},
"type": "object",
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -32,6 +44,28 @@
],
"type": "string"
},
"additional_titles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {
"description": "Title of the record.",
"type": "string"
},
"type": {
"description": "Type of title.",
"$ref": "#/definitions/title_type"
},
"lang": {
"description": "Language of the title.",
"type": "string"
}
},
"required": ["title"]
},
"uniqueItems": true
},
"contributors": {
"description": "Contributors in order of importance.",
"minItems": 1,
Expand Down
15 changes: 15 additions & 0 deletions invenio_rdm_records/mappings/v6/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
"access_right": {
"type": "keyword"
},
"additional_titles": {
"type": "object",
"properties": {
"title": {
"type": "text",
"copy_to": "suggest_title"
},
"type": {
"type": "keyword"
},
"lang": {
"type": "keyword"
}
}
},
"contributors": {
"type": "object",
"properties": {
Expand Down
15 changes: 15 additions & 0 deletions invenio_rdm_records/mappings/v7/records/record-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
"access_right": {
"type": "keyword"
},
"additional_titles": {
"type": "object",
"properties": {
"title": {
"type": "text",
"copy_to": "suggest_title"
},
"type": {
"type": "keyword"
},
"lang": {
"type": "keyword"
}
}
},
"$schema": {
"type": "keyword",
"index": false
Expand Down
10 changes: 10 additions & 0 deletions invenio_rdm_records/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,22 @@ def dump_openaire_type(self, obj):
return missing


class TitleSchemaV1(StrictKeysMixin):
"""Schema for the main title."""

title = SanitizedUnicode(required=True, validate=validate.Length(min=3))
# TODO: Shall it be checked agains the enum?
alt_title_type = SanitizedUnicode()
lang = SanitizedUnicode()


class MetadataSchemaV1(StrictKeysMixin):
"""Schema for the record metadata."""

# TODO: Check enumeration (i.e. only open/embargoed/... accepted)
access_right = SanitizedUnicode(required=True)
access = fields.Nested(AccessSchemaV1)
alternative_titles = fields.List(fields.Nested(TitleSchemaV1))
recid = PersistentIdentifier()
title = SanitizedUnicode(required=True, validate=validate.Length(min=3))
description = SanitizedUnicode()
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_schemas_json_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ def test_invalid_resource_type(val):
data, errors = MetadataSchemaV1(partial=['resource_type']).load(
dict(resource_type=val))
assert 'resource_type' in errors


@pytest.mark.parametrize(('val', 'expected'), [
('Test', 'Test',),
(' Test ', 'Test'),
('', None),
(' ', None),
])
def test_title(val, expected):
"""Test title."""
data, errors = MetadataSchemaV1(partial=['title']).load(
dict(title=val))
if expected is not None:
assert data['title'] == expected
else:
assert 'title' in errors
assert 'title' not in data

# TODO add tests for alternative titles

0 comments on commit 3cb2349

Please sign in to comment.