Skip to content

Commit

Permalink
Merge pull request #4844 from sul-dlss/t4757-remove_release_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Apr 11, 2024
2 parents 376c355 + cabcc16 commit 6f4b3b7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 146 deletions.
28 changes: 3 additions & 25 deletions app/services/release_tag_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,11 @@ def self.released_to_searchworks?(cocina_object:)
.find { |tag| tag.to.casecmp?('Searchworks') }&.release || false
end

# Creates ReleaseTag model objects if and only if there are existing ReleaseTag model objects for the item.
# For now it continues to add release tags to the Cocina
# The effect of this will be that ReleaseTag model objects will only be created for items that have been migrated.
# Creates ReleaseTag model objects.
# @param cocina_object [Cocina::Models::DRO, Cocina::Models::Collection] the object to add to
# @param [Cocina::Models::ReleaseTag] tag
def self.create(cocina_object:, tag:)
druid = cocina_object.externalIdentifier
ReleaseTag.from_cocina(druid:, tag:).save! if ReleaseTag.exists?(druid:)
updated_object = cocina_object.new(
administrative: cocina_object.administrative.new(
releaseTags: Array(cocina_object.administrative.releaseTags) + [tag]
)
)
CocinaObjectStore.store(updated_object, skip_lock: true)
ReleaseTag.from_cocina(druid: cocina_object.externalIdentifier, tag:).save!
end

def initialize(cocina_object)
Expand All @@ -57,20 +48,7 @@ def item_tags
private

def tags_for(druid)
release_tags = ReleaseTag.where(druid:).to_a
# If this object's release tags haven't been migrated to ReleaseTag model objects, get from cocina.
return tags_from_cocina(druid) if release_tags.empty?

release_tags.map(&:to_cocina)
end

def tags_from_cocina(druid)
from_cocina_object = if cocina_object.externalIdentifier == druid
cocina_object
else
CocinaObjectStore.find(druid)
end
from_cocina_object.administrative.releaseTags
ReleaseTag.where(druid:).map(&:to_cocina)
end

def collection_tags
Expand Down
11 changes: 5 additions & 6 deletions spec/requests/release_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
describe '#index' do
context 'when a DRO' do
let(:cocina_object) do
build(:dro, id: druid).new(
administrative: {
hasAdminPolicy: 'druid:hy787xj5878',
releaseTags: [tag]
}
)
build(:dro, id: druid)
end

before do
ReleaseTag.from_cocina(druid:, tag:).save!
end

it 'returns the release tags' do
Expand Down
38 changes: 3 additions & 35 deletions spec/services/publish/metadata_transfer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,7 @@
access:,
structural: { contains: [], isMemberOf: ['druid:xh235dd9059'] },
administrative: {
hasAdminPolicy: 'druid:fg890hx1234',
releaseTags: [
{
who: 'dhartwig',
what: 'collection',
date: '2019-01-18T17:03:35.000+00:00',
to: 'Searchworks',
release: true
},
{
who: 'dhartwig',
what: 'collection',
date: '2020-01-18T17:03:35.000+00:00',
to: 'Some_special_place',
release: true
}
]
hasAdminPolicy: 'druid:fg890hx1234'
}
)
end
Expand Down Expand Up @@ -56,23 +40,7 @@
access: { view: 'world' },
structural: { contains: [], isMemberOf: ['druid:xh235dd9059'] },
administrative: {
hasAdminPolicy: 'druid:fg890hx1234',
releaseTags: [
{
who: 'dhartwig',
what: 'collection',
date: '2019-01-18T17:03:35.000+00:00',
to: 'Searchworks',
release: true
},
{
who: 'dhartwig',
what: 'collection',
date: '2020-01-18T17:03:35.000+00:00',
to: 'Some_special_place',
release: true
}
]
hasAdminPolicy: 'druid:fg890hx1234'
}
)
end
Expand Down Expand Up @@ -150,7 +118,7 @@

let(:access) { { view: 'citation-only', download: 'none' } }

it 'identityMetadta, contentMetadata, rightsMetadata, generated dublin core, and public xml' do
it 'identityMetadata, contentMetadata, rightsMetadata, generated dublin core, and public xml' do
service.publish
expect(Publish::PublicXmlService).to have_received(:new).with(public_cocina: Cocina::Models::DRO, thumbnail_service:)
expect(Publish::PublicDescMetadataService).to have_received(:new).with(Cocina::Models::DRO)
Expand Down
74 changes: 35 additions & 39 deletions spec/services/publish/public_xml_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

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

it 'does not include a releaseData element and any info in identityMetadata' do
Expand All @@ -82,7 +82,7 @@

context 'with an embargo' do
let(:cocina_object) do
build(:dro, id: 'druid:bc123df4567').new(
build(:dro, id: druid).new(
access: {
view: 'world',
download: 'world',
Expand All @@ -104,7 +104,7 @@

context 'with a problematic location code' do
let(:cocina_object) do
build(:dro, id: 'druid:bc123df4567').new(
build(:dro, id: druid).new(
access: {
view: 'location-based',
download: 'location-based',
Expand All @@ -124,7 +124,7 @@

context 'produces xml with' do
let(:cocina_object) do
build(:dro, id: 'druid:bc123df4567').new(
build(:dro, id: druid).new(
description:,
structural:,
identification: {
Expand Down Expand Up @@ -269,7 +269,7 @@

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

it 'does not add a thumb node' do
Expand All @@ -283,13 +283,12 @@

context 'when there are single release tags per target' do
let(:cocina_object) do
build(:dro, id: 'druid:bc123df4567').new(description:, administrative: {
hasAdminPolicy: 'druid:qv648vd4392',
releaseTags: [
{ to: 'Searchworks', release: true, date: '2015-10-23T21:49:29.000+00:00', what: 'self' },
{ to: 'PURL sitemap', release: true, date: '2015-10-23T21:49:29.000+00:00', what: 'self' }
]
})
build(:dro, id: druid).new(description:)
end

before do
ReleaseTag.create!(druid:, who: 'petucket', what: 'self', released_to: 'Searchworks', release: true)
ReleaseTag.create!(druid:, who: 'petucket', what: 'self', released_to: 'PURL sitemap', release: true)
end

it 'does not include this release data in identityMetadata' do
Expand All @@ -305,14 +304,13 @@

context 'when there are multiple release tags per target' do
let(:cocina_object) do
build(:dro, id: 'druid:bc123df4567').new(description:, administrative: {
hasAdminPolicy: 'druid:qv648vd4392',
releaseTags: [
{ to: 'Searchworks', release: false, date: '2015-10-23T21:49:29.000+00:00', what: 'self' },
{ to: 'Searchworks', release: true, date: '2018-10-23T21:49:29.000+00:00', what: 'self' },
{ to: 'Some_special_place', release: true, date: '2015-10-23T21:49:29.000+00:00', what: 'self' }
]
})
build(:dro, id: druid).new(description:)
end

before do
ReleaseTag.create!(druid:, who: 'petucket', what: 'self', released_to: 'Searchworks', release: true)
ReleaseTag.create!(druid:, who: 'petucket', what: 'self', released_to: 'Searchworks', release: false, created_at: 1.year.ago)
ReleaseTag.create!(druid:, who: 'petucket', what: 'self', released_to: 'PURL sitemap', release: true)
end

it 'does not include this release data in identityMetadata' do
Expand All @@ -323,14 +321,14 @@
releases = ng_xml.xpath('/publicObject/releaseData/release')
expect(releases.size).to eq 2
expect(releases.map(&:inner_text)).to eq %w[true true]
expect(releases.pluck('to')).to eq %w[Searchworks Some_special_place]
expect(releases.pluck('to')).to eq ['Searchworks', 'PURL sitemap']
end
end
end

context 'with a collection' do
let(:cocina_object) do
build(:collection, id: 'druid:bc123df4567').new(description:)
build(:collection, id: druid).new(description:)
end

it 'publishes the expected datastreams' do
Expand All @@ -353,13 +351,12 @@

context 'when there are single release tags per target' do
let(:cocina_object) do
build(:collection, id: 'druid:bc123df4567').new(description:, administrative: {
hasAdminPolicy: 'druid:qv648vd4392',
releaseTags: [
{ to: 'Searchworks', what: 'collection', release: true, date: '2015-10-23T21:49:29.000+00:00' },
{ to: 'Some_special_place', what: 'collection', release: true, date: '2015-10-23T21:49:29.000+00:00' }
]
})
build(:collection, id: druid).new(description:)
end

before do
ReleaseTag.create!(druid:, who: 'petucket', what: 'collection', released_to: 'Searchworks', release: true)
ReleaseTag.create!(druid:, who: 'petucket', what: 'collection', released_to: 'PURL sitemap', release: true)
end

it 'does not include this release data in identityMetadata' do
Expand All @@ -369,20 +366,19 @@
it 'includes releaseData element from release tags' do
releases = ng_xml.xpath('/publicObject/releaseData/release')
expect(releases.map(&:inner_text)).to eq %w[true true]
expect(releases.pluck('to')).to eq %w[Searchworks Some_special_place]
expect(releases.pluck('to')).to eq ['Searchworks', 'PURL sitemap']
end
end

context 'when there are multiple release tags per target' do
let(:cocina_object) do
build(:collection, id: 'druid:bc123df4567').new(description:, administrative: {
hasAdminPolicy: 'druid:qv648vd4392',
releaseTags: [
{ to: 'Searchworks', what: 'collection', release: false, date: '2015-10-23T21:49:29.000+00:00' },
{ to: 'Searchworks', what: 'collection', release: true, date: '2018-10-23T21:49:29.000+00:00' },
{ to: 'Some_special_place', what: 'collection', release: true, date: '2015-10-23T21:49:29.000+00:00' }
]
})
build(:collection, id: druid).new(description:)
end

before do
ReleaseTag.create!(druid:, who: 'petucket', what: 'collection', released_to: 'Searchworks', release: true)
ReleaseTag.create!(druid:, who: 'petucket', what: 'collection', released_to: 'Searchworks', release: false, created_at: 1.year.ago)
ReleaseTag.create!(druid:, who: 'petucket', what: 'collection', released_to: 'PURL sitemap', release: true)
end

it 'does not include this release data in identityMetadata' do
Expand All @@ -393,7 +389,7 @@
releases = ng_xml.xpath('/publicObject/releaseData/release')
expect(releases.size).to eq 2
expect(releases.map(&:inner_text)).to eq %w[true true]
expect(releases.pluck('to')).to eq %w[Searchworks Some_special_place]
expect(releases.pluck('to')).to eq ['Searchworks', 'PURL sitemap']
end
end
end
Expand Down
43 changes: 2 additions & 41 deletions spec/services/release_tag_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
before do
create(:release_tag, druid:, released_to: 'Searchworks', release: true)
end
# let(:release_data) { [{ to: 'Searchworks', release: true }] }

it { is_expected.to be true }
end
Expand Down Expand Up @@ -182,26 +181,8 @@
allow(CocinaObjectStore).to receive(:store)
end

context 'when ReleaseTag objects already exist for this item' do
before do
create(:release_tag, druid:)
end

it 'adds another release tag and records to the cocina' do
expect { create_tag }.to change { ReleaseTag.where(druid:).count }.by(1)
expect(CocinaObjectStore).to have_received(:store) do |dro|
expect(dro.administrative.releaseTags.size).to eq 4
end
end
end

context 'when no ReleaseTag objects exist for this item' do
it 'records to the cocina and adds no ReleaseTag' do
expect { create_tag }.not_to(change { ReleaseTag.where(druid:).count })
expect(CocinaObjectStore).to have_received(:store) do |dro|
expect(dro.administrative.releaseTags.size).to eq 4
end
end
it 'adds another release tag and' do
expect { create_tag }.to change { ReleaseTag.where(druid:).count }.by(1)
end
end

Expand All @@ -217,25 +198,5 @@
]
end
end

context 'when no ReleaseTag objects exist for this item' do
let(:cocina_release_tags) do
[
{
who: 'carrickr',
what: 'collection',
date: '2015-01-06T23:33:47.000+00:00',
to: 'Revs',
release: true
}
]
end

it 'returns release tags from the cocina object' do
expect(releases).to eq [
Cocina::Models::ReleaseTag.new(to: 'Revs', release: true, date: '2015-01-06T23:33:47Z', who: 'carrickr', what: 'collection')
]
end
end
end
end

0 comments on commit 6f4b3b7

Please sign in to comment.