Loading acorn-lib/src/schema/mod.rs +29 −17 Original line number Diff line number Diff line Loading @@ -960,31 +960,43 @@ impl ResearchActivity { | None => sections.to_string(), } } /// Format research activity data /// Formats research activity data /// /// Actions: /// - Resolves URL of first media object (if found) and add empty caption /// - Resolves keywords, technology, organization, partners, sponsors, and affiliation using fuzzy matching against controlled vocabularies /// - Formats telephone number pub fn format(self, path: Option<PathBuf>) -> ResearchActivity { let mut clone = self.clone().copy(); let parent = match path { | Some(value) => value.parent().unwrap().to_path_buf(), | None => PathBuf::from("."), }; let name = match image_paths(parent.clone()) { | value if !value.is_empty() => value[0].file_name().unwrap().to_string_lossy().to_string(), | _ => DEFAULT_GRAPHIC_HREF.to_string(), | value if !value.is_empty() => Some(value[0].file_name().unwrap().to_string_lossy().to_string()), | _ => None, }; debug!(name, "=> {} First image", Label::using()); if let Some(value) = name { debug!(value, "=> {} First image", Label::using()); // Make sure first graphic is well formed with a resolved image URL and caption let first_graphic = match self.meta.clone().media { | Some(values) if !values.is_empty() => { let caption = self.meta.clone().first_image_caption(); let image_data = ImageObject::init().caption(caption.to_string()).content_url(name.clone()).build(); let image_data = ImageObject::init().caption(caption.to_string()).content_url(value.clone()).build(); MediaObject::Image(image_data) } | Some(_) | None => { let image_data = ImageObject::init().caption("".to_string()).content_url(name.clone()).build(); let image_data = ImageObject::init().caption("".to_string()).content_url(value.clone()).build(); MediaObject::Image(image_data) } }; let mut clone = self.clone().copy(); // TODO: Add rest of media objects to clone.meta.media clone.meta.media = Some(vec![first_graphic]); // Get the rest of the media objects let rest = match self.clone().meta.media { | Some(values) if !values.is_empty() => values.into_iter().skip(1).collect::<Vec<_>>(), | Some(_) | None => vec![], }; clone.meta.media = Some([vec![first_graphic], rest].concat()); }; clone.meta.keywords = self.clone().resolve(FuzzyValue::Keyword); clone.meta.technology = self.clone().resolve(FuzzyValue::Technology); clone.contact.telephone = match format_phone_number(&self.contact.telephone) { Loading acorn-lib/src/schema/tests/mod.rs +10 −10 Original line number Diff line number Diff line Loading @@ -257,30 +257,30 @@ fn test_research_activity_format() { assert!(pre.meta.media.is_some()); assert_eq!(pre.contact.affiliation, Some("Not an actual affiliation".to_string())); let post = pre.format(None); assert_eq!(post.clone().meta.media.unwrap()[0].clone().content_url(), Some("00.png".to_string())); assert!(post.clone().meta.media.unwrap()[0].clone().content_url().is_none()); assert_eq!(post.clone().meta.first_image().unwrap().description(), "".to_string()); assert_eq!(post.contact.affiliation, Some("Oak Ridge National Laboratory".to_string())); // // // // with more unresolved changes // // // // with more unresolved changes // let mut pre = post.clone().copy(); pre.contact.organization = "Not an actual organization".to_string(); pre.contact.affiliation = None; let post = pre.format(None); assert_eq!(post.contact.organization, "".to_string()); assert_eq!(post.contact.affiliation, Some("Oak Ridge National Laboratory".to_string())); // // // // with ORNL as organization and no affiliation // // // // with ORNL as organization and no affiliation // let mut pre = post.clone().copy(); pre.contact.organization = "Oak Ridge National Laboratory".to_string(); pre.contact.affiliation = None; let post = pre.format(None); assert_eq!(post.contact.organization, "Oak Ridge National Laboratory".to_string()); assert_eq!(post.contact.affiliation, Some("Oak Ridge National Laboratory".to_string())); // // // // without changes // // // // without changes // let pre = ResearchActivity::read(PathBuf::from(FIXTURES).join("data/format/no_changes.json")).unwrap(); assert_eq!(pre.clone().meta.media.unwrap()[0].clone().content_url(), Some("00.png".to_string())); assert_eq!(pre.contact.affiliation, Some("National Security Sciences Directorate".to_string())); Loading lcov.info +1462 −1269 File changed.Preview size limit exceeded, changes collapsed. Show changes tests/fixtures/data/valid_highlight/abc.png 0 → 100644 +0 −0 Empty file added. tests/fixtures/data/valid_highlight/valid_highlight.json +1 −5 Original line number Diff line number Diff line Loading @@ -10,11 +10,7 @@ "url": "https://code.ornl.gov/research-enablement/acorn" } ], "graphics": [ { "caption": "This is an image caption." } ], "media": [], "keywords": [], "sponsors": [ "ORNL" Loading Loading
acorn-lib/src/schema/mod.rs +29 −17 Original line number Diff line number Diff line Loading @@ -960,31 +960,43 @@ impl ResearchActivity { | None => sections.to_string(), } } /// Format research activity data /// Formats research activity data /// /// Actions: /// - Resolves URL of first media object (if found) and add empty caption /// - Resolves keywords, technology, organization, partners, sponsors, and affiliation using fuzzy matching against controlled vocabularies /// - Formats telephone number pub fn format(self, path: Option<PathBuf>) -> ResearchActivity { let mut clone = self.clone().copy(); let parent = match path { | Some(value) => value.parent().unwrap().to_path_buf(), | None => PathBuf::from("."), }; let name = match image_paths(parent.clone()) { | value if !value.is_empty() => value[0].file_name().unwrap().to_string_lossy().to_string(), | _ => DEFAULT_GRAPHIC_HREF.to_string(), | value if !value.is_empty() => Some(value[0].file_name().unwrap().to_string_lossy().to_string()), | _ => None, }; debug!(name, "=> {} First image", Label::using()); if let Some(value) = name { debug!(value, "=> {} First image", Label::using()); // Make sure first graphic is well formed with a resolved image URL and caption let first_graphic = match self.meta.clone().media { | Some(values) if !values.is_empty() => { let caption = self.meta.clone().first_image_caption(); let image_data = ImageObject::init().caption(caption.to_string()).content_url(name.clone()).build(); let image_data = ImageObject::init().caption(caption.to_string()).content_url(value.clone()).build(); MediaObject::Image(image_data) } | Some(_) | None => { let image_data = ImageObject::init().caption("".to_string()).content_url(name.clone()).build(); let image_data = ImageObject::init().caption("".to_string()).content_url(value.clone()).build(); MediaObject::Image(image_data) } }; let mut clone = self.clone().copy(); // TODO: Add rest of media objects to clone.meta.media clone.meta.media = Some(vec![first_graphic]); // Get the rest of the media objects let rest = match self.clone().meta.media { | Some(values) if !values.is_empty() => values.into_iter().skip(1).collect::<Vec<_>>(), | Some(_) | None => vec![], }; clone.meta.media = Some([vec![first_graphic], rest].concat()); }; clone.meta.keywords = self.clone().resolve(FuzzyValue::Keyword); clone.meta.technology = self.clone().resolve(FuzzyValue::Technology); clone.contact.telephone = match format_phone_number(&self.contact.telephone) { Loading
acorn-lib/src/schema/tests/mod.rs +10 −10 Original line number Diff line number Diff line Loading @@ -257,30 +257,30 @@ fn test_research_activity_format() { assert!(pre.meta.media.is_some()); assert_eq!(pre.contact.affiliation, Some("Not an actual affiliation".to_string())); let post = pre.format(None); assert_eq!(post.clone().meta.media.unwrap()[0].clone().content_url(), Some("00.png".to_string())); assert!(post.clone().meta.media.unwrap()[0].clone().content_url().is_none()); assert_eq!(post.clone().meta.first_image().unwrap().description(), "".to_string()); assert_eq!(post.contact.affiliation, Some("Oak Ridge National Laboratory".to_string())); // // // // with more unresolved changes // // // // with more unresolved changes // let mut pre = post.clone().copy(); pre.contact.organization = "Not an actual organization".to_string(); pre.contact.affiliation = None; let post = pre.format(None); assert_eq!(post.contact.organization, "".to_string()); assert_eq!(post.contact.affiliation, Some("Oak Ridge National Laboratory".to_string())); // // // // with ORNL as organization and no affiliation // // // // with ORNL as organization and no affiliation // let mut pre = post.clone().copy(); pre.contact.organization = "Oak Ridge National Laboratory".to_string(); pre.contact.affiliation = None; let post = pre.format(None); assert_eq!(post.contact.organization, "Oak Ridge National Laboratory".to_string()); assert_eq!(post.contact.affiliation, Some("Oak Ridge National Laboratory".to_string())); // // // // without changes // // // // without changes // let pre = ResearchActivity::read(PathBuf::from(FIXTURES).join("data/format/no_changes.json")).unwrap(); assert_eq!(pre.clone().meta.media.unwrap()[0].clone().content_url(), Some("00.png".to_string())); assert_eq!(pre.contact.affiliation, Some("National Security Sciences Directorate".to_string())); Loading
tests/fixtures/data/valid_highlight/valid_highlight.json +1 −5 Original line number Diff line number Diff line Loading @@ -10,11 +10,7 @@ "url": "https://code.ornl.gov/research-enablement/acorn" } ], "graphics": [ { "caption": "This is an image caption." } ], "media": [], "keywords": [], "sponsors": [ "ORNL" Loading