active-fedora 4.0.0.rc16 → 4.0.0.rc17

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (4.0.0.rc16)
4
+ active-fedora (4.0.0.rc17)
5
5
  activeresource (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
  equivalent-xml
@@ -9,7 +9,7 @@ PATH
9
9
  mime-types (>= 1.16)
10
10
  multipart-post (= 1.1.2)
11
11
  nokogiri
12
- om (~> 1.6.0.rc1)
12
+ om (~> 1.6.0.rc3)
13
13
  rdf
14
14
  rdf-rdfxml (= 0.3.5)
15
15
  rsolr
@@ -56,19 +56,19 @@ GEM
56
56
  logger (1.2.8)
57
57
  mediashelf-loggable (0.4.9)
58
58
  metaclass (0.0.1)
59
- mime-types (1.17.2)
59
+ mime-types (1.18)
60
60
  mocha (0.10.5)
61
61
  metaclass (~> 0.0.1)
62
62
  multi_json (1.1.0)
63
63
  multipart-post (1.1.2)
64
64
  nokogiri (1.5.2)
65
65
  nori (1.1.0)
66
- om (1.6.0.rc1)
66
+ om (1.6.0.rc3)
67
67
  mediashelf-loggable
68
68
  nokogiri (>= 1.4.2)
69
69
  rack (1.4.1)
70
70
  rake (0.9.2.2)
71
- rdf (0.3.5)
71
+ rdf (0.3.5.1)
72
72
  addressable (>= 2.2.6)
73
73
  rdf-rdfxml (0.3.5)
74
74
  nokogiri (>= 1.4.4)
@@ -77,14 +77,14 @@ GEM
77
77
  mime-types (>= 1.16)
78
78
  rsolr (1.0.7)
79
79
  builder (>= 2.1.2)
80
- rspec (2.8.0)
81
- rspec-core (~> 2.8.0)
82
- rspec-expectations (~> 2.8.0)
83
- rspec-mocks (~> 2.8.0)
84
- rspec-core (2.8.0)
85
- rspec-expectations (2.8.0)
86
- diff-lcs (~> 1.1.2)
87
- rspec-mocks (2.8.0)
80
+ rspec (2.9.0)
81
+ rspec-core (~> 2.9.0)
82
+ rspec-expectations (~> 2.9.0)
83
+ rspec-mocks (~> 2.9.0)
84
+ rspec-core (2.9.0)
85
+ rspec-expectations (2.9.0)
86
+ diff-lcs (~> 1.1.3)
87
+ rspec-mocks (2.9.0)
88
88
  rubydora (0.5.7)
89
89
  activemodel
90
90
  activesupport
@@ -108,7 +108,7 @@ GEM
108
108
  om (>= 1.5.0)
109
109
  stomp
110
110
  xml-simple
111
- stomp (1.2.1)
111
+ stomp (1.2.2)
112
112
  wasabi (2.1.0)
113
113
  nokogiri (>= 1.4.0)
114
114
  xml-simple (1.1.1)
@@ -123,5 +123,5 @@ DEPENDENCIES
123
123
  jettywrapper (>= 1.2.0)
124
124
  mocha (>= 0.9.8)
125
125
  rake
126
- rspec (~> 2.0)
126
+ rspec (>= 2.9.0)
127
127
  yard
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency('mime-types', '>= 1.16')
21
21
  s.add_dependency('multipart-post', "= 1.1.2")
22
22
  s.add_dependency('nokogiri')
23
- s.add_dependency('om', '~> 1.6.0.rc1')
23
+ s.add_dependency('om', '~> 1.6.0.rc3')
24
24
  s.add_dependency('solrizer', '~>1.2.0')
25
25
  s.add_dependency("activeresource", '>= 3.0.0')
26
26
  s.add_dependency("activesupport", '>= 3.0.0')
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_development_dependency("rake")
35
35
  # s.add_development_dependency("rcov") # not ruby 1.9 compatible
36
36
  s.add_development_dependency("jettywrapper", ">=1.2.0")
37
- s.add_development_dependency("rspec", "~> 2.0")
37
+ s.add_development_dependency("rspec", ">= 2.9.0")
38
38
  s.add_development_dependency("mocha", ">= 0.9.8")
39
39
 
40
40
  s.files = `git ls-files`.split("\n")
@@ -5,6 +5,11 @@ require 'active_fedora/rubydora_connection'
5
5
  require 'active_support/core_ext/class/attribute'
6
6
  require 'active_support/core_ext/object'
7
7
  require 'active_support/core_ext/hash/indifferent_access'
8
+ # require "solrizer"
9
+ # require 'nokogiri'
10
+ # require "loggable"
11
+
12
+
8
13
 
9
14
  SOLR_DOCUMENT_ID = ActiveFedora::SolrService.id_field unless defined?(SOLR_DOCUMENT_ID)
10
15
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
@@ -22,7 +27,6 @@ module ActiveFedora #:nodoc:
22
27
 
23
28
  eager_autoload do
24
29
  autoload :Associations
25
- autoload :AttributeMethods
26
30
  autoload :Base
27
31
  autoload :ContentModel
28
32
  autoload :Callbacks
@@ -33,6 +37,7 @@ module ActiveFedora #:nodoc:
33
37
  autoload :FileManagement
34
38
  autoload :RelationshipGraph
35
39
  autoload :Datastream
40
+ autoload :DatastreamHash
36
41
  autoload :Datastreams
37
42
  autoload :Delegating
38
43
  autoload :DigitalObject
@@ -1,9 +1,3 @@
1
- require "solrizer"
2
- require 'nokogiri'
3
- require "loggable"
4
- require 'active_fedora/datastream_hash'
5
-
6
-
7
1
  SOLR_DOCUMENT_ID = "id" unless (defined?(SOLR_DOCUMENT_ID) && !SOLR_DOCUMENT_ID.nil?)
8
2
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
9
3
 
@@ -30,8 +24,9 @@ module ActiveFedora
30
24
  class Base
31
25
  include SemanticNode
32
26
 
33
- class_attribute :fedora_connection
27
+ class_attribute :fedora_connection, :profile_solr_name
34
28
  self.fedora_connection = {}
29
+ self.profile_solr_name = ActiveFedora::SolrService.solr_name("object_profile", :string, :displayable)
35
30
 
36
31
  def method_missing(name, *args)
37
32
  # if [:collection_members, :part_of, :parts, :part_of_append, :file_objects].include? name
@@ -228,9 +223,10 @@ module ActiveFedora
228
223
  #system_create_date, system_modified_date, active_fedora_model_field,
229
224
  #and the object id.
230
225
  def fields
226
+ # TODO this can likely be removed once find_by_fields_by_solr is removed
231
227
  fields = {:id => {:values => [pid]}, :system_create_date => {:values => [self.create_date], :type=>:date}, :system_modified_date => {:values => [self.modified_date], :type=>:date}, :active_fedora_model => {:values => [self.class.inspect], :type=>:symbol}}
232
228
  datastreams.values.each do |ds|
233
- fields.merge!(ds.fields) if ds.kind_of?(ActiveFedora::MetadataDatastream)
229
+ fields.merge!(ds.fields) if [ActiveFedora::MetadataDatastream, ActiveFedora::QualifiedDublinCoreDatastream].include?(ds.class)
234
230
  end
235
231
  return fields
236
232
  end
@@ -283,8 +279,8 @@ module ActiveFedora
283
279
  solrize_profile(solr_doc)
284
280
  end
285
281
  datastreams.each_value do |ds|
286
- solr_doc = ds.solrize_profile(solr_doc)
287
282
  ds.ensure_xml_loaded if ds.respond_to? :ensure_xml_loaded ### Can't put this in the model because it's often implemented in Solrizer::XML::TerminologyBasedSolrizer
283
+ #puts "\n\nQDC #{ds.to_solr(solr_doc).inspect}" if ds.kind_of?(ActiveFedora::QualifiedDublinCoreDatastream)
288
284
  solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::RDFDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ds.kind_of?(ActiveFedora::MetadataDatastream)
289
285
  end
290
286
  solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
@@ -292,16 +288,18 @@ module ActiveFedora
292
288
  end
293
289
 
294
290
  def solrize_profile(solr_doc = Hash.new) # :nodoc:
291
+ profile_hash = { 'datastreams' => {} }
295
292
  if inner_object.respond_to? :profile
296
293
  inner_object.profile.each_pair do |property,value|
297
294
  if property =~ /Date/
298
295
  value = Time.parse(value) unless value.is_a?(Time)
299
296
  value = value.xmlschema
300
297
  end
301
- solr_doc[ActiveFedora::SolrService.solr_name("objProfile_#{property}", property =~ /Date/ ? :date : :symbol)] = value
298
+ profile_hash[property] = value
302
299
  end
303
300
  end
304
- solr_doc
301
+ self.datastreams.each_pair { |dsid,ds| profile_hash['datastreams'][dsid] = ds.solrize_profile }
302
+ solr_doc[self.class.profile_solr_name] = profile_hash.to_json
305
303
  end
306
304
 
307
305
  # Serialize the datastream's RDF relationships to solr
@@ -378,12 +376,20 @@ module ActiveFedora
378
376
  else
379
377
  ActiveFedora::Base
380
378
  end
381
-
382
- obj = klass.allocate.init_with(SolrDigitalObject.new(solr_doc, klass))
379
+
380
+ profile_json = Array(solr_doc[ActiveFedora::Base.profile_solr_name]).first
381
+ unless profile_json.present?
382
+ raise ActiveFedora::ObjectNotFoundError, "Object #{pid} does not contain a solrized profile"
383
+ end
384
+ profile_hash = ActiveSupport::JSON.decode(profile_json)
385
+ obj = klass.allocate.init_with(SolrDigitalObject.new(solr_doc, profile_hash, klass))
383
386
  #set by default to load any dependent relationship objects from solr as well
384
387
  #need to call rels_ext once so it exists when iterating over datastreams
385
388
  obj.rels_ext
386
389
  obj.datastreams.each_value do |ds|
390
+ if ds.respond_to?(:profile_from_hash)
391
+ ds.profile_from_hash(profile_hash['datastreams'][ds.dsid])
392
+ end
387
393
  if ds.respond_to?(:from_solr)
388
394
  ds.from_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(ActiveFedora::RelsExtDatastream))
389
395
  end
@@ -16,10 +16,15 @@ module ActiveFedora
16
16
  klass.name.gsub(/(::)/, '_')
17
17
  end
18
18
 
19
+ # list all of the models asserted by the provided object
19
20
  def self.models_asserted_by(obj)
20
21
  obj.relationships(:has_model)
21
22
  end
22
23
 
24
+ # returns an array of the model classes that are defined in the current
25
+ # application that the given object asserts (ie. if the object asserts
26
+ # a StreamingVideo model but the application doesn't define a
27
+ # StreamingVideo model, it will be excluded from this list.
23
28
  def self.known_models_for(obj)
24
29
  models_array = []
25
30
  models_asserted_by( obj ).each do |model_uri|
@@ -28,7 +28,7 @@ module ActiveFedora
28
28
  end
29
29
 
30
30
  def inspect
31
- "#<#{self.class}:#{self.hash} @pid=\"#{pid}\" @dsid=\"#{dsid}\" @controlGroup=\"#{controlGroup}\" @dirty=\"#{dirty}\" @mimeType=\"#{mimeType}\" >"
31
+ "#<#{self.class}:#{self.hash} @pid=\"#{digital_object ? pid : nil}\" @dsid=\"#{dsid}\" @controlGroup=\"#{controlGroup}\" @dirty=\"#{dirty}\" @mimeType=\"#{mimeType}\" >"
32
32
  end
33
33
 
34
34
  #compatibility method for rails' url generators. This method will
@@ -89,26 +89,21 @@ module ActiveFedora
89
89
  tmpl
90
90
  end
91
91
 
92
- def solrize_profile(solr_doc = Hash.new) # :nodoc:
92
+ def solrize_profile # :nodoc:
93
+ profile_hash = {}
93
94
  profile.each_pair do |property,value|
94
95
  if property =~ /Date/
95
96
  value = Time.parse(value) unless value.is_a?(Time)
96
97
  value = value.xmlschema
97
98
  end
98
- solr_doc[ActiveFedora::SolrService.solr_name("#{dsid}_dsProfile_#{property}", property =~ /Date/ ? :date : :symbol)] = value
99
+ profile_hash[property] = value
99
100
  end
100
- solr_doc
101
+ profile_hash
101
102
  end
102
103
 
103
- def from_solr(solr_doc)
104
- profile_from_solr(solr_doc)
105
- end
106
-
107
- def profile_from_solr(solr_doc)
108
- profile_attrs = solr_doc.keys.select { |k| k =~ /^#{dsid}_dsProfile_/ }
109
- profile_attrs.each do |key|
110
- attr_name = key.split(/_/)[2..-2].join('_')
111
- profile[attr_name] = solr_doc[key].to_s
104
+ def profile_from_hash(profile_hash)
105
+ profile_hash.each_pair do |key,value|
106
+ profile[key] = value.to_s
112
107
  end
113
108
  end
114
109
  end
@@ -35,7 +35,7 @@ module ActiveFedora
35
35
  end
36
36
 
37
37
  def self.index(pid)
38
- ActiveFedora::Base.find(pid).update_index
38
+ ActiveFedora::Base.find(pid, :cast=>true).update_index
39
39
  end
40
40
 
41
41
  def self.import_to_fedora(filename, pid='0')
@@ -45,7 +45,6 @@ module ActiveFedora
45
45
  def from_solr(solr_doc)
46
46
  @content = self.to_xml
47
47
  self.xml_loaded = true
48
- profile_from_solr(solr_doc)
49
48
  fields.each do |field_key, field_info|
50
49
  field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
51
50
  value = (solr_doc[field_symbol].nil? ? solr_doc[field_symbol.to_s]: solr_doc[field_symbol])
@@ -181,6 +181,7 @@ module ActiveFedora
181
181
  # :field_list => array, defaults to ["*", "score"]
182
182
  #
183
183
  def find_by_fields_by_solr(query_fields,opts={})
184
+ ActiveSupport::Deprecation.warn("find_by_fields_by_solr is deprecated and will be removed in the next release")
184
185
  #create solr_args from fields passed in, needs to be comma separated list of form field1=value1,field2=value2,...
185
186
  escaped_class_name = self.name.gsub(/(:)/, '\\:')
186
187
  query = "#{ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}"
@@ -40,8 +40,17 @@ module ActiveFedora
40
40
  end
41
41
 
42
42
  def ng_xml
43
- ensure_xml_loaded
44
- return @ng_xml
43
+ @ng_xml ||= begin
44
+ self.dirty = false
45
+ self.xml_loaded = true
46
+
47
+ if new?
48
+ ## Load up the template
49
+ self.class.xml_template
50
+ else
51
+ Nokogiri::XML::Document.parse(content)
52
+ end
53
+ end
45
54
  end
46
55
 
47
56
  def ng_xml=(new_xml)
@@ -65,7 +74,6 @@ module ActiveFedora
65
74
 
66
75
 
67
76
  def to_xml(xml = nil)
68
- ensure_xml_loaded
69
77
  xml = self.ng_xml if xml.nil?
70
78
  ng_xml = self.ng_xml
71
79
  if ng_xml.respond_to?(:root) && ng_xml.root.nil? && self.class.respond_to?(:root_property_ref) && !self.class.root_property_ref.nil?
@@ -100,7 +108,6 @@ module ActiveFedora
100
108
  #
101
109
  # See ActiveFedora::Base.load_instance_from_solr and +get_values_from_solr+ for more information.
102
110
  def from_solr(solr_doc)
103
- profile_from_solr(solr_doc)
104
111
  #just initialize internal_solr_doc since any value retrieval will be done via lazy loading on this doc on-demand
105
112
  @internal_solr_doc = solr_doc
106
113
  end
@@ -295,7 +302,6 @@ module ActiveFedora
295
302
  if self.class.terminology.nil?
296
303
  raise "No terminology is set for this NokogiriDatastream class. Cannot perform update_indexed_attributes"
297
304
  end
298
- ensure_xml_loaded
299
305
  # remove any fields from params that this datastream doesn't recognize
300
306
  # make sure to make a copy of params so not to modify hash that might be passed to other methods
301
307
  current_params = params.clone
@@ -317,13 +323,11 @@ module ActiveFedora
317
323
  end
318
324
 
319
325
  def get_values(field_key,default=[])
320
- ensure_xml_loaded
321
326
  term_values(*field_key)
322
327
  end
323
328
 
324
329
 
325
330
  def find_by_terms(*termpointer)
326
- ensure_xml_loaded
327
331
  super
328
332
  end
329
333
 
@@ -349,7 +353,6 @@ module ActiveFedora
349
353
  #lazy load values from solr on demand
350
354
  get_values_from_solr(*term_pointer)
351
355
  else
352
- ensure_xml_loaded
353
356
  om_term_values(*term_pointer)
354
357
  end
355
358
  end
@@ -5,87 +5,118 @@ module ActiveFedora
5
5
  #Fedora Dublin Core XML datastreams structure.
6
6
  #
7
7
  #Fields can still be overridden if more specificity is desired (see ActiveFedora::Datastream#fields method).
8
- class QualifiedDublinCoreDatastream < MetadataDatastream
8
+ class QualifiedDublinCoreDatastream < NokogiriDatastream
9
+
10
+ class_attribute :class_fields
11
+ self.class_fields = []
12
+ attr_accessor :fields # TODO this can be removed when Model.find_by_fields_by_solr has been removed.
13
+
14
+
15
+ set_terminology do |t|
16
+ t.root(:path=>"dc", :xmlns=>"http://purl.org/dc/terms/")
17
+ t.contributor(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
18
+ t.coverage(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
19
+ t.creator(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
20
+ t.date(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
21
+ t.description(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
22
+ t.format(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
23
+ t.identifier(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
24
+ t.language(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
25
+ t.publisher(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
26
+ t.relation(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
27
+ t.rights(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
28
+ t.source(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
29
+ t.spatial(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
30
+ t.type_(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
31
+ t.medium(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
32
+ t.rights(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
33
+ t.subject(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
34
+ t.title(:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms")
35
+ end
36
+
37
+ define_template :creator do |xml,name|
38
+ xml.creator() do
39
+ xml.text(name)
40
+ end
41
+ end
9
42
 
10
43
  #A frozen array of Dublincore Terms.
11
44
  DCTERMS = [
12
45
  :contributor, :coverage, :creator, :description, :format, :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, :format, :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, :type, :valid
13
46
  ]
14
47
  DCTERMS.freeze
15
-
16
- #Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
17
- #when this method returns. Each term is marked as a multivalue string.
18
- def initialize(digital_object, dsid )
19
- super(digital_object, dsid)
20
- DCTERMS.each do |el|
21
- field el, :string, :multiple=>true
48
+
49
+ # This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
50
+ # each field will have the 3 magic methods:
51
+ # name_values=(arg)
52
+ # name_values
53
+ # name_append(arg)
54
+ #
55
+ #
56
+ # Calling any of the generated methods marks self as dirty.
57
+ #
58
+ # 'tupe' is a datatype, currently :string, :text and :date are supported.
59
+ #
60
+ # opts is an options hash, which will affect the generation of the xml representation of this datastream.
61
+ #
62
+ # Currently supported modifiers:
63
+ # For +QualifiedDublinCorDatastreams+:
64
+ # :element_attrs =>{:foo=>:bar} - hash of xml element attributes
65
+ # :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
66
+ # :encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
67
+ # :multiple=>true - mark this field as a multivalue field (on by default)
68
+ #
69
+ #At some point, these modifiers will be ported up to work for any +ActiveFedora::MetadataDatastream+.
70
+ #
71
+ #There is quite a good example of this class in use in spec/examples/oral_history.rb
72
+ #
73
+ #!! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
74
+ #you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
75
+ #whenever you edit the field's values.
76
+ def field(name, tupe=nil, opts={})
77
+ fields ||= {}
78
+ @fields[name.to_s.to_sym]={:type=>tupe, :values=>[]}.merge(opts)
79
+ # add term to template
80
+ self.class.class_fields << name.to_s
81
+ # add term to terminology
82
+ unless self.class.terminology.has_term?(name.to_sym)
83
+ term = OM::XML::Term.new(name.to_sym, {:xmlns=>"http://purl.org/dc/terms/", :namespace_prefix => "dcterms"}, self.class.terminology)
84
+ self.class.terminology.add_term(term)
85
+ term.generate_xpath_queries!
22
86
  end
23
- self.class.from_xml(nil, self)
87
+
24
88
  end
25
89
 
26
- # Populate a QualifiedDublinCoreDatastream object based on the "datastream" node from a FOXML file
27
- # @param [String] node the xml from the content. Assumes that the content of this datastream is that of an ActiveFedora QualifiedDublinCoreDatastream
28
- # @param [ActiveFedora::Datastream] tmpl the Datastream object that you are building
29
- def self.from_xml(xml, tmpl) # :nodoc:
30
- return if !xml.present?
31
- node = Nokogiri::XML::Document.parse(xml)
32
- tmpl.fields.each do |z|
33
- fname = z.first
34
- fspec = z.last
35
- node_name = "dcterms:#{fspec[:xml_node] ? fspec[:xml_node] : fname}"
36
- attr_modifier= "[@xsi:type='#{fspec[:encoding]}']" if fspec[:encoding]
37
- query = "/dc/#{node_name}#{attr_modifier}"
38
-
39
- node.xpath(query).each do |f|
40
- tmpl.send("#{fname}_append", f.text)
90
+ def update_indexed_attributes(params={}, opts={})
91
+ # if the params are just keys, not an array, make then into an array.
92
+ new_params = {}
93
+ params.each do |key, val|
94
+ if key.is_a? Array
95
+ new_params[key] = val
96
+ else
97
+ new_params[[key.to_sym]] = val
41
98
  end
42
-
43
99
  end
44
- tmpl.instance_variable_set(:@dirty, false)
45
- tmpl
46
- end
47
-
48
- def to_xml()
49
- to_dc_xml()
100
+ super(new_params, opts)
50
101
  end
102
+
51
103
 
52
104
  def self.xml_template
53
105
  Nokogiri::XML::Document.parse("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>")
54
106
  end
55
107
 
56
- #Render self as a Fedora DC xml document.
57
- def to_dc_xml
58
- #TODO: pull the modifiers up into MDDS
59
- xml = REXML::Document.new("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>")
60
- fields.each do |field_name,field_info|
61
- el = REXML::Element.new("dcterms:#{field_name.to_s}")
62
- if field_info.class == Hash
63
- field_info.each do |k, v|
64
- case k
65
- when :element_attrs
66
- v.each{|k,v| el.add_attribute(k.to_s, v.to_s)}
67
- when :values, :type
68
- # do nothing to the :values array
69
- when :xml_node
70
- el.name = "dcterms:#{v}"
71
- when :encoding, :encoding_scheme
72
- el.add_attribute("xsi:type", v)
73
- when :multiple
74
- next
75
- else
76
- el.add_attribute(k.to_s, v)
77
- end
78
- end
79
- field_info = field_info[:values]
80
- end
81
- field_info.each do |val|
82
- el = el.clone
83
- el.text = val.to_s
84
- xml.root.elements.add(el)
85
- end
86
- end
87
- return xml.to_s
88
- end
108
+ def to_solr(solr_doc = Hash.new) # :nodoc:
109
+ @fields.each do |field_key, field_info|
110
+ things = send(field_key)
111
+ if things
112
+ field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
113
+ things.val.each do |val|
114
+ ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val )
115
+ end
116
+ end
117
+ end
118
+ return solr_doc
119
+ end
89
120
 
90
121
  end
91
122
  end