• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / 3165b919-56f4-4faa-baf4-b5a08621230c

18 Sep 2025 03:08PM UTC coverage: 90.866% (+0.2%) from 90.675%
3165b919-56f4-4faa-baf4-b5a08621230c

Pull #2927

circleci

Ryan Laddusaw
Add QA DSpace config
Pull Request #2927: Index theses from dspace 7+

1411 of 1519 new or added lines in 16 files covered. (92.89%)

41 existing lines in 7 files now uncovered.

8874 of 9766 relevant lines covered (90.87%)

338.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.44
/lib/bibdata_rs/src/ephemera/ephemera_folder/subject.rs
1
use serde::{Deserialize, Deserializer, Serialize};
2
use serde_json::Value;
3

4
#[derive(Clone, Deserialize, Debug)]
5
pub struct Subject {
6
    pub exact_match: ExactMatch,
7
    #[serde(rename = "pref_label")]
8
    pub label: String,
9
}
10

11
#[derive(Clone, Serialize, Debug)]
12
pub struct ExactMatch {
13
    pub id: Id,
14
}
15
#[derive(Clone, Deserialize, Serialize, Debug)]
16
pub struct Id {
17
    #[serde(rename = "@id")]
18
    pub id: String,
19
}
20
impl Id {
21
    fn subject_ids(&self) -> anyhow::Result<Vec<String>> {
313✔
22
        if self.id.starts_with('[') {
313✔
UNCOV
23
            let v: Vec<String> = serde_json::from_str(&self.id)?;
×
24
            Ok(v)
×
25
        } else {
26
            Ok(vec![self.id.clone()])
313✔
27
        }
28
    }
313✔
29
}
30

31
impl ExactMatch {
32
    pub fn accepted_loc_vocabulary(&self) -> bool {
157✔
33
        matches!(&self.id.subject_ids(), Ok(s) if s.iter().any(|url| {
157✔
34
                  url.starts_with("http://id.loc.gov")
157✔
35
        }))
157✔
36
    }
157✔
37

38
    pub fn accepted_homoit_vocabulary(&self) -> bool {
156✔
39
        matches!(&self.id.subject_ids(), Ok(s) if s.iter().any(|url| {
156✔
40
            url.starts_with("https://homosaurus.org/")
156✔
41
        }))
156✔
42
    }
156✔
43
}
44

45
impl<'de> Deserialize<'de> for ExactMatch {
46
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
83✔
47
    where
83✔
48
        D: Deserializer<'de>,
83✔
49
    {
50
        let value = Value::deserialize(deserializer)?;
83✔
51
        if let Some(id_value) = value.get("@id") {
83✔
52
            if id_value.is_string() {
83✔
53
                return Ok(ExactMatch {
83✔
54
                    id: Id {
83✔
55
                        id: id_value.as_str().unwrap().to_string(),
83✔
56
                    },
83✔
57
                });
83✔
58
            } else if id_value.is_object() {
×
UNCOV
59
                if let Some(nested_id) = id_value.get("@id") {
×
UNCOV
60
                    if nested_id.is_string() {
×
UNCOV
61
                        return Ok(ExactMatch {
×
UNCOV
62
                            id: Id {
×
UNCOV
63
                                id: nested_id.as_str().unwrap().to_string(),
×
UNCOV
64
                            },
×
UNCOV
65
                        });
×
UNCOV
66
                    }
×
UNCOV
67
                }
×
UNCOV
68
            }
×
UNCOV
69
        }
×
UNCOV
70
        Err(serde::de::Error::custom(
×
UNCOV
71
            "Could not parse ExactMatch Subject id",
×
UNCOV
72
        ))
×
73
    }
83✔
74
}
75

76
#[cfg(test)]
77
mod tests {
78
    use super::*;
79

80
    #[test]
81
    fn it_can_parse_exact_match_from_the_json_ld() {
1✔
82
        let json_ld = r#"[
1✔
83
            {
1✔
84
                "@id": "https://figgy-staging.princeton.edu/catalog/abf14319-f4bd-48d3-b4ab-5369354cc4aa",
1✔
85
                "@type": "skos:Concept",
1✔
86
                "pref_label": "Music",
1✔
87
                "in_scheme": {
1✔
88
                    "@id": "https://figgy.princeton.edu/ns/lAESubjects/artsAndCulture",
1✔
89
                    "@type": "skos:ConceptScheme",
1✔
90
                    "pref_label": "Arts and culture"
1✔
91
                },
1✔
92
                "exact_match": {
1✔
93
                   "@id": "http://id.loc.gov/authorities/subjects/sh85088762"
1✔
94
                }
1✔
95
            }
1✔
96
        ]"#;
1✔
97
        let subject: Vec<Subject> = serde_json::from_str(json_ld).unwrap();
1✔
98
        assert_eq!(
1✔
99
            subject[0].exact_match.id.id,
1✔
100
            "http://id.loc.gov/authorities/subjects/sh85088762"
101
        );
102
        assert_eq!(subject[0].label, "Music")
1✔
103
    }
1✔
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc