Class: Krikri::Provider

Inherits:
ActiveModelBase show all
Defined in:
app/models/krikri/provider.rb

Overview

Provider is an ActiveModel object. It represents a provider that has been indexed in Solr.

This is a read-only object. It does not write new providers to Solr, nor does it update or delete providers.

If Provider is initialized with a valid value for :rdf_subject, the model can extrapolate all other attributes.

A DPLA::MAP::Agent object can be constructed from an instance of this ActiveModel object using the :agent method. The DPLA::MAP::Agent object interacts with Marmotta, rather than Solr.

@example Krikri::Provider.new(rdf_subject: 'http://blah.com/123').agent
  => [DPLA::MAP::Agent]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveModelBase

#initialize, #persisted?

Constructor Details

This class inherits a constructor from Krikri::ActiveModelBase

Instance Attribute Details

#:field_value_reports(: field_value_reports) ⇒ Object (readonly)

the provider, read from Marmotta.



33
# File 'app/models/krikri/provider.rb', line 33

attr_accessor :rdf_subject, :name, :field_value_reports

#:id(: id) ⇒ Object (readonly)

the stub id @example: “123”



33
# File 'app/models/krikri/provider.rb', line 33

attr_accessor :rdf_subject, :name, :field_value_reports

#:name(: name) ⇒ Object (readonly)

the human-redable name of the provider



33
# File 'app/models/krikri/provider.rb', line 33

attr_accessor :rdf_subject, :name, :field_value_reports

#:rdf_subject(: rdf_subject) ⇒ Object (readonly)

the URI identifying the provider @example: “blah.com/contributor/123



33
# File 'app/models/krikri/provider.rb', line 33

attr_accessor :rdf_subject, :name, :field_value_reports

#agentObject (readonly)

Returns the value of attribute agent.



34
35
36
# File 'app/models/krikri/provider.rb', line 34

def agent
  @agent
end

#field_value_reportsObject

the provider, read from Marmotta.



33
34
35
# File 'app/models/krikri/provider.rb', line 33

def field_value_reports
  @field_value_reports
end

#idObject (readonly)

Returns the value of attribute id.



34
35
36
# File 'app/models/krikri/provider.rb', line 34

def id
  @id
end

#nameObject

the provider, read from Marmotta.



33
34
35
# File 'app/models/krikri/provider.rb', line 33

def name
  @name
end

#rdf_subjectObject

the provider, read from Marmotta.



33
34
35
# File 'app/models/krikri/provider.rb', line 33

def rdf_subject
  @rdf_subject
end

Class Method Details

.allArray<Krikri::Provider>

Gives a list of all providers, ignoring those with no URI (bnodes).

Providers will be initialized with both an :rdf_subject and a :name, if both exist in the Solr index.

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/krikri/provider.rb', line 43

def self.all
  query_params = { :rows => 0,
                   :id => '*:*',
                   :facet => true,
                   'facet.pivot' => 'provider_id,provider_name' }
  response = Krikri::SolrResponseBuilder.new(query_params).response

  response.facet_pivot['provider_id,provider_name'].map do |facet|
    rdf_subject = facet['value']
    name = facet['pivot'].present? ? facet['pivot'].first['value'] :
      rdf_subject
    provider = new({ :rdf_subject => rdf_subject, :name => name })
    provider.valid_rdf_subject? ? provider : nil
  end.compact
end

.base_uriString

Get the base of the :rdf_subject for any provider

Returns:

  • (String)

    ending in “/”



82
83
84
85
# File 'app/models/krikri/provider.rb', line 82

def self.base_uri
  base_uri = Krikri::Settings.prov.provider_base
  base_uri.end_with?('/') ? base_uri : base_uri << '/'
end

.find(id) ⇒ Krikri::Provider

Finds a provider in Solr that matches the given ID, ignoring bnodes.

Parameters:

  • :id (String)

    or :rdf_subject

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/krikri/provider.rb', line 65

def self.find(id)
  rdf_subject = id.start_with?(base_uri) ? id : base_uri + id
  query_params = { :rows => 1,
                   :q => rdf_subject,
                   :qf => 'provider_id',
                   :fl => 'provider_id provider_name' }
  response = Krikri::SolrResponseBuilder.new(query_params).response
  return nil unless response.docs.count > 0
  name = response.docs.first['provider_name'].respond_to?(:first) ?
    response.docs.first['provider_name'].first : rdf_subject
  new({ :rdf_subject => rdf_subject,
        :name => name })
end

Instance Method Details

#:agent=(: agent=(value)) ⇒ Object

an ActiveTriples representation of



33
# File 'app/models/krikri/provider.rb', line 33

attr_accessor :rdf_subject, :name, :field_value_reports

#valid_rdf_subject?Boolean

Tests for providers that have valid a :rdf_subject (not a bnode). A valid :rdf_subject does not necessarily match and :rdf_subject in the Solr index, but it has the correct URI format.

Returns:

  • (Boolean)


107
108
109
110
# File 'app/models/krikri/provider.rb', line 107

def valid_rdf_subject?
  return false unless rdf_subject.present?
  rdf_subject.start_with?(self.class.base_uri) ? true : false
end