diff --git a/sonar/common/jsonschemas/license-v1.0.0.json b/sonar/common/jsonschemas/license-v1.0.0.json new file mode 100644 index 00000000..2dad6e06 --- /dev/null +++ b/sonar/common/jsonschemas/license-v1.0.0.json @@ -0,0 +1,55 @@ +{ + "title": "License", + "type": "string", + "enum": [ + "CC0", + "CC BY", + "CC BY-NC", + "CC BY-NC-ND", + "CC BY-NC-SA", + "CC BY-ND", + "CC BY-SA", + "Other OA / license undefined", + "Not OA / Rights reserved" + ], + "form": { + "options": [ + { + "label": "CC0", + "value": "CC0" + }, + { + "label": "CC BY", + "value": "CC BY" + }, + { + "label": "CC BY-NC", + "value": "CC BY-NC" + }, + { + "label": "CC BY-NC-ND", + "value": "CC BY-NC-ND" + }, + { + "label": "CC BY-NC-SA", + "value": "CC BY-NC-SA" + }, + { + "label": "CC BY-ND", + "value": "CC BY-ND" + }, + { + "label": "CC BY-SA", + "value": "CC BY-SA" + }, + { + "label": "Other OA / license undefined", + "value": "Other OA / license undefined" + }, + { + "label": "Not OA / Rights reserved", + "value": "Not OA / Rights reserved" + } + ] + } +} diff --git a/sonar/modules/deposits/api.py b/sonar/modules/deposits/api.py index b4440981..4e8d773c 100644 --- a/sonar/modules/deposits/api.py +++ b/sonar/modules/deposits/api.py @@ -285,6 +285,11 @@ def create_document(self): if contributors: metadata['contribution'] = contributors + # License + metadata['usageAndAccessPolicy'] = { + 'license': self['diffusion']['license'] + } + document = DocumentRecord.create(metadata, dbcommit=True, with_bucket=True) diff --git a/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json b/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json index b0bd31d9..47eb1634 100644 --- a/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json +++ b/sonar/modules/deposits/jsonschemas/deposits/deposit-v1.0.0_src.json @@ -842,7 +842,13 @@ }, "diffusion": { "type": "object", - "properties": {} + "additionalProperties": false, + "properties": { + "license": { + "$ref": "license-v1.0.0.json" + } + }, + "required": ["license"] }, "document": { "title": "Document", diff --git a/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json b/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json index df5443b9..69dadc82 100644 --- a/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json +++ b/sonar/modules/deposits/mappings/v6/deposits/deposit-v1.0.0.json @@ -228,7 +228,12 @@ "type": "keyword" }, "diffusion": { - "type": "object" + "type": "object", + "properties": { + "license": { + "type": "keyword" + } + } }, "document": { "type": "object", diff --git a/sonar/modules/documents/dojson/rerodoc/model.py b/sonar/modules/documents/dojson/rerodoc/model.py index f0bd4fb2..f8cdd60e 100644 --- a/sonar/modules/documents/dojson/rerodoc/model.py +++ b/sonar/modules/documents/dojson/rerodoc/model.py @@ -670,11 +670,16 @@ def marc21_to_dissertation_field_508(self, key, value): @marc21tojson.over('usageAndAccessPolicy', '^540..') -@utils.for_each_value @utils.ignore_value def marc21_to_usage_and_access_policy(self, key, value): """Extract usage and access policy.""" - return value.get('a') + if not value.get('a'): + return None + + return { + 'label': value.get('a'), + 'license': 'Other OA / license undefined' + } @marc21tojson.over('contribution', '^100..') diff --git a/sonar/modules/documents/dojson/rerodoc/overdo.py b/sonar/modules/documents/dojson/rerodoc/overdo.py index 2e91fcde..0ddac3ae 100644 --- a/sonar/modules/documents/dojson/rerodoc/overdo.py +++ b/sonar/modules/documents/dojson/rerodoc/overdo.py @@ -94,6 +94,12 @@ def do(self, blob, ignore_missing=True, exception_handlers=None): # Verify data integrity self.verify(result) + # Add default license if not set. + if not result.get('usageAndAccessPolicy'): + result['usageAndAccessPolicy'] = { + 'license': 'Other OA / license undefined' + } + return result def get_contributor_role(self, role_700=None): diff --git a/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json b/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json index 1403b6fd..22264e99 100644 --- a/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json +++ b/sonar/modules/documents/jsonschemas/documents/document-v1.0.0_src.json @@ -1089,14 +1089,21 @@ "hideExpression": "!['coar:c_46ec', 'coar:c_7a1f', 'coar:c_db06', 'coar:c_bdcc', 'habilitation_thesis', 'advanced_studies_thesis', 'other'].includes(field.parent.model.documentType)" }, "usageAndAccessPolicy": { - "title": "Usage and access policies", - "type": "array", - "minItems": 1, - "items": { - "title": "Usage and access policy", - "type": "string", - "minLength": 1 + "title": "Usage and access policy", + "type": "object", + "additionalProperties": false, + "properties": { + "license": { + "$ref": "license-v1.0.0.json" + }, + "label": { + "title": "Label", + "type": "string", + "minLength": 1 + } }, + "propertiesOrder": ["license", "label"], + "required": ["license"], "form": { "hide": true, "templateOptions": { diff --git a/sonar/modules/documents/mappings/v6/documents/document-v1.0.0.json b/sonar/modules/documents/mappings/v6/documents/document-v1.0.0.json index 2ceead5f..6fb2787d 100644 --- a/sonar/modules/documents/mappings/v6/documents/document-v1.0.0.json +++ b/sonar/modules/documents/mappings/v6/documents/document-v1.0.0.json @@ -320,7 +320,15 @@ } }, "usageAndAccessPolicy": { - "type": "text" + "type": "object", + "properties": { + "label": { + "type": "text" + }, + "license": { + "type": "keyword" + } + } }, "contribution": { "type": "object", diff --git a/sonar/modules/documents/marshmallow/json.py b/sonar/modules/documents/marshmallow/json.py index 0c64bd62..184e73a7 100644 --- a/sonar/modules/documents/marshmallow/json.py +++ b/sonar/modules/documents/marshmallow/json.py @@ -90,6 +90,7 @@ class DocumentMetadataSchemaV1(StrictKeysMixin): specificCollections = fields.List(SanitizedUnicode()) dissertation = fields.Dict() otherEdition = fields.List(fields.Dict()) + usageAndAccessPolicy = fields.Dict() _bucket = SanitizedUnicode() _files = Nested(FileSchemaV1, many=True) # When loading, if $schema is not provided, it's retrieved by diff --git a/sonar/modules/documents/templates/documents/record.html b/sonar/modules/documents/templates/documents/record.html index 2a926828..477a8a47 100644 --- a/sonar/modules/documents/templates/documents/record.html +++ b/sonar/modules/documents/templates/documents/record.html @@ -26,18 +26,20 @@
-
+
{% if files and files | length > 0 %}
{{ thumbnail('documents', record, files | first) }}
{% endif %} + {% if record.documentType %} -
{{ _('document_type_' + record.documentType) }}
+
{{ _('document_type_' + record.documentType) }}
{% endif %} + {% if files and files | length > 1 %} -

+

+ {{ (files | length) - 1 }} {{ _('other files') }}

{% endif %} @@ -215,6 +217,19 @@
{% endfor %} {% endif %} + + {% if record.usageAndAccessPolicy %} +
+ {{ _('License') }} +
+
+ {{ _(record.usageAndAccessPolicy.license) }} + {% if record.usageAndAccessPolicy.label %} +
{{ record.usageAndAccessPolicy.label }} + {% endif %} +
+ {% endif %} + {% set link = record.get_permanent_link(request.host_url, record.pid, view_code) %}
diff --git a/tests/conftest.py b/tests/conftest.py index dee780d1..b48e0b67 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -486,6 +486,9 @@ def deposit_json(): 'value': '10.1038/nphys1170' }] }, + 'diffusion': { + 'license': 'CC0' + }, 'status': 'in_progress', 'step': diff --git a/tests/ui/documents/dojson/rerodoc/test_rerodoc_model.py b/tests/ui/documents/dojson/rerodoc/test_rerodoc_model.py index 1541eb4f..fd91ddca 100644 --- a/tests/ui/documents/dojson/rerodoc/test_rerodoc_model.py +++ b/tests/ui/documents/dojson/rerodoc/test_rerodoc_model.py @@ -1827,7 +1827,10 @@ def test_marc21_to_usage_and_access_policy(): """ marc21json = create_record(marc21xml) data = marc21tojson.do(marc21json) - assert data.get('usageAndAccessPolicy') == ['Springer-Verlag Berlin'] + assert data.get('usageAndAccessPolicy') == { + 'label': 'Springer-Verlag Berlin', + 'license': 'Other OA / license undefined' + } # Multiple marc21xml = """ @@ -1842,7 +1845,10 @@ def test_marc21_to_usage_and_access_policy(): """ marc21json = create_record(marc21xml) data = marc21tojson.do(marc21json) - assert data.get('usageAndAccessPolicy') == ['Usage 1', 'Usage 2'] + assert data.get('usageAndAccessPolicy') == { + 'label': 'Usage 2', + 'license': 'Other OA / license undefined' + } # Without $a marc21xml = """ @@ -1852,7 +1858,9 @@ def test_marc21_to_usage_and_access_policy(): """ marc21json = create_record(marc21xml) data = marc21tojson.do(marc21json) - assert not data.get('usageAndAccessPolicy') + assert data.get('usageAndAccessPolicy') == { + 'license': 'Other OA / license undefined' + } # Without 540 marc21xml = """ @@ -1860,7 +1868,9 @@ def test_marc21_to_usage_and_access_policy(): """ marc21json = create_record(marc21xml) data = marc21tojson.do(marc21json) - assert not data.get('usageAndAccessPolicy') + assert data.get('usageAndAccessPolicy') == { + 'license': 'Other OA / license undefined' + } def test_marc21_to_contribution_field_100():