Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oaipmh #565

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions app/oaipmh/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ def getRecord(self, root, metadata_dict, verb, identifier, metadata_prefix):
identifier_element = etree.SubElement(header, 'identifier')
identifier_element.text = identifier
datestamp_element = etree.SubElement(header, 'datestamp')
datestamp_element.text = self.earliest_datestamp
if record_data.get('creation_date'):
datestamp_element.text = record_data.get('creation_date').strftime("%Y-%m-%d")
if 'creation_date' in record_data:
datestamp_element.text = record_data['creation_date'].strftime("%Y-%m-%d")
else: # if creation_date is not present in the metadata
datestamp_element.text = self.earliest_datestamp

metadata_element = etree.SubElement(record, 'metadata')

Expand Down Expand Up @@ -203,9 +204,11 @@ def listIdentifiers(self, root, metadata_dict, verb, metadata_prefix, from_date=
identifier_element = etree.Element('identifier')
identifier_element.text = f'{self.repository_indentifier_base_url}{record_identifier}'
datestamp_element = etree.Element('datestamp')
datestamp_element.text = self.earliest_datestamp
if metadata_dict[record_identifier].get('creation_date'):
datestamp_element.text = metadata_dict[record_identifier].get('creation_date').strftime("%Y-%m-%d")
record_metadata = metadata_dict[record_identifier]
if 'creation_date' in record_metadata:
datestamp_element.text = record_metadata['creation_date'].strftime("%Y-%m-%d")
else: # if creation_date is not present in the metadata
datestamp_element.text = f'{self.earliest_datestamp}'

header_element.append(identifier_element)
header_element.append(datestamp_element)
Expand Down Expand Up @@ -278,16 +281,17 @@ def listRecords(self, root, metadata_dict, verb, metadata_prefix, from_date=None
root.append(error_element)
return etree.tostring(root, pretty_print=True, encoding='unicode')
else:
for record_name in filtered_identifiers:
for record_name, record_metadata in filtered_identifiers:
record_element = etree.Element('record')

header_element = etree.Element('header')
identifier_element = etree.Element('identifier')
identifier_element.text = f'{self.repository_indentifier_base_url}{record_name}'
datestamp_element = etree.Element('datestamp')
datestamp_element.text = 'datestamp'
if metadata_dict[record_name].get('creation_date'):
datestamp_element.text = metadata_dict[record_name].get('creation_date').strftime("%Y-%m-%d")
if 'creation_date' in record_metadata:
datestamp_element.text = record_metadata['creation_date'].strftime("%Y-%m-%d")
else: # if creation_date is not present in the metadata
datestamp_element.text = f'{self.earliest_datestamp}'

metadata_element = etree.Element('metadata')

Expand Down Expand Up @@ -339,6 +343,9 @@ def addIdentifyElements(self, identify_element):
protocol_version_element = etree.SubElement(identify_element, 'protocolVersion')
protocol_version_element.text = self.repository_protocol_version

admin_email_element = etree.SubElement(identify_element, 'adminEmail')
admin_email_element.text = self.repository_admin_email

earliest_datestamp_element = etree.SubElement(identify_element, 'earliestDatestamp')
earliest_datestamp_element.text = self.earliest_datestamp

Expand All @@ -348,9 +355,6 @@ def addIdentifyElements(self, identify_element):
granularity_element = etree.SubElement(identify_element, 'granularity')
granularity_element.text = self.datestamp_granularity

admin_email_element = etree.SubElement(identify_element, 'adminEmail')
admin_email_element.text = self.repository_admin_email

def addRequestElement(self, root, verb=None, metadata_prefix=None, identifier=None,
from_date=None, until_date=None, set_spec=None, resumption_token=None):
if verb:
Expand Down Expand Up @@ -427,7 +431,7 @@ def mapOAIRE(self, metadata_dict):
etree.register_namespace('oai_dc', nsmap['oai_dc'])

for key, value in metadata_dict.items():
if key == 'display_name':
if key == 'template_name':
title_element = etree.Element('{http://datacite.org/schema/kernel-4}title')
title_element.text = value
root.append(title_element)
Expand Down Expand Up @@ -465,7 +469,7 @@ def mapOAIRE(self, metadata_dict):
version_element = etree.Element('{http://purl.org/dc/elements/1.1/}version')
version_element.text = value
root.append(version_element)
if key == 'subject':
if key == 'display_name': # tag
subject_element = etree.Element('{http://namespace.openaire.eu/schema/oaire/}subject')
subject_element.text = value
root.append(subject_element)
Expand Down Expand Up @@ -501,7 +505,7 @@ def mapDC(self, metadata_dict):
etree.register_namespace('oai_dc', nsmap['oai_dc'])

for key, value in metadata_dict.items():
if key == 'display_name':
if key == 'template_name':
title_element = etree.Element('{http://purl.org/dc/elements/1.1/}title')
title_element.text = value
root.append(title_element)
Expand Down Expand Up @@ -533,14 +537,14 @@ def mapDC(self, metadata_dict):
related_identifier_element = etree.Element('{http://purl.org/dc/elements/1.1/}version')
related_identifier_element.text = value
root.append(related_identifier_element)
if key == 'tag':
if key == 'display_name': # tag
subject_element = etree.Element('{http://purl.org/dc/elements/1.1/}subject')
subject_element.text = value
root.append(subject_element)
if key == 'childs':
related_identifier_element = etree.Element('{http://purl.org/dc/elements/1.1/}relation')
# childs = value["childs"]
# related_identifier_element.text = ', '.join(childs)
childs = value
related_identifier_element.text = ', '.join(childs)
root.append(related_identifier_element)
if key == 'format':
format_element = etree.Element('{http://purl.org/dc/elements/1.1/}format')
Expand Down