Class: ActiveFedora::QualifiedDublinCoreDatastream
- Inherits:
-
NokogiriDatastream
- Object
- Rubydora::Datastream
- Datastream
- NokogiriDatastream
- 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::MetdataDatastream 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::Datastream#fields method).
Constant Summary collapse
- DCTERMS =
A frozen array of Dublincore Terms.
[ :contributor, :coverage, :creator, :description, :identifier, :language, :publisher, :relation, :source, :title, :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, :issued, :isVersionOf, :language, :license, :mediator, :medium, :modified, :provenance, :publisher, :references, :relation, :replaces, :requires, :rights, :rightsHolder, :source, :spatial, :subject, :tableOfContents, :temporal, :valid ]
Instance Attribute Summary collapse
-
#fields ⇒ Object
TODO this can be removed when Model.find_by_fields_by_solr has been removed.
Attributes inherited from NokogiriDatastream
Attributes included from MetadataDatastreamHelper
Attributes inherited from Datastream
#digital_object, #last_modified
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, dsid) ⇒ QualifiedDublinCoreDatastream
constructor
Constructor.
-
#to_solr(solr_doc = Hash.new) ⇒ Object
:nodoc:.
- #update_indexed_attributes(params = {}, opts = {}) ⇒ Object
Methods inherited from NokogiriDatastream
#content=, default_attributes, #find_by_terms, #from_solr, from_xml, #generate_solr_symbol, #get_values, #get_values_from_solr, #has_solr_name?, #is_hierarchical_term_pointer?, #ng_xml, #ng_xml=, #ng_xml_changed?, #ng_xml_will_change!, #om_term_values, #om_update_values, #term_values, #to_xml, #update_values
Methods included from MetadataDatastreamHelper
#ensure_xml_loaded, included, #serialize!
Methods inherited from Datastream
#add_ds_location, #add_mime_type, #create, #dirty, #dirty=, #dirty?, from_xml, #inspect, #new_object?, #profile_from_hash, #save, #serialize!, #size, #solrize_profile, #to_param, #validate_content_present
Constructor Details
#initialize(digital_object, dsid) ⇒ 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.
33 34 35 36 37 38 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 33 def initialize(digital_object, dsid ) super(digital_object, dsid) DCTERMS.each do |el| field el, :string, :multiple=>true end end |
Instance Attribute Details
#fields ⇒ Object
TODO this can be removed when Model.find_by_fields_by_solr has been removed.
12 13 14 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 12 def fields @fields end |
Class Method Details
.xml_template ⇒ Object
94 95 96 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 94 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)
At some point, these modifiers will be ported up to work for any ActiveFedora::MetadataDatastream
.
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.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 66 def field(name, tupe=nil, opts={}) fields ||= {} @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 unless self.class.terminology.has_term?(name.to_sym) term = OM::XML::Term.new(name.to_sym, {:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms"}, self.class.terminology) self.class.terminology.add_term(term) term.generate_xpath_queries! end end |
#to_solr(solr_doc = Hash.new) ⇒ Object
:nodoc:
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 98 def to_solr(solr_doc = Hash.new) # :nodoc: @fields.each do |field_key, field_info| things = send(field_key) if things field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type]) things.val.each do |val| ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val ) end end end return solr_doc end |
#update_indexed_attributes(params = {}, opts = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 80 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 |