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

Implement ONIX 2.1 output compliant with EBSCO Host requirements (#49, #43) #290

Merged
merged 11 commits into from
Oct 1, 2021
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
14 changes: 14 additions & 0 deletions thoth-app/src/models/work/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub trait DisplayWork {
fn onix_projectmuse_endpoint(&self) -> String;
fn onix_oapen_endpoint(&self) -> String;
fn onix_jstor_endpoint(&self) -> String;
fn onix_ebsco_host_endpoint(&self) -> String;
fn csv_endpoint(&self) -> String;
fn kbart_endpoint(&self) -> String;
fn cover_alt_text(&self) -> String;
Expand Down Expand Up @@ -149,6 +150,13 @@ impl DisplayWork for WorkWithRelations {
)
}

fn onix_ebsco_host_endpoint(&self) -> String {
format!(
"{}/specifications/onix_2.1::ebsco_host/work/{}",
THOTH_EXPORT_API, &self.work_id
)
}

fn csv_endpoint(&self) -> String {
format!(
"{}/specifications/csv::thoth/work/{}",
Expand Down Expand Up @@ -370,6 +378,12 @@ impl DisplayWork for WorkWithRelations {
>
{"ONIX (JSTOR)"}
</a>
<a
href={self.onix_ebsco_host_endpoint()}
class="dropdown-item"
>
{"ONIX (EBSCO Host)"}
</a>
<a
href={self.csv_endpoint()}
class="dropdown-item"
Expand Down
1 change: 1 addition & 0 deletions thoth-client/assets/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fragment Work on Work {
imprintName
publisher {
publisherName
publisherUrl
}
}
issues {
Expand Down
1 change: 1 addition & 0 deletions thoth-export-server/src/csv/csv_thoth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ mod tests {
imprint_name: "OA Editions Imprint".to_string(),
publisher: WorkImprintPublisher {
publisher_name: "OA Editions".to_string(),
publisher_url: None,
},
},
issues: vec![],
Expand Down
1 change: 1 addition & 0 deletions thoth-export-server/src/csv/kbart_oclc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ mod tests {
imprint_name: "OA Editions Imprint".to_string(),
publisher: WorkImprintPublisher {
publisher_name: "OA Editions".to_string(),
publisher_url: None,
},
},
issues: vec![
Expand Down
23 changes: 23 additions & 0 deletions thoth-export-server/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ lazy_static! {
format: concat!(env!("THOTH_EXPORT_API"), "/formats/onix_3.0"),
accepted_by: vec![concat!(env!("THOTH_EXPORT_API"), "/platforms/jstor"),],
},
Specification {
id: "onix_2.1::ebsco_host",
name: "EBSCO Host ONIX 2.1",
format: concat!(env!("THOTH_EXPORT_API"), "/formats/onix_2.1"),
accepted_by: vec![concat!(env!("THOTH_EXPORT_API"), "/platforms/ebsco_host"),],
},
Specification {
id: "csv::thoth",
name: "Thoth CSV",
Expand Down Expand Up @@ -77,6 +83,14 @@ lazy_static! {
"/specifications/onix_3.0::jstor"
),],
},
Platform {
id: "ebsco_host",
name: "EBSCO Host",
accepts: vec![concat!(
env!("THOTH_EXPORT_API"),
"/specifications/onix_2.1::ebsco_host"
),],
},
Platform {
id: "oclc_kb",
name: "OCLC KB",
Expand Down Expand Up @@ -131,6 +145,15 @@ lazy_static! {
concat!(env!("THOTH_EXPORT_API"), "/specifications/onix_3.0::oapen"),
],
},
Format {
id: "onix_2.1",
name: "ONIX",
version: Some("2.1"),
specifications: vec![concat!(
env!("THOTH_EXPORT_API"),
"/specifications/onix_2.1::ebsco_host"
),],
},
Format {
id: "csv",
name: "CSV",
Expand Down
33 changes: 29 additions & 4 deletions thoth-export-server/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ use thoth_client::Work;
use thoth_errors::{ThothError, ThothResult};

use crate::csv::{CsvSpecification, CsvThoth, KbartOclc};
use crate::xml::{Onix3Jstor, Onix3Oapen, Onix3ProjectMuse, XmlSpecification};
use crate::xml::{Onix21EbscoHost, Onix3Jstor, Onix3Oapen, Onix3ProjectMuse, XmlSpecification};

pub(crate) trait AsRecord {}
impl AsRecord for Vec<Work> {}

pub const DELIMITER_COMMA: u8 = b',';
pub const DELIMITER_TAB: u8 = b'\t';
pub const XML_DECLARATION: &str = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
pub const DOCTYPE_ONIX21_REF: &str = "<!DOCTYPE ONIXMessage SYSTEM \"http://www.editeur.org/onix/2.1/reference/onix-international.dtd\">\n";

pub(crate) enum MetadataSpecification {
Onix3ProjectMuse(Onix3ProjectMuse),
Onix3Oapen(Onix3Oapen),
Onix3Jstor(Onix3Jstor),
Onix21EbscoHost(Onix21EbscoHost),
CsvThoth(CsvThoth),
KbartOclc(KbartOclc),
}
Expand Down Expand Up @@ -56,6 +59,7 @@ where
MetadataSpecification::Onix3ProjectMuse(_) => Self::XML_MIME_TYPE,
MetadataSpecification::Onix3Oapen(_) => Self::XML_MIME_TYPE,
MetadataSpecification::Onix3Jstor(_) => Self::XML_MIME_TYPE,
MetadataSpecification::Onix21EbscoHost(_) => Self::XML_MIME_TYPE,
MetadataSpecification::CsvThoth(_) => Self::CSV_MIME_TYPE,
MetadataSpecification::KbartOclc(_) => Self::TXT_MIME_TYPE,
}
Expand All @@ -66,6 +70,7 @@ where
MetadataSpecification::Onix3ProjectMuse(_) => self.xml_file_name(),
MetadataSpecification::Onix3Oapen(_) => self.xml_file_name(),
MetadataSpecification::Onix3Jstor(_) => self.xml_file_name(),
MetadataSpecification::Onix21EbscoHost(_) => self.xml_file_name(),
MetadataSpecification::CsvThoth(_) => self.csv_file_name(),
MetadataSpecification::KbartOclc(_) => self.txt_file_name(),
}
Expand Down Expand Up @@ -101,10 +106,17 @@ impl MetadataRecord<Vec<Work>> {
fn generate(&self) -> ThothResult<String> {
match &self.specification {
MetadataSpecification::Onix3ProjectMuse(onix3_project_muse) => {
onix3_project_muse.generate(&self.data)
onix3_project_muse.generate(&self.data, None)
}
MetadataSpecification::Onix3Oapen(onix3_oapen) => {
onix3_oapen.generate(&self.data, None)
}
MetadataSpecification::Onix3Jstor(onix3_jstor) => {
onix3_jstor.generate(&self.data, None)
}
MetadataSpecification::Onix21EbscoHost(onix21_ebsco_host) => {
onix21_ebsco_host.generate(&self.data, Some(DOCTYPE_ONIX21_REF))
}
MetadataSpecification::Onix3Oapen(onix3_oapen) => onix3_oapen.generate(&self.data),
MetadataSpecification::Onix3Jstor(onix3_jstor) => onix3_jstor.generate(&self.data),
MetadataSpecification::CsvThoth(csv_thoth) => {
csv_thoth.generate(&self.data, QuoteStyle::Always, DELIMITER_COMMA)
}
Expand Down Expand Up @@ -162,6 +174,9 @@ impl FromStr for MetadataSpecification {
}
"onix_3.0::oapen" => Ok(MetadataSpecification::Onix3Oapen(Onix3Oapen {})),
"onix_3.0::jstor" => Ok(MetadataSpecification::Onix3Jstor(Onix3Jstor {})),
"onix_2.1::ebsco_host" => {
Ok(MetadataSpecification::Onix21EbscoHost(Onix21EbscoHost {}))
}
"csv::thoth" => Ok(MetadataSpecification::CsvThoth(CsvThoth {})),
"kbart::oclc" => Ok(MetadataSpecification::KbartOclc(KbartOclc {})),
_ => Err(ThothError::InvalidMetadataSpecification(input.to_string())),
Expand All @@ -175,6 +190,7 @@ impl ToString for MetadataSpecification {
MetadataSpecification::Onix3ProjectMuse(_) => "onix_3.0::project_muse".to_string(),
MetadataSpecification::Onix3Oapen(_) => "onix_3.0::oapen".to_string(),
MetadataSpecification::Onix3Jstor(_) => "onix_3.0::jstor".to_string(),
MetadataSpecification::Onix21EbscoHost(_) => "onix_2.1::ebsco_host".to_string(),
MetadataSpecification::CsvThoth(_) => "csv::thoth".to_string(),
MetadataSpecification::KbartOclc(_) => "kbart::oclc".to_string(),
}
Expand Down Expand Up @@ -232,6 +248,15 @@ mod tests {
to_test.file_name(),
"onix_3.0__jstor__some_id.xml".to_string()
);
let to_test = MetadataRecord::new(
"some_id".to_string(),
MetadataSpecification::Onix21EbscoHost(Onix21EbscoHost {}),
vec![],
);
assert_eq!(
to_test.file_name(),
"onix_2.1__ebsco_host__some_id.xml".to_string()
);
let to_test = MetadataRecord::new(
"some_id".to_string(),
MetadataSpecification::KbartOclc(KbartOclc {}),
Expand Down
10 changes: 8 additions & 2 deletions thoth-export-server/src/xml/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::record::XML_DECLARATION;
use std::collections::HashMap;
use std::io::Write;
use thoth_client::Work;
Expand Down Expand Up @@ -42,9 +43,12 @@ pub(crate) fn write_full_element_block<W: Write, F: Fn(&mut EventWriter<W>) -> T
}

pub(crate) trait XmlSpecification {
fn generate(&self, works: &[Work]) -> ThothResult<String> {
let mut buffer = Vec::new();
fn generate(&self, works: &[Work], doctype: Option<&str>) -> ThothResult<String> {
let mut buffer = format!("{}{}", XML_DECLARATION, doctype.unwrap_or_default())
.as_bytes()
.to_vec();
let mut writer = EmitterConfig::new()
.write_document_declaration(false)
.perform_indent(true)
.create_writer(&mut buffer);
Self::handle_event(&mut writer, works)
Expand Down Expand Up @@ -81,3 +85,5 @@ mod onix3_oapen;
pub(crate) use onix3_oapen::Onix3Oapen;
mod onix3_jstor;
pub(crate) use onix3_jstor::Onix3Jstor;
mod onix21_ebsco_host;
pub(crate) use onix21_ebsco_host::Onix21EbscoHost;
Loading