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.
- data/Gemfile.lock +15 -15
- data/active-fedora.gemspec +2 -2
- data/lib/active_fedora.rb +6 -1
- data/lib/active_fedora/base.rb +19 -13
- data/lib/active_fedora/content_model.rb +5 -0
- data/lib/active_fedora/datastream.rb +8 -13
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/metadata_datastream.rb +0 -1
- data/lib/active_fedora/model.rb +1 -0
- data/lib/active_fedora/nokogiri_datastream.rb +11 -8
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +95 -64
- data/lib/active_fedora/rdf_datastream.rb +23 -34
- data/lib/active_fedora/rels_ext_datastream.rb +0 -1
- data/lib/active_fedora/solr_digital_object.rb +4 -9
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +2 -1
- data/spec/integration/base_find_by_fields_spec.rb +3 -0
- data/spec/integration/full_featured_model_spec.rb +24 -18
- data/spec/integration/metadata_datastream_helper_spec.rb +15 -14
- data/spec/integration/model_spec.rb +0 -5
- data/spec/integration/solr_service_spec.rb +1 -8
- data/spec/samples/oral_history_sample_model.rb +2 -11
- data/spec/samples/special_thing.rb +1 -1
- data/spec/unit/base_extra_spec.rb +8 -14
- data/spec/unit/base_spec.rb +4 -8
- data/spec/unit/inheritance_spec.rb +4 -8
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +60 -116
- data/spec/unit/solr_digital_object_spec.rb +2 -2
- data/spec/unit/solr_service_spec.rb +0 -1
- metadata +11 -13
- data/lib/active_fedora/attribute_methods.rb +0 -9
- data/spec/fixtures/oh_qdc.xml +0 -32
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active-fedora (4.0.0.
|
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.
|
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.
|
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.
|
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.
|
81
|
-
rspec-core (~> 2.
|
82
|
-
rspec-expectations (~> 2.
|
83
|
-
rspec-mocks (~> 2.
|
84
|
-
rspec-core (2.
|
85
|
-
rspec-expectations (2.
|
86
|
-
diff-lcs (~> 1.1.
|
87
|
-
rspec-mocks (2.
|
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.
|
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 (
|
126
|
+
rspec (>= 2.9.0)
|
127
127
|
yard
|
data/active-fedora.gemspec
CHANGED
@@ -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.
|
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", "
|
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")
|
data/lib/active_fedora.rb
CHANGED
@@ -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
|
data/lib/active_fedora/base.rb
CHANGED
@@ -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
|
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
|
-
|
298
|
+
profile_hash[property] = value
|
302
299
|
end
|
303
300
|
end
|
304
|
-
|
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
|
-
|
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
|
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
|
-
|
99
|
+
profile_hash[property] = value
|
99
100
|
end
|
100
|
-
|
101
|
+
profile_hash
|
101
102
|
end
|
102
103
|
|
103
|
-
def
|
104
|
-
|
105
|
-
|
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
|
@@ -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])
|
data/lib/active_fedora/model.rb
CHANGED
@@ -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
|
-
|
44
|
-
|
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 <
|
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
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
87
|
+
|
24
88
|
end
|
25
89
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|