Skip to content

Commit

Permalink
Merge pull request #625 from thoth-pub/feature/update_ebsco_related_p…
Browse files Browse the repository at this point in the history
…roducts

Feature/update ebsco related products
  • Loading branch information
ja573 authored Sep 5, 2024
2 parents 40f8c5e + fd093d4 commit eed9007
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
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

0 comments on commit eed9007

Please sign in to comment.