Skip to content

Commit

Permalink
add case where PDS4 label misses the DOI, in this case get it from tr…
Browse files Browse the repository at this point in the history
…ansaction database and raise a warning
  • Loading branch information
thomas loubrieu committed Jul 22, 2022
1 parent 25d90ec commit ed05d67
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 21 deletions.
75 changes: 54 additions & 21 deletions src/pds_doi_service/core/actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pds_doi_service.core.entities.doi import Doi
from pds_doi_service.core.entities.doi import DoiStatus
from pds_doi_service.core.entities.exceptions import collect_exception_classes_and_messages
from pds_doi_service.core.entities.exceptions import UnknownIdentifierException
from pds_doi_service.core.entities.exceptions import CriticalDOIException
from pds_doi_service.core.entities.exceptions import DuplicatedTitleDOIException
from pds_doi_service.core.entities.exceptions import InputFormatException
Expand Down Expand Up @@ -220,36 +221,68 @@ def _update_dois(self, dois):
updated_dois = []

for updated_doi in dois:
if not updated_doi.doi :
if self._force:
updated_doi.doi = self._record_service
else:
raise WarningDOIException(
f"Record provided for identifier {updated_doi.pds_identifier} does not have a DOI assigned in the label.\n"
"Use the Reserve action to acquire a DOI and add it in the Citation_Information/doi tag \n"
"if the version of PDS4 information model you are using allows it."
if updated_doi.doi:
existing_doi = self._get_doi_record_from_doi_identifier(updated_doi.doi)
elif self._force:
try:
# try to get DOI from the local database
existing_doi = self._get_doi_record_from_pds_identifier(updated_doi.pds_identifier)
except UnknownIdentifierException as e:
raise CriticalDOIException(
f"The identifier {updated_doi.pds_identifier} does not have DOI yet"
"use the reserve step to get one"
)

else:
raise WarningDOIException(
f"Record provided for identifier {updated_doi.pds_identifier} does not have a DOI assigned.\n"
"Add it in the Citation_Information/doi tag in the label\n"
" if the version of PDS4 information model you are using allows it.\n"
"Otherwise ignore this warning"
)

updated_doi = self._meld_dois(existing_doi, updated_doi)

updated_dois.append(updated_doi)

# Get the record from the transaction database for the current DOI value
transaction_record = self._list_action.transaction_for_doi(updated_doi.doi)
return updated_dois

# Get the last output label associated with the transaction.
# This represents the latest version of the metadata for the DOI.
output_label = self._list_action.output_label_for_transaction(transaction_record)
def _get_doi_record_from_pds_identifier(self, pds_identifier):

# Output labels can contain multiple entries, so get only the one for
# the current DOI value
existing_doi_label, _ = self._web_parser.get_record_for_doi(output_label, updated_doi.doi)
# Get the record from the transaction database for the current DOI value
transaction_record = self._list_action.transaction_for_identifier(pds_identifier)

# Parse the existing Doi object, and meld it with the new one
existing_dois, _ = self._web_parser.parse_dois_from_label(existing_doi_label)
# Get the last output label associated with the transaction.
# This represents the latest version of the metadata for the DOI.
output_label = self._list_action.output_label_for_transaction(transaction_record)

updated_doi = self._meld_dois(existing_dois[0], updated_doi)
# Output labels can contain multiple entries, so get only the one for
# the current DOI value
existing_doi_label, _ = self._web_parser.get_record_for_identifier(output_label, pds_identifier)

updated_dois.append(updated_doi)
# Parse the existing Doi object, and meld it with the new one
existing_dois, _ = self._web_parser.parse_dois_from_label(existing_doi_label)

return existing_dois[0]

def _get_doi_record_from_doi_identifier(self, doi_identifier):

# Get the record from the transaction database for the current DOI value
transaction_record = self._list_action.transaction_for_doi(doi_identifier)

# Get the last output label associated with the transaction.
# This represents the latest version of the metadata for the DOI.
output_label = self._list_action.output_label_for_transaction(transaction_record)

# Output labels can contain multiple entries, so get only the one for
# the current DOI value
existing_doi_label, _ = self._web_parser.get_record_for_doi(output_label, doi_identifier)

# Parse the existing Doi object, and meld it with the new one
existing_dois, _ = self._web_parser.parse_dois_from_label(existing_doi_label)

return existing_dois[0]

return updated_dois

def _validate_dois(self, dois):
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/end_to_end/bundle_pds4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://pds.nasa.gov/pds4/pds/v1">
<Identification_Area>
<<<<<<< Updated upstream
<logical_identifier>{{random_lid}}</logical_identifier>
<version_id>1.0</version_id>
<title>InSight Cameras Bundle</title>
=======
<logical_identifier>urn:nasa:pds:insight_cameras</logical_identifier>
<version_id>54.0</version_id>
<title>InSight Cameras XXXX Example Bundle</title>
>>>>>>> Stashed changes
<information_model_version>1.11.1.0</information_model_version>
<product_class>Product_Bundle</product_class>
<Citation_Information>
Expand All @@ -20,6 +26,10 @@
<description>
InSight Cameras Experiment Data Record (EDR) and Reduced Data Record (RDR) Data Products
</description>
<<<<<<< Updated upstream
=======
<doi>10.13143/43g3-kk20</doi>
>>>>>>> Stashed changes
</Citation_Information>
</Identification_Area>
<Context_Area>
Expand Down

0 comments on commit ed05d67

Please sign in to comment.