Skip to content

Commit

Permalink
grab goobi workflow name from the object; use default if none found; …
Browse files Browse the repository at this point in the history
…more tests
  • Loading branch information
peetucket committed Nov 2, 2016
1 parent ebac31c commit c9c756f
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 18 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ group :test, :development do
gem 'rack-console'
gem 'rubocop'
gem 'rubocop-rspec'
gem 'equivalent-xml'
end

group :deployment do
Expand Down
4 changes: 2 additions & 2 deletions config/environments/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

goobi do
url 'https://goobi-api-url'
dpg_workflow_name 'dpgImageWF' # the dpg workflow name to put into the XML
goobi_workflow_name 'Sample_workflow' # the goobi workflow name to put into the XML
dpg_workflow_name 'goobiWF' # the dpg workflow name to put into the XML
default_goobi_workflow_name 'Sample_workflow' # the default goobi workflow name to use if none found in the object
max_tries 5 # the number of attempts to retry service calls before failing
max_sleep_seconds 120 # max sleep seconds between tries
base_sleep_seconds 10 # base sleep seconds between tries
Expand Down
6 changes: 3 additions & 3 deletions lib/goobi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def register
def xml_request
<<-END
<stanfordCreationRequest>
<objectId>#{@druid_obj.id}</objectId>
<objectType>#{object_type}</objectType>
<objectId>#{@druid_obj.id}</objectId>
<objectType>#{object_type}</objectType>
<sourceID>#{@druid_obj.source_id.encode(:xml => :text)}</sourceID>
<title>#{@druid_obj.label.encode(:xml => :text)}</title>
<contentType>#{@druid_obj.content_type_tag}</contentType>
Expand All @@ -27,7 +27,7 @@ def xml_request
<collectionId>#{collection_id}</collectionId>
<collectionName>#{collection_name.encode(:xml => :text)}</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>#{Dor::Config.goobi.goobi_workflow_name}</goobiWorkflow>
<goobiWorkflow>#{goobi_workflow_name}</goobiWorkflow>
</stanfordCreationRequest>
END
end
Expand Down
23 changes: 11 additions & 12 deletions lib/service_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ def object_type
end
end

# @return [String] value with object_type in it, or empty x subfield if none exists
# look in identityMetadata/objectType
def content_type
@object_type ||= begin
node = @druid_obj.datastreams['identityMetadata'].ng_xml.at_xpath('//identityMetadata/objectType')
node.content unless node.nil?
end
end

# the barcode
# @return [String] value with barcode in it, or empty x subfield if none exists
# look in identityMetadata/otherId name="barcode"
Expand Down Expand Up @@ -69,10 +60,18 @@ def collection_name
end

# returns the name of the project by examining the objects tags
# @return [String] project tag value if one exists (blank if none)
# @return [String] first project tag value if one exists (blank if none)
def project_name
content_tag = @druid_obj.tags.select { |tag| tag.include?('Project : ') }
content_tag.empty? ? '' : content_tag[0].gsub('Project : ', '').strip
project_tag_id = 'Project : '
content_tag = @druid_obj.tags.select { |tag| tag.include?(project_tag_id) }
content_tag.empty? ? '' : content_tag[0].gsub(project_tag_id, '').strip
end

# returns the name of the goobiworkflow in the object by examining the objects tags
# @return [String] first goobi workflow tag value if one exists (default from config if none)
def goobi_workflow_name
content_tag = @druid_obj.tags.select { |tag| tag.include?('DPG : Workflow : ') }
content_tag.empty? ? Dor::Config.goobi.default_goobi_workflow_name : content_tag[0].split(':').last.strip
end
end
end
35 changes: 34 additions & 1 deletion spec/goobi_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
require 'spec_helper'

describe Dor::Goobi do
xit 'should create the correct xml request' do
let(:pid) { 'druid:aa123bb4567' }
let(:item) { Dor::Item.new(pid: pid) }

before(:each) do
allow(Dor::Item).to receive(:find).and_return(item)
allow(item).to receive(:source_id).and_return('some_source_id')
allow(item).to receive(:label).and_return('Object Title')
allow(item).to receive(:content_type_tag).and_return('book')
@goobi = Dor::Goobi.new(item)
allow(@goobi).to receive(:project_name).and_return('Project Name')
allow(@goobi).to receive(:object_type).and_return('item')
allow(@goobi).to receive(:ckey).and_return('ckey_12345')
allow(@goobi).to receive(:goobi_workflow_name).and_return('goobi_workflow')
allow(@goobi).to receive(:barcode).and_return('barcode_12345')
allow(@goobi).to receive(:collection_id).and_return('druid:oo000oo0001')
allow(@goobi).to receive(:collection_name).and_return('collection name')
end
it 'should create the correct xml request' do
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
<objectType>item</objectType>
<sourceID>some_source_id</sourceID>
<title>Object Title</title>
<contentType>book</contentType>
<project>Project Name</project>
<catkey>ckey_12345</catkey>
<barcode>barcode_12345</barcode>
<collectionId>druid:oo000oo0001</collectionId>
<collectionName>collection name</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>goobi_workflow</goobiWorkflow>
</stanfordCreationRequest>
END
end
xit 'should make a call to the goobi server with the appropriate xml params' do
end
Expand Down
36 changes: 36 additions & 0 deletions spec/service_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@
end
end

describe '.goobi_workflow_name' do
it 'should return goobi_workflow_name from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', '')
identity_metadata_ng_xml = Nokogiri::XML(build_identity_metadata_1)
identity_metadata_ds = double(Dor::IdentityMetadataDS)

allow(@dor_item).to receive(:datastreams).and_return('identityMetadata' => identity_metadata_ds)
allow(identity_metadata_ds).to receive(:ng_xml).and_return(identity_metadata_ng_xml)
allow(@dor_item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'Process : Content Type : Book (flipbook, ltr)'])

expect(@si.goobi_workflow_name).to eq('book_workflow')
end
it 'should return first goobi_workflow_name if multiple are in the tags' do
setup_test_objects('druid:aa111aa1111', '')
identity_metadata_ng_xml = Nokogiri::XML(build_identity_metadata_1)
identity_metadata_ds = double(Dor::IdentityMetadataDS)

allow(@dor_item).to receive(:datastreams).and_return('identityMetadata' => identity_metadata_ds)
allow(identity_metadata_ds).to receive(:ng_xml).and_return(identity_metadata_ng_xml)
allow(@dor_item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'DPG : Workflow : another_workflow', 'Process : Content Type : Book (flipbook, ltr)'])

expect(@si.goobi_workflow_name).to eq('book_workflow')
end
it 'should return blank for goobi_workflow_name if none are found' do
setup_test_objects('druid:aa111aa1111', '')
identity_metadata_ng_xml = Nokogiri::XML(build_identity_metadata_1)
identity_metadata_ds = double(Dor::IdentityMetadataDS)

allow(@dor_item).to receive(:datastreams).and_return('identityMetadata' => identity_metadata_ds)
allow(identity_metadata_ds).to receive(:ng_xml).and_return(identity_metadata_ng_xml)
allow(@dor_item).to receive(:tags).and_return(['Process : Content Type : Book (flipbook, ltr)'])

expect(@si.goobi_workflow_name).to eq(Dor::Config.goobi.default_goobi_workflow_name)
end
end

describe '.object_type' do
it 'should return object_type from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', '')
Expand Down
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'simplecov'
require 'coveralls'
require 'fakeweb'
require 'rspec/matchers' # req by equivalent-xml custom matcher `be_equivalent_to`
require 'equivalent-xml'

Coveralls.wear!

Expand Down Expand Up @@ -58,6 +60,7 @@ def build_identity_metadata_1
<tag>Process : Content Type : Map</tag>
<tag>Project : Batchelor Maps : Batch 1</tag>
<tag>LAB : MAPS</tag>
<tag>DPG : Workflow : book_workflow</tag>
<tag>Registered By : dfuzzell</tag>
<tag>Remediated By : 4.15</tag>
<release displayType="image" release="true" to="Searchworks" what="self" when="2015-07-27T21:43:27Z" who="lauraw15">true</release>
Expand Down

0 comments on commit c9c756f

Please sign in to comment.