Class: ActiveFedora::OmDatastream

Inherits:
File
  • Object
show all
Extended by:
Deprecation
Includes:
Datastreams::NokogiriDatastreams, OM::XML::Document, OM::XML::TerminologyBasedSolrizer
Defined in:
lib/active_fedora/om_datastream.rb

Direct Known Subclasses

QualifiedDublinCoreDatastream

Constant Summary

Constants included from AttributeMethods

AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS

Constants included from Callbacks

Callbacks::CALLBACKS

Instance Method Summary collapse

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, #checksum, #content, #content=, #content_changed?, #datastream_will_change!, #described_by, #exists!, #inspect, #ldp_connection, #metadata, #metadata_changed?, #new_record?, #refresh, #reload, #remote_content, #serialize!, #uri=

Methods included from Querying

#default_sort_params, extended

Methods included from Scoping

#initialize_internals_callback, #populate_with_current_scope_attributes

Methods included from Identifiable

#id, #id=, #uri

Methods included from AttributeMethods

#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?

Methods included from Callbacks

#destroy

Methods included from Versionable

#create_version, #has_versions?, #model_type, #restore_version, #versions

Methods included from Persistence

#base_path_for_resource=, #delete, #destroy, #destroy!, #destroyed?, #eradicate, #new_record?, #persisted?, #save, #save!, #update

Methods included from File::Streaming

#headers, #stream

Methods included from File::Attributes

#assign_attributes, #create_date, #digest, #dirty_size, #empty?, #has_content?, #mime_type, #original_name, #original_name=, #persisted_size, #size

Methods included from Common

#<=>, #==, #freeze, #frozen?, #ldp_source, #readonly!, #readonly?

Constructor Details

#initialize(*args) ⇒ OmDatastream

Returns a new instance of OmDatastream.



20
21
22
23
# File 'lib/active_fedora/om_datastream.rb', line 20

def initialize(*args)
  super
  Deprecation.warn(OmDatastream, "OmDatastream is deprecated and will be removed in ActiveFedora 11")
end

Instance Method Details

#default_mime_typeObject



25
26
27
# File 'lib/active_fedora/om_datastream.rb', line 25

def default_mime_type
  'text/xml'
end

#find_by_terms(*termpointer) ⇒ Object



93
94
95
# File 'lib/active_fedora/om_datastream.rb', line 93

def find_by_terms(*termpointer)
  super
end

#get_values(field_key, _default = []) ⇒ Object



89
90
91
# File 'lib/active_fedora/om_datastream.rb', line 89

def get_values(field_key, _default = [])
  term_values(*field_key)
end

#metadata?Boolean

Indicates that this datastream has metadata content.

Returns:

  • (Boolean)

    true



31
32
33
# File 'lib/active_fedora/om_datastream.rb', line 31

def metadata?
  true
end

#om_update_valuesObject



18
# File 'lib/active_fedora/om_datastream.rb', line 18

alias 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.



37
38
39
40
# File 'lib/active_fedora/om_datastream.rb', line 37

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>

Parameters:

  • params (Hash) (defaults to: {})

    The params specifying which fields to update and their new values. The syntax of the params Hash is the same as that expected by term_pointers must be a valid OM Term pointers (ie. [:name]). Strings will be ignored.

  • _opts (Hash) (defaults to: {})

    This is not currently used by the datastream-level update_indexed_attributes method



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/active_fedora/om_datastream.rb', line 67

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.is_a?(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 = {}
  result = update_values(current_params) unless current_params.empty?

  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

Examples:

Updating multiple values with a Hash of Term pointers and values

ds.update_values( {[{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, [{:person=>1}, :family_name]=>"Andronicus", [{"person"=>"1"},:given_name]=>["Titus"],[{:person=>1},:role,:text]=>["otherrole1","otherrole2"] } )
=> {"person_0_role_text"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, "person_1_role_text"=>{"0"=>"otherrole1", "1"=>"otherrole2"}}


103
104
105
106
107
108
# File 'lib/active_fedora/om_datastream.rb', line 103

def update_values(params = {})
  raise "can't modify frozen #{self.class}" if frozen?
  ng_xml_will_change!
  result = om_update_values(params)
  result
end