@@ -199,9 +199,9 @@ def _get_oai_dc_metadata(self, record, json, type):
199
199
}
200
200
return meta
201
201
202
- def _get_oai_datacite_metadata (self , record ):
202
+ def _get_oai_datacite_metadata (self , json ):
203
203
datacite_xml = CRS .transform_datasets_to_format (
204
- {'research_dataset' : record . research_dataset }, 'datacite' , False
204
+ {'research_dataset' : json }, 'datacite' , False
205
205
)
206
206
meta = {
207
207
'datacentreSymbol' : 'Metax' ,
@@ -212,17 +212,15 @@ def _get_oai_datacite_metadata(self, record):
212
212
213
213
def _get_metadata_for_record (self , record , json , type , metadata_prefix ):
214
214
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 )
220
216
221
217
if metadata_prefix == 'oai_dc' :
222
218
meta = self ._get_oai_dc_metadata (record , json , type )
223
219
elif metadata_prefix == 'oai_datacite' :
224
- meta = self ._get_oai_datacite_metadata (record )
220
+ meta = self ._get_oai_datacite_metadata (json )
225
221
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.
226
224
meta = self ._get_oai_dc_urnresolver_metadata (record )
227
225
return self ._fix_metadata (meta )
228
226
@@ -331,19 +329,16 @@ def listRecords(self, metadataPrefix=None, set=None, cursor=None, from_=None,
331
329
def getRecord (self , metadataPrefix , identifier ):
332
330
"""Implement OAI-PMH verb GetRecord."""
333
331
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 :
339
337
record = DataCatalog .objects .get (catalog_json__identifier__exact = identifier )
340
338
json = record .catalog_json
341
339
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 )
347
342
348
343
metadata = self ._get_metadata_for_record (record , json , type , metadataPrefix )
349
344
return (common .Header ('' , identifier , self ._get_header_timestamp (record ), ['metax' ], False ),
0 commit comments