Skip to content

Commit

Permalink
datacite: added access right info
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatimah committed Apr 4, 2024
1 parent bc28157 commit 2ce1cd6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@
]
}
}
},
"status": {
"description": "Record access status.",
"type": "string"
}
}
},
Expand Down
15 changes: 15 additions & 0 deletions invenio_rdm_records/resources/serializers/datacite/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,21 @@ def get_rights(self, obj):

serialized_rights.append(serialized_right)

# Adding access_right information
access_right = obj["access"]["status"]
if access_right == "metadata-only":
access_right = "closed"

access_right_formatted = access_right.capitalize() + " Access"
rights_uri = "info:eu-repo/semantics/{}Access".format(access_right)

access_right_serialized = {
"rights": access_right_formatted,
"rightsUri": rights_uri,
}

serialized_rights.append(access_right_serialized)

return serialized_rights if serialized_rights else missing

def get_funding(self, obj):
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ def full_record(users):
"until": "2131-01-01",
"reason": "Only for medical doctors.",
},
"status": "embargoed",
},
"files": {
"enabled": True,
Expand Down Expand Up @@ -846,6 +847,7 @@ def enhanced_full_record(users):
"until": "2131-01-01",
"reason": "Only for medical doctors.",
},
"status": "embargoed",
},
"files": {
"enabled": True,
Expand Down
3 changes: 2 additions & 1 deletion tests/records/full-record.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@
"active": true,
"until": "2131-01-01",
"reason": "Only for medical doctors."
}
},
"status": "embargoed"
},
"files": {
"enabled": true,
Expand Down
5 changes: 5 additions & 0 deletions tests/resources/serializers/test_datacite_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ def test_datacite43_serializer(running_app, full_record):
"rightsIdentifier": "cc-by-4.0",
"rightsUri": "https://creativecommons.org/licenses/by/4.0/legalcode",
},
{
"rights": "Embargoed Access",
"rightsUri": "info:eu-repo/semantics/embargoedAccess",
},
],
"descriptions": [
{
Expand Down Expand Up @@ -313,6 +317,7 @@ def test_datacite43_xml_serializer(running_app, full_record):
" <rightsList>",
' <rights rightsURI="https://customlicense.org/licenses/by/4.0/">A custom license</rights>', # noqa
' <rights rightsURI="https://creativecommons.org/licenses/by/4.0/legalcode" rightsIdentifierScheme="spdx" rightsIdentifier="cc-by-4.0">Creative Commons Attribution 4.0 International</rights>', # noqa
' <rights rightsURI="info:eu-repo/semantics/embargoedAccess">Embargoed Access</rights>',
" </rightsList>",
" <descriptions>",
' <description descriptionType="Abstract">A description ',
Expand Down
8 changes: 8 additions & 0 deletions tests/resources/serializers/test_dcat_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ def test_dcat_serializer(running_app, enhanced_full_record):
' <dcat:centroid rdf:datatype="http://www.opengis.net/ont/geosparql#geoJSONLiteral"><![CDATA[{"type":"Point","coordinates":[-32.94682,-60.63932]}]]></dcat:centroid>', # noqa
" </dct:Location>",
" </dct:spatial>",
' <dct:accessRights rdf:resource="http://publications.europa.eu/resource/authority/access-right/NON_PUBLIC"/>',
" <dct:accessRights>",
' <dct:RightsStatement rdf:about="info:eu-repo/semantics/embargoedAccess">',
" <rdfs:label>Embargoed Access</rdfs:label>",
" </dct:RightsStatement>",
" </dct:accessRights>",
" <dcat:distribution>",
" <dcat:Distribution>",
" <dct:extent>",
Expand Down Expand Up @@ -187,4 +193,6 @@ def test_dcat_serializer(running_app, enhanced_full_record):

serializer = DCATSerializer()
serialized_record = serializer.serialize_object(enhanced_full_record)
print("lol")
print(serialized_record)
assert serialized_record == "\n".join(expected_data)

0 comments on commit 2ce1cd6

Please sign in to comment.