Class: ActiveFedora::QualifiedDublinCoreDatastream
- Inherits:
-
OmDatastream
- Object
- File
- OmDatastream
- ActiveFedora::QualifiedDublinCoreDatastream
- Defined in:
- lib/active_fedora/qualified_dublin_core_datastream.rb
Overview
This class represents a Qualified Dublin Core Datastream. A special case of ActiveFedora::OmDatastream The implementation of this class defines the terms from the Qualified Dublin Core specification. This implementation features customized xml generators and deserialization routines to handle the Fedora Dublin Core XML datastreams structure.
Fields can still be overridden if more specificity is desired (see ActiveFedora::File#fields method).
Constant Summary collapse
- DCTERMS =
A frozen array of Dublincore Terms.
[ :abstract, :accessRights, :accrualMethod, :accrualPeriodicity, :accrualPolicy, :alternative, :audience, :available, :bibliographicCitation, :conformsTo, :contributor, :coverage, :created, :creator, :date, :dateAccepted, :dateCopyrighted, :dateSubmitted, :description, :educationLevel, :extent, :hasFormat, :hasPart, :hasVersion, :identifier, :instructionalMethod, :isFormatOf, :isPartOf, :isReferencedBy, :isReplacedBy, :isRequiredBy, :isVersionOf, :issued, :language, :license, :mediator, :medium, :modified, :provenance, :publisher, :references, :relation, :replaces, :requires, :rights, :rightsHolder, :source, :spatial, :subject, :tableOfContents, :temporal, :title, :type, :valid ].freeze
Constants included from AttributeMethods
AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS
Constants included from Callbacks
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
-
#field(name, tupe = nil, opts = {}) ⇒ Object
This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
-
#initialize(digital_object = nil, dsid = nil, options = {}) ⇒ QualifiedDublinCoreDatastream
constructor
Constructor.
-
#to_solr(solr_doc = {}, _opts = {}) ⇒ Object
:nodoc:.
- #update_indexed_attributes(params = {}, opts = {}) ⇒ Object
Methods inherited from OmDatastream
#default_mime_type, #find_by_terms, #get_values, #has_solr_name?, #is_hierarchical_term_pointer?, #metadata?, #om_update_values, #update_values
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?, #metadata_changed?, #new_record?, #refresh, #reload, #remote_content, #save, #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
Methods included from AttributeMethods
#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?
Methods included from Callbacks
Methods included from Versionable
#create_version, #has_versions?, #model_type, #restore_version, #versions
Methods included from Persistence
#delete, #destroy, #destroy!, #destroyed?, #eradicate, #new_record?, #persisted?, #save, #save!, #update
Methods included from File::Streaming
Methods included from File::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(digital_object = nil, dsid = nil, options = {}) ⇒ QualifiedDublinCoreDatastream
Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist when this method returns. Each term is marked as a multivalue string.
84 85 86 87 88 89 90 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 84 def initialize(digital_object = nil, dsid = nil, = {}) super self.fields = {} DCTERMS.each do |el| field el, :string, multiple: true end end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
9 10 11 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 9 def fields @fields end |
Class Method Details
.xml_template ⇒ Object
142 143 144 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 142 def self.xml_template Nokogiri::XML::Document.parse("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>") end |
Instance Method Details
#field(name, tupe = nil, opts = {}) ⇒ Object
This method generates the various accessor and mutator methods on self for the datastream metadata attributes. each field will have the 2 magic methods:
name=(arg)
name
Calling any of the generated methods marks self as dirty.
‘tupe’ is a datatype, currently :string, :text and :date are supported.
opts is an options hash, which will affect the generation of the xml representation of this datastream.
Currently supported modifiers: For QualifiedDublinCorDatastreams
:
:element_attrs =>{:foo=>:bar} - hash of xml element attributes
:xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
:encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
:multiple=>true - mark this field as a multivalue field (on by default)
There is quite a good example of this class in use in spec/examples/oral_history.rb
!! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them, you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc. whenever you edit the field’s values.
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 117 def field(name, tupe = nil, opts = {}) @fields[name.to_s.to_sym] = { type: tupe, values: [] }.merge(opts) # add term to template self.class.class_fields << name.to_s # add term to terminology return if self.class.terminology.has_term?(name.to_sym) om_term_opts = { xmlns: "http://purl.org/dc/terms/", namespace_prefix: "dcterms", path: opts[:path] } term = OM::XML::Term.new(name.to_sym, om_term_opts, self.class.terminology) self.class.terminology.add_term(term) term.generate_xpath_queries! end |
#to_solr(solr_doc = {}, _opts = {}) ⇒ Object
:nodoc:
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 146 def to_solr(solr_doc = {}, _opts = {}) # :nodoc: @fields.each do |field_key, field_info| things = send(field_key) next unless things field_symbol = ActiveFedora.index_field_mapper.solr_name(field_key, type: field_info[:type]) things.val.each do |val| ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val) end end solr_doc end |
#update_indexed_attributes(params = {}, opts = {}) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 129 def update_indexed_attributes(params = {}, opts = {}) # if the params are just keys, not an array, make then into an array. new_params = {} params.each do |key, val| if key.is_a? Array new_params[key] = val else new_params[[key.to_sym]] = val end end super(new_params, opts) end |