Class: Dor::IdentityMetadataDS

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Includes:
SolrDocHelper
Defined in:
lib/dor/datastreams/identity_metadata_ds.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SolrDocHelper

#add_solr_value

Class Method Details

.xml_templateObject



26
27
28
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 26

def self.xml_template
  Nokogiri::XML('<identityMetadata/>')
end

Instance Method Details

#add_otherId(other_id) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 75

def add_otherId(other_id)
  (name,val) = other_id.split(/:/,2)
  node = ng_xml.root.add_child('<otherId/>').first
  node['name'] = name
  node.content = val
  node
end

#add_value(name, value, attrs = {}) ⇒ Object

self.xml_template



30
31
32
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 30

def add_value(name, value, attrs={})
  add_child_node(ng_xml.root, :value, name, value, attrs)
end

#objectIdObject



34
35
36
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 34

def objectId
  self.find_by_terms(:objectId).text
end

#otherId(type = nil) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 66

def otherId(type = nil)
  result = self.find_by_terms(:otherId).to_a
  if type.nil?
    result.collect { |n| [n['name'],n.text].join(':') }
  else
    result.select { |n| n['name'] == type }.collect { |n| n.text }
  end
end

#sourceIdObject



38
39
40
41
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 38

def sourceId
  node = self.find_by_terms(:sourceId).first
  node ? [node['source'],node.text].join(':') : nil
end

#sourceId=(value) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 43

def sourceId=(value)
  node = self.find_by_terms(:sourceId).first
  unless value.present?
    node.remove unless node.nil?
    nil
  else
    (source,val) = value.split(/:/,2)
    unless source.present? and value.present?
      raise ArgumentError, "Source ID must follow the format namespace:value"
    end
    node = ng_xml.root.add_child('<sourceId/>').first if node.nil?
    node['source'] = source
    node.content = val
    node
  end
end

#tagsObject



59
60
61
62
63
64
65
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 59

def tags()
    result=[]
    self.ng_xml.search('//tag').each do |node|
      result << node.content
    end
    result
end

#to_solr(solr_doc = Hash.new, *args) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 83

def to_solr(solr_doc=Hash.new, *args)
  super(solr_doc, *args)
  if digital_object.respond_to?(:profile)
    digital_object.profile.each_pair do |property,value|
      add_solr_value(solr_doc, property.underscore, value, property =~ /Date/ ? :date : :string, [:searchable])
    end
  end
  if sourceId.present?
    (name,id) = sourceId.split(/:/,2)
    add_solr_value(solr_doc, "dor_id", id, :string, [:searchable])
    add_solr_value(solr_doc, "identifier", sourceId, :string, [:searchable])
    add_solr_value(solr_doc, "source_id", sourceId, :string, [:searchable])
  end
  otherId.compact.each { |qid|
    (name,id) = qid.split(/:/,2)
    add_solr_value(solr_doc, "dor_id", id, :string, [:searchable])
    add_solr_value(solr_doc, "identifier", qid, :string, [:searchable])
    add_solr_value(solr_doc, "#{name}_id", id, :string, [:searchable])
  }
      
  self.find_by_terms(:tag).each { |tag|
    (top,rest) = tag.text.split(/:/,2)
    unless rest.nil?
      add_solr_value(solr_doc, "#{top.downcase.strip.gsub(/\s/,'_')}_tag", rest.strip, :string, [:searchable, :facetable])
    end
  }
  solr_doc
end