Skip to content

Commit

Permalink
add z subfield for stanford only objects
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Feb 16, 2017
1 parent 94da1b4 commit 139f128
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 65 deletions.
1 change: 1 addition & 0 deletions app/models/dor/service_item.rb
Expand Up @@ -14,6 +14,7 @@ def self.get_ckey(object)
def initialize(druid_obj)
@druid_obj = druid_obj
@druid_id = @druid_obj.remove_druid_prefix
@dra_object = druid_obj.rightsMetadata.dra_object
end

# the ckey for the current object
Expand Down
10 changes: 7 additions & 3 deletions app/models/dor/update_marc_record_service.rb
Expand Up @@ -34,7 +34,7 @@ def generate_symphony_record
collection_info = get_x2_collection_info
constituent_info = get_x2_constituent_info

new856 = "#{ckey}\t#{@druid_id}\t#{get_856_cons} #{get_1st_indicator}#{get_2nd_indicator}#{purl_uri}#{get_x1_sdrpurl_marker}#{object_type.prepend('|x')}"
new856 = "#{ckey}\t#{@druid_id}\t#{get_856_cons} #{get_1st_indicator}#{get_2nd_indicator}#{get_z_field}#{purl_uri}#{get_x1_sdrpurl_marker}#{object_type.prepend('|x')}"
new856 << barcode.prepend('|xbarcode:') unless barcode.nil?
new856 << thumb.prepend('|xfile:') unless thumb.nil?
new856 << collection_info unless collection_info.nil?
Expand Down Expand Up @@ -78,9 +78,13 @@ def get_2nd_indicator
'1'
end

# It's a plceholder for the uri label
# It returns text in the z field based on permissions
def get_z_field
# Placeholder to be used in the future
if @dra_object.stanford_only_unrestricted? || @dra_object.stanford_only_downloadable?
'|zAvailable to Stanford-affiliated users.'
else
''
end
end

# It builds the PURL uri based on the druid id
Expand Down
22 changes: 15 additions & 7 deletions spec/controllers/objects_controller_spec.rb
Expand Up @@ -9,7 +9,15 @@

before(:each) do
allow(Dor).to receive(:find).and_return(item)
allow(item).to receive(:remove_druid_prefix).and_return('aa123bb4567')
rights_metadata_xml = Dor::RightsMetadataDS.new
allow(rights_metadata_xml).to receive_messages(:ng_xml => Nokogiri::XML('<xml/>'))
allow(item).to receive_messages(
:id => 'druid:aa123bb4567',
:datastreams => { 'rightsMetadata' => rights_metadata_xml },
:rightsMetadata => rights_metadata_xml,
:remove_druid_prefix => 'aa123bb4567'
)
allow(rights_metadata_xml).to receive(:dra_object).and_return(Dor::RightsAuth.parse(Nokogiri::XML('<xml/>'), true))
end

describe 'object registration' do
Expand All @@ -23,10 +31,10 @@
expect(response.headers['Location']).to match(/\/fedora\/objects\/druid:existing123obj/)
end
end

it 'registers the object with the registration service' do
allow(Dor::RegistrationService).to receive(:create_from_request).and_return(pid: 'druid:xyz')

post :create

expect(response.body).to eq 'druid:xyz'
Expand All @@ -40,7 +48,7 @@
before do
clean_workspace
end

after do
clean_workspace
end
Expand Down Expand Up @@ -74,15 +82,15 @@
end
end
end

describe '/publish' do
it 'calls publish metadata' do
expect(item).to receive(:publish_metadata)
post :publish, params: { id: item.pid }
expect(response.status).to eq(201)
end
end

describe '/update_marc_record' do
it 'updates a marc record' do
# TODO: add some more expectations
Expand All @@ -102,7 +110,7 @@
expect(response.status).to eq(201)
end
end

describe '/release_tags' do
it 'adds a release tag when posted to with false' do
expect(item).to receive(:add_release_node).with(false, :to => 'searchworks', :who => 'carrickr', :what => 'self', :release => false)
Expand Down
11 changes: 6 additions & 5 deletions spec/rails_helper.rb
Expand Up @@ -58,15 +58,16 @@ def clean_workspace
FileUtils.rm_rf Dir.glob(TEST_WORKSPACE + '/*')
end

def setup_test_objects(druid, identityMetadata)
def setup_test_objects(druid, identityMetadata, rightsMetadata = '<xml/>')
@dor_item=double(Dor::Item)
@identityMetadataXML = Dor::IdentityMetadataDS.new
@rightsMetadataXML = Dor::RightsMetadataDS.new
allow(@identityMetadataXML).to receive_messages(:ng_xml => Nokogiri::XML(identityMetadata))
allow(@rightsMetadataXML).to receive_messages(:ng_xml => Nokogiri::XML(rightsMetadata))
allow(@dor_item).to receive_messages(
:id=>druid,
:released_for=>{},
:datastreams => {"identityMetadata"=>@identityMetadataXML},
:identityMetadata => @identityMetadataXML,
:id=>druid, :released_for=>{},
:datastreams => { 'identityMetadata' => @identityMetadataXML, 'rightsMetadata' => @rightsMetadataXML },
:identityMetadata => @identityMetadataXML, :rightsMetadata => @rightsMetadataXML,
:remove_druid_prefix=>druid.gsub('druid:','')
)
@umrs=Dor::UpdateMarcRecordService.new @dor_item
Expand Down
16 changes: 13 additions & 3 deletions spec/service_item_spec.rb
Expand Up @@ -176,9 +176,13 @@
@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)
@rights_metadata_ng_xml = Nokogiri::XML(build_rights_metadata_1)
@rights_metadata_ds = double(Dor::RightsMetadataDS)
allow(@d).to receive(:datastreams).and_return('rightsMetadata' => @rights_metadata_ds, '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)
allow(@rights_metadata_ds).to receive(:ng_xml).and_return(@rights_metadata_ng_xml)
allow(@rights_metadata_ds).to receive(:dra_object).and_return(Dor::RightsAuth.parse(@rights_metadata_ng_xml, true))
end

it 'should return the content_type_tag from dor-services if the value exists' do
Expand All @@ -200,8 +204,11 @@
d = Dor::Item.new(:pid => druid)
content_metadata_ng_xml = Nokogiri::XML(build_content_metadata_1)
content_metadata_ds = double(Dor::ContentMetadataDS)
rights_metadata_ng_xml = Nokogiri::XML(build_rights_metadata_1)
rights_metadata_ds = double(Dor::RightsMetadataDS)
allow(rights_metadata_ds).to receive(:dra_object).and_return(Dor::RightsAuth.parse(rights_metadata_ng_xml, true))

allow(d).to receive(:datastreams).and_return('contentMetadata' => content_metadata_ds)
allow(d).to receive(:datastreams).and_return('rightsMetadata' => rights_metadata_ds, 'contentMetadata' => content_metadata_ds)
allow(content_metadata_ds).to receive(:ng_xml).and_return(content_metadata_ng_xml)

expect(Dor::ServiceItem.new(d).thumb).to eq('bb111bb2222%2Fwt183gy6220_00_0001.jp2')
Expand All @@ -212,8 +219,11 @@
d = Dor::Item.new(:pid => druid)
content_metadata_ng_xml = Nokogiri::XML(build_content_metadata_3)
content_metadata_ds = double(Dor::ContentMetadataDS)
rights_metadata_ng_xml = Nokogiri::XML(build_rights_metadata_1)
rights_metadata_ds = double(Dor::RightsMetadataDS)
allow(rights_metadata_ds).to receive(:dra_object).and_return(Dor::RightsAuth.parse(rights_metadata_ng_xml, true))

allow(d).to receive(:datastreams).exactly(4).times.and_return('contentMetadata' => content_metadata_ds)
allow(d).to receive(:datastreams).exactly(4).times.and_return('rightsMetadata' => rights_metadata_ds, 'contentMetadata' => content_metadata_ds)
allow(content_metadata_ds).to receive(:ng_xml).and_return(content_metadata_ng_xml)

expect(Dor::ServiceItem.new(d).thumb).to be_nil
Expand Down
46 changes: 46 additions & 0 deletions spec/support/datastreams.rb
Expand Up @@ -416,4 +416,50 @@ def build_identity_metadata_without_ckey
<tag>Remediated By : 4.15.4</tag>
</identityMetadata>'
end

def build_rights_metadata_1
'<rightsMetadata>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<world/>
</machine>
</access>
<use>
<human type="useAndReproduction">User agrees that, where applicable, content will not be used to identify or to otherwise infringe the privacy or confidentiality rights of individuals. Content distributed via the Stanford Digital Repository may be subject to additional license and use restrictions applied by the depositor.</human>
</use>
</rightsMetadata>
'
end

def build_rights_metadata_2
'<rightsMetadata>
<copyright>
<human type="copyright">Courtesy of The Revs Institute for Automotive Research, Inc. All rights reserved unless otherwise indicated.</human>
</copyright>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<group>Stanford</group>
<world rule="no-download"/>
</machine>
</access>
<use>
<human type="useAndReproduction">Users must contact The Revs Institute for Automotive Research, Inc. for re-use and reproduction information.</human>
</use>
<use>
<human type="creativeCommons"/>
<machine type="creativeCommons"/>
</use>
</rightsMetadata>
'
end
# rubocop:enable Metrics/MethodLength, Metrics/LineLength

0 comments on commit 139f128

Please sign in to comment.