Class: Krikri::ValidationReport

Inherits:
Object
  • Object
show all
Defined in:
app/models/krikri/validation_report.rb

Constant Summary collapse

REQUIRED_FIELDS =
['dataProvider_providedLabel', 'isShownAt_id', 'preview_id',
'sourceResource_rights', 'sourceResource_title',
'sourceResource_type_id']

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pageObject

Returns the value of attribute page.



3
4
5
# File 'app/models/krikri/validation_report.rb', line 3

def page
  @page
end

#provider_idObject

Returns the value of attribute provider_id.



3
4
5
# File 'app/models/krikri/validation_report.rb', line 3

def provider_id
  @provider_id
end

#rowsObject

Returns the value of attribute rows.



3
4
5
# File 'app/models/krikri/validation_report.rb', line 3

def rows
  @rows
end

Instance Method Details

#allArray<Blacklight::SolrResponse::Facets::FacetField>

Returns a report for missing values in each of the ‘REQUIRED_FIELDS`.

Examples:

ValidationReport.new.all
=> [#<Blacklight::SolrResponse::Facets::FacetField:0x007fce32f46fe8 ...]
report = ValidationReport.new
report.provider_id = '0123'
report.all
=> [#<Blacklight::SolrResponse::Facets::FacetField:0x007fce32f46fe8 ...]

Returns:

  • (Array<Blacklight::SolrResponse::Facets::FacetField>)

    a report for missing values in each of the ‘REQUIRED_FIELDS`



22
23
24
25
26
27
28
29
30
31
# File 'app/models/krikri/validation_report.rb', line 22

def all
  query_params = { :rows => 0,
                   'facet.field' => REQUIRED_FIELDS,
                   'facet.mincount' => 10000000,
                   'facet.missing' => true }
  query_params[:fq] = "provider_id:\"#{provider_uri}\"" if
    provider_id.present?

  Krikri::SolrResponseBuilder.new(query_params).response.facets
end

#find(id) ⇒ Blacklight::SolrResponse

TODO:

possibly make better use of blacklight controllers? This currently assumes that the default pagination is 10. Anything else will cause trouble.

Examples:

ValidationReport.new.find('sourceResource_title')
=> {"responseHeader"=>{"status"=>0, "QTime"=>123},
    "response"=>{"numFound"=>2653, "start"=>0, "docs"=>[...]}}
report = ValidationReport.new
report.provider_id = '0123'
report.rows = 100
report.find('sourceResource_title')

Parameters:

  • id (String)

    a field to check for missing values

Returns:

  • (Blacklight::SolrResponse)

Raises:

  • (RSolr::Error::Http)

    for non-existant field requests



53
54
55
56
57
58
59
60
61
62
# File 'app/models/krikri/validation_report.rb', line 53

def find(id)
  query_params = { :qt => 'standard', :q => "-#{id}:[* TO *]" }
  query_params[:rows] = @rows.present? ? @rows : '10'
  query_params[:fq] = "provider_id:\"#{provider_uri}\"" if
    provider_id.present?
  multiplier = @rows ? @rows.to_i : 10
  query_params[:start] = ((@page.to_i - 1) * multiplier) if @page.present?

  Krikri::SolrResponseBuilder.new(query_params).response
end