Skip to content

Commit

Permalink
Merge e760f82 into 3e194a6
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Oct 11, 2018
2 parents 3e194a6 + e760f82 commit 10cb932
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 64 deletions.
30 changes: 20 additions & 10 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-10-03 14:24:25 -0500 using RuboCop version 0.57.2.
# on 2018-10-11 13:34:20 -0700 using RuboCop version 0.57.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -40,7 +40,7 @@ Layout/SpaceAfterComma:
Exclude:
- 'spec/rails_helper.rb'

# Offense count: 5
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Layout/SpaceAroundOperators:
Expand Down Expand Up @@ -89,16 +89,21 @@ Lint/UriEscapeUnescape:
- 'app/controllers/sdr_controller.rb'
- 'spec/controllers/sdr_controller_spec.rb'

# Offense count: 9
# Offense count: 11
Metrics/AbcSize:
Max: 30
Max: 32

# Offense count: 5
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 127

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 14
Max: 13

# Offense count: 8
# Offense count: 9
Naming/AccessorMethodName:
Exclude:
- 'app/models/dor/update_marc_record_service.rb'
Expand Down Expand Up @@ -154,7 +159,7 @@ RSpec/DescribeClass:
Exclude:
- 'spec/features/about_spec.rb'

# Offense count: 30
# Offense count: 32
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Expand Down Expand Up @@ -193,7 +198,7 @@ RSpec/ExpectInHook:
Exclude:
- 'spec/dor/update_marc_record_service_spec.rb'

# Offense count: 141
# Offense count: 92
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
Expand Down Expand Up @@ -239,6 +244,11 @@ RSpec/ScatteredSetup:
- 'spec/controllers/sdr_controller_spec.rb'
- 'spec/controllers/versions_controller_spec.rb'

# Offense count: 5
RSpec/SubjectStub:
Exclude:
- 'spec/dor/update_marc_record_service_spec.rb'

# Offense count: 17
# Configuration parameters: IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Expand Down Expand Up @@ -326,7 +336,7 @@ Style/IfUnlessModifier:
Style/NumericLiterals:
MinDigits: 11

# Offense count: 12
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Expand Down
43 changes: 43 additions & 0 deletions app/models/dor/update_marc_record_service.rb
Expand Up @@ -34,6 +34,7 @@ def push_symphony_records
# Subfield x #5 (optional): the file-id to be used as thumb if available, recorded as file:file-id-value
# Subfield x #6..n (optional): Collection(s) this object is a member of, recorded as collection:druid-value:ckey-value:title
# Subfield x #7..n (optional): Set(s) this object is a member of, recorded as set:druid-value:ckey-value:title
# Subfield x #8..n (optional): label and part sort keys for the member
def generate_symphony_records
return [] unless ckeys?

Expand Down Expand Up @@ -71,6 +72,7 @@ def new_856_record(ckey)
new856 << thumb.prepend('|xfile:') unless thumb.nil?
new856 << get_x2_collection_info unless get_x2_collection_info.nil?
new856 << get_x2_constituent_info unless get_x2_constituent_info.nil?
new856 << get_x2_part_info unless get_x2_part_info.nil?
end

def get_identifier(ckey)
Expand Down Expand Up @@ -138,6 +140,26 @@ def get_x2_constituent_info
end.join('')
end

def get_x2_part_info
title_info = primary_mods_title_info_element

return '' unless title_info

part_parts = title_info.children.select do |child|
%w(partName partNumber).include?(child.name)
end

part_label = part_parts.map(&:text).compact.join(parts_delimiter(part_parts))

part_sort = @druid_obj.datastreams['descMetadata'].ng_xml.xpath('//*[@type="date/sequential designation"]').first

str = ''
str << "|xlabel:#{part_label}" unless part_label.empty?
str << "|xsort:#{part_sort.text}" if part_sort

str
end

def born_digital?
BORN_DIGITAL_APOS.include? @druid_obj.admin_policy_object_id
end
Expand All @@ -156,5 +178,26 @@ def dor_items_for_constituents
Dor::Item.find(cons_druid)
end
end

def primary_mods_title_info_element
return nil unless @druid_obj.datastreams['descMetadata']

title_info = @druid_obj.datastreams['descMetadata'].ng_xml.xpath('//mods/titleInfo[not(@type)]').first
title_info ||= @druid_obj.datastreams['descMetadata'].ng_xml.xpath('//mods/titleInfo[@usage="primary"]').first
title_info ||= @druid_obj.datastreams['descMetadata'].ng_xml.xpath('//mods/titleInfo').first

title_info
end

# adapted from mods_display
def parts_delimiter(elements)
# index will retun nil which is not comparable so we call 100
# if the element isn't present (thus meaning it's at the end of the list)
if (elements.index { |c| c.name == 'partNumber' } || 100) < (elements.index { |c| c.name == 'partName' } || 100)
', '
else
'. '
end
end
end
end
68 changes: 36 additions & 32 deletions spec/dor/service_item_spec.rb
@@ -1,23 +1,27 @@
require 'rails_helper'

RSpec.describe Dor::ServiceItem do
subject(:si) { Dor::ServiceItem.new dor_item }

let(:dor_item) { @dor_item }

describe '#catkey' do
it 'returns catkey from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
expect(@si.ckey).to eq('8832162')
expect(@si.previous_ckeys).to eq([])
expect(si.ckey).to eq('8832162')
expect(si.previous_ckeys).to eq([])
end

it 'returns nil for current catkey but values for previous catkeys in identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_5)
expect(@si.ckey).to be_nil
expect(@si.previous_ckeys).to eq(%w(123 456))
expect(si.ckey).to be_nil
expect(si.previous_ckeys).to eq(%w(123 456))
end

it 'returns nil for current catkey and empty array for previous catkeys in identityMetadata without either' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_4)
expect(@si.ckey).to be_nil
expect(@si.previous_ckeys).to eq([])
expect(si.ckey).to be_nil
expect(si.previous_ckeys).to eq([])
end
end

Expand All @@ -28,17 +32,17 @@

it 'returns goobi_workflow_name from a valid identityMetadata' do
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')
expect(si.goobi_workflow_name).to eq('book_workflow')
end

it 'returns first goobi_workflow_name if multiple are in the tags' do
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')
expect(si.goobi_workflow_name).to eq('book_workflow')
end

it 'returns blank for goobi_workflow_name if none are found' do
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)
expect(si.goobi_workflow_name).to eq(Dor::Config.goobi.default_goobi_workflow_name)
end
end

Expand All @@ -49,24 +53,24 @@

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.length).to eq 3
@si.goobi_tag_list.each { |goobi_tag| expect(goobi_tag.class).to eq Dor::GoobiTag }
expect(@si.goobi_tag_list[0]).to have_attributes(name: 'DPG', value: 'Workflow : book_workflow')
expect(@si.goobi_tag_list[1]).to have_attributes(name: 'Process', value: 'Content Type : Book (flipbook, ltr)')
expect(@si.goobi_tag_list[2]).to have_attributes(name: 'LAB', value: 'Map Work')
expect(si.goobi_tag_list.length).to eq 3
si.goobi_tag_list.each { |goobi_tag| expect(goobi_tag.class).to eq Dor::GoobiTag }
expect(si.goobi_tag_list[0]).to have_attributes(name: 'DPG', value: 'Workflow : book_workflow')
expect(si.goobi_tag_list[1]).to have_attributes(name: 'Process', value: 'Content Type : Book (flipbook, ltr)')
expect(si.goobi_tag_list[2]).to have_attributes(name: 'LAB', value: '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([])
expect(si.goobi_tag_list).to eq([])
end

it 'works with singleton tags (no colon, so no value, just a name)' do
allow(@dor_item).to receive(:tags).and_return(['Name : Some Value', 'JustName'])
expect(@si.goobi_tag_list.length).to eq 2
expect(@si.goobi_tag_list[0].class).to eq Dor::GoobiTag
expect(@si.goobi_tag_list[0]).to have_attributes(name: 'Name', value: 'Some Value')
expect(@si.goobi_tag_list[1]).to have_attributes(name: 'JustName', value: nil)
expect(si.goobi_tag_list.length).to eq 2
expect(si.goobi_tag_list[0].class).to eq Dor::GoobiTag
expect(si.goobi_tag_list[0]).to have_attributes(name: 'Name', value: 'Some Value')
expect(si.goobi_tag_list[1]).to have_attributes(name: 'JustName', value: nil)
end
end

Expand All @@ -77,29 +81,29 @@

it 'returns false if the goobi ocr tag is not present' do
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
expect(si.goobi_ocr_tag_present?).to be false
end

it 'returns true if the goobi ocr tag is present' do
allow(@dor_item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'DPG : OCR : TRUE'])
expect(@si.goobi_ocr_tag_present?).to be true
expect(si.goobi_ocr_tag_present?).to be true
end

it 'returns true if the goobi ocr tag is present even if the case is mixed' do
allow(@dor_item).to receive(:tags).and_return(['DPG : Workflow : book_workflow', 'DPG : ocr : true'])
expect(@si.goobi_ocr_tag_present?).to be true
expect(si.goobi_ocr_tag_present?).to be true
end
end

describe '#object_type' do
it 'returns object_type from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
expect(@si.object_type).to eq('item')
expect(si.object_type).to eq('item')
end

it 'returns a blank object type for identityMetadata without object_type' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_6)
expect(@si.object_type).to be_nil
expect(si.object_type).to be_nil
end
end

Expand All @@ -110,12 +114,12 @@

it 'returns project name from a valid identityMetadata' do
allow(@dor_item).to receive(:tags).and_return(['Project : Batchelor Maps : Batch 1', 'Process : Content Type : Book (flipbook, ltr)'])
expect(@si.project_name).to eq('Batchelor Maps : Batch 1')
expect(si.project_name).to eq('Batchelor Maps : Batch 1')
end

it 'returns blank for project name if not in tag' do
allow(@dor_item).to receive(:tags).and_return(['Process : Content Type : Book (flipbook, ltr)'])
expect(@si.project_name).to eq('')
expect(si.project_name).to eq('')
end
end

Expand All @@ -128,26 +132,26 @@
collection = Dor::Collection.new(:pid => 'druid:cc111cc1111')
allow(collection).to receive_messages(label: 'Collection label', id: 'druid:cc111cc1111')
allow(@dor_item).to receive(:collections).and_return([collection])
expect(@si.collection_name).to eq('Collection label')
expect(@si.collection_id).to eq('druid:cc111cc1111')
expect(si.collection_name).to eq('Collection label')
expect(si.collection_id).to eq('druid:cc111cc1111')
end

it 'returns blank for collection name and id if there are none' do
allow(@dor_item).to receive(:collections).and_return([])
expect(@si.collection_name).to eq('')
expect(@si.collection_id).to eq('')
expect(si.collection_name).to eq('')
expect(si.collection_id).to eq('')
end
end

describe '#barcode' do
it 'returns barcode from a valid identityMetadata' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_1)
expect(@si.barcode).to eq('36105216275185')
expect(si.barcode).to eq('36105216275185')
end

it 'returns an empty string without barcode' do
setup_test_objects('druid:aa111aa1111', build_identity_metadata_3)
expect(@si.barcode).to be_nil
expect(si.barcode).to be_nil
end
end

Expand Down

0 comments on commit 10cb932

Please sign in to comment.