Skip to content

Commit

Permalink
add ability to set content_type from contentMetadata as well as proce…
Browse files Browse the repository at this point in the history
…ss tag
  • Loading branch information
peetucket committed Nov 7, 2016
1 parent eef5bf5 commit 3d696c5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/goobi.rb
Expand Up @@ -20,7 +20,7 @@ def xml_request
<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>
<contentType>#{content_type}</contentType>
<project>#{project_name.encode(:xml => :text)}</project>
<catkey>#{ckey}</catkey>
<barcode>#{barcode}</barcode>
Expand Down
11 changes: 11 additions & 0 deletions lib/service_item.rb
Expand Up @@ -59,6 +59,17 @@ def collection_name
@druid_obj.collections.empty? ? '' : @druid_obj.collections.first.label
end

# returns the value of the content_type_tag from dor services if it exists, else returns the value from contentMetadata object type
# @return [String] first collection name the item is in (blank if none)
def content_type
if @druid_obj.content_type_tag.empty?
node = @druid_obj.datastreams['contentMetadata'].ng_xml.at_xpath('//contentMetadata/@type')
node.blank? ? '' : node.content
else
@druid_obj.content_type_tag
end
end

# returns the name of the project by examining the objects tags
# @return [String] first project tag value if one exists (blank if none)
def project_name
Expand Down
26 changes: 26 additions & 0 deletions spec/service_item_spec.rb
Expand Up @@ -168,6 +168,32 @@
end
end

describe '.content_type' do
before :each do
druid = 'bb111bb2222'
@d = Dor::Item.new(:pid => druid)
@content_metadata_ng_xml = Nokogiri::XML(build_content_metadata_1)
@content_metadata_ds = double(Dor::ContentMetadataDS)
@identity_metadata_ng_xml = Nokogiri::XML(build_identity_metadata_1)
@identity_metadata_ds = double(Dor::IdentityMetadataDS)
allow(@d).to receive(:datastreams).and_return('contentMetadata' => @content_metadata_ds, 'identityMetadata' => @identity_metadata_ds)
allow(@content_metadata_ds).to receive(:ng_xml).and_return(@content_metadata_ng_xml)
allow(@identity_metadata_ds).to receive(:ng_xml).and_return(@identity_metadata_ng_xml)
end

it 'should return the content_type_tag from dor-services if the value exists' do
fake_tags = ['Tag 1', 'Tag 2', 'Process : Content Type : Process Value']
allow(@identity_metadata_ds).to receive_messages(:tags => fake_tags, :tag => fake_tags)
expect(Dor::ServiceItem.new(@d).content_type).to eq('Process Value')
end

it 'should return the type from contentMetadata if content_type_tag from dor-services does not have a value' do
fake_tags = ['Tag 1', 'Tag 2', 'Tag 3']
allow(@identity_metadata_ds).to receive_messages(:tags => fake_tags, :tag => fake_tags)
expect(Dor::ServiceItem.new(@d).content_type).to eq('map')
end
end

describe '.thumb' do
it 'should return thumb from a valid contentMetadata' do
druid = 'bb111bb2222'
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -57,7 +57,6 @@ def build_identity_metadata_1
<otherId name="catkey">8832162</otherId>
<otherId name="barcode">36105216275185</otherId>
<otherId name="uuid">ff3ce224-9ffb-11e3-aaf2-0050569b3c3c</otherId>
<tag>Process : Content Type : Map</tag>
<tag>Project : Batchelor Maps : Batch 1</tag>
<tag>LAB : MAPS</tag>
<tag>DPG : Workflow : book_workflow</tag>
Expand Down

0 comments on commit 3d696c5

Please sign in to comment.