• 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

96.21
/lib/bibdata_rs/src/solr/dataspace_solr_mapping.rs
1
// This module is responsible for mapping Dataspace metadata to the catalog's solr schema
2

3
use super::SolrDocument;
4
use crate::theses::dataspace::document::DataspaceDocument;
5
use crate::theses::legacy_dataspace::document::DataspaceDocument as LegacyDataspaceDocument;
6

7
impl From<&DataspaceDocument> for SolrDocument {
8
    fn from(doc: &DataspaceDocument) -> Self {
26✔
9
        SolrDocument::builder()
26✔
10
            .with_id(match &doc.id {
26✔
11
                Some(id) => id,
5✔
12
                None => "",
21✔
13
            })
14
            .with_access_facet(doc.access_facet())
26✔
15
            .with_advanced_location_s(doc.advanced_location())
26✔
16
            .with_advisor_display(doc.contributor_advisor.clone())
26✔
17
            .with_author_display(doc.contributor_author.clone())
26✔
18
            .with_author_s(doc.all_authors())
26✔
19
            .with_author_sort(match &doc.contributor_author {
26✔
20
                Some(authors) => authors.first().cloned(),
2✔
21
                None => None,
24✔
22
            })
23
            .with_call_number_browse_s(doc.call_number())
26✔
24
            .with_call_number_display(doc.call_number())
26✔
25
            .with_certificate_display(doc.authorized_ceritificates())
26✔
26
            .with_contributor_display(doc.contributor.clone())
26✔
27
            .with_department_display(doc.authorized_departments())
26✔
28
            .with_format(vec![super::FormatFacet::SeniorThesis])
26✔
29
            .with_holdings_1display(doc.physical_holding_string())
26✔
30
            .with_location(doc.location())
26✔
31
            .with_location_code_s(doc.location_code())
26✔
32
            .with_location_display(doc.location_display())
26✔
33
            .with_electronic_access_1display(doc.ark_hash())
26✔
34
            .with_electronic_portfolio_s(doc.online_portfolio_statements())
26✔
35
            .with_restrictions_note_display(doc.restrictions_note_display())
26✔
36
            .with_title_citation_display(match &doc.title {
26✔
37
                Some(titles) => titles.first().cloned(),
2✔
38
                None => None,
24✔
39
            })
40
            .with_title_display(match &doc.title {
26✔
41
                Some(titles) => titles.first().cloned(),
2✔
42
                None => None,
24✔
43
            })
44
            .with_title_sort(title_sort(doc.title.as_ref()))
26✔
45
            .with_title_t(doc.title_search_versions())
26✔
46
            .with_language_facet(doc.languages())
26✔
47
            .with_language_name_display(doc.languages())
26✔
48
            .with_class_year_s(doc.class_year().map(|year| vec![year]))
26✔
49
            .with_pub_date_start_sort(doc.class_year())
26✔
50
            .with_pub_date_end_sort(doc.class_year())
26✔
51
            .with_description_display(doc.format_extent.clone())
26✔
52
            .with_summary_note_display(doc.description_abstract.clone())
26✔
53
            .build()
26✔
54
    }
26✔
55
}
56

57
impl From<&LegacyDataspaceDocument> for SolrDocument {
58
    fn from(doc: &LegacyDataspaceDocument) -> Self {
26✔
59
        SolrDocument::builder()
26✔
60
            .with_id(match &doc.id {
26✔
61
                Some(id) => id,
5✔
62
                None => "",
21✔
63
            })
64
            .with_access_facet(doc.access_facet())
26✔
65
            .with_advanced_location_s(doc.advanced_location())
26✔
66
            .with_advisor_display(doc.contributor_advisor.clone())
26✔
67
            .with_author_display(doc.contributor_author.clone())
26✔
68
            .with_author_s(doc.all_authors())
26✔
69
            .with_author_sort(match &doc.contributor_author {
26✔
70
                Some(authors) => authors.first().cloned(),
2✔
71
                None => None,
24✔
72
            })
73
            .with_call_number_browse_s(doc.call_number())
26✔
74
            .with_call_number_display(doc.call_number())
26✔
75
            .with_certificate_display(doc.authorized_ceritificates())
26✔
76
            .with_contributor_display(doc.contributor.clone())
26✔
77
            .with_department_display(doc.authorized_departments())
26✔
78
            .with_format(vec![super::FormatFacet::SeniorThesis])
26✔
79
            .with_holdings_1display(doc.physical_holding_string())
26✔
80
            .with_location(doc.location())
26✔
81
            .with_location_code_s(doc.location_code())
26✔
82
            .with_location_display(doc.location_display())
26✔
83
            .with_electronic_access_1display(doc.ark_hash())
26✔
84
            .with_electronic_portfolio_s(doc.online_portfolio_statements())
26✔
85
            .with_restrictions_note_display(doc.restrictions_note_display())
26✔
86
            .with_title_citation_display(match &doc.title {
26✔
87
                Some(titles) => titles.first().cloned(),
2✔
88
                None => None,
24✔
89
            })
90
            .with_title_display(match &doc.title {
26✔
91
                Some(titles) => titles.first().cloned(),
2✔
92
                None => None,
24✔
93
            })
94
            .with_title_sort(title_sort(doc.title.as_ref()))
26✔
95
            .with_title_t(doc.title_search_versions())
26✔
96
            .with_language_facet(doc.languages())
26✔
97
            .with_language_name_display(doc.languages())
26✔
98
            .with_class_year_s(doc.class_year().map(|year| vec![year]))
26✔
99
            .with_pub_date_start_sort(doc.class_year())
26✔
100
            .with_pub_date_end_sort(doc.class_year())
26✔
101
            .with_description_display(doc.format_extent.clone())
26✔
102
            .with_summary_note_display(doc.description_abstract.clone())
26✔
103
            .build()
26✔
104
    }
26✔
105
}
106

107
fn title_sort(titles: Option<&Vec<String>>) -> Option<String> {
60✔
108
    match titles {
60✔
109
        Some(title_vec) => {
12✔
110
            let first = title_vec.first()?;
12✔
111
            Some(
112
                first
12✔
113
                    .to_lowercase()
12✔
114
                    .chars()
12✔
115
                    .filter(|c| !c.is_ascii_punctuation())
260✔
116
                    .collect::<String>()
12✔
117
                    .trim_start_matches("a ")
12✔
118
                    .trim_start_matches("an ")
12✔
119
                    .trim_start_matches("the ")
12✔
120
                    .chars()
12✔
121
                    .filter(|c| !c.is_whitespace())
234✔
122
                    .collect::<String>(),
12✔
123
            )
124
        }
125
        None => None,
48✔
126
    }
127
}
60✔
128

129
#[cfg(test)]
130
mod tests {
131
    use crate::solr::{AccessFacet, FormatFacet};
132

133
    use super::*;
134

135
    #[test]
136
    fn it_can_convert_into_solr_document() {
1✔
137
        let metadata = DataspaceDocument::builder()
1✔
138
            .with_id("dsp01b2773v788")
1✔
139
            .with_description_abstract(vec!("Summary".into()))
1✔
140
            .with_contributor(vec!("Wolff, Tamsen".into()))
1✔
141
            .with_contributor_advisor(vec!("Sandberg, Robert".into()))
1✔
142
            .with_contributor_author(vec!("Clark, Hillary".into()))
1✔
143
            .with_date_classyear(vec!("2014".into()))
1✔
144
            .with_department(vec!("Princeton University. Department of English".into()))
1✔
145
            .with_department(vec!("Princeton University. Program in Theater".into()))
1✔
146
            .with_format_extent(vec!("102 pages".into()))
1✔
147
            .with_language_iso(vec!("en_US".into()))
1✔
148
            .with_title(vec!("Dysfunction: A Play in One Act".into()))
1✔
149
            .build();
1✔
150

151
        let solr = SolrDocument::from(&metadata);
1✔
152

153
        assert_eq!(solr.id, "dsp01b2773v788");
1✔
154
        assert_eq!(
1✔
155
            solr.title_t.unwrap(),
1✔
156
            vec!["Dysfunction: A Play in One Act"]
1✔
157
        );
158
        assert_eq!(
1✔
159
            solr.title_citation_display.unwrap(),
1✔
160
            "Dysfunction: A Play in One Act"
161
        );
162
        assert_eq!(
1✔
163
            solr.title_display.unwrap(),
1✔
164
            "Dysfunction: A Play in One Act"
165
        );
166
        assert_eq!(solr.title_sort.unwrap(), "dysfunctionaplayinoneact");
1✔
167
    }
1✔
168

169
    #[test]
170
    fn it_adds_the_expected_fields() {
1✔
171
        let document = DataspaceDocument::builder()
1✔
172
            .with_id("dsp01b2773v788")
1✔
173
            .with_description_abstract(vec!("Summary".into()))
1✔
174
            .with_contributor(vec!("Wolff, Tamsen".into()))
1✔
175
            .with_contributor_advisor(vec!("Sandberg, Robert".into()))
1✔
176
            .with_contributor_author(vec!("Clark, Hillary".into()))
1✔
177
            .with_identifier_uri(vec!("http://arks.princeton.edu/ark:/88435/dsp01b2773v788".into()))
1✔
178
            .with_format_extent(vec!("102 pages".into()))
1✔
179
            .with_language_iso(vec!("en_US".into()))
1✔
180
            .with_title(vec!("Dysfunction: A Play in One Act".into()))
1✔
181
            .with_date_classyear(vec!("2014".into()))
1✔
182
            .with_department(vec!("Princeton University. Department of English".into()))
1✔
183
            .with_department(vec!("Princeton University. Program in Theater".into()))
1✔
184
            .with_rights_access_rights(vec!("Walk-in Access...".into()))
1✔
185
            .build();
1✔
186
        let solr = SolrDocument::from(&document);
1✔
187
        assert_eq!(solr.author_display, Some(vec!["Clark, Hillary".to_owned()]));
1✔
188
        assert_eq!(
1✔
189
            solr.author_s.unwrap().sort(),
1✔
190
            [
1✔
191
                "Clark, Hillary".to_owned(),
1✔
192
                "Sandberg, Robert".to_owned(),
1✔
193
                "Wolff, Tamsen".to_owned()
1✔
194
            ]
1✔
195
            .sort()
1✔
196
        );
197
        assert_eq!(solr.summary_note_display, Some(vec!["Summary".to_owned()]))
1✔
198
    }
1✔
199

200
    #[test]
201
    fn it_is_senior_thesis() {
1✔
202
        let document = DataspaceDocument::builder().build();
1✔
203
        let solr = SolrDocument::from(&document);
1✔
204
        assert_eq!(solr.format, Some(vec![FormatFacet::SeniorThesis]));
1✔
205
    }
1✔
206

207
    #[test]
208
    fn integer_in_classyear_field() {
1✔
209
        let document = DataspaceDocument::builder()
1✔
210
            .with_date_classyear(vec!("2014".into()))
1✔
211
            .build();
1✔
212
        let solr = SolrDocument::from(&document);
1✔
213
        assert_eq!(solr.class_year_s.unwrap(), vec![2014]);
1✔
214
        assert_eq!(solr.pub_date_start_sort.unwrap(), 2014);
1✔
215
        assert_eq!(solr.pub_date_end_sort.unwrap(), 2014);
1✔
216
    }
1✔
217

218
    #[test]
219
    fn non_integer_in_classyear_field() {
1✔
220
        let document = DataspaceDocument::builder()
1✔
221
            .with_date_classyear(vec!("Undated".into()))
1✔
222
            .build();
1✔
223
        let solr = SolrDocument::from(&document);
1✔
224
        assert!(solr.class_year_s.is_none());
1✔
225
        assert!(solr.pub_date_start_sort.is_none());
1✔
226
        assert!(solr.pub_date_end_sort.is_none());
1✔
227
    }
1✔
228

229
    #[test]
230
    fn no_classyear() {
1✔
231
        let document = DataspaceDocument::builder().build();
1✔
232
        let solr = SolrDocument::from(&document);
1✔
233
        assert!(solr.class_year_s.is_none());
1✔
234
        assert!(solr.pub_date_start_sort.is_none());
1✔
235
        assert!(solr.pub_date_end_sort.is_none());
1✔
236
    }
1✔
237

238
    #[test]
239
    fn with_access_rights() {
1✔
240
        let document = DataspaceDocument::builder()
1✔
241
            .with_rights_access_rights(vec!("Walk-in Access...".into()))
1✔
242
            .build();
1✔
243
        let solr = SolrDocument::from(&document);
1✔
244
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
245
        assert!(solr.advanced_location_s.is_none());
1✔
246
    }
1✔
247

248
    #[test]
249
    fn with_embargo() {
1✔
250
        let document = DataspaceDocument::builder()
1✔
251
            .with_rights_access_rights(vec!("Walk-in Access...".into()))
1✔
252
            .with_embargo_terms(vec!("2100-01-01".into()))
1✔
253
            .build();
1✔
254
        let solr = SolrDocument::from(&document);
1✔
255
        assert!(solr.access_facet.is_none());
1✔
256
        assert_eq!(
1✔
257
            solr.advanced_location_s.unwrap(),
1✔
258
            vec![
1✔
259
                "mudd$stacks".to_owned(),
1✔
260
                "Mudd Manuscript Library".to_owned()
1✔
261
            ]
262
        );
263
    }
1✔
264

265
    #[test]
266
    fn it_has_electronic_portfolio_s_by_default() {
1✔
267
        let document = DataspaceDocument::builder().build();
1✔
268
        let solr = SolrDocument::from(&document);
1✔
269
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
270
        assert!(solr.electronic_portfolio_s.unwrap().contains("thesis"));
1✔
271
    }
1✔
272

273
    #[test]
274
    fn it_has_no_electronic_portfolio_s_if_location_specified_and_older_thesis() {
1✔
275
        let document = DataspaceDocument::builder()
1✔
276
            .with_date_classyear(vec!("1955".into()))
1✔
277
            .with_location(vec!(r#"This thesis can be viewed in person at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.  \nTo order a copy complete the <a href=\"http://rbsc.princeton.edu/senior-thesis-order-form\" target=\"_blank\">Senior Thesis Request Form</a>.  \nFor more information contact <a href=mailto:mudd@princeton.edu>mudd@princeton.edu</a>."#.into()))
1✔
278
            .build();
1✔
279
        let solr = SolrDocument::from(&document);
1✔
280
        assert!(solr.electronic_portfolio_s.is_none());
1✔
281
    }
1✔
282

283
    #[test]
284
    fn with_allowed_department_name() {
1✔
285
        let document = DataspaceDocument::builder()
1✔
286
            .with_department(vec!("English".into()))
1✔
287
            .build();
1✔
288
        let solr = SolrDocument::from(&document);
1✔
289
        assert_eq!(
1✔
290
            solr.department_display.unwrap(),
1✔
291
            vec!["Princeton University. Department of English"],
1✔
NEW
292
            "it should map to the LC authorized name for the department"
×
293
        );
294
    }
1✔
295

296
    #[test]
297
    fn with_disallowed_department_name() {
1✔
298
        let document = DataspaceDocument::builder().with_department(vec!("NA".into())).build();
1✔
299
        let solr = SolrDocument::from(&document);
1✔
300
        assert!(
1✔
301
            solr.department_display.unwrap().is_empty(),
1✔
NEW
302
            "it should not include department names that are not in the authorized list"
×
303
        );
304
    }
1✔
305

306
    #[test]
307
    fn with_multiple_allowed_department_names() {
1✔
308
        let document = DataspaceDocument::builder()
1✔
309
            .with_department(vec!("English".into()))
1✔
310
            .with_department(vec!("German".into()))
1✔
311
            .build();
1✔
312
        let solr = SolrDocument::from(&document);
1✔
313
        assert_eq!(
1✔
314
            solr.department_display.unwrap(),
1✔
315
            vec![
1✔
316
                "Princeton University. Department of English",
317
                "Princeton University. Department of Germanic Languages and Literatures"
1✔
318
            ],
NEW
319
            "it should map to all LC authorized department names"
×
320
        );
321
    }
1✔
322

323
    #[test]
324
    fn with_allowed_certificate_name() {
1✔
325
        let document = DataspaceDocument::builder()
1✔
326
            .with_certificate(vec!("Creative Writing Program".into()))
1✔
327
            .build();
1✔
328
        let solr = SolrDocument::from(&document);
1✔
329
        assert_eq!(
1✔
330
            solr.certificate_display.unwrap(),
1✔
331
            vec!["Princeton University. Creative Writing Program"],
1✔
NEW
332
            "it should map to the LC authorized name for the program"
×
333
        );
334
    }
1✔
335

336
    #[test]
337
    fn with_disallowed_certificate_name() {
1✔
338
        let document = DataspaceDocument::builder().with_certificate(vec!("NA".into())).build();
1✔
339
        let solr = SolrDocument::from(&document);
1✔
340
        assert!(
1✔
341
            solr.certificate_display.unwrap().is_empty(),
1✔
NEW
342
            "it should not include program names that are not in the authorized list"
×
343
        );
344
    }
1✔
345

346
    #[test]
347
    fn with_multiple_allowed_certificate_names() {
1✔
348
        let document = DataspaceDocument::builder()
1✔
349
            .with_certificate(vec!("Environmental Studies Program".into()))
1✔
350
            .with_certificate(vec!("African Studies Program".into()))
1✔
351
            .build();
1✔
352
        let solr = SolrDocument::from(&document);
1✔
353
        assert_eq!(
1✔
354
            solr.certificate_display.unwrap(),
1✔
355
            vec![
1✔
356
                "Princeton University. Program in Environmental Studies",
357
                "Princeton University. Program in African Studies"
1✔
358
            ],
NEW
359
            "it should map to all LC authorized program names"
×
360
        );
361
    }
1✔
362

363
    #[test]
364
    fn location_code_s() {
1✔
365
        let document = DataspaceDocument::builder()
1✔
366
            .with_date_classyear(vec!("2020".into()))
1✔
367
            .build();
1✔
368
        let solr = SolrDocument::from(&document);
1✔
369
        assert_eq!(solr.location_code_s, None);
1✔
370

371
        let document = DataspaceDocument::builder()
1✔
372
            .with_date_classyear(vec!("1980".into()))
1✔
373
            .with_rights_access_rights(vec!("Limited access".into()))
1✔
374
            .build();
1✔
375
        let solr = SolrDocument::from(&document);
1✔
376
        assert_eq!(solr.location_code_s.unwrap(), "mudd$stacks");
1✔
377
    }
1✔
378

379
    #[test]
380
    fn location_display() {
1✔
381
        let document = DataspaceDocument::builder()
1✔
382
            .with_mudd_walkin(vec!("yes".into()))
1✔
383
            .with_date_classyear(vec!("1995".into()))
1✔
384
            .build();
1✔
385
        let solr = SolrDocument::from(&document);
1✔
386
        assert_eq!(solr.location_display.unwrap(), "Mudd Manuscript Library");
1✔
387
    }
1✔
388

389
    #[test]
390
    fn holdings_1display() {
1✔
391
        let document = DataspaceDocument::builder()
1✔
392
            .with_rights_access_rights(vec!("Limited access".into()))
1✔
393
            .with_date_classyear(vec!("2005".into()))
1✔
394
            .build();
1✔
395
        let solr = SolrDocument::from(&document);
1✔
396
        assert_eq!(
1✔
397
            solr.holdings_1display.unwrap(),
1✔
398
            "{\"thesis\":{\"location\":\"Mudd Manuscript Library\",\"library\":\"Mudd Manuscript Library\",\"location_code\":\"mudd$stacks\",\"call_number\":\"AC102\",\"call_number_browse\":\"AC102\",\"dspace\":true}}",
NEW
399
            "holdings_1display should be present when physical thesis has limited access"
×
400
        );
401

402
        let document = DataspaceDocument::builder()
1✔
403
            .with_identifier_uri(vec!("http://arks.princeton.edu/ark:/88435/dsp0141687h67f".into()))
1✔
404
            .build();
1✔
405
        let solr = SolrDocument::from(&document);
1✔
406
        assert!(
1✔
407
            solr.holdings_1display.is_none(),
1✔
NEW
408
            "holdings_1display should not be present when newer thesis has no location information"
×
409
        );
410
    }
1✔
411

412
    #[test]
413
    fn call_number_browse_s() {
1✔
414
        let document = DataspaceDocument::builder()
1✔
415
            .with_rights_access_rights(vec!("Limited access".into()))
1✔
416
            .with_date_classyear(vec!("2005".into()))
1✔
417
            .build();
1✔
418
        let solr = SolrDocument::from(&document);
1✔
419
        assert_eq!(solr.call_number_browse_s, "AC102");
1✔
420
    }
1✔
421

422
    #[test]
423
    fn language_facet() {
1✔
424
        let document = DataspaceDocument::builder().with_language_iso(vec!("it".into())).build();
1✔
425
        let solr = SolrDocument::from(&document);
1✔
426
        assert_eq!(solr.language_facet, vec!["Italian".to_owned()]);
1✔
427
    }
1✔
428

429
    mod restrictions_note_display {
430
        use super::*;
431

432
        #[test]
433
        fn when_lift_date_is_invalid() {
1✔
434
            let document = DataspaceDocument::builder()
1✔
435
                .with_id("test-id")
1✔
436
                .with_embargo_lift(vec!("invalid".into()))
1✔
437
                .build();
1✔
438
            let solr = SolrDocument::from(&document);
1✔
439
            assert_eq!(solr.restrictions_note_display, Some(vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>.".to_string()]));
1✔
440
        }
1✔
441

442
        #[test]
443
        fn when_terms_date_is_invalid() {
1✔
444
            let document = DataspaceDocument::builder()
1✔
445
                .with_id("test-id")
1✔
446
                .with_embargo_terms(vec!("invalid".into()))
1✔
447
                .build();
1✔
448
            let solr = SolrDocument::from(&document);
1✔
449
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>."]);
1✔
450
        }
1✔
451

452
        #[test]
453
        fn when_there_are_access_rights() {
1✔
454
            let document = DataspaceDocument::builder()
1✔
455
                .with_id("test-id")
1✔
456
                .with_rights_access_rights(vec!("Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.".into()))
1✔
457
                .build();
1✔
458
            let solr = SolrDocument::from(&document);
1✔
459
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>."]);
1✔
460
        }
1✔
461
    }
462

463
    mod title_sort {
464
        use super::*;
465

466
        #[test]
467
        fn it_can_create_sortable_version_of_title() {
1✔
468
            assert_eq!(
1✔
469
                title_sort(Some(&vec!["\"Some quote\" : Blah blah".to_owned()])).unwrap(),
1✔
470
                "somequoteblahblah",
NEW
471
                "it should strip punctuation"
×
472
            );
473
            assert_eq!(
1✔
474
                title_sort(Some(&vec!["A title : blah blah".to_owned()])).unwrap(),
1✔
475
                "titleblahblah",
NEW
476
                "it should strip articles"
×
477
            );
478
            assert_eq!(
1✔
479
                title_sort(Some(&vec!["\"A quote\" : Blah blah".to_owned()])).unwrap(),
1✔
480
                "quoteblahblah",
NEW
481
                "it should strip punctuation and articles"
×
482
            );
483
            assert_eq!(
1✔
484
                title_sort(Some(&vec!["thesis".to_owned()])).unwrap(),
1✔
485
                "thesis",
NEW
486
                "it should leave words that start with articles alone"
×
487
            );
488
        }
1✔
489
    }
490
}
491

492
#[cfg(test)]
493
mod legacy_tests {
494
    use crate::solr::{AccessFacet, FormatFacet};
495

496
    use super::*;
497

498
    #[test]
499
    fn it_can_convert_into_solr_document() {
1✔
500
        let metadata = LegacyDataspaceDocument::builder()
1✔
501
            .with_id("dsp01b2773v788")
1✔
502
            .with_description_abstract("Summary")
1✔
503
            .with_contributor("Wolff, Tamsen".to_string())
1✔
504
            .with_contributor_advisor("Sandberg, Robert".to_string())
1✔
505
            .with_contributor_author("Clark, Hillary".to_string())
1✔
506
            .with_date_classyear("2014")
1✔
507
            .with_department("Princeton University. Department of English")
1✔
508
            .with_department("Princeton University. Program in Theater")
1✔
509
            .with_format_extent("102 pages")
1✔
510
            .with_language_iso("en_US")
1✔
511
            .with_title("Dysfunction: A Play in One Act".to_string())
1✔
512
            .build();
1✔
513

514
        let solr = SolrDocument::from(&metadata);
1✔
515

516
        assert_eq!(solr.id, "dsp01b2773v788");
1✔
517
        assert_eq!(
1✔
518
            solr.title_t.unwrap(),
1✔
519
            vec!["Dysfunction: A Play in One Act"]
1✔
520
        );
521
        assert_eq!(
1✔
522
            solr.title_citation_display.unwrap(),
1✔
523
            "Dysfunction: A Play in One Act"
524
        );
525
        assert_eq!(
1✔
526
            solr.title_display.unwrap(),
1✔
527
            "Dysfunction: A Play in One Act"
528
        );
529
        assert_eq!(solr.title_sort.unwrap(), "dysfunctionaplayinoneact");
1✔
530
    }
1✔
531

532
    #[test]
533
    fn it_adds_the_expected_fields() {
1✔
534
        let document = LegacyDataspaceDocument::builder()
1✔
535
            .with_id("dsp01b2773v788")
1✔
536
            .with_description_abstract("Summary")
1✔
537
            .with_contributor("Wolff, Tamsen")
1✔
538
            .with_contributor_advisor("Sandberg, Robert")
1✔
539
            .with_contributor_author("Clark, Hillary")
1✔
540
            .with_identifier_uri("http://arks.princeton.edu/ark:/88435/dsp01b2773v788")
1✔
541
            .with_format_extent("102 pages")
1✔
542
            .with_language_iso("en_US")
1✔
543
            .with_title("Dysfunction: A Play in One Act")
1✔
544
            .with_date_classyear("2014")
1✔
545
            .with_department("Princeton University. Department of English")
1✔
546
            .with_department("Princeton University. Program in Theater")
1✔
547
            .with_rights_access_rights("Walk-in Access...")
1✔
548
            .build();
1✔
549
        let solr = SolrDocument::from(&document);
1✔
550
        assert_eq!(solr.author_display, Some(vec!["Clark, Hillary".to_owned()]));
1✔
551
        assert_eq!(
1✔
552
            solr.author_s.unwrap().sort(),
1✔
553
            [
1✔
554
                "Clark, Hillary".to_owned(),
1✔
555
                "Sandberg, Robert".to_owned(),
1✔
556
                "Wolff, Tamsen".to_owned()
1✔
557
            ]
1✔
558
            .sort()
1✔
559
        );
560
        assert_eq!(solr.summary_note_display, Some(vec!["Summary".to_owned()]))
1✔
561
    }
1✔
562

563
    #[test]
564
    fn it_is_senior_thesis() {
1✔
565
        let document = LegacyDataspaceDocument::builder().build();
1✔
566
        let solr = SolrDocument::from(&document);
1✔
567
        assert_eq!(solr.format, Some(vec![FormatFacet::SeniorThesis]));
1✔
568
    }
1✔
569

570
    #[test]
571
    fn integer_in_classyear_field() {
1✔
572
        let document = LegacyDataspaceDocument::builder()
1✔
573
            .with_date_classyear("2014")
1✔
574
            .build();
1✔
575
        let solr = SolrDocument::from(&document);
1✔
576
        assert_eq!(solr.class_year_s.unwrap(), vec![2014]);
1✔
577
        assert_eq!(solr.pub_date_start_sort.unwrap(), 2014);
1✔
578
        assert_eq!(solr.pub_date_end_sort.unwrap(), 2014);
1✔
579
    }
1✔
580

581
    #[test]
582
    fn non_integer_in_classyear_field() {
1✔
583
        let document = LegacyDataspaceDocument::builder()
1✔
584
            .with_date_classyear("Undated")
1✔
585
            .build();
1✔
586
        let solr = SolrDocument::from(&document);
1✔
587
        assert!(solr.class_year_s.is_none());
1✔
588
        assert!(solr.pub_date_start_sort.is_none());
1✔
589
        assert!(solr.pub_date_end_sort.is_none());
1✔
590
    }
1✔
591

592
    #[test]
593
    fn no_classyear() {
1✔
594
        let document = LegacyDataspaceDocument::builder().build();
1✔
595
        let solr = SolrDocument::from(&document);
1✔
596
        assert!(solr.class_year_s.is_none());
1✔
597
        assert!(solr.pub_date_start_sort.is_none());
1✔
598
        assert!(solr.pub_date_end_sort.is_none());
1✔
599
    }
1✔
600

601
    #[test]
602
    fn with_access_rights() {
1✔
603
        let document = LegacyDataspaceDocument::builder()
1✔
604
            .with_rights_access_rights("Walk-in Access...")
1✔
605
            .build();
1✔
606
        let solr = SolrDocument::from(&document);
1✔
607
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
608
        assert!(solr.advanced_location_s.is_none());
1✔
609
    }
1✔
610

611
    #[test]
612
    fn with_embargo() {
1✔
613
        let document = LegacyDataspaceDocument::builder()
1✔
614
            .with_rights_access_rights("Walk-in Access...")
1✔
615
            .with_embargo_terms("2100-01-01")
1✔
616
            .build();
1✔
617
        let solr = SolrDocument::from(&document);
1✔
618
        assert!(solr.access_facet.is_none());
1✔
619
        assert_eq!(
1✔
620
            solr.advanced_location_s.unwrap(),
1✔
621
            vec![
1✔
622
                "mudd$stacks".to_owned(),
1✔
623
                "Mudd Manuscript Library".to_owned()
1✔
624
            ]
625
        );
626
    }
1✔
627

628
    #[test]
629
    fn it_has_electronic_portfolio_s_by_default() {
1✔
630
        let document = LegacyDataspaceDocument::builder().build();
1✔
631
        let solr = SolrDocument::from(&document);
1✔
632
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
633
        assert!(solr.electronic_portfolio_s.unwrap().contains("thesis"));
1✔
634
    }
1✔
635

636
    #[test]
637
    fn it_has_no_electronic_portfolio_s_if_location_specified_and_older_thesis() {
1✔
638
        let document = LegacyDataspaceDocument::builder()
1✔
639
            .with_date_classyear("1955")
1✔
640
            .with_location(r#"This thesis can be viewed in person at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.  \nTo order a copy complete the <a href=\"http://rbsc.princeton.edu/senior-thesis-order-form\" target=\"_blank\">Senior Thesis Request Form</a>.  \nFor more information contact <a href=mailto:mudd@princeton.edu>mudd@princeton.edu</a>."#)
1✔
641
            .build();
1✔
642
        let solr = SolrDocument::from(&document);
1✔
643
        assert!(solr.electronic_portfolio_s.is_none());
1✔
644
    }
1✔
645

646
    #[test]
647
    fn with_allowed_department_name() {
1✔
648
        let document = LegacyDataspaceDocument::builder()
1✔
649
            .with_department("English")
1✔
650
            .build();
1✔
651
        let solr = SolrDocument::from(&document);
1✔
652
        assert_eq!(
1✔
653
            solr.department_display.unwrap(),
1✔
654
            vec!["Princeton University. Department of English"],
1✔
655
            "it should map to the LC authorized name for the department"
×
656
        );
657
    }
1✔
658

659
    #[test]
660
    fn with_disallowed_department_name() {
1✔
661
        let document = LegacyDataspaceDocument::builder().with_department("NA").build();
1✔
662
        let solr = SolrDocument::from(&document);
1✔
663
        assert!(
1✔
664
            solr.department_display.unwrap().is_empty(),
1✔
665
            "it should not include department names that are not in the authorized list"
×
666
        );
667
    }
1✔
668

669
    #[test]
670
    fn with_multiple_allowed_department_names() {
1✔
671
        let document = LegacyDataspaceDocument::builder()
1✔
672
            .with_department("English")
1✔
673
            .with_department("German")
1✔
674
            .build();
1✔
675
        let solr = SolrDocument::from(&document);
1✔
676
        assert_eq!(
1✔
677
            solr.department_display.unwrap(),
1✔
678
            vec![
1✔
679
                "Princeton University. Department of English",
680
                "Princeton University. Department of Germanic Languages and Literatures"
1✔
681
            ],
682
            "it should map to all LC authorized department names"
×
683
        );
684
    }
1✔
685

686
    #[test]
687
    fn with_allowed_certificate_name() {
1✔
688
        let document = LegacyDataspaceDocument::builder()
1✔
689
            .with_certificate("Creative Writing Program")
1✔
690
            .build();
1✔
691
        let solr = SolrDocument::from(&document);
1✔
692
        assert_eq!(
1✔
693
            solr.certificate_display.unwrap(),
1✔
694
            vec!["Princeton University. Creative Writing Program"],
1✔
695
            "it should map to the LC authorized name for the program"
×
696
        );
697
    }
1✔
698

699
    #[test]
700
    fn with_disallowed_certificate_name() {
1✔
701
        let document = LegacyDataspaceDocument::builder().with_certificate("NA").build();
1✔
702
        let solr = SolrDocument::from(&document);
1✔
703
        assert!(
1✔
704
            solr.certificate_display.unwrap().is_empty(),
1✔
705
            "it should not include program names that are not in the authorized list"
×
706
        );
707
    }
1✔
708

709
    #[test]
710
    fn with_multiple_allowed_certificate_names() {
1✔
711
        let document = LegacyDataspaceDocument::builder()
1✔
712
            .with_certificate("Environmental Studies Program")
1✔
713
            .with_certificate("African Studies Program")
1✔
714
            .build();
1✔
715
        let solr = SolrDocument::from(&document);
1✔
716
        assert_eq!(
1✔
717
            solr.certificate_display.unwrap(),
1✔
718
            vec![
1✔
719
                "Princeton University. Program in Environmental Studies",
720
                "Princeton University. Program in African Studies"
1✔
721
            ],
722
            "it should map to all LC authorized program names"
×
723
        );
724
    }
1✔
725

726
    #[test]
727
    fn location_code_s() {
1✔
728
        let document = LegacyDataspaceDocument::builder()
1✔
729
            .with_date_classyear("2020")
1✔
730
            .build();
1✔
731
        let solr = SolrDocument::from(&document);
1✔
732
        assert_eq!(solr.location_code_s, None);
1✔
733

734
        let document = LegacyDataspaceDocument::builder()
1✔
735
            .with_date_classyear("1980")
1✔
736
            .with_rights_access_rights("Limited access")
1✔
737
            .build();
1✔
738
        let solr = SolrDocument::from(&document);
1✔
739
        assert_eq!(solr.location_code_s.unwrap(), "mudd$stacks");
1✔
740
    }
1✔
741

742
    #[test]
743
    fn location_display() {
1✔
744
        let document = LegacyDataspaceDocument::builder()
1✔
745
            .with_mudd_walkin("yes")
1✔
746
            .with_date_classyear("1995")
1✔
747
            .build();
1✔
748
        let solr = SolrDocument::from(&document);
1✔
749
        assert_eq!(solr.location_display.unwrap(), "Mudd Manuscript Library");
1✔
750
    }
1✔
751

752
    #[test]
753
    fn holdings_1display() {
1✔
754
        let document = LegacyDataspaceDocument::builder()
1✔
755
            .with_rights_access_rights("Limited access")
1✔
756
            .with_date_classyear("2005")
1✔
757
            .build();
1✔
758
        let solr = SolrDocument::from(&document);
1✔
759
        assert_eq!(
1✔
760
            solr.holdings_1display.unwrap(),
1✔
761
            "{\"thesis\":{\"location\":\"Mudd Manuscript Library\",\"library\":\"Mudd Manuscript Library\",\"location_code\":\"mudd$stacks\",\"call_number\":\"AC102\",\"call_number_browse\":\"AC102\",\"dspace\":true}}",
762
            "holdings_1display should be present when physical thesis has limited access"
×
763
        );
764

765
        let document = LegacyDataspaceDocument::builder()
1✔
766
            .with_identifier_uri("http://arks.princeton.edu/ark:/88435/dsp0141687h67f")
1✔
767
            .build();
1✔
768
        let solr = SolrDocument::from(&document);
1✔
769
        assert!(
1✔
770
            solr.holdings_1display.is_none(),
1✔
771
            "holdings_1display should not be present when newer thesis has no location information"
×
772
        );
773
    }
1✔
774

775
    #[test]
776
    fn call_number_browse_s() {
1✔
777
        let document = LegacyDataspaceDocument::builder()
1✔
778
            .with_rights_access_rights("Limited access")
1✔
779
            .with_date_classyear("2005")
1✔
780
            .build();
1✔
781
        let solr = SolrDocument::from(&document);
1✔
782
        assert_eq!(solr.call_number_browse_s, "AC102");
1✔
783
    }
1✔
784

785
    #[test]
786
    fn language_facet() {
1✔
787
        let document = LegacyDataspaceDocument::builder().with_language_iso("it").build();
1✔
788
        let solr = SolrDocument::from(&document);
1✔
789
        assert_eq!(solr.language_facet, vec!["Italian".to_owned()]);
1✔
790
    }
1✔
791

792
    mod restrictions_note_display {
793
        use super::*;
794

795
        #[test]
796
        fn when_lift_date_is_invalid() {
1✔
797
            let document = LegacyDataspaceDocument::builder()
1✔
798
                .with_id("test-id")
1✔
799
                .with_embargo_lift("invalid")
1✔
800
                .build();
1✔
801
            let solr = SolrDocument::from(&document);
1✔
802
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>."]);
1✔
803
        }
1✔
804

805
        #[test]
806
        fn when_terms_date_is_invalid() {
1✔
807
            let document = LegacyDataspaceDocument::builder()
1✔
808
                .with_id("test-id")
1✔
809
                .with_embargo_terms("invalid")
1✔
810
                .build();
1✔
811
            let solr = SolrDocument::from(&document);
1✔
812
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>."]);
1✔
813
        }
1✔
814

815
        #[test]
816
        fn when_there_are_access_rights() {
1✔
817
            let document = LegacyDataspaceDocument::builder()
1✔
818
                .with_id("test-id")
1✔
819
                .with_rights_access_rights("Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.")
1✔
820
                .build();
1✔
821
            let solr = SolrDocument::from(&document);
1✔
822
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>."]);
1✔
823
        }
1✔
824
    }
825

826
    mod title_sort {
827
        use super::*;
828

829
        #[test]
830
        fn it_can_create_sortable_version_of_title() {
1✔
831
            assert_eq!(
1✔
832
                title_sort(Some(&vec!["\"Some quote\" : Blah blah".to_owned()])).unwrap(),
1✔
833
                "somequoteblahblah",
834
                "it should strip punctuation"
×
835
            );
836
            assert_eq!(
1✔
837
                title_sort(Some(&vec!["A title : blah blah".to_owned()])).unwrap(),
1✔
838
                "titleblahblah",
839
                "it should strip articles"
×
840
            );
841
            assert_eq!(
1✔
842
                title_sort(Some(&vec!["\"A quote\" : Blah blah".to_owned()])).unwrap(),
1✔
843
                "quoteblahblah",
844
                "it should strip punctuation and articles"
×
845
            );
846
            assert_eq!(
1✔
847
                title_sort(Some(&vec!["thesis".to_owned()])).unwrap(),
1✔
848
                "thesis",
849
                "it should leave words that start with articles alone"
×
850
            );
851
        }
1✔
852
    }
853
}
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