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

pulibrary / pdc_discovery / d4e0f429-48ab-46c0-b837-27bacddd2a41

24 Apr 2024 06:43PM UTC coverage: 92.63% (-4.4%) from 97.039%
d4e0f429-48ab-46c0-b837-27bacddd2a41

Pull #614

circleci

leefaisonr
Remove firefox from ci

Co-authored-by: Bess Sadler <bess@users.noreply.github.com>
Pull Request #614: Remove firefox from ci

2878 of 3107 relevant lines covered (92.63%)

495.74 hits per line

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

93.39
/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
  around_action :retry_on_exception
1✔
10

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

16
  def retry_on_exception
1✔
17
    yield
24✔
18
  rescue Blacklight::Exceptions::ECONNREFUSED, RSolr::Error::ConnectionRefused
19
    # If the Solr service is available, retry the HTTP request
20
    if search_service.repository.ping
2✔
21
      retry
×
22
    else
23
      error_page = Rails.env.production? || Rails.env.staging? ? '/discovery/errors/network_error' : '/errors/network_error'
2✔
24
      redirect_to error_page
2✔
25
    end
26
  end
27

28
  configure_blacklight do |config|
1✔
29
    ## Class for sending and receiving requests from a search index
30
    # config.repository_class = Blacklight::Solr::Repository
31
    #
32
    ## Class for converting Blacklight's url parameters to into request parameters for the search index
33
    # config.search_builder_class = ::SearchBuilder
34
    #
35
    ## Model that maps search index responses to the blacklight response model
36
    # config.response_model = Blacklight::Solr::Response
37
    #
38
    ## Should the raw solr document endpoint (e.g. /catalog/:id/raw) be enabled
39
    config.raw_endpoint.enabled = true
1✔
40

41
    ## Default parameters to send to solr for all search-like requests. See also SearchBuilder#processed_parameters
42
    config.default_solr_params = {
1✔
43
      rows: 10
44
    }
45

46
    # solr path which will be added to solr base url before the other solr params.
47
    # config.solr_path = 'select'
48
    # config.document_solr_path = 'get'
49

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

53
    # solr field configuration for search results/index views
54
    config.index.title_field = 'title_tesim'
1✔
55
    # config.index.display_type_field = 'format'
56
    # config.index.thumbnail_field = 'thumbnail_path_ss'
57

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

60
    config.add_results_collection_tool(:sort_widget)
1✔
61
    config.add_results_collection_tool(:per_page_widget)
1✔
62
    config.add_results_collection_tool(:view_type_group)
1✔
63

64
    config.add_show_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
1✔
65
    config.add_show_tools_partial(:email, callback: :email_action, validator: :validate_email_params)
1✔
66
    config.add_show_tools_partial(:sms, if: :render_sms_action?, callback: :sms_action, validator: :validate_sms_params)
1✔
67
    config.add_show_tools_partial(:citation)
1✔
68

69
    config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark', if: :render_bookmarks_control?)
1✔
70
    config.add_nav_action(:search_history, partial: 'blacklight/nav/search_history')
1✔
71

72
    # solr field configuration for document/show views
73
    # config.show.display_type_field = 'format'
74
    # config.show.thumbnail_field = 'thumbnail_path_ss'
75

76
    # solr fields that will be treated as facets by the blacklight application
77
    #   The ordering of the field names is the order of the display
78
    #
79
    # Setting a limit will trigger Blacklight's 'more' facet values link.
80
    # * If left unset, then all facet values returned by solr will be displayed.
81
    # * If set to an integer, then "f.somefield.facet.limit" will be added to
82
    # solr request, with actual solr request being +1 your configured limit --
83
    # you configure the number of items you actually want _displayed_ in a page.
84
    # * If set to 'true', then no additional parameters will be sent to solr,
85
    # but any 'sniffed' request limit parameters will be used for paging, with
86
    # paging at requested limit -1. Can sniff from facet.limit or
87
    # f.specific_field.facet.limit solr request params. This 'true' config
88
    # can be used if you set limits in :default_solr_params, or as defaults
89
    # on the solr side in the request handler itself. Request handler defaults
90
    # sniffing requires solr requests to be made with "echoParams=all", for
91
    # app code to actually have it echo'd back to see it.
92
    #
93
    # :show may be set to false if you don't want the facet to be drawn in the
94
    # facet bar
95
    #
96
    # set :index_range to true if you want the facet pagination view to have facet prefix-based navigation
97
    #  (useful when user clicks "more" on a large facet and wants to navigate alphabetically across a large set of results)
98
    # :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)
99

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

102
    # config.add_facet_field 'example_query_facet_field', label: 'Publish Date', query: {
103
    #   years_5: { label: 'within 5 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 5} TO *]" },
104
    #   years_10: { label: 'within 10 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 10} TO *]" },
105
    #   years_25: { label: 'within 25 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 25} TO *]" }
106
    # }
107

108
    # TODO: When we upgrade to Blacklight 8
109
    #  We can remove the `component: Blacklight::FacetFieldListComponent` from the `add_facet_field` lines
110
    #  It is only present to remove a deprecation warning in Blacklight 7 that ironically is not needed for Blacklight 8
111
    #
112
    config.add_facet_field 'domain_ssim', label: 'Domain', limit: 5, component: Blacklight::FacetFieldListComponent
1✔
113
    config.add_facet_field 'communities_ssim', label: 'Community', limit: 5, component: Blacklight::FacetFieldListComponent
1✔
114
    config.add_facet_field 'subcommunities_ssim', label: 'Subcommunity', limit: 5, component: Blacklight::FacetFieldListComponent
1✔
115

116
    config.add_facet_field 'collection_tag_ssim', label: 'Collection Tags', limit: 5, component: Blacklight::FacetFieldListComponent
1✔
117
    config.add_facet_field 'authors_affiliation_ssim', label: 'Affiliation', limit: 5, component: Blacklight::FacetFieldListComponent
1✔
118

119
    config.add_facet_field 'genre_ssim', label: 'Type', limit: 5, component: Blacklight::FacetFieldListComponent
1✔
120
    config.add_facet_field 'year_available_itsi', label: 'Year Published', range: true
1✔
121

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

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

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

135
    # solr fields to be displayed in the index (search results) view
136
    #   The ordering of the field names is the order of the display
137

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

144
    config.add_index_field 'format', label: 'Format'
1✔
145
    config.add_index_field 'abstract_tsim', label: 'Abstract'
1✔
146
    config.add_index_field 'published_ssim', label: 'Published'
1✔
147
    config.add_index_field 'published_vern_ssim', label: 'Published'
1✔
148
    config.add_index_field 'genre_ssim', label: 'Type'
1✔
149
    config.add_index_field 'issue_date_ssim', label: 'Issue Date'
1✔
150

151
    # solr fields to be displayed in the show (single result) view
152
    #   The ordering of the field names is the order of the display
153
    config.add_show_field 'author_tesim', label: 'Author'
1✔
154
    config.add_show_field 'format', label: 'Format'
1✔
155
    config.add_show_field 'url_fulltext_ssim', label: 'URL'
1✔
156
    config.add_show_field 'url_suppl_ssim', label: 'More Information'
1✔
157
    config.add_show_field 'language_ssim', label: 'Language'
1✔
158
    config.add_show_field 'published_ssim', label: 'Published'
1✔
159
    config.add_show_field 'published_vern_ssim', label: 'Published'
1✔
160
    config.add_show_field 'lc_callnum_ssim', label: 'Call number'
1✔
161
    config.add_show_field 'isbn_ssim', label: 'ISBN'
1✔
162
    config.add_show_field 'handle_ssim', label: 'Handle'
1✔
163

164
    config.add_show_field 'abstract_tsim', label: 'Abstract'
1✔
165
    config.add_show_field 'contributor_tsim', label: 'Author'
1✔
166
    config.add_show_field 'description_tsim', label: 'Description'
1✔
167
    config.add_show_field 'issue_date_ssim', label: 'Issued Date'
1✔
168
    config.add_show_field 'methods_tsim', label: 'Methods'
1✔
169

170
    # "fielded" search configuration. Used by pulldown among other places.
171
    # For supported keys in hash, see rdoc for Blacklight::SearchFields
172
    #
173
    # Search fields will inherit the :qt solr request handler from
174
    # config[:default_solr_parameters], OR can specify a different one
175
    # with a :qt key/value. Below examples inherit, except for subject
176
    # that specifies the same :qt as default for our own internal
177
    # testing purposes.
178
    #
179
    # The :key is what will be used to identify this BL search field internally,
180
    # as well as in URLs -- so changing it after deployment may break bookmarked
181
    # urls.  A display label will be automatically calculated from the :key,
182
    # or can be specified manually to be different.
183

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

188
    config.add_search_field 'all_fields', label: 'All Fields'
1✔
189

190
    # Now we see how to over-ride Solr request handler defaults, in this
191
    # case for a BL "search field", which is really a dismax aggregate
192
    # of Solr search fields.
193

194
    config.add_search_field('title') do |field|
1✔
195
      # solr_parameters hash are sent to Solr as ordinary url query params.
196
      field.solr_parameters = {
1✔
197
        'spellcheck.dictionary': 'title',
198
        qf: '${title_qf}',
199
        pf: '${title_pf}'
200
      }
201
    end
202

203
    config.add_search_field('author') do |field|
1✔
204
      field.solr_parameters = {
1✔
205
        'spellcheck.dictionary': 'author',
206
        qf: '${author_qf}',
207
        pf: '${author_pf}'
208
      }
209
    end
210

211
    config.add_search_field('orcid') do |field|
1✔
212
      field.label = "ORCID"
1✔
213
      field.solr_parameters = {
1✔
214
        qf: 'authors_orcid_ssim',
215
        pf: 'authors_orcid_ssim'
216
      }
217
    end
218

219
    # Specifying a :qt only to show it's possible, and so our internal automated
220
    # tests can test it. In this case it's the same as
221
    # config[:default_solr_parameters][:qt], so isn't actually neccesary.
222
    config.add_search_field('subject') do |field|
1✔
223
      field.qt = 'search'
1✔
224
      field.solr_parameters = {
1✔
225
        'spellcheck.dictionary': 'subject',
226
        qf: '${subject_qf}',
227
        pf: '${subject_pf}'
228
      }
229
    end
230

231
    # "sort results by" select (pulldown)
232
    # label in pulldown is followed by the name of the Solr field to sort by and
233
    # whether the sort is ascending or descending (it must be asc or desc
234
    # except in the relevancy case). Add the sort: option to configure a
235
    # custom Blacklight url parameter value separate from the Solr sort fields.
236
    config.add_sort_field 'relevance', sort: 'score desc, issue_date_strict_ssi desc, title_si asc', label: 'relevance'
1✔
237
    config.add_sort_field 'year', sort: 'issue_date_strict_ssi desc, title_si asc', label: 'year'
1✔
238
    config.add_sort_field 'author', sort: 'author_si asc, title_si asc', label: 'author'
1✔
239
    config.add_sort_field 'title', sort: 'title_si asc, issue_date_strict_ssi desc', label: 'title'
1✔
240

241
    # If there are more than this many search results, no spelling ("did you
242
    # mean") suggestion is offered.
243
    config.spell_max = 5
1✔
244

245
    # # Configuration for autocomplete suggester
246
    # config.autocomplete_enabled = true
247
    # config.autocomplete_path = 'suggest'
248
    # # if the name of the solr.SuggestComponent provided in your solrconfig.xml is not the
249
    # # default 'mySuggester', uncomment and provide it below
250
    # # config.autocomplete_suggester = 'mySuggester'
251
    config.search_state_fields = config.search_state_fields + [
1✔
252
      :doi, :ark, :id,
253
      :a # this is in the search parameters becuase the search bar is shown on the error page
254
    ]
255
  end
256

257
  def show
1✔
258
    super
4✔
259
    if params["format"] == "json"
2✔
260
      render json: DocumentExport.new(@document)
×
261
    end
262
  end
263

264
  # Returns the raw BibTex citation information
265
  def bibtex
1✔
266
    _unused, @document = search_service.fetch(params[:id])
×
267
    citation = @document.cite("BibTeX")
×
268
    send_data citation, filename: "#{@document.bibtex_id}.bibtex", type: 'text/plain', disposition: 'attachment'
×
269
  end
270

271
  def resolve_doi
1✔
272
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:doi)
3✔
273

274
    doi_query = params[:doi]
3✔
275
    query = { q: "uri_ssim:*\"#{doi_query}\"" }
3✔
276

277
    solr_response = search_service.repository.search(**query)
3✔
278
    documents = solr_response.documents
3✔
279

280
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
3✔
281
    preferred = documents.select { |d| d.data_source == 'pdc_discovery' }
6✔
282
    document = if preferred.empty?
3✔
283
                 documents.first
3✔
284
               else
285
                 preferred.first
×
286
               end
287

288
    redirect_to(solr_document_path(id: document.id))
3✔
289
  end
290

291
  def resolve_ark
1✔
292
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:ark)
2✔
293

294
    ark = params[:ark]
2✔
295
    ark_query = "uri_ssim:*\"#{ark}\""
2✔
296
    query = { q: ark_query }
2✔
297

298
    solr_response = search_service.repository.search(**query)
2✔
299
    documents = solr_response.documents
2✔
300

301
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
2✔
302
    document = documents.first
2✔
303

304
    redirect_to(solr_document_path(id: document.id))
2✔
305
  end
306

307
  # Create an endpoint for PPPL / OSTI harvesting that provides full datacite records
308
  def pppl_reporting_feed
1✔
309
    # Limit to items from PPPL
310
    lucene_queries = ['data_source_ssi:pdc_describe', 'group_code_ssi:"PPPL"']
5✔
311
    lucene_expr = lucene_queries.join(" ")
5✔
312
    page = params["page"] || "1"
5✔
313
    per_page = params["per_page"] || "10"
5✔
314
    start = per_page.to_i * (page.to_i - 1)
5✔
315

316
    query_sort = 'internal_id_lsi desc'
5✔
317
    query_fl = 'pdc_describe_json_ss'
5✔
318
    query_format = 'json'
5✔
319
    query = {
320
      q: lucene_expr,
5✔
321
      fl: query_fl,
322
      format: query_format,
323
      sort: query_sort,
324
      rows: per_page,
325
      start: start
326
    }
327

328
    solr_response = search_service.repository.search(**query)
5✔
329

330
    @documents = solr_response.documents
5✔
331
    respond_to do |format|
5✔
332
      format.json { render json: @documents }
10✔
333
    end
334
  end
335
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