Skip to content

Commit

Permalink
Updated onix3_google_books.rs to allow BIC, BISAC or LCC Subject code…
Browse files Browse the repository at this point in the history
…s, onix3_jstor.rs to only allow BISAC codes
  • Loading branch information
brendan-oconnell committed Feb 23, 2024
1 parent 2581a13 commit a24386b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions thoth-export-server/src/xml/onix3_google_books.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ impl XmlSpecification for Onix3GoogleBooks {

impl XmlElementBlock<Onix3GoogleBooks> for Work {
fn xml_element<W: Write>(&self, w: &mut EventWriter<W>) -> ThothResult<()> {
// Don't output works with no BIC or BISAC subject code
// Don't output works with no BIC, BISAC or LCC subject code
// Google Books can only ingest works which have at least one
if !self
.subjects
.iter()
.any(|s| matches!(s.subject_type, SubjectType::BISAC | SubjectType::BIC))
.any(|s| matches!(s.subject_type, SubjectType::BISAC | SubjectType::BIC | SubjectType::LCC))
{
return Err(ThothError::IncompleteMetadataRecord(
ONIX_ERROR.to_string(),
"No BIC or BISAC subject code".to_string(),
"No BIC, BISAC or LCC subject code".to_string(),
));
}
// Don't output works with no publication date (mandatory in Google Books)
Expand Down Expand Up @@ -1117,12 +1117,12 @@ mod tests {
assert!(!output.contains(r#" <Text language="eng">1. Chapter 1</Text>"#));

// Remove all subjects
// Result: error (can't generate Google Books ONIX without either a BIC or BISAC subject)
// Result: error (can't generate Google Books ONIX without a BIC, BISAC, or LCC subject)
test_work.subjects.clear();
let output = generate_test_output(false, &test_work);
assert_eq!(
output,
"Could not generate onix_3.0::google_books: No BIC or BISAC subject code".to_string()
"Could not generate onix_3.0::google_books: No BIC, BISAC or LCC subject code".to_string()
);

// Reinstate the BIC subject but remove publication date: result is error
Expand Down
16 changes: 8 additions & 8 deletions thoth-export-server/src/xml/onix3_jstor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ impl XmlSpecification for Onix3Jstor {

impl XmlElementBlock<Onix3Jstor> for Work {
fn xml_element<W: Write>(&self, w: &mut EventWriter<W>) -> ThothResult<()> {
// Don't output works with no BIC or BISAC subject code
// Don't output works with no BISAC subject code
// JSTOR can only ingest works which have at least one
if !self
.subjects
.iter()
.any(|s| matches!(s.subject_type, SubjectType::BISAC | SubjectType::BIC))
.any(|s| matches!(s.subject_type, SubjectType::BISAC))
{
return Err(ThothError::IncompleteMetadataRecord(
ONIX_ERROR.to_string(),
"No BIC or BISAC subject code".to_string(),
"No BISAC subject code".to_string(),
));
}
// We can only generate the document if there's a PDF
Expand Down Expand Up @@ -1031,19 +1031,19 @@ mod tests {
assert!(!output.contains(r#" <IDValue>9781402894626</IDValue>"#));

// Remove all subjects
// Result: error (can't generate JSTOR ONIX without either a BIC or BISAC subject)
// Result: error (can't generate JSTOR ONIX without a BISAC subject)
test_work.subjects.clear();
let output = generate_test_output(false, &test_work);
assert_eq!(
output,
"Could not generate onix_3.0::jstor: No BIC or BISAC subject code".to_string()
"Could not generate onix_3.0::jstor: No BISAC subject code".to_string()
);

// Reinstate the BIC subject but remove the only publication, which is the PDF
// Reinstate the BISAC subject but remove the only publication, which is the PDF
// Result: error (can't generate JSTOR ONIX without PDF URL)
test_work.subjects = vec![WorkSubjects {
subject_code: "AAB".to_string(),
subject_type: SubjectType::BIC,
subject_code: "AAA000000".to_string(),
subject_type: SubjectType::BISAC,
subject_ordinal: 1,
}];
test_work.publications.clear();
Expand Down

0 comments on commit a24386b

Please sign in to comment.