active-fedora 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/active-fedora.gemspec +2 -2
- data/lib/active_fedora/base.rb +8 -1
- data/lib/active_fedora/content_model.rb +11 -3
- data/lib/active_fedora/model.rb +14 -3
- data/lib/active_fedora/semantic_node.rb +4 -2
- data/lib/fedora/repository.rb +4 -2
- data/script/console +1 -1
- data/spec/integration/base_spec.rb +12 -4
- data/spec/unit/base_spec.rb +1 -0
- data/spec/unit/content_model_spec.rb +8 -0
- data/spec/unit/model_spec.rb +4 -4
- data/spec/unit/semantic_node_spec.rb +10 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.8
|
data/active-fedora.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{active-fedora}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matt Zumwalt", "McClain Looney"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-15}
|
13
13
|
s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.}
|
14
14
|
s.email = %q{matt.zumwalt@yourmediashelf.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/active_fedora/base.rb
CHANGED
@@ -56,12 +56,19 @@ module ActiveFedora
|
|
56
56
|
|
57
57
|
# Constructor. If +attrs+ does not comtain +:pid+, we assume we're making a new one,
|
58
58
|
# and call off to the Fedora Rest API for the next available Fedora pid, and mark as new object.
|
59
|
+
# Also, if +attrs+ does not contain +:pid+ but does contain +:namespace+ it will pass the
|
60
|
+
# +:namespace+ value to Fedora::Repository.nextid to generate the next pid available within
|
61
|
+
# the given namespace.
|
59
62
|
#
|
60
63
|
# If there is a pid, we're re-hydrating an existing object, and new object is false. Once the @inner_object is stored,
|
61
64
|
# we configure any defined datastreams.
|
62
65
|
def initialize(attrs = {})
|
63
66
|
unless attrs[:pid]
|
64
|
-
|
67
|
+
if attrs[:namespace]
|
68
|
+
attrs = attrs.merge!({:pid=>Fedora::Repository.instance.nextid({:namespace=>attrs[:namespace]})})
|
69
|
+
else
|
70
|
+
attrs = attrs.merge!({:pid=>Fedora::Repository.instance.nextid})
|
71
|
+
end
|
65
72
|
@new_object=true
|
66
73
|
else
|
67
74
|
@new_object = attrs[:new_object] == false ? false : true
|
@@ -13,8 +13,16 @@ module ActiveFedora
|
|
13
13
|
|
14
14
|
def self.pid_from_ruby_class(klass,attrs={})
|
15
15
|
sanitized_class_name = klass.name.gsub(/(::)/, '_')
|
16
|
-
|
17
|
-
|
16
|
+
unless klass.respond_to? :pid_suffix
|
17
|
+
pid_suffix = attrs.has_key?(:pid_suffix) ? attrs[:pid_suffix] : CMODEL_PID_SUFFIX
|
18
|
+
else
|
19
|
+
pid_suffix = klass.pid_suffix
|
20
|
+
end
|
21
|
+
unless klass.respond_to? :pid_namespace
|
22
|
+
namespace = attrs.has_key?(:namespace) ? attrs[:namespace] : CMODEL_NAMESPACE
|
23
|
+
else
|
24
|
+
namespace = klass.pid_namespace
|
25
|
+
end
|
18
26
|
return "#{namespace}:#{sanitized_class_name}#{pid_suffix}"
|
19
27
|
end
|
20
28
|
|
@@ -71,4 +79,4 @@ module ActiveFedora
|
|
71
79
|
end
|
72
80
|
|
73
81
|
end
|
74
|
-
end
|
82
|
+
end
|
data/lib/active_fedora/model.rb
CHANGED
@@ -53,21 +53,32 @@ module ActiveFedora
|
|
53
53
|
# Takes :all or a pid as arguments
|
54
54
|
# Returns an Array of objects of the Class that +find+ is being
|
55
55
|
# called on
|
56
|
-
def find(args)
|
56
|
+
def find(args, opts={})
|
57
|
+
opts = {:rows=>25}.merge(opts)
|
58
|
+
return_multiple = false
|
57
59
|
if args == :all
|
60
|
+
return_multiple = true
|
58
61
|
escaped_class_name = self.name.gsub(/(:)/, '\\:')
|
59
62
|
q = "#{ActiveFedora::SolrService.solr_name(:active_fedora_model, :symbol)}:#{escaped_class_name}"
|
60
63
|
elsif args.class == String
|
61
64
|
escaped_id = args.gsub(/(:)/, '\\:')
|
62
65
|
q = "#{SOLR_DOCUMENT_ID}:#{escaped_id}"
|
63
66
|
end
|
64
|
-
|
67
|
+
if return_multiple == true
|
68
|
+
hits = SolrService.instance.conn.query(q, :rows=>opts[:rows]).hits
|
69
|
+
else
|
70
|
+
hits = SolrService.instance.conn.query(q).hits
|
71
|
+
end
|
65
72
|
results = hits.map do |hit|
|
66
73
|
obj = Fedora::Repository.instance.find_model(hit[SOLR_DOCUMENT_ID], self)
|
67
74
|
#obj.inner_object.new_object = false
|
68
75
|
#return obj
|
69
76
|
end
|
70
|
-
|
77
|
+
if return_multiple == true
|
78
|
+
return results
|
79
|
+
else
|
80
|
+
return results.first
|
81
|
+
end
|
71
82
|
end
|
72
83
|
|
73
84
|
#Sends a query directly to SolrService
|
@@ -606,8 +606,9 @@ module ActiveFedora
|
|
606
606
|
def create_inbound_relationship_finders(name, predicate, opts = {})
|
607
607
|
class_eval <<-END
|
608
608
|
def #{name}(opts={})
|
609
|
+
opts = {:rows=>25}.merge(opts)
|
609
610
|
escaped_uri = self.internal_uri.gsub(/(:)/, '\\:')
|
610
|
-
solr_result = SolrService.instance.conn.query("#{predicate}_s:\#{escaped_uri}")
|
611
|
+
solr_result = SolrService.instance.conn.query("#{predicate}_s:\#{escaped_uri}", :rows=>opts[:rows])
|
611
612
|
if opts[:response_format] == :solr
|
612
613
|
return solr_result
|
613
614
|
else
|
@@ -684,6 +685,7 @@ module ActiveFedora
|
|
684
685
|
|
685
686
|
class_eval <<-END
|
686
687
|
def #{name}(opts={})
|
688
|
+
opts = {:rows=>25}.merge(opts)
|
687
689
|
if opts[:response_format] == :solr || opts[:response_format] == :load_from_solr
|
688
690
|
escaped_uri = self.internal_uri.gsub(/(:)/, '\\:')
|
689
691
|
query = "#{inbound_predicate}_s:\#{escaped_uri}"
|
@@ -691,7 +693,7 @@ module ActiveFedora
|
|
691
693
|
outbound_id_array = #{outbound_method_name}(:response_format=>:id_array)
|
692
694
|
query = query + " OR " + ActiveFedora::SolrService.construct_query_for_pids(outbound_id_array)
|
693
695
|
|
694
|
-
solr_result = SolrService.instance.conn.query(query)
|
696
|
+
solr_result = SolrService.instance.conn.query(query, :rows=>opts[:rows])
|
695
697
|
|
696
698
|
if opts[:response_format] == :solr
|
697
699
|
return solr_result
|
data/lib/fedora/repository.rb
CHANGED
@@ -116,8 +116,10 @@ module Fedora
|
|
116
116
|
object.new_object? ? create(object) : update(object)
|
117
117
|
end
|
118
118
|
|
119
|
-
def nextid
|
120
|
-
|
119
|
+
def nextid(attrs={})
|
120
|
+
request_url = fedora_url.path+"/management/getNextPID?xml=true"
|
121
|
+
request_url += "&namespace=#{attrs[:namespace]}" if attrs[:namespace]
|
122
|
+
d = REXML::Document.new(connection.post(request_url).body)
|
121
123
|
d.elements['//pid'].text
|
122
124
|
end
|
123
125
|
|
data/script/console
CHANGED
@@ -70,10 +70,18 @@ describe ActiveFedora::Base do
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
73
|
+
describe ".initialize" do
|
74
|
+
it "calling constructor should create a new Fedora Object" do
|
75
|
+
@test_object.should have(0).errors
|
76
|
+
@test_object.pid.should_not be_nil
|
77
|
+
end
|
78
|
+
|
79
|
+
it "passing namespace to constructor with no pid should generate a pid with the supplied namespace" do
|
80
|
+
@test_object2 = ActiveFedora::Base.new({:namespace=>"randomNamespace"})
|
81
|
+
#@test_object2.pid.match('changeme:\d+').to_a.first.should == @test_object2.pid
|
82
|
+
# will be nil if match failed, otherwise will equal pid
|
83
|
+
@test_object2.pid.match('randomNamespace:\d+').to_a.first.should == @test_object2.pid
|
84
|
+
end
|
77
85
|
end
|
78
86
|
|
79
87
|
describe ".save" do
|
data/spec/unit/base_spec.rb
CHANGED
@@ -50,6 +50,14 @@ describe ActiveFedora::ContentModel do
|
|
50
50
|
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "afmodel:ActiveFedora_ContentModel"
|
51
51
|
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class, :namespace => "foo", :pid_suffix => "BarBar").should == "foo:ActiveFedora_ContentModelBarBar"
|
52
52
|
end
|
53
|
+
it "should construct pids with the namespace declared in the model" do
|
54
|
+
ActiveFedora::ContentModel.stubs(:pid_namespace).returns("test-cModel")
|
55
|
+
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "test-cModel:ActiveFedora_ContentModel"
|
56
|
+
end
|
57
|
+
it "should construct pids with the suffix declared in the model" do
|
58
|
+
ActiveFedora::ContentModel.stubs(:pid_suffix).returns("-TEST-SUFFIX")
|
59
|
+
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == 'afmodel:ActiveFedora_ContentModel-TEST-SUFFIX'
|
60
|
+
end
|
53
61
|
end
|
54
62
|
|
55
63
|
describe "models_asserted_by" do
|
data/spec/unit/model_spec.rb
CHANGED
@@ -103,11 +103,11 @@ describe ActiveFedora::Model do
|
|
103
103
|
mock_solr = mock("SolrConnection")
|
104
104
|
mock_result = mock("MockResult")
|
105
105
|
mock_result.expects(:hits).returns([{"id" => "changeme:30"}, {"id" => "changeme:22"}])
|
106
|
-
mock_solr.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic').returns(mock_result)
|
106
|
+
mock_solr.expects(:query).with('active_fedora_model_s:SpecModel\:\:Basic', :rows=>1001).returns(mock_result)
|
107
107
|
ActiveFedora::SolrService.expects(:instance).returns(mock("SolrService", :conn => mock_solr))
|
108
|
-
Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake
|
109
|
-
Fedora::Repository.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake
|
110
|
-
SpecModel::Basic.find(:all)
|
108
|
+
Fedora::Repository.instance.expects(:find_model).with("changeme:30", SpecModel::Basic).returns("Fake Object1")
|
109
|
+
Fedora::Repository.instance.expects(:find_model).with("changeme:22", SpecModel::Basic).returns("Fake Object2")
|
110
|
+
SpecModel::Basic.find(:all, :rows=>1001).should == ["Fake Object1", "Fake Object2"]
|
111
111
|
end
|
112
112
|
|
113
113
|
it "(String) should query solr for an object with the given id and return that object" do
|
@@ -244,7 +244,7 @@ describe ActiveFedora::SemanticNode do
|
|
244
244
|
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
245
245
|
local_node = SpecNode.new()
|
246
246
|
local_node.expects(:internal_uri).returns("info:fedora/test:sample_pid")
|
247
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid").returns(solr_result)
|
247
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(solr_result)
|
248
248
|
Fedora::Repository.expects(:instance).returns(mock_repo).times(3)
|
249
249
|
Kernel.expects(:const_get).with("AudioRecord").returns("AudioRecord").times(3)
|
250
250
|
local_node.parts.should == ["AR1", "AR2", "AR3"]
|
@@ -257,8 +257,8 @@ describe ActiveFedora::SemanticNode do
|
|
257
257
|
mock_repo = mock("repo")
|
258
258
|
mock_repo.expects(:find_model).never
|
259
259
|
local_node.expects(:internal_uri).returns("info:fedora/test:sample_pid")
|
260
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid").returns(solr_result)
|
261
|
-
local_node.constituents(:response_format => :solr).should equal(solr_result)
|
260
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid", :rows=>101).returns(solr_result)
|
261
|
+
local_node.constituents(:response_format => :solr, :rows=>101).should equal(solr_result)
|
262
262
|
end
|
263
263
|
|
264
264
|
|
@@ -266,7 +266,7 @@ describe ActiveFedora::SemanticNode do
|
|
266
266
|
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
267
267
|
local_node = SpecNode.new
|
268
268
|
local_node.expects(:internal_uri).returns("info:fedora/test:sample_pid")
|
269
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid").returns(mock("solr result", :hits => [Hash["id"=>"pid1"], Hash["id"=>"pid2"]]))
|
269
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(mock("solr result", :hits => [Hash["id"=>"pid1"], Hash["id"=>"pid2"]]))
|
270
270
|
local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
|
271
271
|
end
|
272
272
|
|
@@ -366,21 +366,21 @@ describe ActiveFedora::SemanticNode do
|
|
366
366
|
@local_node.should respond_to(:all_parts_outbound)
|
367
367
|
end
|
368
368
|
it "should rely on inbound & outbound finders" do
|
369
|
-
@local_node.expects(:all_parts_inbound).returns(["foo1"])
|
370
|
-
@local_node.expects(:all_parts_outbound).returns(["foo2"])
|
369
|
+
@local_node.expects(:all_parts_inbound).with(:rows => 25).returns(["foo1"])
|
370
|
+
@local_node.expects(:all_parts_outbound).with(:rows => 25).returns(["foo2"])
|
371
371
|
@local_node.all_parts.should == ["foo1", "foo2"]
|
372
372
|
end
|
373
373
|
it "(:response_format => :id_array) should rely on inbound & outbound finders" do
|
374
|
-
@local_node.expects(:all_parts_inbound).with(:response_format=>:id_array).returns(["fooA"])
|
375
|
-
@local_node.expects(:all_parts_outbound).with(:response_format=>:id_array).returns(["fooB"])
|
376
|
-
@local_node.all_parts(:response_format=>:id_array).should == ["fooA", "fooB"]
|
374
|
+
@local_node.expects(:all_parts_inbound).with(:response_format=>:id_array, :rows => 34).returns(["fooA"])
|
375
|
+
@local_node.expects(:all_parts_outbound).with(:response_format=>:id_array, :rows => 34).returns(["fooB"])
|
376
|
+
@local_node.all_parts(:response_format=>:id_array, :rows => 34).should == ["fooA", "fooB"]
|
377
377
|
end
|
378
378
|
it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
|
379
379
|
# get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
|
380
380
|
@local_node.expects(:all_parts_outbound).with(:response_format=>:id_array).returns(["mypid:1"])
|
381
381
|
id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
|
382
382
|
solr_result = mock("solr result")
|
383
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid OR #{id_array_query}").returns(solr_result)
|
383
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid OR #{id_array_query}", :rows=>25).returns(solr_result)
|
384
384
|
@local_node.all_parts(:response_format=>:solr)
|
385
385
|
end
|
386
386
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 8
|
10
|
+
version: 1.2.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Zumwalt
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-12-15 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|