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

Commit 71cf1e2

Browse files
committed
CSCMETAX-280:[FIX] according to review comments.
1 parent 73353bc commit 71cf1e2

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

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

+13-18
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ def _get_oai_dc_metadata(self, record, json, type):
199199
}
200200
return meta
201201

202-
def _get_oai_datacite_metadata(self, record):
202+
def _get_oai_datacite_metadata(self, json):
203203
datacite_xml = CRS.transform_datasets_to_format(
204-
{'research_dataset': record.research_dataset}, 'datacite', False
204+
{'research_dataset': json}, 'datacite', False
205205
)
206206
meta = {
207207
'datacentreSymbol': 'Metax',
@@ -212,17 +212,15 @@ def _get_oai_datacite_metadata(self, record):
212212

213213
def _get_metadata_for_record(self, record, json, type, metadata_prefix):
214214
meta = {}
215-
216-
# strip sensitive fields from research_dataset. note: the modified research_dataset
217-
# is placed back into the record's research_dataset -field. meaning, an accidental call
218-
# of record.save() would overwrite the original data
219-
record.research_dataset = CRS.strip_catalog_record(json)
215+
json = CRS.strip_catalog_record(json)
220216

221217
if metadata_prefix == 'oai_dc':
222218
meta = self._get_oai_dc_metadata(record, json, type)
223219
elif metadata_prefix == 'oai_datacite':
224-
meta = self._get_oai_datacite_metadata(record)
220+
meta = self._get_oai_datacite_metadata(json)
225221
elif metadata_prefix == 'oai_dc_urnresolver':
222+
# This is a special case. Only identifier values are retrieved from the record,
223+
# so strip_catalog_record is not applicable here.
226224
meta = self._get_oai_dc_urnresolver_metadata(record)
227225
return self._fix_metadata(meta)
228226

@@ -331,19 +329,16 @@ def listRecords(self, metadataPrefix=None, set=None, cursor=None, from_=None,
331329
def getRecord(self, metadataPrefix, identifier):
332330
"""Implement OAI-PMH verb GetRecord."""
333331
try:
334-
if CatalogRecord.objects.filter(identifier__exact=identifier).exists():
335-
record = CatalogRecord.objects.get(identifier__exact=identifier)
336-
json = record.research_dataset
337-
type = 'Dataset'
338-
else:
332+
record = CatalogRecord.objects.get(identifier__exact=identifier)
333+
json = record.research_dataset
334+
type = 'Dataset'
335+
except CatalogRecord.DoesNotExist:
336+
try:
339337
record = DataCatalog.objects.get(catalog_json__identifier__exact=identifier)
340338
json = record.catalog_json
341339
type = 'Datacatalog'
342-
343-
except CatalogRecord.DoesNotExist:
344-
raise IdDoesNotExistError("No dataset with id %s available through the OAI-PMH interface." % identifier)
345-
except DataCatalog.DoesNotExist:
346-
raise IdDoesNotExistError("No datacatalog with id %s available through the OAI-PMH interface." % identifier)
340+
except DataCatalog.DoesNotExist:
341+
raise IdDoesNotExistError("No record with id %s available." % identifier)
347342

348343
metadata = self._get_metadata_for_record(record, json, type, metadataPrefix)
349344
return (common.Header('', identifier, self._get_header_timestamp(record), ['metax'], False),

0 commit comments

Comments
 (0)