Skip to content

Commit

Permalink
add <tags> to goobi notify call with object tags in specified format
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Aug 24, 2018
1 parent 9c2e064 commit 7aebb0f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/models/dor/goobi.rb
Expand Up @@ -31,6 +31,9 @@ def xml_request
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>#{goobi_workflow_name}</goobiWorkflow>
<ocr>#{goobi_ocr_tag_present?}</ocr>
<tags>
#{goobi_tag_list.map { |tag_name, tag_value| "<tag name=\"#{tag_name}\" value=\"#{tag_value}\"></tag>" }.join("\n")}
</tags>
</stanfordCreationRequest>
END
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/dor/service_item.rb
Expand Up @@ -112,5 +112,15 @@ def goobi_ocr_tag_present?
@druid_obj.tags.any? { |tag| tag.casecmp(dpg_goobi_ocr_tag).zero? } # case insensitive compare
end
end

# returns an array of arrays, each element contains an array of [name, value] of DOR object tags in the format expected to pass to Goobi
# the name of the tag is the first namespace part of the tag (before first colon), value of the tag is everything after this
# @return [Array]
def goobi_tag_list
@druid_obj.tags.map do |tag|
tag_split = tag.split(':', 2).map(&:strip) # only split on the first colon
[tag_split[0], tag_split[1]]
end
end
end
end
35 changes: 33 additions & 2 deletions spec/goobi_spec.rb
Expand Up @@ -22,7 +22,7 @@
end

it 'creates the correct xml request without ocr tag present' do
allow(@goobi).to receive(:goobi_ocr_tag_present?).and_return(false)
allow(item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'Process : Content Type : Book (flipbook, ltr)', 'LAB : MAPS'])
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -38,12 +38,17 @@
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<ocr>false</ocr>
<tags>
<tag name="DPG" value="Workflow : book_workflow"></tag>
<tag name="Process" value="Content Type : Book (flipbook, ltr)"></tag>
<tag name="LAB" value="MAPS"></tag>
</tags>
</stanfordCreationRequest>
END
end

it 'creates the correct xml request with ocr tag present' do
allow(@goobi).to receive(:goobi_ocr_tag_present?).and_return(true)
allow(item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'DPG : OCR : TRUE'])
expect(@goobi.xml_request).to be_equivalent_to <<-END
<stanfordCreationRequest>
<objectId>#{pid}</objectId>
Expand All @@ -59,6 +64,32 @@
<sdrWorkflow>#{Dor::Config.goobi.dpg_workflow_name}</sdrWorkflow>
<goobiWorkflow>goobi_workflow</goobiWorkflow>
<ocr>true</ocr>
<tags>
<tag name="DPG" value="Workflow : book_workflow"></tag>
<tag name="DPG" value="OCR : TRUE"></tag>
</tags>
</stanfordCreationRequest>
END
end

it 'creates the correct xml request with no tags present' do
allow(item).to receive(:tags).and_return([])
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>false</ocr>
<tags></tags>
</stanfordCreationRequest>
END
end
Expand Down
16 changes: 16 additions & 0 deletions spec/service_item_spec.rb
Expand Up @@ -42,6 +42,22 @@
end
end

describe '.goobi_tag_list' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
end

it 'returns an array of arrays with the tags from the object in the key:value format expected to be passed to goobi' do
allow(@dor_item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'Process : Content Type : Book (flipbook, ltr)', 'LAB : Map Work'])
expect(@si.goobi_tag_list).to eq([['DPG', 'Workflow : book_workflow'], ['Process', 'Content Type : Book (flipbook, ltr)'], ['LAB', 'Map Work']])
end

it 'returns an empty array when there are no tags' do
allow(@dor_item).to receive(:tags).and_return([])
expect(@si.goobi_tag_list).to eq([])
end
end

describe '.goobi_ocr_tag_present?' do
before do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
Expand Down

0 comments on commit 7aebb0f

Please sign in to comment.