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

pulibrary / pdc_discovery / 529bb1cf-d0bf-4901-97c6-12679aea8117

17 Aug 2023 01:30PM UTC coverage: 90.265% (-6.3%) from 96.544%
529bb1cf-d0bf-4901-97c6-12679aea8117

Pull #478

circleci

carolyncole
Updates to css to fix tests after bundle update
Also ran rubocop -A && Prettier
Pull Request #478: Switching to selenium to fix CI

2 of 2 new or added lines in 2 files covered. (100.0%)

2142 of 2373 relevant lines covered (90.27%)

93.35 hits per line

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

71.84
/app/controllers/catalog_controller.rb
1
# frozen_string_literal: true
2

3
class CatalogController < ApplicationController
1✔
4
  include Blacklight::Catalog
1✔
5
  include BlacklightRangeLimit::ControllerOverride
1✔
6

7
  include Blacklight::Marc::Catalog
1✔
8

9
  rescue_from Blacklight::Exceptions::RecordNotFound do
1✔
10
    error_page = Rails.env.production? || Rails.env.staging? ? '/discovery/errors/not_found' : '/errors/not_found'
1✔
11
    redirect_to error_page
1✔
12
  end
13

14
  configure_blacklight do |config|
1✔
15
    ## Class for sending and receiving requests from a search index
16
    # config.repository_class = Blacklight::Solr::Repository
17
    #
18
    ## Class for converting Blacklight's url parameters to into request parameters for the search index
19
    # config.search_builder_class = ::SearchBuilder
20
    #
21
    ## Model that maps search index responses to the blacklight response model
22
    # config.response_model = Blacklight::Solr::Response
23
    #
24
    ## Should the raw solr document endpoint (e.g. /catalog/:id/raw) be enabled
25
    config.raw_endpoint.enabled = true
1✔
26

27
    ## Default parameters to send to solr for all search-like requests. See also SearchBuilder#processed_parameters
28
    config.default_solr_params = {
1✔
29
      rows: 10
30
    }
31

32
    # solr path which will be added to solr base url before the other solr params.
33
    # config.solr_path = 'select'
34
    # config.document_solr_path = 'get'
35

36
    # items to show per page, each number in the array represent another option to choose from.
37
    # config.per_page = [10,20,50,100]
38

39
    # solr field configuration for search results/index views
40
    config.index.title_field = 'title_tesim'
1✔
41
    # config.index.display_type_field = 'format'
42
    # config.index.thumbnail_field = 'thumbnail_path_ss'
43

44
    config.add_results_document_tool(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
1✔
45

46
    config.add_results_collection_tool(:sort_widget)
1✔
47
    config.add_results_collection_tool(:per_page_widget)
1✔
48
    config.add_results_collection_tool(:view_type_group)
1✔
49

50
    config.add_show_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
1✔
51
    config.add_show_tools_partial(:email, callback: :email_action, validator: :validate_email_params)
1✔
52
    config.add_show_tools_partial(:sms, if: :render_sms_action?, callback: :sms_action, validator: :validate_sms_params)
1✔
53
    config.add_show_tools_partial(:citation)
1✔
54

55
    config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark', if: :render_bookmarks_control?)
1✔
56
    config.add_nav_action(:search_history, partial: 'blacklight/nav/search_history')
1✔
57

58
    # solr field configuration for document/show views
59
    # config.show.display_type_field = 'format'
60
    # config.show.thumbnail_field = 'thumbnail_path_ss'
61

62
    # solr fields that will be treated as facets by the blacklight application
63
    #   The ordering of the field names is the order of the display
64
    #
65
    # Setting a limit will trigger Blacklight's 'more' facet values link.
66
    # * If left unset, then all facet values returned by solr will be displayed.
67
    # * If set to an integer, then "f.somefield.facet.limit" will be added to
68
    # solr request, with actual solr request being +1 your configured limit --
69
    # you configure the number of items you actually want _displayed_ in a page.
70
    # * If set to 'true', then no additional parameters will be sent to solr,
71
    # but any 'sniffed' request limit parameters will be used for paging, with
72
    # paging at requested limit -1. Can sniff from facet.limit or
73
    # f.specific_field.facet.limit solr request params. This 'true' config
74
    # can be used if you set limits in :default_solr_params, or as defaults
75
    # on the solr side in the request handler itself. Request handler defaults
76
    # sniffing requires solr requests to be made with "echoParams=all", for
77
    # app code to actually have it echo'd back to see it.
78
    #
79
    # :show may be set to false if you don't want the facet to be drawn in the
80
    # facet bar
81
    #
82
    # set :index_range to true if you want the facet pagination view to have facet prefix-based navigation
83
    #  (useful when user clicks "more" on a large facet and wants to navigate alphabetically across a large set of results)
84
    # :index_range can be an array or range of prefixes that will be used to create the navigation (note: It is case sensitive when searching values)
85

86
    # config.add_facet_field 'example_pivot_field', label: 'Pivot Field', pivot: %w[format language_ssim], collapsing: true
87

88
    # config.add_facet_field 'example_query_facet_field', label: 'Publish Date', query: {
89
    #   years_5: { label: 'within 5 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 5} TO *]" },
90
    #   years_10: { label: 'within 10 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 10} TO *]" },
91
    #   years_25: { label: 'within 25 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 25} TO *]" }
92
    # }
93

94
    config.add_facet_field 'domain_ssim', label: 'Domain'
1✔
95
    config.add_facet_field 'communities_ssim', label: 'Community'
1✔
96
    config.add_facet_field 'subcommunities_ssim', label: 'Subcommunity'
1✔
97

98
    config.add_facet_field 'collection_tag_ssim', label: 'Collection Tags'
1✔
99
    config.add_facet_field 'authors_affiliation_ssim', label: 'Affiliation'
1✔
100

101
    config.add_facet_field 'genre_ssim', label: 'Type'
1✔
102
    config.add_facet_field 'year_available_itsi', label: 'Year Published', range: true
1✔
103

104
    # Notice that is facet is not shown. Yet facet searches by this field do work
105
    # and we use them when users click on the "Keywords" links in the Show page.
106
    config.add_facet_field 'subject_all_ssim', label: 'Keywords', show: false
1✔
107

108
    # An extra facet to filter DataSpace vs PDC Describe records at will
109
    # (this is handy during the migration)
110
    config.add_facet_field 'data_source_ssi', label: 'Source'
1✔
111

112
    # Have BL send all facet field names to Solr, which has been the default
113
    # previously. Simply remove these lines if you'd rather use Solr request
114
    # handler defaults, or have no facets.
115
    config.add_facet_fields_to_solr_request!
1✔
116

117
    # solr fields to be displayed in the index (search results) view
118
    #   The ordering of the field names is the order of the display
119

120
    # Notice that for the author field we key of the `author_tesim` field but in reality
121
    # we render a different value (see the helper). We use `author_tesim` in here because
122
    # that is a common field between all our records, the ones coming from DataSpace
123
    # and the ones coming from PDC Describe.
124
    config.add_index_field 'author_tesim', label: 'Author(s)', helper_method: :authors_search_results_helper
1✔
125

126
    config.add_index_field 'format', label: 'Format'
1✔
127
    config.add_index_field 'abstract_tsim', label: 'Abstract'
1✔
128
    config.add_index_field 'published_ssim', label: 'Published'
1✔
129
    config.add_index_field 'published_vern_ssim', label: 'Published'
1✔
130
    config.add_index_field 'genre_ssim', label: 'Type'
1✔
131
    config.add_index_field 'issue_date_ssim', label: 'Issue Date'
1✔
132

133
    # solr fields to be displayed in the show (single result) view
134
    #   The ordering of the field names is the order of the display
135
    config.add_show_field 'author_tesim', label: 'Author'
1✔
136
    config.add_show_field 'format', label: 'Format'
1✔
137
    config.add_show_field 'url_fulltext_ssim', label: 'URL'
1✔
138
    config.add_show_field 'url_suppl_ssim', label: 'More Information'
1✔
139
    config.add_show_field 'language_ssim', label: 'Language'
1✔
140
    config.add_show_field 'published_ssim', label: 'Published'
1✔
141
    config.add_show_field 'published_vern_ssim', label: 'Published'
1✔
142
    config.add_show_field 'lc_callnum_ssim', label: 'Call number'
1✔
143
    config.add_show_field 'isbn_ssim', label: 'ISBN'
1✔
144
    config.add_show_field 'handle_ssim', label: 'Handle'
1✔
145

146
    config.add_show_field 'abstract_tsim', label: 'Abstract'
1✔
147
    config.add_show_field 'contributor_tsim', label: 'Author'
1✔
148
    config.add_show_field 'description_tsim', label: 'Description'
1✔
149
    config.add_show_field 'issue_date_ssim', label: 'Issued Date'
1✔
150
    config.add_show_field 'methods_tsim', label: 'Methods'
1✔
151

152
    # "fielded" search configuration. Used by pulldown among other places.
153
    # For supported keys in hash, see rdoc for Blacklight::SearchFields
154
    #
155
    # Search fields will inherit the :qt solr request handler from
156
    # config[:default_solr_parameters], OR can specify a different one
157
    # with a :qt key/value. Below examples inherit, except for subject
158
    # that specifies the same :qt as default for our own internal
159
    # testing purposes.
160
    #
161
    # The :key is what will be used to identify this BL search field internally,
162
    # as well as in URLs -- so changing it after deployment may break bookmarked
163
    # urls.  A display label will be automatically calculated from the :key,
164
    # or can be specified manually to be different.
165

166
    # This one uses all the defaults set by the solr request handler. Which
167
    # solr request handler? The one set in config[:default_solr_parameters][:qt],
168
    # since we aren't specifying it otherwise.
169

170
    config.add_search_field 'all_fields', label: 'All Fields'
1✔
171

172
    # Now we see how to over-ride Solr request handler defaults, in this
173
    # case for a BL "search field", which is really a dismax aggregate
174
    # of Solr search fields.
175

176
    config.add_search_field('title') do |field|
1✔
177
      # solr_parameters hash are sent to Solr as ordinary url query params.
178
      field.solr_parameters = {
1✔
179
        'spellcheck.dictionary': 'title',
180
        qf: '${title_qf}',
181
        pf: '${title_pf}'
182
      }
183
    end
184

185
    config.add_search_field('author') do |field|
1✔
186
      field.solr_parameters = {
1✔
187
        'spellcheck.dictionary': 'author',
188
        qf: '${author_qf}',
189
        pf: '${author_pf}'
190
      }
191
    end
192

193
    config.add_search_field('orcid') do |field|
1✔
194
      field.label = "ORCID"
1✔
195
      field.solr_parameters = {
1✔
196
        qf: 'authors_orcid_ssim',
197
        pf: 'authors_orcid_ssim'
198
      }
199
    end
200

201
    # Specifying a :qt only to show it's possible, and so our internal automated
202
    # tests can test it. In this case it's the same as
203
    # config[:default_solr_parameters][:qt], so isn't actually neccesary.
204
    config.add_search_field('subject') do |field|
1✔
205
      field.qt = 'search'
1✔
206
      field.solr_parameters = {
1✔
207
        'spellcheck.dictionary': 'subject',
208
        qf: '${subject_qf}',
209
        pf: '${subject_pf}'
210
      }
211
    end
212

213
    # "sort results by" select (pulldown)
214
    # label in pulldown is followed by the name of the Solr field to sort by and
215
    # whether the sort is ascending or descending (it must be asc or desc
216
    # except in the relevancy case). Add the sort: option to configure a
217
    # custom Blacklight url parameter value separate from the Solr sort fields.
218
    config.add_sort_field 'relevance', sort: 'score desc, year_available_itsi desc, title_si asc', label: 'relevance'
1✔
219
    config.add_sort_field 'year', sort: 'year_available_itsi desc, title_si asc', label: 'year'
1✔
220
    config.add_sort_field 'author', sort: 'author_si asc, title_si asc', label: 'author'
1✔
221
    config.add_sort_field 'title', sort: 'title_si asc, year_available_itsi desc', label: 'title'
1✔
222

223
    # If there are more than this many search results, no spelling ("did you
224
    # mean") suggestion is offered.
225
    config.spell_max = 5
1✔
226

227
    # # Configuration for autocomplete suggester
228
    # config.autocomplete_enabled = true
229
    # config.autocomplete_path = 'suggest'
230
    # # if the name of the solr.SuggestComponent provided in your solrconfig.xml is not the
231
    # # default 'mySuggester', uncomment and provide it below
232
    # # config.autocomplete_suggester = 'mySuggester'
233
    config.search_state_fields = config.search_state_fields + [
1✔
234
      :doi, :ark, :id,
235
      :a # this is in the search parameters becuase the search bar is shown on the error page
236
    ]
237
  end
238

239
  # Returns the raw BibTex citation information
240
  def bibtex
1✔
241
    _unused, @document = search_service.fetch(params[:id])
×
242
    citation = @document.cite("BibTeX")
×
243
    send_data citation, filename: "#{@document.bibtex_id}.bibtex", type: 'text/plain', disposition: 'attachment'
×
244
  end
245

246
  def resolve_doi
1✔
247
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:doi)
×
248

249
    doi_query = params[:doi]
×
250
    query = { q: "uri_ssim:*\"#{doi_query}\"" }
×
251

252
    solr_response = search_service.repository.search(**query)
×
253
    documents = solr_response.documents
×
254

255
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
×
256
    document = documents.first
×
257

258
    redirect_to(solr_document_path(id: document.id))
×
259
  end
260

261
  def resolve_ark
1✔
262
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:ark)
×
263

264
    ark = params[:ark]
×
265
    ark_query = "uri_ssim:*\"#{ark}\""
×
266
    query = { q: ark_query }
×
267

268
    solr_response = search_service.repository.search(**query)
×
269
    documents = solr_response.documents
×
270

271
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
×
272
    document = documents.first
×
273

274
    redirect_to(solr_document_path(id: document.id))
×
275
  end
276

277
  # Create an endpoint for PPPL / OSTI harvesting that provides full datacite records
278
  def pppl_reporting_feed
1✔
279
    # Limit to items from PPPL
280
    pppl_query = 'data_source_ssi:pdc_describe group_code_ssi:"PPPL"'
×
281
    page = params["page"] || "1"
×
282
    per_page = params["per_page"] || "10"
×
283
    start = per_page.to_i * (page.to_i - 1)
×
284

285
    query = { q: pppl_query, fl: 'pdc_describe_json_ss', format: 'json', sort: 'timestamp desc', rows: per_page, start: start }
×
286

287
    solr_response = search_service.repository.search(**query)
×
288

289
    @documents = solr_response.documents
×
290
    respond_to do |format|
×
291
      format.json { render json: @documents }
×
292
    end
293
  end
294
end
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