Skip to content
This repository was archived by the owner on Sep 16, 2022. It is now read-only.

Commit 8106f62

Browse files
committed
CSCMETAX-280:[FIX] proper handling of language field data.
1 parent 71cf1e2 commit 8106f62

File tree

2 files changed

+145
-4
lines changed

2 files changed

+145
-4
lines changed

src/metax_api/api/oaipmh/base/metax_oai_server.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def _get_oai_dc_metadata(self, record, json, type):
142142
publisher = []
143143
publisher_data = json.get('publisher', {})
144144
for key, value in publisher_data.get('name', {}).items():
145-
publisher.append(self._get_oaic_dc_value(value))
145+
publisher.append(self._get_oaic_dc_value(value, key))
146146

147147
contributor = []
148148
contributor_data = json.get('contributor', [])
@@ -155,8 +155,8 @@ def _get_oai_dc_metadata(self, record, json, type):
155155
language = []
156156
language_data = json.get('language', [])
157157
for value in language_data:
158-
for key, value2 in value.items():
159-
language.append(self._get_oaic_dc_value(value2))
158+
if 'identifier' in value:
159+
language.append(self._get_oaic_dc_value(value['identifier']))
160160

161161
relation = []
162162
relation_data = json.get('relation', [])

src/metax_api/tests/api/oaipmh/minimal_api.py

+142-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,138 @@ class OAIPMHReadTests(APITestCase, TestClassUtils):
1919
'dct': "http://purl.org/dc/terms/",
2020
'datacite': 'http://schema.datacite.org/oai/oai-1.0/'}
2121

22+
_datacatalog_record = {
23+
"id": 2,
24+
"catalog_json": {
25+
"title": {
26+
"en": "Test data catalog name",
27+
"fi": "Testidatakatalogin nimi"
28+
},
29+
"issued": "2014-02-27T08:19:58Z",
30+
"homepage": [
31+
{
32+
"title": {
33+
"en": "Test website",
34+
"fi": "Testi-verkkopalvelu"
35+
},
36+
"identifier": "http://testing.com"
37+
},
38+
{
39+
"title": {
40+
"en": "Another website",
41+
"fi": "Toinen verkkopalvelu"
42+
},
43+
"identifier": "http://www.testing.fi"
44+
}
45+
],
46+
"language": [
47+
{
48+
"title": {
49+
"en": "Finnish language",
50+
"fi": "Suomen kieli",
51+
"sv": "finska",
52+
"und": "Suomen kieli"
53+
},
54+
"identifier": "http://lexvo.org/id/iso639-3/fin"
55+
},
56+
{
57+
"title": {
58+
"en": "English language",
59+
"fi": "Englannin kieli",
60+
"sv": "engelska",
61+
"und": "Englannin kieli"
62+
},
63+
"identifier": "http://lexvo.org/id/iso639-3/eng"
64+
}
65+
],
66+
"modified": "2014-01-17T08:19:58Z",
67+
"harvested": False,
68+
"publisher": {
69+
"name": {
70+
"en": "Data catalog publisher organization",
71+
"fi": "Datakatalogin julkaisijaorganisaatio"
72+
},
73+
"homepage": [
74+
{
75+
"title": {
76+
"en": "Publisher organization website",
77+
"fi": "Julkaisijaorganisaation kotisivu"
78+
},
79+
"identifier": "http://www.publisher.fi/"
80+
}
81+
],
82+
"identifier": "http://isni.org/isni/0000000405129137"
83+
},
84+
"identifier": "urn:nbn:fi:att:2955e904-e3dd-4d7e-99f1-3fed446f96d2",
85+
"access_rights": {
86+
"license": [
87+
{
88+
"title": {
89+
"en": "Creative Commons Attribution 4.0 International (CC BY 4.0)",
90+
"fi": "Creative Commons Nimeä 4.0 Kansainvälinen (CC BY 4.0)",
91+
"und": "Creative Commons Nimeä 4.0 Kansainvälinen (CC BY 4.0)"
92+
},
93+
"license": "https://creativecommons.org/licenses/by/4.0/",
94+
"identifier": "https://creativecommons.org/licenses/by/4.0/"
95+
}
96+
],
97+
"access_type": [
98+
{
99+
"identifier": "http://purl.org/att/es/reference_data/access_type/access_type_open_access",
100+
"pref_label": {
101+
"en": "Open",
102+
"fi": "Avoin",
103+
"und": "Avoin"
104+
}
105+
}
106+
],
107+
"description": [
108+
{
109+
"fi": "Käyttöehtojen kuvaus"
110+
}
111+
],
112+
"has_rights_related_agent": [
113+
{
114+
"name": {
115+
"en": "A rights related organization",
116+
"fi": "Oikeuksiin liittyvä organisaatio"
117+
},
118+
"identifier": "org_id"
119+
},
120+
{
121+
"name": {
122+
"und": "Aalto yliopisto"
123+
},
124+
"email": "[email protected]",
125+
"telephone": [
126+
"+12353495823424"
127+
],
128+
"identifier": "http://purl.org/att/es/organization_data/organization/organization_10076"
129+
}
130+
]
131+
},
132+
"field_of_science": [
133+
{
134+
"identifier": "http://www.yso.fi/onto/okm-tieteenala/ta1172",
135+
"pref_label": {
136+
"en": "Environmental sciences",
137+
"fi": "Ympäristötiede",
138+
"sv": "Miljövetenskap",
139+
"und": "Ympäristötiede"
140+
}
141+
}
142+
],
143+
"dataset_versioning": True,
144+
"research_dataset_schema": "ida"
145+
},
146+
"catalog_record_group_edit": "default-record-edit-group",
147+
"catalog_record_group_create": "default-record-create-group",
148+
"date_modified": "2018-06-01T16:54:32+03:00",
149+
"date_created": "2017-05-15T13:07:22+03:00",
150+
"service_modified": "metax",
151+
"service_created": "metax"
152+
}
153+
22154
@classmethod
23155
def setUpClass(cls):
24156
"""
@@ -254,7 +386,7 @@ def test_write_oai_dc_with_lang(self):
254386
self.assertTrue('<dc:title xml:lang="fi">title2</dc:title>' in result)
255387
self.assertTrue('<dc:description>value</dc:description>' in result)
256388

257-
def test_get_oai_dc_metadata(self):
389+
def test_get_oai_dc_metadata_dataset(self):
258390
cr = CatalogRecord.objects.get(pk=11)
259391
from metax_api.api.oaipmh.base.metax_oai_server import MetaxOAIServer
260392
s = MetaxOAIServer()
@@ -263,6 +395,15 @@ def test_get_oai_dc_metadata(self):
263395
self.assertTrue('title' in md)
264396
self.assertTrue('lang' in md['title'][0])
265397

398+
def test_get_oai_dc_metadata_datacatalog(self):
399+
cr = DataCatalog.objects.get(pk=1)
400+
from metax_api.api.oaipmh.base.metax_oai_server import MetaxOAIServer
401+
s = MetaxOAIServer()
402+
md = s._get_oai_dc_metadata(cr, self._datacatalog_record['catalog_json'], 'Datacatalog')
403+
self.assertTrue('identifier' in md)
404+
self.assertTrue('title' in md)
405+
self.assertTrue('lang' in md['title'][0])
406+
266407
def test_sensitive_fields_are_removed(self):
267408
"""
268409
Ensure some sensitive fields are never present in output of OAI-PMH apis

0 commit comments

Comments
 (0)