Skip to content

Commit

Permalink
Merge pull request #645 from thoth-pub/feature/642_change_product_ava…
Browse files Browse the repository at this point in the history
…ilability

Feature/642 change product availability
  • Loading branch information
ja573 authored Nov 4, 2024
2 parents e0f28d8 + eae2726 commit 1b9725d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
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

0 comments on commit 1b9725d

Please sign in to comment.