Skip to content

Commit

Permalink
document, deposit: add relatedTo field
Browse files Browse the repository at this point in the history
* Adds relatedTo field on the document and the deposit resource.
* Updates Dublin Core to export the new relatedTo field
  into the relations.
* Updates of the creation of the document from the deposit for
  the new relatedTo field.
* Closes rero#544.

⚠️  ES update mapping

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed May 9, 2022
1 parent 7869ea3 commit c1dd481
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 16 deletions.
9 changes: 9 additions & 0 deletions sonar/modules/deposits/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ def create_document(self):
'publicNote': link['publicNote']
} for link in self['metadata']['otherElectronicVersions']]

# related to
if self['metadata'].get('relatedTo'):
metadata['relatedTo'] = [{
'document': {
'electronicLocator': link['url']
},
'publicNote': link['publicNote']
} for link in self['metadata']['relatedTo']]

# Collections
if self['metadata'].get('collections'):
collections = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
"publication",
"dissertation",
"otherElectronicVersions",
"relatedTo",
"collections",
"classification",
"abstracts",
Expand Down Expand Up @@ -731,7 +732,17 @@
"title": "URL",
"type": "string",
"minLength": 1,
"pattern": "^https?://.+"
"pattern": "^https?://.+",
"form": {
"templateOptions": {
"placeholder": "Example: https://www.rero.ch"
},
"validation": {
"messages": {
"patternMessage": "Should be a valid URL format."
}
}
}
}
}
},
Expand Down Expand Up @@ -1066,6 +1077,59 @@
}
}
}
},
"relatedTo": {
"title": "Related to",
"type": "array",
"items": {
"title": "Related to",
"description": "Relationship with a document, dataset, etc.",
"type": "object",
"propertiesOrder": [
"publicNote",
"url"
],
"required": [
"publicNote",
"url"
],
"additionalProperties": false,
"properties": {
"publicNote": {
"title": "Public note",
"type": "string",
"minLength": 1,
"form": {
"templateOptions": {
"placeholder": "Example: Research dataset"
}
}
},
"url": {
"title": "URL",
"type": "string",
"minLength": 1,
"pattern": "^https?://.+",
"form": {
"templateOptions": {
"placeholder": "Example: https://www.rero.ch"
},
"validation": {
"messages": {
"patternMessage": "Should be a valid URL format."
}
}
}
}
}
},
"form": {
"templateOptions": {
"wrappers": [
"card"
]
}
}
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions sonar/modules/deposits/mappings/v7/deposits/deposit-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,22 @@
"type": "text"
}
}
},
"relatedTo": {
"type": "object",
"properties": {
"document": {
"type": "object",
"properties": {
"electronicLocator": {
"type": "keyword"
}
}
},
"publicNote": {
"type": "text"
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@
"format": "uri",
"pattern": "^https?://.*",
"form": {
"hideExpression": "true"
"hideExpression": "true",
"validation": {
"messages": {
"patternMessage": "Should be a valid URL format."
}
}
}
},
"force_external_url": {
Expand Down Expand Up @@ -949,7 +954,16 @@
"electronicLocator": {
"title": "URL",
"type": "string",
"minLength": 1
"minLength": 1,
"pattern": "^https?://.+",
"form": {
"placeholder": "Example: https://www.rero.ch",
"validation": {
"messages": {
"patternMessage": "Should be a valid URL format."
}
}
}
}
},
"required": [
Expand Down Expand Up @@ -978,6 +992,62 @@
"hide": true
}
},
"relatedTo": {
"title": "Related to",
"type": "array",
"minItems": 1,
"items": {
"title": "Related to",
"description": "Relationship with a document, dataset, etc.",
"type": "object",
"additionalProperties": false,
"properties": {
"document": {
"title": "Document",
"type": "object",
"additionalProperties": false,
"properties": {
"electronicLocator": {
"title": "URL",
"type": "string",
"pattern": "^https?://.+",
"minLength": 1,
"form": {
"placeholder": "Example: https://www.rero.ch",
"validation": {
"messages": {
"patternMessage": "Should be a valid URL format."
}
}
}
}
},
"required": [
"electronicLocator"
]
},
"publicNote": {
"title": "Public note",
"type": "string",
"minLength": 1,
"form": {
"placeholder": "Example: Research dataset"
}
}
},
"propertiesOrder": [
"publicNote",
"document"
],
"required": [
"document",
"publicNote"
]
},
"form": {
"hide": true
}
},
"collections": {
"title": "Collections",
"type": "array",
Expand Down Expand Up @@ -1952,6 +2022,7 @@
"dissertation",
"editionStatement",
"otherEdition",
"relatedTo",
"provisionActivity",
"partOf",
"collections",
Expand Down
16 changes: 16 additions & 0 deletions sonar/modules/documents/mappings/v7/documents/document-v1.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@
}
}
},
"relatedTo": {
"type": "object",
"properties": {
"document": {
"type": "object",
"properties": {
"electronicLocator": {
"type": "keyword"
}
}
},
"publicNote": {
"type": "text"
}
}
},
"collections": {
"type": "object",
"properties": {
Expand Down
1 change: 1 addition & 0 deletions sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class DocumentMetadataSchemaV1(StrictKeysMixin):
collections = fields.List(fields.Dict())
dissertation = fields.Dict()
otherEdition = fields.List(fields.Dict())
relatedTo = fields.List(fields.Dict())
usageAndAccessPolicy = fields.Dict()
projects = fields.List(fields.Dict())
oa_status = SanitizedUnicode()
Expand Down
3 changes: 3 additions & 0 deletions sonar/modules/documents/serializers/schemas/dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def get_relations(self, obj):
items = [
other_edition['document']['electronicLocator']
for other_edition in obj['metadata'].get('otherEdition', [])
] + [
other_edition['document']['electronicLocator']
for other_edition in obj['metadata'].get('relatedTo', [])
]

result = 'info:eu-repo/semantics/altIdentifier/{schema}/{identifier}'
Expand Down
32 changes: 32 additions & 0 deletions sonar/modules/documents/templates/documents/_other_edition.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{# -*- coding: utf-8 -*-
Swiss Open Access Repository
Copyright (C) 2023 RERO

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
<http: //www.gnu.org/licenses />.
#}

{% if data %}
<dt class="col-lg-3">{{ fieldLabel }}</dt>
<dd class="col-lg-9">
{% for element in data %}
<p class="m-0">
<a href="{{ element.document.electronicLocator }}"
target="_blank">
<i class="fa fa-external-link mx-1"></i>
{{ element.publicNote }}
</a>
</p>
{% endfor %}
</dd>
{% endif %}
19 changes: 8 additions & 11 deletions sonar/modules/documents/templates/documents/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,14 @@ <h5 class="d-inline">
{% endif %}

<!-- OTHER EDITION -->
{% if record.otherEdition %}
<dt class="col-lg-3">
{{ _('Other electronic version') }}
</dt>
<dd class="col-lg-9">
{% for otherEdition in record.otherEdition %}
<p class="m-0">{{ otherEdition.publicNote }} : <a href="{{ otherEdition.document.electronicLocator }}"
target="_blank">{{ otherEdition.document.electronicLocator }}</a></p>
{% endfor %}
</dd>
{% endif %}
{% with fieldLabel=_('Other electronic version'), data=record.otherEdition %}
{% include 'documents/_other_edition.html' %}
{% endwith %}

<!-- RELATED TO -->
{% with fieldLabel=_('Related to'), data=record.relatedTo %}
{% include 'documents/_other_edition.html' %}
{% endwith %}

<!-- SERIES -->
{% if record.series %}
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ def deposit_json(collection, subdivision):
'publicNote': 'Published version',
'url': 'https://some.url/document.pdf'
}],
'relatedTo': [{
'publicNote': 'Related to version',
'url': 'https://some.url/related.pdf'
}],
'collections': [{
'$ref':
f'https://sonar.ch/api/collections/{collection["pid"]}'
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/deposits/test_deposits_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def test_create_document(app, db, project, client, deposit, submitter,
},
'publicNote': 'Published version'
}]
assert document['relatedTo'] == [{
'document': {
'electronicLocator': 'https://some.url/related.pdf'
},
'publicNote': 'Related to version'
}]
assert len(document['collections']) == 1
assert document['classification'] == [{
'type': 'bf:ClassificationUdc',
Expand Down
19 changes: 17 additions & 2 deletions tests/ui/documents/test_dc_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,25 @@ def test_relations(minimal_document):
'electronicLocator': 'https://some.url.2'
}
}]
result = SonarDublinCoreXMLSerializer().transform_record(minimal_document)
assert result['relations'] == ['https://some.url.1', 'https://some.url.2']

minimal_document['relatedTo'] = [{
'document': {
'electronicLocator': 'https://some.url.3'
}
}, {
'document': {
'electronicLocator': 'https://some.url.4'
}
}]

result = SonarDublinCoreXMLSerializer().transform_record(minimal_document)
assert result['relations'] == [
'https://some.url.1', 'https://some.url.2',
'https://some.url.3', 'https://some.url.4',
]
minimal_document.pop('otherEdition', None)
minimal_document.pop('relatedTo', None)

minimal_document['identifiedBy'] = [{
'type': 'bf:Identifier',
'value': 'ark:/13030/tf5p30086k'
Expand Down

0 comments on commit c1dd481

Please sign in to comment.