Class: ActiveFedora::OmDatastream
- Includes:
- Datastreams::NokogiriDatastreams, OM::XML::Document, OM::XML::TerminologyBasedSolrizer
- Defined in:
- lib/active_fedora/om_datastream.rb
Direct Known Subclasses
Constant Summary
Constants included from AttributeMethods
Instance Attribute Summary
Attributes inherited from File
Instance Method Summary collapse
- #default_mime_type ⇒ Object
- #find_by_terms(*termpointer) ⇒ Object
- #get_values(field_key, default = []) ⇒ Object
-
#has_solr_name?(name, solr_doc = Hash.new) ⇒ Boolean
** Experimental **.
-
#is_hierarchical_term_pointer?(*term_pointer) ⇒ Boolean
** Experimental ** ====Example: [:image, :title_set=>1, :title] return true [:image, :title_set, :title] return false.
-
#metadata? ⇒ Boolean
Indicates that this datastream has metadata content.
- #om_update_values ⇒ Object
-
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
Return a hash suitable for indexing in solr.
-
#update_indexed_attributes(params = {}, opts = {}) ⇒ Object
Update field values within the current datastream using #update_values, which is a wrapper for OM::TermValueOperators#update_values Ignores any fields from params that this datastream’s Terminology doesn’t recognize .
-
#update_values(params = {}) ⇒ Object
Update values in the datastream’s xml This wraps OM::TermValueOperators#update_values so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only.
Methods included from Datastreams::NokogiriDatastreams
#autocreate?, #content, #content=, #content_changed?, #ng_xml, #ng_xml=, #ng_xml_changed?, #ng_xml_doesnt_change!, #ng_xml_will_change!, #refresh_attributes, #remote_content, #to_xml, #xml_loaded
Methods inherited from File
#attribute_will_change!, #changed?, #check_fixity, #content_changed?, #datastream_will_change!, default_attributes, #default_attributes, #default_attributes=, #described_by, #digest, #dirty_size, #empty?, #exists!, #freeze, #frozen?, #has_content?, #initialize, #inspect, #ldp_connection, #ldp_source, #metadata, #new_record?, #original_name, #original_name=, #persisted_size, #reload, #remote_content, #reset, #serialize!, #size, #uri, #uri=
Methods included from Versionable
#create_version, #has_versions?, #model_type, #restore_version, #versions
Methods included from File::Streaming
#authorization_key, #headers, #stream
Methods included from File::Persistence
#content, #content=, #retrieve_content, #save
Methods included from AttributeMethods
#[], #[]=, #attribute_names, #attributes
Constructor Details
This class inherits a constructor from ActiveFedora::File
Instance Method Details
#default_mime_type ⇒ Object
20 21 22 |
# File 'lib/active_fedora/om_datastream.rb', line 20 def default_mime_type 'text/xml' end |
#find_by_terms(*termpointer) ⇒ Object
115 116 117 |
# File 'lib/active_fedora/om_datastream.rb', line 115 def find_by_terms(*termpointer) super end |
#get_values(field_key, default = []) ⇒ Object
110 111 112 |
# File 'lib/active_fedora/om_datastream.rb', line 110 def get_values(field_key,default=[]) term_values(*field_key) end |
#has_solr_name?(name, solr_doc = Hash.new) ⇒ Boolean
** Experimental **
41 42 43 |
# File 'lib/active_fedora/om_datastream.rb', line 41 def has_solr_name?(name, solr_doc=Hash.new) !solr_doc[name].nil? || !solr_doc[name.to_s].nil? end |
#is_hierarchical_term_pointer?(*term_pointer) ⇒ Boolean
** Experimental **
Example:
[:image, {:title_set=>1}, :title] return true
[:image, :title_set, :title] return false
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_fedora/om_datastream.rb', line 50 def is_hierarchical_term_pointer?(*term_pointer) if term_pointer.length>1 term_pointer.each do |pointer| if pointer.kind_of?(Hash) return true end end end return false end |
#metadata? ⇒ Boolean
Indicates that this datastream has metadata content.
26 27 28 |
# File 'lib/active_fedora/om_datastream.rb', line 26 def true end |
#om_update_values ⇒ Object
18 |
# File 'lib/active_fedora/om_datastream.rb', line 18 alias_method(:om_update_values, :update_values) |
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
Return a hash suitable for indexing in solr. Every field name is prefixed with the value returned by the prefix
method.
32 33 34 35 |
# File 'lib/active_fedora/om_datastream.rb', line 32 def to_solr(solr_doc = {}, opts = {}) prefix = self.prefix(opts[:name]) solr_doc.merge super({}).each_with_object({}) { |(key, value), new| new[[prefix,key].join] = value } end |
#update_indexed_attributes(params = {}, opts = {}) ⇒ Object
Update field values within the current datastream using #update_values, which is a wrapper for OM::TermValueOperators#update_values Ignores any fields from params that this datastream’s Terminology doesn’t recognize
Example:
@mods_ds.update_indexed_attributes( {[{":person"=>"0"}, "role"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} })
=> {"person_0_role"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}}
@mods_ds.to_xml # (the following is an approximation)
<mods>
<mods:name type="person">
<mods:role>
<mods:roleTerm>role1</mods:roleTerm>
</mods:role>
<mods:role>
<mods:roleTerm>role2</mods:roleTerm>
</mods:role>
<mods:role>
<mods:roleTerm>role3</mods:roleTerm>
</mods:role>
</mods:name>
</mods>
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/active_fedora/om_datastream.rb', line 86 def update_indexed_attributes(params={}, opts={}) if self.class.terminology.nil? raise "No terminology is set for this OmDatastream class. Cannot perform update_indexed_attributes" end # remove any fields from params that this datastream doesn't recognize # make sure to make a copy of params so not to modify hash that might be passed to other methods current_params = params.clone current_params.delete_if do |term_pointer,new_values| if term_pointer.kind_of?(String) ActiveFedora::Base.logger.warn "WARNING: #{self.class.name} ignoring {#{term_pointer.inspect} => #{new_values.inspect}} because #{term_pointer.inspect} is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it." if ActiveFedora::Base.logger true else !self.class.terminology.has_term?(*OM.destringify(term_pointer)) end end result = {} unless current_params.empty? result = update_values( current_params ) end return result end |
#update_values(params = {}) ⇒ Object
Update values in the datastream’s xml This wraps OM::TermValueOperators#update_values so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only
125 126 127 128 129 130 |
# File 'lib/active_fedora/om_datastream.rb', line 125 def update_values(params={}) raise "can't modify frozen #{self.class}" if frozen? ng_xml_will_change! result = om_update_values(params) return result end |