rubydora 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitmodules +1 -0
- data/VERSION +1 -1
- data/lib/rubydora/datastream.rb +18 -4
- data/lib/rubydora/digital_object.rb +16 -8
- data/spec/lib/datastream_spec.rb +13 -3
- data/spec/lib/digital_object_spec.rb +1 -0
- metadata +2 -2
data/.gitmodules
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/rubydora/datastream.rb
CHANGED
@@ -118,7 +118,7 @@ module Rubydora
|
|
118
118
|
# Does this datastream already exist?
|
119
119
|
# @return [Boolean]
|
120
120
|
def new?
|
121
|
-
|
121
|
+
digital_object.nil? || digital_object.new? || profile_xml.blank?
|
122
122
|
end
|
123
123
|
|
124
124
|
# Retrieve the content of the datastream (and cache it)
|
@@ -178,18 +178,31 @@ module Rubydora
|
|
178
178
|
## Force a recheck of the profile if they've passed :validateChecksum and we don't have dsChecksumValid
|
179
179
|
return @profile
|
180
180
|
end
|
181
|
+
|
181
182
|
return @profile = {} unless digital_object.respond_to? :repository
|
183
|
+
|
182
184
|
@profile = begin
|
185
|
+
xml = profile_xml(opts)
|
186
|
+
|
187
|
+
(self.profile_xml_to_hash(xml) unless xml.blank?) || {}
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def profile_xml opts = {}
|
192
|
+
@profile_xml = nil unless opts.empty?
|
193
|
+
|
194
|
+
@profile_xml ||= begin
|
195
|
+
|
183
196
|
options = { :pid => pid, :dsid => dsid }
|
184
197
|
options.merge!(opts)
|
185
198
|
options[:asOfDateTime] = asOfDateTime if asOfDateTime
|
186
199
|
options[:validateChecksum] = true if repository.config[:validateChecksum]
|
187
|
-
|
200
|
+
repository.datastream(options)
|
188
201
|
rescue RestClient::Unauthorized => e
|
189
202
|
raise e
|
190
203
|
rescue RestClient::ResourceNotFound
|
191
204
|
# the datastream is new
|
192
|
-
|
205
|
+
''
|
193
206
|
end
|
194
207
|
end
|
195
208
|
|
@@ -231,7 +244,7 @@ module Rubydora
|
|
231
244
|
def create
|
232
245
|
check_if_read_only
|
233
246
|
run_callbacks :create do
|
234
|
-
repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
|
247
|
+
repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid, :content => content })
|
235
248
|
reset_profile_attributes
|
236
249
|
self.class.new(digital_object, dsid, @options)
|
237
250
|
end
|
@@ -290,6 +303,7 @@ module Rubydora
|
|
290
303
|
# @return [Hash]
|
291
304
|
def reset_profile_attributes
|
292
305
|
@profile = nil
|
306
|
+
@profile_xml = nil
|
293
307
|
@changed_attributes = {}
|
294
308
|
end
|
295
309
|
|
@@ -90,7 +90,6 @@ module Rubydora
|
|
90
90
|
_run_initialize_callbacks do
|
91
91
|
self.pid = pid
|
92
92
|
@repository = repository
|
93
|
-
@new = true
|
94
93
|
@options = options
|
95
94
|
|
96
95
|
options.each do |key, value|
|
@@ -110,8 +109,7 @@ module Rubydora
|
|
110
109
|
# Does this object already exist?
|
111
110
|
# @return [Boolean]
|
112
111
|
def new?
|
113
|
-
self.
|
114
|
-
@new
|
112
|
+
self.profile_xml.blank?
|
115
113
|
end
|
116
114
|
|
117
115
|
def asOfDateTime asOfDateTime = nil
|
@@ -129,10 +127,9 @@ module Rubydora
|
|
129
127
|
# Retrieve the object profile as a hash (and cache it)
|
130
128
|
# @return [Hash] see Fedora #getObject documentation for keys
|
131
129
|
def profile
|
130
|
+
return {} if profile_xml.nil?
|
131
|
+
|
132
132
|
@profile ||= begin
|
133
|
-
options = { :pid => pid }
|
134
|
-
options[:asOfDateTime] = asOfDateTime if asOfDateTime
|
135
|
-
profile_xml = repository.object(options)
|
136
133
|
profile_xml.gsub! '<objectProfile', '<objectProfile xmlns="http://www.fedora.info/definitions/1/0/access/"' unless profile_xml =~ /xmlns=/
|
137
134
|
doc = Nokogiri::XML(profile_xml)
|
138
135
|
h = doc.xpath('/access:objectProfile/*', {'access' => "http://www.fedora.info/definitions/1/0/access/"} ).inject({}) do |sum, node|
|
@@ -153,11 +150,20 @@ module Rubydora
|
|
153
150
|
@new = false
|
154
151
|
|
155
152
|
h
|
156
|
-
|
157
|
-
{}
|
153
|
+
|
158
154
|
end.freeze
|
159
155
|
end
|
160
156
|
|
157
|
+
def profile_xml
|
158
|
+
@profile_xml ||= begin
|
159
|
+
options = { :pid => pid }
|
160
|
+
options[:asOfDateTime] = asOfDateTime if asOfDateTime
|
161
|
+
repository.object(options)
|
162
|
+
rescue RestClient::ResourceNotFound => e
|
163
|
+
''
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
161
167
|
def versions
|
162
168
|
versions_xml = repository.object_versions(:pid => pid)
|
163
169
|
versions_xml.gsub! '<fedoraObjectHistory', '<fedoraObjectHistory xmlns="http://www.fedora.info/definitions/1/0/access/"' unless versions_xml =~ /xmlns=/
|
@@ -210,6 +216,7 @@ module Rubydora
|
|
210
216
|
if self.new?
|
211
217
|
self.pid = repository.ingest to_api_params.merge(:pid => pid)
|
212
218
|
@profile = nil #will cause a reload with updated data
|
219
|
+
@profile_xml = nil
|
213
220
|
else
|
214
221
|
p = to_api_params
|
215
222
|
repository.modify_object p.merge(:pid => pid) unless p.empty?
|
@@ -228,6 +235,7 @@ module Rubydora
|
|
228
235
|
run_callbacks :destroy do
|
229
236
|
@datastreams = nil
|
230
237
|
@profile = nil
|
238
|
+
@profile_xml = nil
|
231
239
|
@pid = nil
|
232
240
|
nil
|
233
241
|
end
|
data/spec/lib/datastream_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe Rubydora::Datastream do
|
|
4
4
|
before do
|
5
5
|
@mock_repository = mock(Rubydora::Repository, :config=>{})
|
6
6
|
@mock_object = mock(Rubydora::DigitalObject)
|
7
|
-
@mock_object.stub(:repository => @mock_repository, :pid => 'pid')
|
7
|
+
@mock_object.stub(:repository => @mock_repository, :pid => 'pid', :new? => false)
|
8
8
|
end
|
9
9
|
|
10
10
|
|
@@ -53,7 +53,8 @@ describe Rubydora::Datastream do
|
|
53
53
|
|
54
54
|
|
55
55
|
it "should call the appropriate api on save" do
|
56
|
-
@
|
56
|
+
@datastream.stub(:content => 'content')
|
57
|
+
@mock_repository.should_receive(:add_datastream).with(hash_including(:content => 'content', :pid => 'pid', :dsid => 'dsid', :controlGroup => 'M', :dsState => 'A'))
|
57
58
|
@datastream.save
|
58
59
|
end
|
59
60
|
|
@@ -211,7 +212,11 @@ describe Rubydora::Datastream do
|
|
211
212
|
end
|
212
213
|
|
213
214
|
describe "has_content?" do
|
214
|
-
|
215
|
+
before(:each) do
|
216
|
+
subject.stub(:new? => true)
|
217
|
+
end
|
218
|
+
|
219
|
+
subject { Rubydora::Datastream.new mock(:pid => 'asdf', :new? => false), 'asdf' }
|
215
220
|
it "should have content if it is persisted" do
|
216
221
|
subject.stub(:new? => false)
|
217
222
|
subject.should have_content
|
@@ -223,6 +228,7 @@ describe Rubydora::Datastream do
|
|
223
228
|
end
|
224
229
|
|
225
230
|
it "should have content if it has a dsLocation" do
|
231
|
+
|
226
232
|
subject.dsLocation = "urn:abc"
|
227
233
|
subject.controlGroup = 'E'
|
228
234
|
subject.should have_content
|
@@ -310,6 +316,7 @@ describe Rubydora::Datastream do
|
|
310
316
|
describe "when versions are in the repo" do
|
311
317
|
before(:each) do
|
312
318
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
319
|
+
@datastream.stub(:new? => false)
|
313
320
|
@mock_repository.should_receive(:datastream_versions).any_number_of_times.and_return <<-XML
|
314
321
|
<datastreamHistory>
|
315
322
|
<datastreamProfile>
|
@@ -334,6 +341,7 @@ describe Rubydora::Datastream do
|
|
334
341
|
|
335
342
|
it "should lookup content of datastream using the asOfDateTime parameter" do
|
336
343
|
@mock_repository.should_receive(:datastream_dissemination).with(hash_including(:asOfDateTime => '2008-08-05T01:30:05.012Z'))
|
344
|
+
Rubydora::Datastream.any_instance.stub(:new? => false)
|
337
345
|
@datastream.versions.last.content
|
338
346
|
end
|
339
347
|
end
|
@@ -599,6 +607,7 @@ describe Rubydora::Datastream do
|
|
599
607
|
describe "with existing properties" do
|
600
608
|
before(:each) do
|
601
609
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
610
|
+
@datastream.stub(:new? => false)
|
602
611
|
@datastream.stub(:profile) { {'dsMIME' => 'application/rdf+xml', 'dsChecksumType' =>'DISABLED', 'dsVersionable'=>true, 'dsControlGroup'=>'M', 'dsState'=>'A'} }
|
603
612
|
end
|
604
613
|
it "should not set unchanged values except for mimeType" do
|
@@ -616,6 +625,7 @@ describe Rubydora::Datastream do
|
|
616
625
|
describe "without existing properties" do
|
617
626
|
before(:each) do
|
618
627
|
@datastream = Rubydora::Datastream.new @mock_object, 'dsid'
|
628
|
+
@datastream.stub(:new? => true )
|
619
629
|
@datastream.stub(:profile) { {} }
|
620
630
|
end
|
621
631
|
it "should compile parameters to hash" do
|
@@ -92,6 +92,7 @@ describe Rubydora::DigitalObject do
|
|
92
92
|
"<objectDatastreams><datastream dsid='a'></datastream>><datastream dsid='b'></datastream>><datastream dsid='c'></datastream></objectDatastreams>"
|
93
93
|
end
|
94
94
|
@object = Rubydora::DigitalObject.new 'pid', @mock_repository
|
95
|
+
@object.stub(:new? => false)
|
95
96
|
end
|
96
97
|
|
97
98
|
describe "datastreams" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fastercsv
|