active-fedora 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +30 -0
- data/NG_XML_DATASTREAM.textile +25 -0
- data/VERSION +1 -1
- data/active-fedora.gemspec +3 -2
- data/lib/active_fedora.rb +16 -13
- data/lib/active_fedora/base.rb +212 -22
- data/lib/active_fedora/metadata_datastream.rb +8 -2
- data/lib/active_fedora/metadata_datastream_helper.rb +10 -7
- data/lib/active_fedora/nokogiri_datastream.rb +5 -0
- data/lib/active_fedora/rels_ext_datastream.rb +9 -0
- data/lib/active_fedora/semantic_node.rb +253 -40
- data/lib/fedora/connection.rb +13 -12
- data/lib/fedora/repository.rb +3 -1
- data/spec/unit/base_extra_spec.rb +1 -1
- data/spec/unit/base_file_management_spec.rb +25 -9
- data/spec/unit/metadata_datastream_spec.rb +6 -0
- data/spec/unit/repository_spec.rb +7 -0
- data/spec/unit/semantic_node_spec.rb +44 -0
- data/spec/unit/solr_config_options_spec.rb +1 -1
- metadata +5 -4
data/lib/fedora/connection.rb
CHANGED
@@ -19,7 +19,7 @@ module Fedora
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_s
|
22
|
-
"Failed with #{response.code} #{
|
22
|
+
"Failed with #{response.code} #{@message.to_s}"
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -155,29 +155,30 @@ module Fedora
|
|
155
155
|
|
156
156
|
# Handles response and error codes from remote service.
|
157
157
|
def handle_response(response)
|
158
|
+
message = "Error from Fedora: #{response.body}"
|
158
159
|
case response.code.to_i
|
159
160
|
when 301,302
|
160
161
|
raise(Redirection.new(response))
|
161
162
|
when 200...400
|
162
163
|
response
|
163
164
|
when 400
|
164
|
-
raise(BadRequest.new(response))
|
165
|
+
raise(BadRequest.new(response, message))
|
165
166
|
when 401
|
166
|
-
raise(UnauthorizedAccess.new(response))
|
167
|
+
raise(UnauthorizedAccess.new(response, message))
|
167
168
|
when 403
|
168
|
-
raise(ForbiddenAccess.new(response))
|
169
|
+
raise(ForbiddenAccess.new(response, message))
|
169
170
|
when 404
|
170
|
-
raise(ResourceNotFound.new(response))
|
171
|
+
raise(ResourceNotFound.new(response, message))
|
171
172
|
when 405
|
172
|
-
raise(MethodNotAllowed.new(response))
|
173
|
+
raise(MethodNotAllowed.new(response, message))
|
173
174
|
when 409
|
174
|
-
raise(ResourceConflict.new(response))
|
175
|
+
raise(ResourceConflict.new(response, message))
|
175
176
|
when 422
|
176
|
-
raise(ResourceInvalid.new(response))
|
177
|
-
when
|
178
|
-
raise(ClientError.new(response))
|
177
|
+
raise(ResourceInvalid.new(response, message))
|
178
|
+
when 423...500
|
179
|
+
raise(ClientError.new(response, message))
|
179
180
|
when 500...600
|
180
|
-
raise(ServerError.new(response))
|
181
|
+
raise(ServerError.new(response, message))
|
181
182
|
else
|
182
183
|
raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
|
183
184
|
end
|
@@ -211,4 +212,4 @@ module Fedora
|
|
211
212
|
(@site.user || @site.password ? { 'Authorization' => 'Basic ' + ["#{@site.user}:#{ @site.password}"].pack('m').delete("\r\n") } : {})
|
212
213
|
end
|
213
214
|
end
|
214
|
-
end
|
215
|
+
end
|
data/lib/fedora/repository.rb
CHANGED
@@ -100,7 +100,9 @@ module Fedora
|
|
100
100
|
|
101
101
|
def find_model(pid, klazz)
|
102
102
|
obj = self.find_objects("pid=#{pid}").first
|
103
|
-
|
103
|
+
if obj.nil?
|
104
|
+
raise ActiveFedora::ObjectNotFoundError, "The repository does not have an object with pid #{pid}. The repository URL is #{self.base_url}"
|
105
|
+
end
|
104
106
|
doc = Nokogiri::XML::Document.parse(obj.object_xml)
|
105
107
|
klazz.deserialize(doc)
|
106
108
|
end
|
@@ -98,7 +98,7 @@ describe ActiveFedora::Base do
|
|
98
98
|
end
|
99
99
|
|
100
100
|
it "should delete object from repository and index" do
|
101
|
-
@test_object.
|
101
|
+
@test_object.stubs(:pid).returns("foo")
|
102
102
|
ActiveFedora::SolrService.instance.conn.expects(:delete).with("foo")
|
103
103
|
Fedora::Repository.instance.stubs(:delete).with(@test_object.inner_object)
|
104
104
|
@test_object.delete
|
@@ -15,22 +15,38 @@ describe ActiveFedora::Base do
|
|
15
15
|
it "should be a supported method" do
|
16
16
|
@base.should respond_to("file_objects")
|
17
17
|
end
|
18
|
-
it "should wrap .collection_members" do
|
19
|
-
@base.expects(:collection_members)
|
18
|
+
it "should wrap .collection_members and .parts" do
|
19
|
+
@base.expects(:collection_members).returns([])
|
20
|
+
@base.expects(:parts).returns(["Foo"])
|
20
21
|
@base.file_objects
|
21
22
|
end
|
22
|
-
describe "_append" do
|
23
|
-
it "should wrap collection_members_append" do
|
24
|
-
mocko = mock("object")
|
25
|
-
@base.expects(:collection_members_append).with(mocko)
|
26
|
-
@base.file_objects_append(mocko)
|
27
|
-
end
|
28
|
-
end
|
29
23
|
describe "_remove" do
|
30
24
|
it "should wrap collection_members_remove"
|
31
25
|
end
|
32
26
|
end
|
33
27
|
|
28
|
+
describe ".file_objects_append" do
|
29
|
+
it "should make the file object being appended assert isPartOf pointing back at the current object" do
|
30
|
+
mock_child = ActiveFedora::Base.new
|
31
|
+
mock_child.expects(:add_relationship).with(:is_part_of, @base)
|
32
|
+
@base.file_objects_append(mock_child)
|
33
|
+
end
|
34
|
+
it "should load the file object being appended if only a pid is provided" do
|
35
|
+
mock_child = mock("object")
|
36
|
+
mock_child.expects(:add_relationship).with(:is_part_of, @base)
|
37
|
+
ActiveFedora::Base.expects(:load_instance).with("_PID_").returns(mock_child)
|
38
|
+
@base.file_objects_append("_PID_")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".parts" do
|
43
|
+
it "should search for both (outbound) has_part and (inbound) is_part_of relationships, removing duplicates" do
|
44
|
+
@base.expects(:parts_outbound).returns(["A", "B"])
|
45
|
+
@base.expects(:parts_inbound).returns(["B", "C"])
|
46
|
+
@base.parts.should == ["B", "C", "A"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
34
50
|
describe ".collection_members" do
|
35
51
|
it "should return an array" do
|
36
52
|
@base.collection_members.should be_kind_of(Array)
|
@@ -146,6 +146,12 @@ describe ActiveFedora::MetadataDatastream do
|
|
146
146
|
@test_ds.fubar_values.should == ["val1", "val2"]
|
147
147
|
end
|
148
148
|
|
149
|
+
it "should not get tripped up by field names wrapped in arrays" do
|
150
|
+
att = {[:fubar]=>{"0"=>"eco3bv"}}
|
151
|
+
@test_ds.update_indexed_attributes(att)
|
152
|
+
@test_ds.fubar_values.should == ['eco3bv']
|
153
|
+
end
|
154
|
+
|
149
155
|
end
|
150
156
|
|
151
157
|
describe ".get_values" do
|
@@ -111,6 +111,13 @@ describe Fedora::Repository do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
describe ".find_model" do
|
115
|
+
it "should raise an ObjectNotFound error if there is no object" do
|
116
|
+
Fedora::Repository.instance.expects(:find_objects).returns([])
|
117
|
+
lambda { Fedora::Repository.instance.find_model("mypid", ActiveFedora::Base) }.should raise_error(ActiveFedora::ObjectNotFoundError)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
114
121
|
describe "#register" do
|
115
122
|
after(:all) do
|
116
123
|
Fedora::Repository.register(ActiveFedora.fedora_config[:url])
|
@@ -45,6 +45,8 @@ describe ActiveFedora::SemanticNode do
|
|
45
45
|
@test_relationship1 = ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "demo:10")
|
46
46
|
@test_relationship2 = ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_part_of, :object => "demo:11")
|
47
47
|
@test_relationship3 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => :has_part, :object => "demo:12")
|
48
|
+
@test_cmodel_relationship1 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => :has_model, :object => "afmodel:SampleModel")
|
49
|
+
@test_cmodel_relationship2 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => "hasModel", :object => "afmodel:OtherModel")
|
48
50
|
end
|
49
51
|
|
50
52
|
after(:each) do
|
@@ -352,6 +354,44 @@ describe ActiveFedora::SemanticNode do
|
|
352
354
|
end
|
353
355
|
end
|
354
356
|
|
357
|
+
describe ".create_bidirectional_relationship_finder" do
|
358
|
+
before(:each) do
|
359
|
+
SpecNode.create_bidirectional_relationship_finders("all_parts", :has_part, :is_part_of)
|
360
|
+
@local_node = SpecNode.new
|
361
|
+
@local_node.pid = @pid
|
362
|
+
@local_node.internal_uri = @uri
|
363
|
+
end
|
364
|
+
it "should create inbound & outbound finders" do
|
365
|
+
@local_node.should respond_to(:all_parts_inbound)
|
366
|
+
@local_node.should respond_to(:all_parts_outbound)
|
367
|
+
end
|
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"])
|
371
|
+
@local_node.all_parts.should == ["foo1", "foo2"]
|
372
|
+
end
|
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"]
|
377
|
+
end
|
378
|
+
it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
|
379
|
+
# get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
|
380
|
+
@local_node.expects(:all_parts_outbound).with(:response_format=>:id_array).returns(["mypid:1"])
|
381
|
+
id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
|
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)
|
384
|
+
@local_node.all_parts(:response_format=>:solr)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
describe "#has_bidirectional_relationship" do
|
389
|
+
it "should ..." do
|
390
|
+
SpecNode.expects(:create_bidirectional_relationship_finders).with("all_parts", :has_part, :is_part_of, {})
|
391
|
+
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
355
395
|
describe ".add_relationship" do
|
356
396
|
it "should add relationship to the relationships hash" do
|
357
397
|
@node.add_relationship(@test_relationship)
|
@@ -419,6 +459,8 @@ describe ActiveFedora::SemanticNode do
|
|
419
459
|
<isMemberOf rdf:resource='info:fedora/demo:10' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
420
460
|
<isPartOf rdf:resource='info:fedora/demo:11' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
421
461
|
<hasPart rdf:resource='info:fedora/demo:12' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
462
|
+
<hasModel rdf:resource='info:fedora/afmodel:OtherModel' xmlns='info:fedora/fedora-system:def/model#'/>
|
463
|
+
<hasModel rdf:resource='info:fedora/afmodel:SampleModel' xmlns='info:fedora/fedora-system:def/model#'/>
|
422
464
|
</rdf:Description>
|
423
465
|
</rdf:RDF>
|
424
466
|
EOS
|
@@ -428,6 +470,8 @@ describe ActiveFedora::SemanticNode do
|
|
428
470
|
@node.add_relationship(@test_relationship1)
|
429
471
|
@node.add_relationship(@test_relationship2)
|
430
472
|
@node.add_relationship(@test_relationship3)
|
473
|
+
@node.add_relationship(@test_cmodel_relationship1)
|
474
|
+
@node.add_relationship(@test_cmodel_relationship2)
|
431
475
|
@node.internal_uri = @uri
|
432
476
|
returned_xml = XmlSimple.xml_in(@node.to_rels_ext(@pid))
|
433
477
|
returned_xml.should == XmlSimple.xml_in(@sample_rels_ext_xml)
|
@@ -92,7 +92,7 @@ describe ActiveFedora do
|
|
92
92
|
end
|
93
93
|
it "should prevent Base.delete from deleting the corresponding Solr document if false" do
|
94
94
|
Fedora::Repository.instance.expects(:delete)
|
95
|
-
ActiveFedora::SolrService.expects(:
|
95
|
+
ActiveFedora::SolrService.instance.conn.expects(:delete).with(@test_object.pid).never
|
96
96
|
@test_object.delete
|
97
97
|
end
|
98
98
|
end
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 3
|
10
|
+
version: 1.2.3
|
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-10-18 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -321,6 +321,7 @@ files:
|
|
321
321
|
- LICENSE
|
322
322
|
- License.txt
|
323
323
|
- Manifest.txt
|
324
|
+
- NG_XML_DATASTREAM.textile
|
324
325
|
- PostInstall.txt
|
325
326
|
- README.textile
|
326
327
|
- Rakefile
|