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/642 change product availability #645

Merged
merged 4 commits into from
Nov 4, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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
- [642](https://github.com/thoth-pub/thoth/issues/642) - Output `ProductAvailability` based on work status in Thoth ONIX 3.0
- [642](https://github.com/thoth-pub/thoth/issues/642) - Use `UnpricedItemType` code `01` (Free of charge) for unpriced products in Thoth ONIX 3.0


## [[0.12.13]](https://github.com/thoth-pub/thoth/releases/tag/v0.12.13) - 2024-10-23
### Fixed
Expand Down
21 changes: 15 additions & 6 deletions thoth-export-server/src/xml/onix3_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,9 +924,18 @@ impl XmlElementBlock<Onix3Thoth> for Work {
}
Ok(())
})?;
// 99 Contact supplier
write_element_block("ProductAvailability", w, |w| {
w.write(XmlEvent::Characters("99")).map_err(|e| e.into())
let availability = match self.work_status {
WorkStatus::CANCELLED => "01", // 01 – Cancelled
WorkStatus::FORTHCOMING => "10", // 10 – Not yet available
WorkStatus::POSTPONED_INDEFINITELY => "09", // 09 – Not yet available, postponed indefinitely
WorkStatus::ACTIVE => "20", // 20 – Available
WorkStatus::SUPERSEDED => "41", // 41 – Not available, replaced by new product
WorkStatus::WITHDRAWN => "49", // 49 – Recalled
WorkStatus::Other(_) => unreachable!(),
};
w.write(XmlEvent::Characters(availability))
.map_err(|e| e.into())
})?;
if let Some(date) = &self.publication_date {
write_element_block("SupplyDate", w, |w| {
Expand All @@ -949,9 +958,9 @@ impl XmlElementBlock<Onix3Thoth> for Work {
})?;
}
if publication.prices.is_empty() {
// 04 Contact supplier
// 01 Free of charge
write_element_block("UnpricedItemType", w, |w| {
w.write(XmlEvent::Characters("04")).map_err(|e| e.into())
w.write(XmlEvent::Characters("01")).map_err(|e| e.into())
})
} else {
for price in &publication.prices {
Expand Down Expand Up @@ -2836,7 +2845,7 @@ mod tests {
<WebsiteLink>https://www.book.com/pb_landing</WebsiteLink>
</Website>
</Supplier>
<ProductAvailability>99</ProductAvailability>
<ProductAvailability>20</ProductAvailability>
<SupplyDate>
<SupplyDateRole>08</SupplyDateRole>
<Date dateformat="00">19991231</Date>
Expand Down Expand Up @@ -3357,7 +3366,7 @@ mod tests {
</Website>"#
));
// UnpricedItemType block instead of any Prices
assert!(output.contains(r#" <UnpricedItemType>04</UnpricedItemType>"#));
assert!(output.contains(r#" <UnpricedItemType>01</UnpricedItemType>"#));
assert!(!output.contains(r#" <Price>"#));

// Remove chapter DOI: can't output ContentDetail block
Expand Down
Loading