Skip to content

Commit

Permalink
use the new multipart update datastream API, with a basic integration…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
cbeer committed Feb 20, 2013
1 parent 3718b07 commit c30ffe9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rubydora/digital_object.rb
Expand Up @@ -223,7 +223,15 @@ def save
end
end

self.datastreams.select { |dsid, ds| ds.changed? }.each { |dsid, ds| ds.save }
if self.repository.version >= 4.0
managed_ds, external_ds = self.datastreams.select { |dsid, ds| ds.changed? }.partition { |dsid, ds| ['M', 'X'].include? ds.controlGroup }

repository.add_multipart_datastreams :pid => self.pid, :datastreams => Hash[*managed_ds.map { |(dsid, ds)| [ds.dsid, ds.content] }.flatten(1)]

external_ds.each { |dsid, ds| ds.save }
else
self.datastreams.select { |dsid, ds| ds.changed? }.each { |dsid, ds| ds.save }
end
self
end

Expand Down
16 changes: 16 additions & 0 deletions lib/rubydora/rest_api_client.rb
Expand Up @@ -271,6 +271,22 @@ def datastream_dissemination options = {}, &block_response
rescue_with_handler(exception) || raise
end

def add_multipart_datastreams options = {}

pid = options.delete(:pid)

multipart_request = { :multipart => true }

options[:datastreams].each do |dsid, file|
run_hook :before_add_datastream, :pid => pid, :dsid => dsid, :file => file, :options => options
str = file.respond_to?(:read) ? file.read : file
multipart_request[dsid] = file
file.rewind if file.respond_to?(:rewind)
end

client[datastream_url(pid)].post(multipart_request)
end

# {include:RestApiClient::API_DOCUMENTATION}
# @param [Hash] options
# @option options [String] :pid
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/fcrepo4_integration_spec.rb
@@ -0,0 +1,31 @@
require 'spec_helper'


# These tests require a fedora repository with the resource index enabled (and with syncUpdates = true)
describe "Integration testing against a live Fedora repository", :integration => true do
REPOSITORY_CONFIG = { :url => "http://localhost:#{ENV['TEST_JETTY_PORT'] || 8080}/rest", :user => 'fedoraAdmin', :password => 'fedoraAdmin' }
before(:all) do
@repository = Rubydora.connect REPOSITORY_CONFIG
@repository.find('test:1').delete rescue nil
end

it "should use the multipart api" do
obj = @repository.find('test:1')
ds = obj.datastreams['ds1']
ds.content = '123'

ds = obj.datastreams['ds2']
ds.content = '456'

@repository.should_not_receive(:add_datastream)


obj.save


obj = @repository.find('test:1')
obj.datastreams['ds1'].content.should == '123'
obj.datastreams['ds2'].content.should == '456'
end

end

0 comments on commit c30ffe9

Please sign in to comment.