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

pulibrary / bibdata / 234b9333-676b-4d43-b1c6-d1512d649e59

17 Sep 2025 04:04PM UTC coverage: 90.885% (+0.2%) from 90.675%
234b9333-676b-4d43-b1c6-d1512d649e59

Pull #2927

circleci

Ryan Laddusaw
Merge generated files and fix some bugs
Pull Request #2927: Index theses from dspace 7+

1411 of 1518 new or added lines in 16 files covered. (92.95%)

40 existing lines in 6 files now uncovered.

8874 of 9764 relevant lines covered (90.88%)

346.0 hits per line

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

80.13
/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<Option<String>>>,
10
    contributor: Option<Vec<Option<String>>>,
11
    contributor_advisor: Option<Vec<Option<String>>>,
12
    contributor_author: Option<Vec<Option<String>>>,
13
    date_classyear: Option<Vec<Option<String>>>,
14
    description_abstract: Option<Vec<Option<String>>>,
15
    department: Option<Vec<Option<String>>>,
16
    embargo_lift: Option<Vec<Option<String>>>,
17
    embargo_terms: Option<Vec<Option<String>>>,
18
    format_extent: Option<Vec<Option<String>>>,
19
    identifier_other: Option<Vec<Option<String>>>,
20
    identifier_uri: Option<Vec<Option<String>>>,
21
    language_iso: Option<Vec<Option<String>>>,
22
    location: Option<Vec<Option<String>>>,
23
    mudd_walkin: Option<Vec<Option<String>>>,
24
    rights_access_rights: Option<Vec<Option<String>>>,
25
    title: Option<Vec<Option<String>>>,
26
}
27

28
impl DataspaceDocumentBuilder {
29
    pub fn with_id(mut self, id: impl Into<String>) -> Self {
51✔
30
        self.id = Some(id.into());
51✔
31
        self
51✔
32
    }
51✔
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() }))
1✔
38
        } else {
39
            self.certificate = Some(certificate.iter().map(|md| { md.value.clone()}).collect::<Vec<Option<String>>>())
12✔
40
        }
41
        self
11✔
42
    }
11✔
43

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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