Skip to content

Commit

Permalink
Merge pull request #4955 from sul-dlss/move-label-building
Browse files Browse the repository at this point in the history
Move label building from PublicXmlService to PublicCocinaService
  • Loading branch information
jcoyne authored May 1, 2024
2 parents 8a4f25c + 2cc415d commit c5215f7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
6 changes: 4 additions & 2 deletions app/services/publish/public_cocina_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ def initialize(cocina)
@cocina = cocina
end

# update the label to match what is in the description.title (used by sul-embed and searchworks_traject_indexer (via PublicXmlService))
# remove any file that is not published
# remove any file_set that doesn't have at least one published file
# remove partOfProject (similar to how we remove tags from identityMetadata)
def build
label = Cocina::Models::Builders::TitleBuilder.build(cocina.description.title)
if cocina.dro?
cocina.new(structural: build_structural, administrative: build_administrative)
cocina.new(label:, structural: build_structural, administrative: build_administrative)
elsif cocina.collection?
cocina.new(administrative: build_administrative)
cocina.new(label:, administrative: build_administrative)
else
raise "unexpected call to PublicCocinaService.build for #{cocina.externalIdentifier}"
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/publish/public_xml_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def release_date

# catkeys are used by PURL
# objectType is used by purl-fetcher
# objectLabel is used by https://github.com/sul-dlss/searchworks_traject_indexer/blob/b5ed9906a5a0130eca5e68fbb0e8633bdbe6ffd6/lib/sdr_stuff.rb#L54
# objectLabel is used by https://github.com/sul-dlss/searchworks_traject_indexer/blob/72195e34e364fb2c191c40b23fe51679746f6419/lib/public_xml_record.rb#L34
# Barcode and sourceId are used by the CdlController in Stacks https://github.com/sul-dlss/stacks/blame/master/app/controllers/cdl_controller.rb#L121
def public_identity_metadata
nodes = catalog_record_ids(SYMPHONY).map { |catkey| " <otherId name=\"catkey\">#{catkey}</otherId>" }
Expand All @@ -87,7 +87,7 @@ def public_identity_metadata
<<~XML
<identityMetadata>
<objectType>#{public_cocina.collection? ? 'collection' : 'item'}</objectType>
<objectLabel>#{Cocina::Models::Builders::TitleBuilder.build(public_cocina.description.title)}</objectLabel>
<objectLabel>#{public_cocina.label}</objectLabel>
#{nodes.join("\n")}
</identityMetadata>
XML
Expand Down
4 changes: 2 additions & 2 deletions spec/services/publish/metadata_transfer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
before do
expect_any_instance_of(described_class).to receive(:transfer_to_document_store).with(/{"cocinaVersion"/, 'cocina.json')
expect_any_instance_of(described_class).to receive(:transfer_to_document_store).with(/<publicObject/, 'public')
expect_any_instance_of(described_class).to receive(:publish_notify_on_success).with(cocina_object)
expect_any_instance_of(described_class).to receive(:publish_notify_on_success).with(Cocina::Models::DRO)
end

let(:access) { { view: 'citation-only', download: 'none' } }
Expand All @@ -133,7 +133,7 @@
before do
expect_any_instance_of(described_class).to receive(:transfer_to_document_store).with(/{"cocinaVersion"/, 'cocina.json')
expect_any_instance_of(described_class).to receive(:transfer_to_document_store).with(/<publicObject/, 'public')
expect_any_instance_of(described_class).to receive(:publish_notify_on_success).with(cocina_object)
expect_any_instance_of(described_class).to receive(:publish_notify_on_success).with(Cocina::Models::Collection)
expect_any_instance_of(described_class).to receive(:republish_members!).with(no_args)
end

Expand Down
12 changes: 11 additions & 1 deletion spec/services/publish/public_cocina_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@

context 'with a DRO' do
let(:publish_files) { false }
let(:druid) { 'druid:bc123df4567' }

let(:cocina_object) do
build(:dro).new(
build(:dro, id: druid).new(
description: {
title: [{ value: 'Constituent label &amp; A Special character' }],
purl: "https://purl.stanford.edu/#{druid.delete_prefix('druid:')}"
},
structural: {
contains: [
{
Expand Down Expand Up @@ -124,6 +130,10 @@
)
end

it 'updates the label' do
expect(create.label).to eq 'Constituent label &amp; A Special character'
end

context 'when there are no published files' do
it 'discards the non-published filesets and files' do
expect(create.structural.contains.size).to eq 0
Expand Down
21 changes: 7 additions & 14 deletions spec/services/publish/public_xml_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

let(:thumbnail_service) { ThumbnailService.new(public_cocina) }

let(:description) do
{
title: [{ value: 'Constituent label &amp; A Special character' }],
purl: "https://purl.stanford.edu/#{druid.delete_prefix('druid:')}"
}
end
let(:structural) do
{
contains: [{
Expand Down Expand Up @@ -71,7 +65,7 @@

context 'when there are no release tags' do
let(:public_cocina) do
build(:dro, id: druid).new(description:)
build(:dro, id: druid)
end

it 'does not include a releaseData element and any info in identityMetadata' do
Expand Down Expand Up @@ -124,8 +118,7 @@

context 'produces xml with' do
let(:public_cocina) do
build(:dro, id: druid).new(
description:,
build(:dro, id: druid, label: 'Constituent label &amp; A Special character').new(
structural:,
identification: {
barcode: '36105132211504',
Expand Down Expand Up @@ -277,7 +270,7 @@

context 'when no thumb is present' do
let(:public_cocina) do
build(:dro, id: druid).new(description:)
build(:dro, id: druid)
end

it 'does not add a thumb node' do
Expand All @@ -293,7 +286,7 @@

context 'when there are single release tags per target' do
let(:public_cocina) do
build(:dro, id: druid).new(description:, administrative:)
build(:dro, id: druid).new(administrative:)
end

let(:administrative) do
Expand All @@ -320,7 +313,7 @@

context 'with a collection' do
let(:public_cocina) do
build(:collection, id: druid).new(description:)
build(:collection, id: druid, label: 'Constituent label &amp; A Special character')
end

it 'publishes the expected datastreams' do
Expand All @@ -343,7 +336,7 @@

context 'when there are release tags' do
let(:public_cocina) do
build(:collection, id: druid).new(description:, administrative:)
build(:collection, id: druid).new(administrative:)
end

let(:administrative) do
Expand Down Expand Up @@ -371,7 +364,7 @@
context 'with external references' do
let(:druid) { 'druid:hj097bm8879' }
let(:public_cocina) do
build(:dro, id: druid, type: Cocina::Models::ObjectType.map).new(description:, structural:)
build(:dro, id: druid, type: Cocina::Models::ObjectType.map).new(structural:)
end
let(:structural) do
{
Expand Down

0 comments on commit c5215f7

Please sign in to comment.