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

pulibrary / pdc_discovery / 3823446b-c57e-4abf-8330-d3cff9d77076

pending completion
3823446b-c57e-4abf-8330-d3cff9d77076

Pull #382

circleci

Hector Correa
When importing dataspace records, skip those that have matching records already imported from PDC Describe
Pull Request #382: Give priority to PDC Describe records when indexing records

5 of 5 new or added lines in 1 file covered. (100.0%)

1714 of 1932 relevant lines covered (88.72%)

102.07 hits per line

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

97.44
/app/models/solr_document.rb
1
# frozen_string_literal: true
2

3
# rubocop:disable Metrics/ClassLength
4
class SolrDocument
1✔
5
  include Blacklight::Solr::Document
1✔
6
  # The following shows how to setup this blacklight document to display marc documents
7
  extension_parameters[:marc_source_field] = :marc_ss
1✔
8
  extension_parameters[:marc_format_type] = :marcxml
1✔
9
  use_extension(Blacklight::Solr::Document::Marc) do |document|
1✔
10
    document.key?(SolrDocument.extension_parameters[:marc_source_field])
24✔
11
  end
12

13
  field_semantics.merge!(
1✔
14
    title: 'title_tesim',
15
    contributor: 'author_tesim',
16
    format: 'genre_ssim',
17
    date: 'issue_date_ssim'
18
  )
19

20
  # self.unique_key = 'id'
21

22
  # Email uses the semantic field mappings below to generate the body of an email.
23
  SolrDocument.use_extension(Blacklight::Document::Email)
1✔
24

25
  # SMS uses the semantic field mappings below to generate the body of an SMS email.
26
  SolrDocument.use_extension(Blacklight::Document::Sms)
1✔
27

28
  # DublinCore uses the semantic field mappings below to assemble an OAI-compliant Dublin Core document
29
  # Semantic mappings of solr stored fields. Fields may be multi or
30
  # single valued. See Blacklight::Document::SemanticFields#field_semantics
31
  # and Blacklight::Document::SemanticFields#to_semantic_values
32
  # Recommendation: Use field names from Dublin Core
33
  use_extension(Blacklight::Document::DublinCore)
1✔
34

35
  ABSTRACT_FIELD = 'abstract_tsim'
1✔
36
  DESCRIPTION_FIELD = 'description_tsim'
1✔
37
  ISSUED_DATE_FIELD = 'issue_date_ssim'
1✔
38
  METHODS_FIELD = 'methods_tsim'
1✔
39
  TITLE_FIELD = 'title_tesim'
1✔
40

41
  # These icons map to CSS classes in Bootstrap
42
  ICONS = {
1✔
43
    "dataset" => "bi-stack",
44
    "moving image" => "bi-film",
45
    "software" => "bi-code-slash",
46
    "image" => "bi-image",
47
    "text" => "bi-card-text",
48
    "collection" => "bi-collection-fill",
49
    "article" => "bi-journal-text",
50
    "interactive resource" => "bi-pc-display-horizontal"
51
  }.freeze
52

53
  def id
1✔
54
    fetch('id')
25✔
55
  end
56

57
  def titles
1✔
58
    fetch(TITLE_FIELD, [])
10✔
59
  end
60

61
  def title
1✔
62
    titles.first
10✔
63
  end
64

65
  def authors
1✔
66
    fetch('author_tesim', [])
16✔
67
  end
68

69
  # Returns a string with the authors and shortens it if there are more than 2 authors.
70
  # https://owl.purdue.edu/owl/research_and_citation/apa_style/apa_formatting_and_style_guide/in_text_citations_author_authors.html
71
  def authors_et_al
1✔
72
    authors_all = authors
8✔
73
    if authors_all.count <= 2
8✔
74
      authors_all.join(" & ")
6✔
75
    else
76
      authors_all.first + " et al."
2✔
77
    end
78
  end
79

80
  def creators
1✔
81
    fetch('creator_tesim', [])
2✔
82
  end
83

84
  def community_path
1✔
85
    fetch("community_path_name_ssi", "")
2✔
86
  end
87

88
  def collection_name
1✔
89
    fetch("collection_name_ssi", "")
2✔
90
  end
91

92
  def collection_tags
1✔
93
    fetch("collection_tag_ssim", [])
4✔
94
  end
95

96
  def contributors
1✔
97
    fetch("contributor_tsim", [])
2✔
98
  end
99

100
  def accessioned_dates
1✔
101
    fetch("date_accessioned_ssim", [])
2✔
102
  end
103

104
  def accessioned_date
1✔
105
    accessioned_dates.first
2✔
106
  end
107

108
  def issued_dates
1✔
109
    fetch(ISSUED_DATE_FIELD, [])
10✔
110
  end
111

112
  def issued_date
1✔
113
    issued_dates.first
10✔
114
  end
115

116
  def abstracts
1✔
117
    fetch(ABSTRACT_FIELD, [])
2✔
118
  end
119

120
  def abstract
1✔
121
    abstracts.first
×
122
  end
123

124
  def descriptions
1✔
125
    fetch(DESCRIPTION_FIELD, [])
2✔
126
  end
127

128
  def description
1✔
129
    descriptions.first
×
130
  end
131

132
  def methods
1✔
133
    fetch(METHODS_FIELD, [])
×
134
  end
135

136
  # rubocop:disable Lint/UselessAssignment
137
  def files
1✔
138
    files ||= begin
7✔
139
      data = JSON.parse(fetch("files_ss", "[]"))
7✔
140
      data.map { |x| DatasetFile.from_hash(x) }.sort_by(&:sequence)
13✔
141
    end
142
  end
143
  # rubocop:enable Lint/UselessAssignment
144

145
  # Returns an array with the counts by file extension
146
  # e.g. [{extension: "txt", file_count: 3}, {extension: "csv", file_count: 1}]
147
  def file_counts
1✔
148
    groups = files.group_by(&:extension)
5✔
149
    groups.map { |key, value| { extension: key, file_count: value.count } }.sort_by { |group| -group[:file_count] }
13✔
150
  end
151

152
  def table_of_contents
1✔
153
    fetch("tableofcontents_tesim", [])
2✔
154
  end
155

156
  def referenced_by
1✔
157
    fetch("referenced_by_ssim", [])
2✔
158
  end
159

160
  def uri
1✔
161
    fetch("uri_ssim", [])
10✔
162
  end
163

164
  def doi_url
1✔
165
    uri.each do |link|
6✔
166
      return link if link.downcase.start_with?('https://doi.org/')
6✔
167
    end
168
    nil
169
  end
170

171
  def doi_value
1✔
172
    doi_url&.gsub('https://doi.org/', '')
2✔
173
  end
174

175
  def format
1✔
176
    fetch("format_ssim", [])
2✔
177
  end
178

179
  def globus_uri
1✔
180
    uri.each do |link|
2✔
181
      return link if link.downcase.start_with?('https://app.globus.org/')
4✔
182
    end
183
    nil
184
  end
185

186
  def extent
1✔
187
    fetch("extent_ssim", [])
2✔
188
  end
189

190
  def medium
1✔
191
    fetch("medium_ssim", [])
2✔
192
  end
193

194
  def mimetype
1✔
195
    fetch("mimetype_ssim", [])
2✔
196
  end
197

198
  def language
1✔
199
    fetch("language_ssim", [])
2✔
200
  end
201

202
  def publisher
1✔
203
    fetch("publisher_ssim", [])
4✔
204
  end
205

206
  def publisher_place
1✔
207
    fetch("publisher_place_ssim", [])
2✔
208
  end
209

210
  def publisher_corporate
1✔
211
    fetch("publisher_corporate_ssim", [])
2✔
212
  end
213

214
  def relation
1✔
215
    fetch("relation_ssim", [])
2✔
216
  end
217

218
  def relation_is_format_of
1✔
219
    fetch("relation_is_format_of_ssim", [])
2✔
220
  end
221

222
  def relation_has_format
1✔
223
    fetch("relation_has_format_ssim", [])
2✔
224
  end
225

226
  def relation_is_part_of
1✔
227
    fetch("relation_is_part_of_ssim", [])
2✔
228
  end
229

230
  def relation_is_part_of_series
1✔
231
    fetch("relation_is_part_of_series_ssim", [])
2✔
232
  end
233

234
  def relation_has_part
1✔
235
    fetch("relation_has_part_ssim", [])
2✔
236
  end
237

238
  def relation_is_version_of
1✔
239
    fetch("relation_is_version_of_ssim", [])
2✔
240
  end
241

242
  def relation_has_version
1✔
243
    fetch("relation_has_version_ssim", [])
2✔
244
  end
245

246
  def relation_is_based_on
1✔
247
    fetch("relation_is_based_on_ssim", [])
2✔
248
  end
249

250
  def relation_is_referenced_by
1✔
251
    fetch("relation_is_referenced_by_ssim", [])
2✔
252
  end
253

254
  def relation_is_required_by
1✔
255
    fetch("relation_is_required_by_ssim", [])
2✔
256
  end
257

258
  def relation_requires
1✔
259
    fetch("relation_requires_ssim", [])
2✔
260
  end
261

262
  def relation_replaces
1✔
263
    fetch("relation_replaces_ssim", [])
2✔
264
  end
265

266
  def relation_is_replaced_by
1✔
267
    fetch("relation_is_replaced_by_ssim", [])
2✔
268
  end
269

270
  def relation_uri
1✔
271
    fetch("relation_uri_ssim", [])
2✔
272
  end
273

274
  def rights
1✔
275
    fetch("rights_ssim", [])
×
276
  end
277

278
  def rights_uri
1✔
279
    fetch("rights_uri_ssim", [])
×
280
  end
281

282
  # For PDC Describe records we have a single value for the name and the uri
283
  # and we can safely assume they are related.
284
  def rights_name_and_uri
1✔
285
    name = fetch("rights_name_ssi", nil)
6✔
286
    uri = fetch("rights_uri_ssi", nil)
6✔
287
    return nil if name.nil? || uri.nil?
6✔
288
    { name: name, uri: uri }
6✔
289
  end
290

291
  def rights_holder
1✔
292
    fetch("rights_holder_ssim", [])
2✔
293
  end
294

295
  def subject
1✔
296
    fetch("subject_tesim", [])
2✔
297
  end
298

299
  def subject_classification
1✔
300
    fetch("subject_classification_tesim", [])
2✔
301
  end
302

303
  def subject_ddc
1✔
304
    fetch("subject_ddc_tesim", [])
2✔
305
  end
306

307
  def subject_lcc
1✔
308
    fetch("subject_lcc_tesim", [])
2✔
309
  end
310

311
  def subject_lcsh
1✔
312
    fetch("subject_lcsh_tesim", [])
2✔
313
  end
314

315
  def subject_mesh
1✔
316
    fetch("subject_mesh_tesim", [])
2✔
317
  end
318

319
  def subject_other
1✔
320
    fetch("subject_other_tesim", [])
2✔
321
  end
322

323
  def alternative_title
1✔
324
    fetch("alternative_title_tesim", [])
2✔
325
  end
326

327
  def genres
1✔
328
    fetch("genre_ssim", []).sort
12✔
329
  end
330

331
  # Sometimes we need a single genre for an item, even though an item may have more than one.
332
  # This method makes sure we always get the same value (the first one from a sorted list).
333
  def genre
1✔
334
    genres.first
10✔
335
  end
336

337
  def peer_review_status
1✔
338
    fetch("peer_review_status_ssim", [])
2✔
339
  end
340

341
  def translator
1✔
342
    fetch("translator_ssim", [])
2✔
343
  end
344

345
  def isan
1✔
346
    fetch("isan_ssim", [])
2✔
347
  end
348

349
  def access_rights
1✔
350
    fetch("access_rights_ssim", [])
2✔
351
  end
352

353
  def funding_agency
1✔
354
    fetch("funding_agency_ssim", [])
2✔
355
  end
356

357
  def provenance
1✔
358
    fetch("provenance_ssim", [])
2✔
359
  end
360

361
  def license
1✔
362
    fetch("license_ssim", [])
2✔
363
  end
364

365
  def accrual_method
1✔
366
    fetch("accrual_method_ssim", [])
2✔
367
  end
368

369
  def accrual_periodicity
1✔
370
    fetch("accrual_periodicity_ssim", [])
2✔
371
  end
372

373
  def accrual_policy
1✔
374
    fetch("accrual_policy_ssim", [])
2✔
375
  end
376

377
  def audience
1✔
378
    fetch("audience_ssim", [])
2✔
379
  end
380

381
  def available
1✔
382
    fetch("available_ssim", [])
2✔
383
  end
384

385
  def bibliographic_citation
1✔
386
    fetch("bibliographic_citation_ssim", [])
2✔
387
  end
388

389
  def conforms_to
1✔
390
    fetch("conforms_to_ssim", [])
2✔
391
  end
392

393
  def coverage
1✔
394
    fetch("coverage_tesim", [])
2✔
395
  end
396

397
  def spatial_coverage
1✔
398
    fetch("spatial_coverage_tesim", [])
2✔
399
  end
400

401
  def temporal_coverage
1✔
402
    fetch("temporal_coverage_tesim", [])
2✔
403
  end
404

405
  def dates_created
1✔
406
    fetch("date_created_ssim", [])
2✔
407
  end
408

409
  def date_created
1✔
410
    dates_created.first
2✔
411
  end
412

413
  def dates_submitted
1✔
414
    fetch("date_submitted_ssim", [])
2✔
415
  end
416

417
  def date_submitted
1✔
418
    dates_submitted.first
2✔
419
  end
420

421
  def dates_accepted
1✔
422
    fetch("date_accepted_ssim", [])
2✔
423
  end
424

425
  def date_accepted
1✔
426
    dates_accepted.first
2✔
427
  end
428

429
  def dates_copyrighted
1✔
430
    fetch("copyright_date_ssim", [])
2✔
431
  end
432

433
  def date_copyrighted
1✔
434
    dates_copyrighted.first
2✔
435
  end
436

437
  def dates_modified
1✔
438
    fetch("date_modified_ssim", [])
2✔
439
  end
440

441
  def date_modified
1✔
442
    dates_modified.first
2✔
443
  end
444

445
  def dates_valid
1✔
446
    fetch("date_valid_ssim", [])
2✔
447
  end
448

449
  def education_level
1✔
450
    fetch("education_level_ssim", [])
2✔
451
  end
452

453
  def other_identifier
1✔
454
    fetch("other_identifier_ssim", [])
2✔
455
  end
456

457
  def instructional_method
1✔
458
    fetch("instructional_method_ssim", [])
2✔
459
  end
460

461
  def mediator
1✔
462
    fetch("mediator_ssim", [])
2✔
463
  end
464

465
  def source
1✔
466
    fetch("source_ssim", [])
2✔
467
  end
468

469
  def domain
1✔
470
    fetch("domain_ssi", "")
2✔
471
  end
472

473
  def icon_css
1✔
474
    ICONS[genre&.downcase] || 'bi-file-earmark-fill'
6✔
475
  end
476

477
  # Returns a DatasetCitation object for the current document
478
  def citation
1✔
479
    @citation ||= begin
8✔
480
      year_available = fetch('year_available_itsi', nil)
2✔
481
      years = year_available ? [year_available.to_s] : []
2✔
482
      DatasetCitation.new(authors, years, title, 'Data set', publisher.first, doi_url)
2✔
483
    end
484
  end
485

486
  # Returns a string with the indicated citation style (e.g. APA or BibTeX)
487
  def cite(style)
1✔
488
    citation.to_s(style)
6✔
489
  end
490

491
  # Returns the ID for a BibTeX citation for this document.
492
  # rubocop:disable Rails/Delegate
493
  def bibtex_id
1✔
494
    citation.bibtex_id
×
495
  end
496
  # rubocop:enable Rails/Delegate
497
end
498
# rubocop:enable Metrics/ClassLength
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