Skip to content

Commit

Permalink
Add logic for crossmark to crossref doi deposit export
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-oconnell committed Jun 6, 2024
1 parent f00fbd4 commit 4679a67
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 20 deletions.
2 changes: 2 additions & 0 deletions thoth-client/assets/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ fragment Work on Work {
doi
publicationDate
withdrawnDate
workStatus
license
shortAbstract
longAbstract
Expand All @@ -175,6 +176,7 @@ fragment Work on Work {
pageInterval
landingPage
imprint {
crossmarkDoi
publisher {
publisherName
}
Expand Down
4 changes: 4 additions & 0 deletions thoth-export-server/src/bibtex/bibtex_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ mod tests {
relation_type: RelationType::IS_CHILD_OF,
relation_ordinal: 7,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Related work title".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -491,6 +492,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand All @@ -505,6 +507,7 @@ mod tests {
relation_type: RelationType::HAS_TRANSLATION,
relation_ordinal: 4,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Irrelevant related work".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -522,6 +525,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down
4 changes: 4 additions & 0 deletions thoth-export-server/src/csv/csv_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ mod tests {
relation_type: RelationType::HAS_CHILD,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Related work title".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -841,6 +842,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down Expand Up @@ -1151,6 +1153,7 @@ mod tests {
relation_type: RelationType::HAS_CHILD,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Related work title".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -1168,6 +1171,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down
2 changes: 2 additions & 0 deletions thoth-export-server/src/json/json_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ mod tests {
relation_type: RelationType::HAS_CHILD,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Related work title".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -402,6 +403,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down
2 changes: 2 additions & 0 deletions thoth-export-server/src/marc21/marc21record_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ pub(crate) mod tests {
relation_type: RelationType::HAS_CHILD,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Chapter One".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -1082,6 +1083,7 @@ pub(crate) mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down
132 changes: 112 additions & 20 deletions thoth-export-server/src/xml/doideposit_crossref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,28 +334,116 @@ fn work_metadata<W: Write>(
Ok(())
})?;
}
if !work.fundings.is_empty() {
write_full_element_block("fr:program", Some(vec![("name", "fundref")]), w, |w| {
for funding in &work.fundings {
XmlElementBlock::<DoiDepositCrossref>::xml_element(funding, w)?;
}
Ok(())

if let Some(crossmark_doi) = &work.imprint.crossmark_doi {

let update_type = match &work.work_status {
thoth_client::WorkStatus::WITHDRAWN_FROM_SALE => "withdrawal",
thoth_client::WorkStatus::SUPERSEDED => "new_edition",
// Only the above work_status count as an "update" in crossmark.
thoth_client::WorkStatus::FORTHCOMING
| thoth_client::WorkStatus::ACTIVE
| thoth_client::WorkStatus::POSTPONED_INDEFINITELY
| thoth_client::WorkStatus::CANCELLED
| thoth_client::WorkStatus::Other(_) => "no_update",
};

let new_edition_with_doi: Vec<WorkRelations> = work
.relations
.filter(|r| {
r.relation_type == RelationType::IS_REPLACED_BY && r.related_work.doi.is_some()
});

write_element_block("crossmark", w, |w| {
write_element_block("crossmark_version", w, |w| {
w.write(XmlEvent::Characters("2"))
.map_err(|e| e.into())
})?;
write_element_block("crossmark_policy", w, |w| {
w.write(XmlEvent::Characters(&crossmark_doi.to_string()))
.map_err(|e| e.into())
})?;
if update_type != "no_update" {
write_element_block("updates", w, |w| {
if let Some(withdrawn_date) = &work.withdrawn_date {
if let Some(new_edition_doi) = new_edition_with_doi.doi {
write_full_element_block("update",
Some(vec![("type", update_type), ("date", &withdrawn_date.to_string())]),
w, |w| {
w.write(XmlEvent::Characters(&new_edition_doi.to_string()))
.map_err(|e| e.into())
})
} else {
if let Some(doi) = &work.doi {
write_full_element_block("update",
Some(vec![("type", update_type), ("date", &withdrawn_date.to_string())]),
w, |w| {
w.write(XmlEvent::Characters(&doi.to_string()))
.map_err(|e| e.into())
})
} else {
Ok(())
}
}
} else {
Ok(())
}
})
} else {
Ok(())
}?;
// If crossmark metadata is included, funding and access data must be inside the <crossmark> element
// within <custom_metadata> tag
write_element_block("custom_metadata", w, |w| {
if !work.fundings.is_empty() {
write_full_element_block("fr:program", Some(vec![("name", "fundref")]), w, |w| {
for funding in &work.fundings {
XmlElementBlock::<DoiDepositCrossref>::xml_element(funding, w)?;
}
Ok(())
})?;
}
write_full_element_block(
"ai:program",
Some(vec![("name", "AccessIndicators")]),
w,
|w| {
write_element_block("ai:free_to_read", w, |_w| Ok(()))?;
if let Some(license) = &work.license {
write_element_block("ai:license_ref", w, |w| {
w.write(XmlEvent::Characters(license)).map_err(|e| e.into())
})?;
}
Ok(())
},
)
})
})?;
} else {
if !work.fundings.is_empty() {
write_full_element_block("fr:program", Some(vec![("name", "fundref")]), w, |w| {
for funding in &work.fundings {
XmlElementBlock::<DoiDepositCrossref>::xml_element(funding, w)?;
}
Ok(())
})?;
}
write_full_element_block(
"ai:program",
Some(vec![("name", "AccessIndicators")]),
w,
|w| {
write_element_block("ai:free_to_read", w, |_w| Ok(()))?;
if let Some(license) = &work.license {
write_element_block("ai:license_ref", w, |w| {
w.write(XmlEvent::Characters(license)).map_err(|e| e.into())
})?;
}
Ok(())
},
)?;
}
write_full_element_block(
"ai:program",
Some(vec![("name", "AccessIndicators")]),
w,
|w| {
write_element_block("ai:free_to_read", w, |_w| Ok(()))?;
if let Some(license) = &work.license {
write_element_block("ai:license_ref", w, |w| {
w.write(XmlEvent::Characters(license)).map_err(|e| e.into())
})?;
}
Ok(())
},
)?;

if let Some(doi) = &work.doi {
if let Some(landing_page) = &work.landing_page {
write_element_block("doi_data", w, |w| {
Expand Down Expand Up @@ -827,6 +915,7 @@ mod tests {
relation_type: RelationType::HAS_CHILD,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Chapter: One".to_string(),
title: "Chapter".to_string(),
subtitle: Some("One".to_string()),
Expand All @@ -844,6 +933,7 @@ mod tests {
page_interval: Some("10–20".to_string()),
landing_page: Some("https://www.book.com/chapter_one".to_string()),
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "Chapter One Publisher".to_string(),
},
Expand Down Expand Up @@ -1281,6 +1371,7 @@ mod tests {
relation_type: RelationType::HAS_PART,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Part: One".to_string(),
title: "Part".to_string(),
subtitle: Some("One".to_string()),
Expand All @@ -1298,6 +1389,7 @@ mod tests {
page_interval: Some("10–20".to_string()),
landing_page: Some("https://www.book.com/part_one".to_string()),
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "Part One Publisher".to_string(),
},
Expand Down
8 changes: 8 additions & 0 deletions thoth-export-server/src/xml/onix3_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,7 @@ mod tests {
relation_type: RelationType::HAS_TRANSLATION,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "N/A".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -2041,6 +2042,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down Expand Up @@ -2239,6 +2241,7 @@ mod tests {
relation_type: RelationType::HAS_CHILD,
relation_ordinal: 1,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "Related work title".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -2256,6 +2259,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand All @@ -2270,6 +2274,7 @@ mod tests {
relation_type: RelationType::HAS_PART,
relation_ordinal: 2,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "N/A".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -2287,6 +2292,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand All @@ -2301,6 +2307,7 @@ mod tests {
relation_type: RelationType::HAS_TRANSLATION,
relation_ordinal: 3,
related_work: WorkRelationsRelatedWork {
work_status: WorkStatus::ACTIVE,
full_title: "N/A".to_string(),
title: "N/A".to_string(),
subtitle: None,
Expand All @@ -2318,6 +2325,7 @@ mod tests {
page_interval: None,
landing_page: None,
imprint: WorkRelationsRelatedWorkImprint {
crossmark_doi: None,
publisher: WorkRelationsRelatedWorkImprintPublisher {
publisher_name: "N/A".to_string(),
},
Expand Down

0 comments on commit 4679a67

Please sign in to comment.