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

Feature/update ebsco related products #625

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- [623](https://github.com/thoth-pub/thoth/pull/623) - Convert connection pool errors (`r2d2::Error`) to `ThothError`
- [625](https://github.com/thoth-pub/thoth/pull/625) - Use relationcode 13 for physical ISBNs in ONIX 2.1 EBSCOHost output

## [[0.12.8]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.8) - 2024-09-03
### Fixed
Expand Down
72 changes: 43 additions & 29 deletions thoth-export-server/src/xml/onix21_ebsco_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ impl XmlElementBlock<Onix21EbscoHost> for Work {
.map_err(|e| e.into())
})
})?;
write_element_block("ProductIdentifier", w, |w| {
// 15 ISBN-13
write_element_block("ProductIDType", w, |w| {
w.write(XmlEvent::Characters("15")).map_err(|e| e.into())
if let Some(isbn) = &main_isbn {
write_element_block("ProductIdentifier", w, |w| {
// 15 ISBN-13
write_element_block("ProductIDType", w, |w| {
w.write(XmlEvent::Characters("15")).map_err(|e| e.into())
})?;
write_element_block("IDValue", w, |w| {
w.write(XmlEvent::Characters(isbn)).map_err(|e| e.into())
})
})?;
write_element_block("IDValue", w, |w| {
w.write(XmlEvent::Characters(&main_isbn))
.map_err(|e| e.into())
})
})?;
}
if let Some(doi) = &self.doi {
write_element_block("ProductIdentifier", w, |w| {
write_element_block("ProductIDType", w, |w| {
Expand Down Expand Up @@ -365,11 +366,16 @@ impl XmlElementBlock<Onix21EbscoHost> for Work {
})
})?;
if !isbns.is_empty() {
for isbn in &isbns {
for (publication_type, isbn) in &isbns {
let relation_code = match publication_type {
PublicationType::PAPERBACK | PublicationType::HARDBACK => "13", // Epublication based on (print product)
_ => "06", // Alternative format
};

write_element_block("RelatedProduct", w, |w| {
// 06 Alternative format
write_element_block("RelationCode", w, |w| {
w.write(XmlEvent::Characters("06")).map_err(|e| e.into())
w.write(XmlEvent::Characters(relation_code))
.map_err(|e| e.into())
})?;
write_element_block("ProductIdentifier", w, |w| {
// 15 ISBN-13
Expand Down Expand Up @@ -434,24 +440,31 @@ impl XmlElementBlock<Onix21EbscoHost> for Work {
}
}

fn get_publications_data(publications: &[WorkPublications]) -> (String, Vec<String>) {
let mut main_isbn = "".to_string();
let mut isbns: Vec<String> = Vec::new();
fn get_publications_data(
publications: &[WorkPublications],
) -> (Option<String>, Vec<(PublicationType, String)>) {
let isbns: Vec<(PublicationType, String)> = publications
.iter()
.filter_map(|publication| {
publication.isbn.as_ref().map(|isbn| {
(
publication.publication_type.clone(),
isbn.to_hyphenless_string(),
)
})
})
.collect();

for publication in publications {
if let Some(isbn) = &publication.isbn.as_ref() {
isbns.push(isbn.to_hyphenless_string());
// The default product ISBN is the PDF's
if publication.publication_type.eq(&PublicationType::PDF) {
main_isbn = isbn.to_hyphenless_string();
}
// Books that don't have a PDF ISBN will use the paperback's
if publication.publication_type.eq(&PublicationType::PAPERBACK) && main_isbn.is_empty()
{
main_isbn = isbn.to_hyphenless_string();
}
}
}
// The default product ISBN is the PDF's, and fallback to a paperback if not found
let main_isbn = isbns
.iter()
.find(|(publication_type, _)| publication_type == &PublicationType::PDF)
.or_else(|| {
isbns
.iter()
.find(|(publication_type, _)| publication_type == &PublicationType::PAPERBACK)
})
.map(|(_, isbn)| isbn.clone());

(main_isbn, isbns)
}
Expand Down Expand Up @@ -1069,6 +1082,7 @@ mod tests {
assert!(output.contains(r#" <RightsTerritory>WORLD</RightsTerritory>"#));
assert!(output.contains(r#" <RelatedProduct>"#));
assert!(output.contains(r#" <RelationCode>06</RelationCode>"#));
assert!(output.contains(r#" <RelationCode>13</RelationCode>"#));
assert!(output.contains(r#" <ProductIdentifier>"#));
assert!(output.contains(r#" <ProductIDType>15</ProductIDType>"#));
assert!(output.contains(r#" <IDValue>9783161484100</IDValue>"#));
Expand Down
Loading