active-fedora 4.0.0.rc1 → 4.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -11
- data/History.txt +4 -1
- data/active-fedora.gemspec +2 -2
- data/lib/active_fedora/associations/association_collection.rb +1 -1
- data/lib/active_fedora/associations/belongs_to_association.rb +1 -1
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +1 -1
- data/lib/active_fedora/base.rb +10 -6
- data/lib/active_fedora/file_management.rb +1 -1
- data/lib/active_fedora/fixture_loader.rb +1 -1
- data/lib/active_fedora/model.rb +39 -38
- data/lib/active_fedora/nokogiri_datastream.rb +1 -1
- data/lib/active_fedora/persistence.rb +9 -11
- data/lib/active_fedora/predicates.rb +2 -2
- data/lib/active_fedora/rdf_datastream.rb +49 -7
- data/lib/active_fedora/relationships.rb +6 -9
- data/lib/active_fedora/service_definitions.rb +1 -1
- data/lib/active_fedora/solr_service.rb +15 -8
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora.rake +3 -5
- data/lib/tasks/active_fedora_dev.rake +2 -1
- data/spec/fixtures/solr_rdf_descMetadata.nt +7 -0
- data/spec/integration/base_file_management_spec.rb +1 -1
- data/spec/integration/base_find_by_fields_spec.rb +16 -14
- data/spec/integration/base_spec.rb +10 -9
- data/spec/integration/datastream_collections_spec.rb +5 -5
- data/spec/integration/datastream_spec.rb +1 -1
- data/spec/integration/full_featured_model_spec.rb +1 -1
- data/spec/integration/model_spec.rb +14 -11
- data/spec/integration/mods_article_integration_spec.rb +2 -2
- data/spec/integration/nokogiri_datastream_spec.rb +1 -1
- data/spec/integration/ntriples_datastream_spec.rb +1 -0
- data/spec/integration/rels_ext_datastream_spec.rb +5 -6
- data/spec/integration/semantic_node_spec.rb +0 -1
- data/spec/integration/solr_service_spec.rb +8 -8
- data/spec/unit/base_extra_spec.rb +47 -7
- data/spec/unit/base_file_management_spec.rb +1 -1
- data/spec/unit/base_spec.rb +44 -15
- data/spec/unit/model_spec.rb +16 -29
- data/spec/unit/ntriples_datastream_spec.rb +152 -1
- data/spec/unit/relationships_spec.rb +16 -18
- data/spec/unit/solr_config_options_spec.rb +1 -3
- data/spec/unit/solr_service_spec.rb +12 -24
- metadata +68 -86
- data/spec/integration/base_loader_spec.rb +0 -40
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.rc2)
|
5
5
|
activeresource (>= 3.0.0)
|
6
6
|
activesupport (>= 3.0.0)
|
7
7
|
equivalent-xml
|
@@ -12,8 +12,8 @@ PATH
|
|
12
12
|
om (>= 1.5.3)
|
13
13
|
rdf
|
14
14
|
rdf-rdfxml
|
15
|
+
rsolr
|
15
16
|
rubydora (~> 0.5.4)
|
16
|
-
solr-ruby (>= 0.0.6)
|
17
17
|
solrizer (~> 1.2.0)
|
18
18
|
xml-simple (>= 1.0.12)
|
19
19
|
|
@@ -101,7 +101,6 @@ GEM
|
|
101
101
|
nokogiri (>= 1.4.0)
|
102
102
|
nori (~> 1.1)
|
103
103
|
wasabi (~> 2.1)
|
104
|
-
solr-ruby (0.0.8)
|
105
104
|
solrizer (1.2.0)
|
106
105
|
daemons
|
107
106
|
mediashelf-loggable (~> 0.4.7)
|
@@ -109,13 +108,6 @@ GEM
|
|
109
108
|
om (>= 1.5.0)
|
110
109
|
stomp
|
111
110
|
xml-simple
|
112
|
-
solrizer-fedora (1.2.5)
|
113
|
-
active-fedora (>= 3.2.0)
|
114
|
-
activesupport (>= 3.0.11)
|
115
|
-
fastercsv
|
116
|
-
rsolr (= 1.0.6)
|
117
|
-
solr-ruby (>= 0.0.6)
|
118
|
-
solrizer (>= 1.0.0)
|
119
111
|
stomp (1.2.0)
|
120
112
|
wasabi (2.1.0)
|
121
113
|
nokogiri (>= 1.4.0)
|
@@ -132,5 +124,4 @@ DEPENDENCIES
|
|
132
124
|
mocha (>= 0.9.8)
|
133
125
|
rake
|
134
126
|
rspec (~> 2.0)
|
135
|
-
solrizer-fedora (~> 1.2.5)
|
136
127
|
yard
|
data/History.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
4.0.0.
|
1
|
+
4.0.0.rc2
|
2
2
|
Removed deprecations
|
3
3
|
* allowing :fedora level in fedora.yml
|
4
4
|
* automatic includes of Relationships and FileMethods is removed
|
@@ -6,6 +6,9 @@ Added sharding TODO add documentation
|
|
6
6
|
Added find_document which determines the correct model and then casts the object to that.
|
7
7
|
Improved loading from solr
|
8
8
|
RDF datastreams
|
9
|
+
Replaced solr-ruby with rsolr. Note: remove any calls to .hits
|
10
|
+
load_instance is now deprecated, replaced with find
|
11
|
+
Find alwasy casts to the appropriate object.
|
9
12
|
|
10
13
|
3.3.2
|
11
14
|
HYDRA-745 No need to require :url be present on external datastreams
|
data/active-fedora.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = "rubyfedora"
|
16
16
|
s.rubygems_version = %q{1.3.7}
|
17
17
|
|
18
|
-
s.add_dependency('
|
18
|
+
s.add_dependency('rsolr')
|
19
19
|
s.add_dependency('xml-simple', '>= 1.0.12')
|
20
20
|
s.add_dependency('mime-types', '>= 1.16')
|
21
21
|
s.add_dependency('multipart-post', "= 1.1.2")
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
s.add_development_dependency("RedCloth") # for RDoc formatting
|
34
34
|
s.add_development_dependency("rake")
|
35
35
|
# s.add_development_dependency("rcov") # not ruby 1.9 compatible
|
36
|
-
s.add_development_dependency("solrizer-fedora", "~>1.2.5") # used by the fixtures rake tasks
|
36
|
+
# s.add_development_dependency("solrizer-fedora", "~>1.2.5") # used by the fixtures rake tasks
|
37
37
|
s.add_development_dependency("jettywrapper", ">=1.2.0")
|
38
38
|
s.add_development_dependency("rspec", "~> 2.0")
|
39
39
|
s.add_development_dependency("mocha", ">= 0.9.8")
|
@@ -131,7 +131,7 @@ module ActiveFedora
|
|
131
131
|
|
132
132
|
def find_target
|
133
133
|
return [] if @finder_query.empty?
|
134
|
-
solr_result = SolrService.
|
134
|
+
solr_result = SolrService.query(@finder_query, :rows=>1000)
|
135
135
|
#TODO, don't reify, just store the solr results and lazily reify.
|
136
136
|
return ActiveFedora::SolrService.reify_solr_results(solr_result)
|
137
137
|
end
|
@@ -27,7 +27,7 @@ module ActiveFedora
|
|
27
27
|
pid = @owner.ids_for_outbound(@reflection.options[:property]).first
|
28
28
|
return if pid.nil?
|
29
29
|
query = ActiveFedora::SolrService.construct_query_for_pids([pid])
|
30
|
-
solr_result = SolrService.
|
30
|
+
solr_result = SolrService.query(query)
|
31
31
|
return ActiveFedora::SolrService.reify_solr_results(solr_result).first
|
32
32
|
end
|
33
33
|
|
@@ -10,7 +10,7 @@ module ActiveFedora
|
|
10
10
|
pids = @owner.ids_for_outbound(@reflection.options[:property])
|
11
11
|
return [] if pids.empty?
|
12
12
|
query = ActiveFedora::SolrService.construct_query_for_pids(pids)
|
13
|
-
solr_result = SolrService.
|
13
|
+
solr_result = SolrService.query(query)
|
14
14
|
return ActiveFedora::SolrService.reify_solr_results(solr_result)
|
15
15
|
end
|
16
16
|
|
data/lib/active_fedora/base.rb
CHANGED
@@ -271,13 +271,17 @@ module ActiveFedora
|
|
271
271
|
# If opts[:model_only] == true, the base object metadata and the RELS-EXT datastream will be omitted. This is mainly to support shelver, which calls .to_solr for each model an object subscribes to.
|
272
272
|
def to_solr(solr_doc = Hash.new, opts={})
|
273
273
|
unless opts[:model_only]
|
274
|
-
|
274
|
+
c_time = create_date
|
275
|
+
c_time = Time.parse(c_time) unless c_time.is_a?(Time)
|
276
|
+
m_time = modified_date
|
277
|
+
m_time = Time.parse(m_time) unless m_time.is_a?(Time)
|
278
|
+
solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => pid, ActiveFedora::SolrService.solr_name(:system_create, :date) => c_time.utc.xmlschema, ActiveFedora::SolrService.solr_name(:system_modified, :date) => m_time.utc.xmlschema, ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol) => self.class.inspect)
|
275
279
|
solrize_profile(solr_doc)
|
276
280
|
end
|
277
281
|
datastreams.each_value do |ds|
|
278
282
|
solr_doc = ds.solrize_profile(solr_doc)
|
279
283
|
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
|
280
|
-
solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::
|
284
|
+
solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::RDFDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ds.kind_of?(ActiveFedora::MetadataDatastream)
|
281
285
|
end
|
282
286
|
solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
|
283
287
|
solr_doc
|
@@ -326,7 +330,7 @@ module ActiveFedora
|
|
326
330
|
if self.inner_object.is_a? DigitalObject
|
327
331
|
raise "#{self.inspect} is already a full digital object"
|
328
332
|
end
|
329
|
-
self.class.
|
333
|
+
self.class.find self.pid
|
330
334
|
end
|
331
335
|
|
332
336
|
# ** EXPERIMENTAL **
|
@@ -341,7 +345,7 @@ module ActiveFedora
|
|
341
345
|
|
342
346
|
# ** EXPERIMENTAL **
|
343
347
|
#
|
344
|
-
# This method can be used instead of ActiveFedora::Model::ClassMethods.
|
348
|
+
# This method can be used instead of ActiveFedora::Model::ClassMethods.find.
|
345
349
|
# It works similarly except it populates an object from Solr instead of Fedora.
|
346
350
|
# It is most useful for objects used in read-only displays in order to speed up loading time. If only
|
347
351
|
# a pid is passed in it will query solr for a corresponding solr document and then use it
|
@@ -351,12 +355,12 @@ module ActiveFedora
|
|
351
355
|
# one passed to populate the object.
|
352
356
|
#
|
353
357
|
# It will anything stored within solr such as metadata and relationships. Non-metadata datastreams will not
|
354
|
-
# be loaded and if needed you should use
|
358
|
+
# be loaded and if needed you should use find instead.
|
355
359
|
def self.load_instance_from_solr(pid,solr_doc=nil)
|
356
360
|
if solr_doc.nil?
|
357
361
|
result = find_by_solr(pid)
|
358
362
|
raise "Object #{pid} not found in solr" if result.nil?
|
359
|
-
solr_doc = result.
|
363
|
+
solr_doc = result.first
|
360
364
|
#double check pid and id in record match
|
361
365
|
raise "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
|
362
366
|
else
|
@@ -45,7 +45,7 @@ module ActiveFedora
|
|
45
45
|
# collection_members_append(obj)
|
46
46
|
unless obj.kind_of? ActiveFedora::Base
|
47
47
|
begin
|
48
|
-
obj = ActiveFedora::Base.
|
48
|
+
obj = ActiveFedora::Base.find(obj)
|
49
49
|
rescue ActiveFedora::ObjectNotFoundError
|
50
50
|
"You must provide either an ActiveFedora object or a valid pid to add it as a file object. You submitted #{obj.inspect}"
|
51
51
|
end
|
@@ -12,7 +12,7 @@ module ActiveFedora
|
|
12
12
|
|
13
13
|
def self.delete(pid)
|
14
14
|
begin
|
15
|
-
ActiveFedora::Base.
|
15
|
+
ActiveFedora::Base.find(pid).delete
|
16
16
|
1
|
17
17
|
rescue ActiveFedora::ObjectNotFoundError
|
18
18
|
logger.debug "The object #{pid} has already been deleted (or was never created)."
|
data/lib/active_fedora/model.rb
CHANGED
@@ -44,12 +44,6 @@ module ActiveFedora
|
|
44
44
|
result
|
45
45
|
end
|
46
46
|
|
47
|
-
def add_metadata
|
48
|
-
end
|
49
|
-
|
50
|
-
def datastream
|
51
|
-
end
|
52
|
-
|
53
47
|
|
54
48
|
#
|
55
49
|
# =Class Methods
|
@@ -80,20 +74,10 @@ module ActiveFedora
|
|
80
74
|
# @example this will return an instance of Book, even if the object hydra:dataset1 asserts that it is a Dataset
|
81
75
|
# Book.load_instance("hydra:dataset1")
|
82
76
|
def load_instance(pid)
|
83
|
-
|
77
|
+
ActiveSupport::Deprecation.warn("load_instance is deprecated. Use find instead")
|
78
|
+
find(pid)
|
84
79
|
end
|
85
80
|
|
86
|
-
# Retrieve the Fedora object with te given pid, explore the returned object, determine its model
|
87
|
-
# using #{known_models_for} and cast to that class.
|
88
|
-
# @param [String] pid of the object to load
|
89
|
-
#
|
90
|
-
# @example because the object hydra:dataset1 asserts it is a Dataset (hasModel info:fedora/afmodel:Dataset), return a Dataset object (not a Book).
|
91
|
-
# Book.find_document("hydra:dataset1")
|
92
|
-
def find_document(pid)
|
93
|
-
af_base = load_instance(pid)
|
94
|
-
the_model = ActiveFedora::ContentModel.known_models_for( af_base ).first
|
95
|
-
af_base.adapt_to(the_model)
|
96
|
-
end
|
97
81
|
|
98
82
|
|
99
83
|
# Returns a suitable uri object for :has_model
|
@@ -120,19 +104,20 @@ module ActiveFedora
|
|
120
104
|
if args == :all
|
121
105
|
escaped_class_uri = SolrService.escape_uri_for_query(self.to_class_uri)
|
122
106
|
q = "#{ActiveFedora::SolrService.solr_name(:has_model, :symbol)}:#{escaped_class_uri}"
|
123
|
-
hits = SolrService.
|
107
|
+
hits = SolrService.query(q, :rows=>opts[:rows])
|
124
108
|
return hits.map do |hit|
|
125
109
|
pid = hit[SOLR_DOCUMENT_ID]
|
126
|
-
|
110
|
+
find_one(pid)
|
127
111
|
end
|
128
112
|
elsif args.class == String
|
129
|
-
return
|
113
|
+
return find_one(args)
|
130
114
|
end
|
131
115
|
end
|
132
116
|
|
117
|
+
|
133
118
|
def find_model(pid)
|
134
|
-
ActiveSupport::
|
135
|
-
|
119
|
+
ActiveSupport::Deprecation.warn("find_model is deprecated. Use find instead")
|
120
|
+
find(pid)
|
136
121
|
end
|
137
122
|
|
138
123
|
|
@@ -142,7 +127,7 @@ module ActiveFedora
|
|
142
127
|
escaped_class_uri = SolrService.escape_uri_for_query(self.to_class_uri)
|
143
128
|
q = "#{ActiveFedora::SolrService.solr_name(:has_model, :symbol)}:#{escaped_class_uri}"
|
144
129
|
q << " AND #{args[:conditions]}" if args[:conditions]
|
145
|
-
SolrService.
|
130
|
+
SolrService.query(q, :raw=>true, :rows=>0)['response']['numFound']
|
146
131
|
end
|
147
132
|
|
148
133
|
#Sends a query directly to SolrService
|
@@ -164,10 +149,10 @@ module ActiveFedora
|
|
164
149
|
def find_by_solr(query, args={})
|
165
150
|
if query == :all
|
166
151
|
escaped_class_name = self.name.gsub(/(:)/, '\\:')
|
167
|
-
SolrService.
|
152
|
+
SolrService.query("#{ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}", args)
|
168
153
|
elsif query.class == String
|
169
154
|
escaped_id = query.gsub(/(:)/, '\\:')
|
170
|
-
SolrService.
|
155
|
+
SolrService.query("#{SOLR_DOCUMENT_ID}:#{escaped_id}", args)
|
171
156
|
end
|
172
157
|
end
|
173
158
|
|
@@ -218,20 +203,20 @@ module ActiveFedora
|
|
218
203
|
|
219
204
|
#set default sort to created date ascending
|
220
205
|
unless query_opts.include?(:sort)
|
221
|
-
query_opts.merge!({:sort=>[ActiveFedora::SolrService.solr_name(:system_create,:date)
|
206
|
+
query_opts.merge!({:sort=>[ActiveFedora::SolrService.solr_name(:system_create,:date)+' asc']})
|
222
207
|
else
|
223
208
|
#need to convert to solr names for all fields
|
224
209
|
sort_array =[]
|
225
210
|
|
226
211
|
opts[:sort].collect do |sort|
|
227
|
-
sort_direction =
|
212
|
+
sort_direction = 'ascending'
|
228
213
|
if sort.respond_to?(:keys)
|
229
214
|
key = sort.keys[0]
|
230
215
|
sort_direction = sort[key]
|
231
|
-
sort_direction =~ /^desc/ ? sort_direction = :descending : :ascending
|
232
216
|
else
|
233
217
|
key = sort.to_s
|
234
218
|
end
|
219
|
+
sort_direction = sort_direction =~ /^desc/ ? 'desc' : 'asc'
|
235
220
|
field_name = key
|
236
221
|
|
237
222
|
if key.to_s =~ /^system_create/
|
@@ -246,14 +231,14 @@ module ActiveFedora
|
|
246
231
|
if class_fields.include?(field_name.to_sym)
|
247
232
|
solr_name = ActiveFedora::SolrService.solr_name(key,class_fields[field_name.to_sym][:type])
|
248
233
|
end
|
249
|
-
sort_array.push({solr_name
|
234
|
+
sort_array.push("#{solr_name} #{sort_direction}")
|
250
235
|
end
|
251
236
|
|
252
|
-
query_opts[:sort] = sort_array
|
237
|
+
query_opts[:sort] = sort_array.join(",")
|
253
238
|
end
|
254
239
|
|
255
240
|
logger.debug "Querying solr for #{self.name} objects with query: '#{query}'"
|
256
|
-
|
241
|
+
SolrService.query(query, query_opts)
|
257
242
|
end
|
258
243
|
|
259
244
|
def class_fields
|
@@ -275,6 +260,22 @@ module ActiveFedora
|
|
275
260
|
instance_variable_get("@#{name}")
|
276
261
|
end
|
277
262
|
|
263
|
+
private
|
264
|
+
# Retrieve the Fedora object with te given pid, explore the returned object, determine its model
|
265
|
+
# using #{known_models_for} and cast to that class.
|
266
|
+
# @param [String] pid of the object to load
|
267
|
+
#
|
268
|
+
# @example because the object hydra:dataset1 asserts it is a Dataset (hasModel info:fedora/afmodel:Dataset), return a Dataset object (not a Book).
|
269
|
+
# Book.find_document("hydra:dataset1")
|
270
|
+
def find_one(pid)
|
271
|
+
af_base = self.allocate.init_with(DigitalObject.find(self, pid))
|
272
|
+
the_model = ActiveFedora::ContentModel.known_models_for( af_base ).first
|
273
|
+
if af_base.class != the_model
|
274
|
+
return af_base.adapt_to(the_model)
|
275
|
+
end
|
276
|
+
af_base
|
277
|
+
end
|
278
|
+
|
278
279
|
end
|
279
280
|
def create_property_getter(property) # :nodoc:
|
280
281
|
|
@@ -295,12 +296,12 @@ module ActiveFedora
|
|
295
296
|
|
296
297
|
private
|
297
298
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
299
|
+
def self.class_exists?(class_name)
|
300
|
+
klass = class_name.constantize
|
301
|
+
return klass.is_a?(Class)
|
302
|
+
rescue NameError
|
303
|
+
return false
|
304
|
+
end
|
304
305
|
|
305
306
|
end
|
306
307
|
end
|
@@ -340,7 +340,7 @@ module ActiveFedora
|
|
340
340
|
# => {"person_0_role_text"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, "person_1_role_text"=>{"0"=>"otherrole1", "1"=>"otherrole2"}}
|
341
341
|
def update_values(params={})
|
342
342
|
if @internal_solr_doc
|
343
|
-
raise "No update performed, this object was initialized via Solr instead of Fedora and is therefore read-only. Please utilize ActiveFedora::Base.
|
343
|
+
raise "No update performed, this object was initialized via Solr instead of Fedora and is therefore read-only. Please utilize ActiveFedora::Base.find to first load object via Fedora instead."
|
344
344
|
else
|
345
345
|
result = om_update_values(params)
|
346
346
|
self.dirty= true
|
@@ -59,18 +59,12 @@ module ActiveFedora
|
|
59
59
|
raise ObjectNotFoundError, "Unable to find #{pid} in the repository"
|
60
60
|
end
|
61
61
|
if ENABLE_SOLR_UPDATES
|
62
|
-
ActiveFedora::SolrService.instance.conn
|
63
|
-
|
64
|
-
|
65
|
-
# solrizer.solrize_delete(pid)
|
66
|
-
# end
|
62
|
+
solr = ActiveFedora::SolrService.instance.conn
|
63
|
+
solr.delete_by_id(pid)
|
64
|
+
solr.commit
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
68
|
# Updates Solr index with self.
|
75
69
|
def update_index
|
76
70
|
if defined?( Solrizer::Fedora::Solrizer )
|
@@ -78,11 +72,15 @@ module ActiveFedora
|
|
78
72
|
solrizer = Solrizer::Fedora::Solrizer.new
|
79
73
|
solrizer.solrize( self )
|
80
74
|
else
|
81
|
-
|
82
|
-
SolrService.instance.conn.
|
75
|
+
SolrService.instance.conn.add(self.to_solr)
|
76
|
+
SolrService.instance.conn.commit
|
83
77
|
end
|
84
78
|
end
|
85
79
|
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
|
86
84
|
# Deals with preparing new object to be saved to Fedora, then pushes it and its datastreams into Fedora.
|
87
85
|
def create
|
88
86
|
assign_pid
|
@@ -28,8 +28,8 @@ module ActiveFedora
|
|
28
28
|
vocabularies[xmlns][rel_predicate]
|
29
29
|
end
|
30
30
|
|
31
|
-
def self.vocabularies
|
32
|
-
@vocabularies ||=
|
31
|
+
def self.vocabularies(vocabs = {})
|
32
|
+
@vocabularies ||= vocabs
|
33
33
|
predicate_mappings.keys.each do |ns|
|
34
34
|
@vocabularies[ns] = RDF::Vocabulary.new(ns) unless @vocabularies.has_key? ns
|
35
35
|
end
|
@@ -5,9 +5,22 @@ module ActiveFedora
|
|
5
5
|
module ModelMethods
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
module ClassMethods
|
8
|
+
attr_accessor :vocabularies
|
8
9
|
def config
|
9
10
|
ActiveFedora::Predicates.predicate_config
|
10
11
|
end
|
12
|
+
def register_vocabularies(*vocabs)
|
13
|
+
@vocabularies = {}
|
14
|
+
vocabs.each do |v|
|
15
|
+
if v.respond_to? :property and v.respond_to? :to_uri
|
16
|
+
@vocabularies[v.to_uri] = v
|
17
|
+
else
|
18
|
+
raise "not an RDF vocabulary: #{v}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
ActiveFedora::Predicates.vocabularies(vocabularies)
|
22
|
+
@vocabularies
|
23
|
+
end
|
11
24
|
def map_predicates(&block)
|
12
25
|
yield self
|
13
26
|
end
|
@@ -16,19 +29,23 @@ module ActiveFedora
|
|
16
29
|
raise "mapping must specify RDF vocabulary as :in argument" unless args.has_key? :in
|
17
30
|
vocab = args[:in]
|
18
31
|
predicate = args.fetch(:to, name)
|
32
|
+
data_type = args.fetch(:type, :string)
|
19
33
|
raise "Vocabulary '#{vocab.inspect}' does not define property '#{predicate.inspect}'" unless vocab.respond_to? predicate
|
20
34
|
vocab = vocab.to_s
|
35
|
+
# this is needed for AF::Predicates integration
|
36
|
+
# stuff data_type in there too for to_solr support
|
21
37
|
if config
|
22
38
|
if config[:predicate_mapping].has_key? vocab
|
23
39
|
config[:predicate_mapping][vocab][name] = predicate
|
40
|
+
config[:predicate_mapping][vocab]["#{name}type".to_sym] = data_type
|
24
41
|
else
|
25
|
-
config[:predicate_mapping][vocab] = { name => predicate }
|
42
|
+
config[:predicate_mapping][vocab] = { name => predicate, "#{name}type".to_sym => data_type }
|
26
43
|
end
|
27
44
|
else
|
28
45
|
config = {
|
29
46
|
:default_namespace => vocab,
|
30
47
|
:predicate_mapping => {
|
31
|
-
vocab => { name => predicate }
|
48
|
+
vocab => { name => predicate, "#{name}type".to_sym => data_type }
|
32
49
|
}
|
33
50
|
}
|
34
51
|
end
|
@@ -85,11 +102,40 @@ module ActiveFedora
|
|
85
102
|
end
|
86
103
|
end
|
87
104
|
|
105
|
+
# returns a Hash, e.g.: {field => {:values => values, :type => type}, ...}
|
106
|
+
def fields
|
107
|
+
field_map = {}
|
108
|
+
graph.relationships.each do |predicate, values|
|
109
|
+
vocab_sym, name = predicate.qname
|
110
|
+
vocabs_list = self.class.vocabularies.select { |ns, v| v.__prefix__ == vocab_sym }
|
111
|
+
vocab = vocabs_list.first.first.to_s
|
112
|
+
mapped_names = self.class.config[:predicate_mapping][vocab].select {|k, v| v.to_s == name.to_s}
|
113
|
+
name = mapped_names.first.first.to_s
|
114
|
+
type = self.class.config[:predicate_mapping][vocab]["#{name}type".to_sym]
|
115
|
+
field_map[name.to_sym] = {:values => values.map {|v| v.to_s}, :type => type}
|
116
|
+
end
|
117
|
+
field_map
|
118
|
+
end
|
119
|
+
|
120
|
+
def to_solr(solr_doc = Hash.new) # :nodoc:
|
121
|
+
fields.each do |field_key, field_info|
|
122
|
+
if field_info.has_key?(:values) && !field_info[:values].nil?
|
123
|
+
field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
|
124
|
+
values = field_info[:values]
|
125
|
+
values = [values] unless values.respond_to? :each
|
126
|
+
values.each do |val|
|
127
|
+
::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
solr_doc
|
132
|
+
end
|
133
|
+
|
88
134
|
# @param [Symbol, RDF::URI] predicate the predicate to insert into the graph
|
89
135
|
def find_predicate(predicate)
|
90
136
|
predicate = predicate.to_sym unless predicate.kind_of? RDF::URI
|
91
137
|
result = ActiveFedora::Predicates.find_predicate(predicate)
|
92
|
-
|
138
|
+
RDF::URI(result.reverse.to_s)
|
93
139
|
end
|
94
140
|
|
95
141
|
def graph
|
@@ -109,10 +155,6 @@ module ActiveFedora
|
|
109
155
|
TermProxy.new(graph, predicate, values)
|
110
156
|
end
|
111
157
|
|
112
|
-
def to_solr
|
113
|
-
# TODO
|
114
|
-
end
|
115
|
-
|
116
158
|
# if there are any existing statements with this predicate, replace them
|
117
159
|
# @param [Symbol, RDF::URI] predicate the predicate to insert into the graph
|
118
160
|
def set_value(predicate, args)
|