Class: Dor::IdentityMetadataDS
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::IdentityMetadataDS
- Includes:
- SolrDocHelper
- Defined in:
- lib/dor/datastreams/identity_metadata_ds.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_otherId(other_id) ⇒ Object
- #add_value(name, value, attrs = {}) ⇒ Object
- #objectId ⇒ Object
- #otherId(type = nil) ⇒ Object
- #sourceId ⇒ Object
-
#sourceId=(value) ⇒ String, Nil
The same value, as per Ruby convention for assignment operators.
- #tags ⇒ Object
- #to_solr(solr_doc = {}, *args) ⇒ Object
Methods included from SolrDocHelper
Class Method Details
.xml_template ⇒ Object
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
74 75 76 77 78 79 80 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 74 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
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 |
#objectId ⇒ Object
34 35 36 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 34 def objectId find_by_terms(:objectId).text end |
#otherId(type = nil) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 65 def otherId(type = nil) result = 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 |
#sourceId ⇒ Object
38 39 40 41 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 38 def sourceId node = find_by_terms(:sourceId).first node ? [node['source'], node.text].join(':') : nil end |
#sourceId=(value) ⇒ String, Nil
Note:
The actual values assigned will have leading/trailing whitespace stripped.
Returns The same value, as per Ruby convention for assignment operators.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 46 def sourceId=(value) node = find_by_terms(:sourceId).first unless value.present? # so setting it to '' is the same as removal: worth documenting maybe? node.remove unless node.nil? return nil end parts = value.split(':').map(&:strip) # parts = value.split(/:/, 2).map(&:strip) # if we needed to allow colons in values or bunched colon separators raise ArgumentError, "Source ID must follow the format 'namespace:value', not '#{value}'" unless parts.length == 2 && parts[0].present? && parts[1].present? node ||= ng_xml.root.add_child('<sourceId/>').first node['source'] = parts[0] node.content = parts[1] end |
#tags ⇒ Object
61 62 63 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 61 def ng_xml.search('//tag').collect(&:content) end |
#to_solr(solr_doc = {}, *args) ⇒ Object
82 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/dor/datastreams/identity_metadata_ds.rb', line 82 def to_solr(solr_doc = {}, *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 : :symbol), [:stored_searchable]) end end if sourceId.present? (name, id) = sourceId.split(/:/, 2) add_solr_value(solr_doc, 'dor_id', id, :symbol, [:stored_searchable]) add_solr_value(solr_doc, 'identifier', sourceId, :symbol, [:stored_searchable]) add_solr_value(solr_doc, 'source_id', sourceId, :symbol, []) end otherId.compact.each { |qid| # this section will solrize barcode and catkey, which live in otherId (name, id) = qid.split(/:/, 2) add_solr_value(solr_doc, 'dor_id', id, :symbol, [:stored_searchable]) add_solr_value(solr_doc, 'identifier', qid, :symbol, [:stored_searchable]) add_solr_value(solr_doc, "#{name}_id", id, :symbol, []) } # do some stuff to make tags in general and project tags specifically more easily searchable and facetable find_by_terms(:tag).each { |tag| (prefix, rest) = tag.text.split(/:/, 2) prefix = prefix.downcase.strip.gsub(/\s/, '_') unless rest.nil? # this part will index a value in a field specific to the tag, e.g. registered_by_tag_*, # book_tag_*, project_tag_*, remediated_by_tag_*, etc. project_tag_* and registered_by_tag_* # definitley get used, but most don't. we can limit the prefixes that get solrized if things # get out of hand. add_solr_value(solr_doc, "#{prefix}_tag", rest.strip, :symbol, []) end # solrize each possible prefix for the tag, inclusive of the full tag. # e.g., for a tag such as "A : B : C", this will solrize to an _ssim field # that contains ["A", "A : B", "A : B : C"]. tag_parts = tag.text.split(/:/) progressive_tag_prefix = '' tag_parts.each_with_index do |part, index| progressive_tag_prefix += ' : ' if index > 0 progressive_tag_prefix += part.strip add_solr_value(solr_doc, 'exploded_tag', progressive_tag_prefix, :symbol, []) end } solr_doc end |