Module: OregonDigital::RDF::DeepFetch

Extended by:
ActiveSupport::Concern
Defined in:
lib/linked_vocabs/deep_fetch.rb

Instance Method Summary collapse

Instance Method Details

#fetch_externalObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/linked_vocabs/deep_fetch.rb', line 4

def fetch_external
  controlled_properties.each do |property|
    get_values(property).each do |value|
      resource = value.respond_to?(:resource) ? value.resource : value
      next unless resource.kind_of?(ActiveFedora::Rdf::Resource)
      fetch_value(resource) if resource.kind_of? ActiveFedora::Rdf::Resource
      resource.persist! unless value.kind_of?(ActiveFedora::Base)
      fix_fedora_index(property, resource)
    end
  end
end

#fix_fedora_index(property, resource) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/linked_vocabs/deep_fetch.rb', line 16

def fix_fedora_index(property, resource)
  # Get assets which have this property set, but don't have the right label.
  if resource.rdf_label.first.blank? || resource.rdf_label.first.to_s == resource.rdf_subject.to_s
    assets = ActiveFedora::Base.where("#{Solrizer.solr_name(apply_prefix(property), :facetable)}:#{RSolr.escape(resource.rdf_subject.to_s)} AND #{Solrizer.solr_name(apply_prefix("#{property}_label"), :facetable)}:[\"\" TO *]")
  else
    assets = ActiveFedora::Base.where(
        Solrizer.solr_name(apply_prefix(property), :facetable) => resource.rdf_subject.to_s,
        "-#{Solrizer.solr_name(apply_prefix("#{property}_label"), :facetable)}" => "#{resource.rdf_label.first}$#{resource.rdf_subject.to_s}"
    )
  end
  assets.each do |a|
    a.skip_queue = 1 if a.respond_to?(:skip_queue=)
    a.update_index
  end
end