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/538 update project muse onix export #609

Merged
merged 5 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- [609](https://github.com/thoth-pub/thoth/pull/609) - Update Project MUSE ONIX 3.0 export to reflect new specifications provided by Project MUSE.
brendan-oconnell marked this conversation as resolved.
Show resolved Hide resolved

## [[0.12.6]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.6) - 2024-06-17
### Fixed
Expand Down
117 changes: 95 additions & 22 deletions thoth-export-server/src/xml/onix3_project_muse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use std::io::Write;
use thoth_client::{
ContributionType, LanguageRelation, PublicationType, SubjectType, Work, WorkContributions,
WorkLanguages, WorkPublications, WorkStatus, WorkType,
WorkFundings, WorkIssues, WorkLanguages, WorkPublications, WorkStatus, WorkType,
};
use xml::writer::{EventWriter, XmlEvent};

Expand Down Expand Up @@ -158,6 +158,9 @@ impl XmlElementBlock<Onix3ProjectMuse> for Work {
})
})?;
}
for issue in &self.issues {
XmlElementBlock::<Onix3ProjectMuse>::xml_element(issue, w).ok();
}
write_element_block("TitleDetail", w, |w| {
// 01 Distinctive title (book)
write_element_block("TitleType", w, |w| {
Expand Down Expand Up @@ -204,8 +207,10 @@ impl XmlElementBlock<Onix3ProjectMuse> for Work {
})?;
}
for subject in &self.subjects {
// Project MUSE can't process records containing keywords
if subject.subject_type != SubjectType::KEYWORD {
// According to spec, Project MUSE only accepts BIC and BISAC subject codes
brendan-oconnell marked this conversation as resolved.
Show resolved Hide resolved
if subject.subject_type == SubjectType::BIC
|| subject.subject_type == SubjectType::BISAC
{
write_element_block("Subject", w, |w| {
XmlElement::<Onix3ProjectMuse>::xml_element(
&subject.subject_type,
Expand All @@ -218,6 +223,16 @@ impl XmlElementBlock<Onix3ProjectMuse> for Work {
})?;
}
}
write_element_block("Audience", w, |w| {
// 01 ONIX audience codes
write_element_block("AudienceCodeType", w, |w| {
w.write(XmlEvent::Characters("01")).map_err(|e| e.into())
})?;
// 06 Professional and scholarly
write_element_block("AudienceCodeValue", w, |w| {
w.write(XmlEvent::Characters("06")).map_err(|e| e.into())
})
})?;
Ok(())
})?;
write_element_block("CollateralDetail", w, |w| {
Expand Down Expand Up @@ -289,6 +304,9 @@ impl XmlElementBlock<Onix3ProjectMuse> for Work {
.map_err(|e| e.into())
})
})?;
for funding in &self.fundings {
XmlElementBlock::<Onix3ProjectMuse>::xml_element(funding, w).ok();
}
if let Some(place) = &self.place {
write_element_block("CityOfPublication", w, |w| {
w.write(XmlEvent::Characters(place)).map_err(|e| e.into())
Expand All @@ -314,6 +332,12 @@ impl XmlElementBlock<Onix3ProjectMuse> for Work {
},
)
})?;
write_element_block("CopyrightStatement", w, |w| {
write_element_block("CopyrightYear", w, |w| {
w.write(XmlEvent::Characters(&date.format("%Y").to_string()))
.map_err(|e| e.into())
})
})?;
}
if let Some(date) = &self.withdrawn_date {
write_element_block("PublishingDate", w, |w| {
Expand Down Expand Up @@ -372,7 +396,7 @@ impl XmlElementBlock<Onix3ProjectMuse> for Work {
supplies.insert(
landing_page.to_string(),
(
"01".to_string(),
"02".to_string(),
brendan-oconnell marked this conversation as resolved.
Show resolved Hide resolved
"Publisher's website: web shop".to_string(),
),
);
Expand Down Expand Up @@ -500,6 +524,53 @@ impl XmlElement<Onix3ProjectMuse> for LanguageRelation {
}
}

impl XmlElementBlock<Onix3ProjectMuse> for WorkFundings {
fn xml_element<W: Write>(&self, w: &mut EventWriter<W>) -> ThothResult<()> {
write_element_block("Publisher", w, |w| {
// 16 Funding body
write_element_block("PublishingRole", w, |w| {
w.write(XmlEvent::Characters("16")).map_err(|e| e.into())
})?;
write_element_block("PublisherName", w, |w| {
w.write(XmlEvent::Characters(&self.institution.institution_name))
.map_err(|e| e.into())
})?;
Ok(())
})
}
}

impl XmlElementBlock<Onix3ProjectMuse> for WorkIssues {
fn xml_element<W: Write>(&self, w: &mut EventWriter<W>) -> ThothResult<()> {
write_element_block("Collection", w, |w| {
// 10 Publisher collection (e.g. series)
write_element_block("CollectionType", w, |w| {
w.write(XmlEvent::Characters("10")).map_err(|e| e.into())
})?;
write_element_block("TitleDetail", w, |w| {
// 01 Cover title (serial)
write_element_block("TitleType", w, |w| {
w.write(XmlEvent::Characters("01")).map_err(|e| e.into())
})?;
write_element_block("TitleElement", w, |w| {
// 02 Collection level
write_element_block("TitleElementLevel", w, |w| {
w.write(XmlEvent::Characters("02")).map_err(|e| e.into())
})?;
write_element_block("SequenceNumber", w, |w| {
w.write(XmlEvent::Characters(&self.issue_ordinal.to_string()))
.map_err(|e| e.into())
})?;
write_element_block("TitleText", w, |w| {
w.write(XmlEvent::Characters(&self.series.series_name))
.map_err(|e| e.into())
})
})
})
})
}
}

impl XmlElement<Onix3ProjectMuse> for ContributionType {
const ELEMENT: &'static str = "ContributorRole";

Expand Down Expand Up @@ -914,12 +985,11 @@ mod tests {
assert!(output.contains(r#" <SubjectCode>AAB</SubjectCode>"#));
assert!(output.contains(r#" <SubjectSchemeIdentifier>10</SubjectSchemeIdentifier>"#));
assert!(output.contains(r#" <SubjectCode>AAA000000</SubjectCode>"#));
assert!(output.contains(r#" <SubjectSchemeIdentifier>04</SubjectSchemeIdentifier>"#));
assert!(output.contains(r#" <SubjectCode>JA85</SubjectCode>"#));
assert!(output.contains(r#" <SubjectSchemeIdentifier>93</SubjectSchemeIdentifier>"#));
assert!(output.contains(r#" <SubjectCode>JWA</SubjectCode>"#));
assert!(output.contains(r#" <SubjectSchemeIdentifier>B2</SubjectSchemeIdentifier>"#));
assert!(output.contains(r#" <SubjectCode>custom1</SubjectCode>"#));
assert!(output.contains(r#" <PublishingRole>16</PublishingRole>"#));
assert!(output.contains(r#" <PublisherName>Name of institution</PublisherName>"#));
assert!(output.contains(r#" <Audience>"#));
assert!(output.contains(r#" <AudienceCodeType>01</AudienceCodeType>"#));
assert!(output.contains(r#" <AudienceCodeValue>06</AudienceCodeValue>"#));
assert!(output.contains(r#" <CollateralDetail>"#));
assert!(output.contains(r#" <TextContent>"#));
assert!(output.contains(r#" <TextType>03</TextType>"#));
Expand All @@ -942,6 +1012,8 @@ mod tests {
assert!(output.contains(r#" <PublishingDate>"#));
assert!(output.contains(r#" <PublishingDateRole>01</PublishingDateRole>"#));
assert!(output.contains(r#" <Date dateformat="00">19991231</Date>"#));
assert!(output.contains(r#" <CopyrightStatement>"#));
assert!(output.contains(r#" <CopyrightYear>1999</CopyrightYear>"#));
assert!(output.contains(r#" <RelatedProduct>"#));
assert!(output.contains(r#" <ProductRelationCode>06</ProductRelationCode>"#));
assert!(output.contains(r#" <ProductIdentifier>"#));
Expand All @@ -953,7 +1025,7 @@ mod tests {
assert!(output.contains(r#" <SupplierRole>09</SupplierRole>"#));
assert!(output.contains(r#" <SupplierName>OA Editions</SupplierName>"#));
assert!(output.contains(r#" <Website>"#));
assert!(output.contains(r#" <WebsiteRole>01</WebsiteRole>"#));
assert!(output.contains(r#" <WebsiteRole>02</WebsiteRole>"#));
assert!(output.contains(
r#" <WebsiteDescription>Publisher's website: web shop</WebsiteDescription>"#
));
Expand All @@ -966,15 +1038,21 @@ mod tests {
assert!(output.contains(r#" <WebsiteDescription>Publisher's website: download the title</WebsiteDescription>"#));
assert!(output
.contains(r#" <WebsiteLink>https://www.book.com/pdf_fulltext</WebsiteLink>"#));
assert!(output.contains(r#" <Collection>"#));
assert!(output.contains(r#" <CollectionType>10</CollectionType>"#));
assert!(output.contains(r#" <TitleElementLevel>02</TitleElementLevel>"#));
assert!(output.contains(r#" <SequenceNumber>1</SequenceNumber>"#));
assert!(output.contains(r#" <TitleText>Name of series</TitleText>"#));

// Test that OAPEN-only blocks are not output in Project MUSE format
assert!(!output.contains(r#" <SubjectSchemeIdentifier>20</SubjectSchemeIdentifier>"#));
assert!(!output.contains(r#" <SubjectCode>keyword1</SubjectCode>"#));
assert!(!output.contains(r#" <Audience>"#));
assert!(!output.contains(r#" <AudienceCodeType>01</AudienceCodeType>"#));
assert!(!output.contains(r#" <AudienceCodeValue>06</AudienceCodeValue>"#));
assert!(!output.contains(r#" <PublishingRole>16</PublishingRole>"#));
assert!(!output.contains(r#" <PublisherName>Name of institution</PublisherName>"#));
assert!(!output.contains(r#" <SubjectSchemeIdentifier>04</SubjectSchemeIdentifier>"#));
assert!(!output.contains(r#" <SubjectCode>JA85</SubjectCode>"#));
assert!(!output.contains(r#" <SubjectSchemeIdentifier>93</SubjectSchemeIdentifier>"#));
assert!(!output.contains(r#" <SubjectCode>JWA</SubjectCode>"#));
assert!(!output.contains(r#" <SubjectSchemeIdentifier>B2</SubjectSchemeIdentifier>"#));
assert!(!output.contains(r#" <SubjectCode>custom1</SubjectCode>"#));
assert!(!output.contains(r#" <Funding>"#));
assert!(!output.contains(r#" <FundingIdentifier>"#));
assert!(!output.contains(r#" <FundingIDType>01</FundingIDType>"#));
Expand All @@ -984,11 +1062,6 @@ mod tests {
assert!(!output.contains(r#" <IDValue>Name of project</IDValue>"#));
assert!(!output.contains(r#" <IDTypeName>grantnumber</IDTypeName>"#));
assert!(!output.contains(r#" <IDValue>Number of grant</IDValue>"#));
assert!(!output.contains(r#" <Collection>"#));
assert!(!output.contains(r#" <CollectionType>10</CollectionType>"#));
assert!(!output.contains(r#" <TitleElementLevel>02</TitleElementLevel>"#));
assert!(!output.contains(r#" <PartNumber>1</PartNumber>"#));
assert!(!output.contains(r#" <TitleText>Name of series</TitleText>"#));

// Add withdrawn_date
test_work.withdrawn_date = chrono::NaiveDate::from_ymd_opt(2020, 12, 31);
Expand Down Expand Up @@ -1051,7 +1124,7 @@ mod tests {
assert!(!output.contains(r#" <PublishingDateRole>01</PublishingDateRole>"#));
assert!(!output.contains(r#" <Date dateformat="00">19991231</Date>"#));
// No landing page supplied: only one SupplyDetail block, linking to PDF download
assert!(!output.contains(r#" <WebsiteRole>01</WebsiteRole>"#));
assert!(!output.contains(r#" <WebsiteRole>02</WebsiteRole>"#));
assert!(!output.contains(
r#" <WebsiteDescription>Publisher's website: web shop</WebsiteDescription>"#
));
Expand Down
Loading