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

pulibrary / bibdata / 6af59736-1eb7-499a-b28b-31234d28f25b

23 Sep 2025 08:17PM UTC coverage: 90.818% (+0.1%) from 90.675%
6af59736-1eb7-499a-b28b-31234d28f25b

Pull #2927

circleci

Ryan Laddusaw
Update Department mapping with feeedback
Pull Request #2927: Index theses from dspace 7+

1340 of 1448 new or added lines in 16 files covered. (92.54%)

41 existing lines in 7 files now uncovered.

8823 of 9715 relevant lines covered (90.82%)

354.65 hits per line

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

80.0
/lib/bibdata_rs/src/theses/dataspace/document/builder.rs
1
// This module provides a convenient way to create a DataspaceDocument using the builder pattern
2

3
use super::DataspaceDocument;
4
use crate::theses::dataspace::document::Metadatum;
5

6
#[derive(Debug, Default)]
7
pub struct DataspaceDocumentBuilder {
8
    id: Option<String>,
9
    certificate: Option<Vec<String>>,
10
    contributor: Option<Vec<String>>,
11
    contributor_advisor: Option<Vec<String>>,
12
    contributor_author: Option<Vec<String>>,
13
    date_classyear: Option<Vec<String>>,
14
    description_abstract: Option<Vec<String>>,
15
    department: Option<Vec<String>>,
16
    embargo_lift: Option<Vec<String>>,
17
    embargo_terms: Option<Vec<String>>,
18
    format_extent: Option<Vec<String>>,
19
    identifier_other: Option<Vec<String>>,
20
    identifier_uri: Option<Vec<String>>,
21
    language_iso: Option<Vec<String>>,
22
    location: Option<Vec<String>>,
23
    mudd_walkin: Option<Vec<String>>,
24
    rights_access_rights: Option<Vec<String>>,
25
    title: Option<Vec<String>>,
26
}
27

28
impl DataspaceDocumentBuilder {
29
    pub fn with_id(mut self, id: impl Into<String>) -> Self {
52✔
30
        self.id = Some(id.into());
52✔
31
        self
52✔
32
    }
52✔
33

34
    pub fn with_certificate(mut self, certificate: Vec<Metadatum>) -> Self {
11✔
35
        if let Some(ref mut vec) = self.certificate {
11✔
36
            vec.extend(certificate.iter()
1✔
37
                .map(|cert| { cert.value.clone().unwrap_or_default() }))
1✔
38
        } else {
39
            self.certificate = Some(certificate.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
12✔
40
        }
41
        self
11✔
42
    }
11✔
43

44
    pub fn with_contributor(mut self, contributors: Vec<Metadatum>) -> Self {
6✔
45
        if let Some(ref mut vec) = self.contributor {
6✔
NEW
46
            vec.extend(contributors.iter()
×
NEW
47
                .map(|contributor| { contributor.value.clone().unwrap_or_default() }))
×
48
        } else {
49
            self.contributor = Some(contributors.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
6✔
50
        }
51
        self
6✔
52
    }
6✔
53

54
    pub fn with_contributor_advisor(mut self, contributor_advisors: Vec<Metadatum>) -> Self {
45✔
55
        if let Some(ref mut vec) = self.contributor_advisor {
45✔
NEW
56
            vec.extend(contributor_advisors.iter()
×
NEW
57
                .map(|ca| { ca.value.clone().unwrap_or_default() }))
×
58
        } else {
59
            self.contributor_advisor = Some(contributor_advisors.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
45✔
60
        }
61
        self
45✔
62
    }
45✔
63

64
    pub fn with_contributor_author(mut self, contributor_author: Vec<Metadatum>) -> Self {
46✔
65
        if let Some(ref mut vec) = self.contributor_author {
46✔
NEW
66
            vec.extend(contributor_author.iter()
×
NEW
67
                .map(|ca| { ca.value.clone().unwrap_or_default() }))
×
68
        } else {
69
            self.contributor_author = Some(contributor_author.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
46✔
70
        }
71
        self
46✔
72
    }
46✔
73

74
    pub fn with_date_classyear(mut self, date_classyear: Vec<Metadatum>) -> Self {
55✔
75
        if let Some(ref mut vec) = self.date_classyear {
55✔
NEW
76
            vec.extend(date_classyear.iter()
×
NEW
77
                .map(|date| { date.value.clone().unwrap_or_default() }))
×
78
        } else {
79
            self.date_classyear = Some(date_classyear.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
55✔
80
        }
81
        self
55✔
82
    }
55✔
83

84
    pub fn with_description_abstract(mut self, description_abstract: Vec<Metadatum>) -> Self {
5✔
85
        if let Some(ref mut vec) = self.description_abstract {
5✔
NEW
86
            vec.extend(description_abstract.iter()
×
NEW
87
                .map(|abs| { abs.value.clone().unwrap_or_default() }))
×
88
        } else {
89
            self.description_abstract = Some(description_abstract.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
5✔
90
        }
91
        self
5✔
92
    }
5✔
93

94
    pub fn with_department(mut self, department: Vec<Metadatum>) -> Self {
55✔
95
        if let Some(ref mut vec) = self.department {
55✔
96
            vec.extend(&mut department.iter()
6✔
97
                .map(|department| { department.value.clone().unwrap_or_default() }))
6✔
98
        } else {
99
            self.department = Some(department.iter().map(|md| { md.value.clone().unwrap_or_default()}).collect::<Vec<String>>())
51✔
100
        }
101
        self
55✔
102
    }
55✔
103

104
    pub fn with_embargo_lift(mut self, embargo_lift: Vec<Metadatum>) -> Self {
7✔
105
        if let Some(ref mut vec) = self.embargo_lift {
7✔
NEW
106
            vec.extend(embargo_lift.iter()
×
NEW
107
                .map(|el| { el.value.clone().unwrap_or_default() }))
×
108
        } else {
109
            self.embargo_lift = Some(embargo_lift.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
7✔
110
        }
111
        self
7✔
112
    }
7✔
113

114
    pub fn with_embargo_terms(mut self, embargo_terms: Vec<Metadatum>) -> Self {
3✔
115
        if let Some(ref mut vec) = self.embargo_terms {
3✔
NEW
116
            vec.extend(embargo_terms.iter()
×
NEW
117
                .map(|terms| { terms.value.clone().unwrap_or_default() }))
×
118
        } else {
119
            self.embargo_terms = Some(embargo_terms.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
3✔
120
        }
121
        self
3✔
122
    }
3✔
123

124
    pub fn with_format_extent(mut self, format_extent: Vec<Metadatum>) -> Self {
5✔
125
        if let Some(ref mut vec) = self.format_extent {
5✔
NEW
126
            vec.extend(format_extent.iter()
×
NEW
127
                .map(|format| { format.value.clone().unwrap_or_default() }))
×
128
        } else {
129
            self.format_extent = Some(format_extent.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
5✔
130
        }
131
        self
5✔
132
    }
5✔
133

134
    pub fn with_identifier_other(mut self, identifier_other: Vec<Metadatum>) -> Self {
1✔
135
        if let Some(ref mut vec) = self.identifier_other {
1✔
NEW
136
            vec.extend(identifier_other.iter()
×
NEW
137
                .map(|identifier| { identifier.value.clone().unwrap_or_default() }))
×
138
        } else {
139
            self.identifier_other = Some(identifier_other.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
1✔
140
        }
141
        self
1✔
142
    }
1✔
143

144
    pub fn with_identifier_uri(mut self, identifier_uri: Vec<Metadatum>) -> Self {
44✔
145
        if let Some(ref mut vec) = self.identifier_uri {
44✔
NEW
146
            vec.extend(identifier_uri.iter()
×
NEW
147
                .map(|uri| { uri.value.clone().unwrap_or_default() }))
×
148
        } else {
149
            self.identifier_uri = Some(identifier_uri.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
44✔
150
        }
151
        self
44✔
152
    }
44✔
153

154
    pub fn with_language_iso(mut self, language_iso: Vec<Metadatum>) -> Self {
46✔
155
        if let Some(ref mut vec) = self.language_iso {
46✔
NEW
156
            vec.extend(language_iso.iter()
×
NEW
157
                .map(|lang| { lang.value.clone().unwrap_or_default() }))
×
158
        } else {
159
            self.language_iso = Some(language_iso.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
46✔
160
        }
161
        self
46✔
162
    }
46✔
163

164
    pub fn with_location(mut self, location: Vec<Metadatum>) -> Self {
2✔
165
        if let Some(ref mut vec) = self.location {
2✔
NEW
166
            vec.extend(location.iter()
×
NEW
167
                .map(|location| { location.value.clone().unwrap_or_default() }))
×
168
        } else {
169
            self.location = Some(location.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
2✔
170
        }
171
        self
2✔
172
    }
2✔
173

174
    pub fn with_mudd_walkin(mut self, mudd_walkin: Vec<Metadatum>) -> Self {
5✔
175
        if let Some(ref mut vec) = self.mudd_walkin {
5✔
NEW
176
            vec.extend(mudd_walkin.iter()
×
NEW
177
                .map(|mw| { mw.value.clone().unwrap_or_default() }));
×
178
        } else {
179
            self.mudd_walkin = Some(mudd_walkin.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
5✔
180
        }
181
        self
5✔
182
    }
5✔
183

184
    pub fn with_rights_access_rights(mut self, rights_access_rights: Vec<Metadatum>) -> Self {
9✔
185
        if let Some(ref mut vec) = self.rights_access_rights {
9✔
NEW
186
            vec.extend(rights_access_rights.iter()
×
NEW
187
                .map(|rights| { rights.value.clone().unwrap_or_default() }))
×
188
        } else {
189
            self.rights_access_rights = Some(rights_access_rights.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
9✔
190
        }
191
        self
9✔
192
    }
9✔
193

194
    pub fn with_title(mut self, title: Vec<Metadatum>) -> Self {
45✔
195
        if let Some(ref mut vec) = self.title {
45✔
NEW
196
            vec.extend(title.iter()
×
NEW
197
                .map(|title| { title.value.clone().unwrap_or_default() }))
×
198
        } else {
199
            self.title = Some(title.iter().map(|md| { md.value.clone().unwrap_or_default() }).collect::<Vec<String>>())
45✔
200
        }
201
        self
45✔
202
    }
45✔
203

204
    pub fn build(self) -> DataspaceDocument {
85✔
205
        DataspaceDocument {
85✔
206
            id: self.id,
85✔
207
            certificate: self.certificate,
85✔
208
            contributor: self.contributor,
85✔
209
            contributor_advisor: self.contributor_advisor,
85✔
210
            contributor_author: self.contributor_author,
85✔
211
            date_classyear: self.date_classyear,
85✔
212
            description_abstract: self.description_abstract,
85✔
213
            department: self.department,
85✔
214
            embargo_lift: self.embargo_lift,
85✔
215
            embargo_terms: self.embargo_terms,
85✔
216
            format_extent: self.format_extent,
85✔
217
            identifier_other: self.identifier_other,
85✔
218
            identifier_uri: self.identifier_uri,
85✔
219
            language_iso: self.language_iso,
85✔
220
            location: self.location,
85✔
221
            mudd_walkin: self.mudd_walkin,
85✔
222
            rights_access_rights: self.rights_access_rights,
85✔
223
            title: self.title,
85✔
224
        }
85✔
225
    }
85✔
226
}
227

228
#[cfg(test)]
229
mod tests {
230
    use super::*;
231

232
    #[test]
233
    fn it_can_create_a_dataspace_document() {
1✔
234
        let builder = DataspaceDocumentBuilder::default();
1✔
235
        let doc = builder.with_id("ABC123").build();
1✔
236
        assert_eq!(doc.id, Some("ABC123".to_owned()));
1✔
237
    }
1✔
238
}
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