Skip to content

Commit

Permalink
Merge pull request #10938 from bodintsov/fix/follow-up-fix-for-doi-cr…
Browse files Browse the repository at this point in the history
…ossref-metadata-update

[ENG-7008] Follow-up fix for DOI CrossRef metadata upload failure
  • Loading branch information
cslzchen authored Jan 22, 2025
2 parents 8d2b3e3 + 0d182e3 commit 2f0beab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
16 changes: 5 additions & 11 deletions tests/identifiers/test_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,18 @@ def test_crossref_build_metadata_versioned(self, crossref_client, preprint_versi
assert root.find('.//{%s}license_ref' % crossref.CROSSREF_ACCESS_INDICATORS).get(
'start_date') == preprint_version.date_published.strftime('%Y-%m-%d')

programs = root.findall('.//{%s}program' % crossref.CROSSREF_RELATIONS)
program_preprint = programs[0]
program_versioned = programs[1]
assert program_preprint is not None
assert program_versioned is not None
program = root.find('.//{%s}program' % crossref.CROSSREF_RELATIONS)

# program preprint version
related_item_preprint = program_preprint.find('.//{%s}related_item' % crossref.CROSSREF_RELATIONS)
assert related_item_preprint is not None
related_items = program.findall('.//{%s}related_item' % crossref.CROSSREF_RELATIONS)
assert related_items is not None
# related items
related_item_preprint, related_item_preprint_version = related_items[0], related_items[1]

intra_work_relation = related_item_preprint.find('.//{%s}intra_work_relation' % crossref.CROSSREF_RELATIONS)
assert intra_work_relation is not None
assert intra_work_relation.get('relationship-type') == 'isPreprintOf'
assert intra_work_relation.get('identifier-type') == 'doi'

# program preprint previous versions
related_item_preprint_version = program_versioned.find('.//{%s}related_item' % crossref.CROSSREF_RELATIONS)

doi = related_item_preprint_version.find('.//{%s}doi' % crossref.CROSSREF_RELATIONS)
assert doi is not None
assert doi.text == settings.DOI_FORMAT.format(prefix=preprint_version.provider.doi_prefix, guid=preprint_version._id)
Expand Down
25 changes: 12 additions & 13 deletions website/identifiers/clients/crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,17 @@ def build_posted_content(self, preprint, element, include_relation):
posted_content.append(
element.program(xmlns=CROSSREF_ACCESS_INDICATORS)
)
relations_program = element.program(xmlns=CROSSREF_RELATIONS)

if preprint.article_doi and preprint.article_doi != self.build_doi(preprint) and include_relation:
posted_content.append(
element.program(
element.related_item(
element.intra_work_relation(
preprint.article_doi,
**{'relationship-type': 'isPreprintOf', 'identifier-type': 'doi'}
)
), xmlns=CROSSREF_RELATIONS
if preprint.article_doi and preprint.article_doi != self.build_doi(preprint) and include_relation:
relations_program.append(
element.related_item(
element.intra_work_relation(
preprint.article_doi,
**{'relationship-type': 'isPreprintOf', 'identifier-type': 'doi'}
)
)

)
doi = self.build_doi(preprint)
doi_data = [
element.doi(doi),
Expand All @@ -141,7 +139,6 @@ def build_posted_content(self, preprint, element, include_relation):

preprint_versions = preprint.get_preprint_versions()
if preprint_versions:
program = element.program(xmlns=CROSSREF_RELATIONS)
for preprint_version, previous_version in zip(preprint_versions, preprint_versions[1:]):
if preprint_version.version > preprint.version:
continue
Expand All @@ -153,8 +150,10 @@ def build_posted_content(self, preprint, element, include_relation):
**{'relationship-type': 'isVersionOf', 'identifier-type': 'doi'}
)
)
program.append(related_item)
posted_content.append(program)
relations_program.append(related_item)

if len(relations_program) > 0:
posted_content.append(relations_program)
return posted_content

def _process_crossref_name(self, contributor):
Expand Down

0 comments on commit 2f0beab

Please sign in to comment.