Skip to content

Commit

Permalink
look for DPG ocr tag when setting attribute in goobi notify call
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed May 8, 2018
1 parent 74e7de8 commit 543f162
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/dor/goobi.rb
Expand Up @@ -30,6 +30,7 @@ def xml_request
<collectionName>#{collection_name.encode(:xml => :text)}</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>#{goobi_workflow_name}</goobiWorkflow>
<OCR>#{goobi_ocr_tag_present?}</OCR>
</stanfordCreationRequest>
END
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/dor/service_item.rb
Expand Up @@ -103,5 +103,14 @@ def goobi_workflow_name
content_tag.empty? ? Dor::Config.goobi.default_goobi_workflow_name : content_tag[0].split(':').last.strip
end
end

# returns true or false depending if the specially defined goobi DPG ocr tag is present in the object
# @return [boolean]
def goobi_ocr_tag_present?
@goobi_ocr_tag_present ||= begin
dpg_goobi_ocr_tag = 'DPG : OCR : TRUE'
@druid_obj.tags.any? { |tag| tag.casecmp(dpg_goobi_ocr_tag).zero? } # case insensitive compare
end
end
end
end
25 changes: 24 additions & 1 deletion spec/goobi_spec.rb
Expand Up @@ -21,7 +21,8 @@
allow(@goobi).to receive(:collection_name).and_return('collection name')
end

it 'should create the correct xml request' do
it 'should create the correct xml request withour ocr tag present' do
allow(@goobi).to receive(:goobi_ocr_tag_present?).and_return(false)
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -36,6 +37,28 @@
<collectionName>collection name</collectionName>
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<OCR>false</OCR>
</stanfordCreationRequest>
END
end

it 'should create the correct xml request with ocr tag present' do
allow(@goobi).to receive(:goobi_ocr_tag_present?).and_return(true)
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>
<OCR>true</OCR>
</stanfordCreationRequest>
END
end
Expand Down
36 changes: 36 additions & 0 deletions spec/service_item_spec.rb
Expand Up @@ -78,6 +78,42 @@
end
end

describe '.goobi_ocr_tag_present?' do
it 'should return false if the goobi ocr tag is not present' 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_ocr_tag_present?).to be false
end
it 'should return true if the goobi ocr tag is present' 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 : OCR : TRUE'])

expect(@si.goobi_ocr_tag_present?).to be true
end
it 'should return true if the goobi ocr tag is present even if the case is mixed' 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 : ocr : true'])

expect(@si.goobi_ocr_tag_present?).to be true
end
end

describe '.object_type' do
it 'should return object_type from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', '')
Expand Down

0 comments on commit 543f162

Please sign in to comment.