Skip to content

Commit

Permalink
fix: bug fix on updating url
Browse files Browse the repository at this point in the history
  • Loading branch information
sagargg committed Feb 21, 2025
1 parent caac0c0 commit 273354f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ckanext/doi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ def update_doi(package_ids):
client = DataciteClient()

same = client.check_for_update(record.identifier, xml_dict)
if True:
if not same:
try:
url = xml_dict.get('alternateIdentifiers', [])[0].get('alternateIdentifier')
client.client.doi_post(record.identifier, url)
client.set_metadata(record.identifier, xml_dict)
click.secho(f'Updated "{title}"', fg='green')
except DataCiteError as e:
Expand Down
9 changes: 5 additions & 4 deletions ckanext/doi/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,9 @@ def set_metadata(self, doi, xml_dict):

# check that the data is valid, this will raise a JSON schema exception if there are issues
schema42.validator.validate(xml_dict)
url = xml_dict.get('alternateIdentifiers', [])[0].get('alternateIdentifier')


xml_doc = schema42.tostring(xml_dict)
# update the URL the DOI points to
self.client.doi_post(doi, url)

# create the metadata on datacite
self.client.metadata_post(xml_doc)

Expand Down Expand Up @@ -225,5 +222,9 @@ def update_doi(self, package_id, pkg_dict=None):
# update doi if metadata has changed
same = self.check_for_update(doi.identifier, xml_dict)
if not same:
url = xml_dict.get('alternateIdentifiers', [])[0].get('alternateIdentifier')
# update the url if it has changed
self.client.doi_post(doi.identifier, url)

# Not the same, so we want to update the metadata
self.set_metadata(doi.identifier, xml_dict)

0 comments on commit 273354f

Please sign in to comment.