active-fedora 3.1.0.pre3 → 3.1.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/active_fedora.rb CHANGED
@@ -227,7 +227,7 @@ module ActiveFedora #:nodoc:
227
227
 
228
228
  # Last choice, check for the default config file
229
229
  config_path = File.expand_path(File.join(File.dirname(__FILE__), "..", "config", "#{config_type}.yml"))
230
- logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type} => '/path/to/#{config_type}.yml) - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
230
+ logger.warn "Using the default #{config_type}.yml that comes with active-fedora. If you want to override this, pass the path to #{config_type}.yml to ActiveFedora - ie. ActiveFedora.init(:#{config_type}_config_path => '/path/to/#{config_type}.yml) - or set Rails.root and put #{config_type}.yml into \#{Rails.root}/config."
231
231
  return config_path if File.file? config_path
232
232
  raise ActiveFedoraConfigurationException "Couldn't load #{config_type} config file!"
233
233
  end
@@ -28,7 +28,7 @@ module ActiveFedora
28
28
  end
29
29
 
30
30
  def self.models_asserted_by(obj)
31
- Array obj.relationships[:self][:has_model]
31
+ obj.ids_for_outbound(:has_model)
32
32
  end
33
33
 
34
34
  def self.known_models_for(obj)
@@ -62,7 +62,14 @@ module ActiveFedora
62
62
  end
63
63
 
64
64
  def self.short_predicate(predicate)
65
- predicate.to_str.gsub(/^[^#]+#/, '').underscore.to_sym
65
+ if match = /^([^#]+#)(.+)$/.match(predicate.to_str)
66
+ namespace = match[1]
67
+ predicate = match[2]
68
+ pred = ActiveFedora::Base.predicate_mappings[namespace].invert[predicate]
69
+ pred
70
+ else
71
+ raise "Unable to parse predicate: #{predicate}"
72
+ end
66
73
  end
67
74
 
68
75
  # Serialize the datastream's RDF relationships to solr
@@ -195,6 +195,27 @@ module ActiveFedora
195
195
  id_array
196
196
  end
197
197
 
198
+ def load_bidirectional(name, inbound_method_name, outbound_method_name, opts)
199
+ opts = {:rows=>25}.merge(opts)
200
+ if opts[:response_format] == :solr || opts[:response_format] == :load_from_solr
201
+ predicate = outbound_relationship_predicates["#{name}_outbound"]
202
+ outbound_id_array = ids_for_outbound(predicate)
203
+ query = self.class.bidirectional_relationship_query(self.pid,"#{name}",outbound_id_array)
204
+ solr_result = SolrService.instance.conn.query(query, :rows=>opts[:rows])
205
+
206
+ if opts[:response_format] == :solr
207
+ return solr_result
208
+ elsif opts[:response_format] == :load_from_solr || self.load_from_solr
209
+ return ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
210
+ else
211
+ return ActiveFedora::SolrService.reify_solr_results(solr_result)
212
+ end
213
+ else
214
+ ary = send(inbound_method_name,opts) + send(outbound_method_name, opts)
215
+ return ary.uniq
216
+ end
217
+ end
218
+
198
219
  def load_outbound_relationship(name, predicate, opts={})
199
220
  id_array = ids_for_outbound(predicate)
200
221
  if opts[:response_format] == :id_array && !self.class.relationship_has_solr_filter_query?(:self,"#{name}")
@@ -418,6 +439,8 @@ module ActiveFedora
418
439
  END
419
440
  end
420
441
 
442
+
443
+
421
444
  # Generates relationship finders for predicates that point in both directions
422
445
  # and registers predicate relationships for each direction.
423
446
  #
@@ -436,30 +459,7 @@ module ActiveFedora
436
459
 
437
460
  class_eval <<-END
438
461
  def #{name}(opts={})
439
- opts = {:rows=>25}.merge(opts)
440
- if opts[:response_format] == :solr || opts[:response_format] == :load_from_solr
441
- outbound_id_array = []
442
- predicate = outbound_relationship_predicates["#{name}_outbound"]
443
- if !outbound_relationships[predicate].nil?
444
- outbound_relationships[predicate].each do |rel|
445
- outbound_id_array << rel.gsub("info:fedora/", "")
446
- end
447
- end
448
- #outbound_id_array = #{outbound_method_name}(:response_format=>:id_array)
449
- query = self.class.bidirectional_relationship_query(self.pid,"#{name}",outbound_id_array)
450
- solr_result = SolrService.instance.conn.query(query, :rows=>opts[:rows])
451
-
452
- if opts[:response_format] == :solr
453
- return solr_result
454
- elsif opts[:response_format] == :load_from_solr || self.load_from_solr
455
- return ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
456
- else
457
- return ActiveFedora::SolrService.reify_solr_results(solr_result)
458
- end
459
- else
460
- ary = #{inbound_method_name}(opts) + #{outbound_method_name}(opts)
461
- return ary.uniq
462
- end
462
+ load_bidirectional("#{name}", :#{inbound_method_name}, :#{outbound_method_name}, opts)
463
463
  end
464
464
  def #{name}_ids
465
465
  #{name}(:response_format => :id_array)
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.1.0.pre3"
2
+ VERSION = "3.1.0.pre4"
3
3
  end
@@ -82,12 +82,12 @@ namespace :active_fedora do
82
82
  end
83
83
 
84
84
  task :load_fixtures => :environment do
85
- require 'solrizer'
86
- require 'solrizer-fedora'
87
- require 'spec/samples/models/hydrangea_article'
88
- ENV["FEDORA_HOME"] ||= File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
89
- retval = `$FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http`
90
- puts "loaded demo objects #{retval}"
85
+ # require 'solrizer'
86
+ # require 'solrizer-fedora'
87
+ # require 'spec/samples/models/hydrangea_article'
88
+ # ENV["FEDORA_HOME"] ||= File.expand_path(File.join(File.dirname(__FILE__),'..','..','jetty','fedora','default'))
89
+ # retval = `$FEDORA_HOME/client/bin/fedora-ingest-demos.sh localhost 8983 fedoraAdmin fedoraAdmin http`
90
+ # puts "loaded demo objects #{retval}"
91
91
  ActiveFedora.init unless Thread.current[:repo]
92
92
 
93
93
  ENV["pid"] = "hydrangea:fixture_mods_article1"
@@ -71,12 +71,12 @@ describe ActiveFedora::ContentModel do
71
71
  describe "models_asserted_by" do
72
72
  it "should return an array of all of the content models asserted by the given object" do
73
73
  mock_object = mock("ActiveFedora Object")
74
- mock_object.expects(:relationships).returns( :self=>{:has_model=>["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"]} )
74
+ mock_object.expects(:ids_for_outbound).with(:has_model).returns(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
75
75
  ActiveFedora::ContentModel.models_asserted_by(mock_object).should == ["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"]
76
76
  end
77
77
  it "should return an empty array if the object doesn't have a RELS-EXT datastream" do
78
78
  mock_object = mock("ActiveFedora Object")
79
- mock_object.expects(:relationships).returns( :self=>{} )
79
+ mock_object.expects(:ids_for_outbound).with(:has_model).returns([])
80
80
  ActiveFedora::ContentModel.models_asserted_by(mock_object).should == []
81
81
  end
82
82
  end
@@ -84,23 +84,23 @@ describe ActiveFedora::ContentModel do
84
84
  describe "known_models_asserted_by" do
85
85
  it "should figure out the applicable models to load" do
86
86
  mock_object = mock("ActiveFedora Object")
87
- mock_object.expects(:relationships).returns( :self=>{:has_model=>["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"]} )
87
+ mock_object.expects(:ids_for_outbound).with(:has_model).returns(["info:fedora/fedora-system:ServiceDefinition-3.0", "info:fedora/afmodel:SampleModel", "info:fedora/afmodel:NonDefinedModel"])
88
88
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [SampleModel]
89
89
  end
90
90
  it "should support namespaced models" do
91
91
  pending "This is harder than it looks."
92
92
  mock_object = mock("ActiveFedora Object")
93
- mock_object.expects(:relationships).returns( :self=>{:has_model=>["info:fedora/afmodel:Sample_NamespacedModel"]} )
93
+ mock_object.expects(:ids_for_outbound).with(:has_model).returns(["info:fedora/afmodel:Sample_NamespacedModel"])
94
94
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [Sample::NamespacedModel]
95
95
  end
96
96
  it "should default to using ActiveFedora::Base as the model" do
97
97
  mock_object = mock("ActiveFedora Object")
98
- mock_object.expects(:relationships).returns( :self=>{:has_model=>["info:fedora/afmodel:NonDefinedModel"]} )
98
+ mock_object.expects(:ids_for_outbound).with(:has_model).returns(["info:fedora/afmodel:NonDefinedModel"])
99
99
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
100
100
  end
101
101
  it "should still work even if the object doesn't have a RELS-EXT datastream" do
102
102
  mock_object = mock("ActiveFedora Object")
103
- mock_object.expects(:relationships).returns( :self=>{} )
103
+ mock_object.expects(:ids_for_outbound).with(:has_model).returns([])
104
104
  ActiveFedora::ContentModel.known_models_for(mock_object).should == [ActiveFedora::Base]
105
105
  end
106
106
  end
@@ -430,7 +430,7 @@ describe ActiveFedora::SemanticNode do
430
430
  end
431
431
  it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
432
432
  # get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
433
- @local_node.expects(:outbound_relationships).returns({:has_part=>["mypid:1"]}).at_least_once()
433
+ @local_node.expects(:ids_for_outbound).with(:has_part).returns(["mypid:1"])
434
434
  id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
435
435
  solr_result = mock("solr result")
436
436
  ActiveFedora::SolrService.instance.conn.expects(:query).with("#{id_array_query} OR (is_part_of_s:info\\:fedora/test\\:sample_pid)", :rows=>25).returns(solr_result)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1923832031
4
+ hash: 1923832017
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
9
  - 0
10
10
  - pre
11
- - 3
12
- version: 3.1.0.pre3
11
+ - 4
12
+ version: 3.1.0.pre4
13
13
  platform: ruby
14
14
  authors:
15
15
  - Matt Zumwalt