Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Adds publish_notify_on_success to touch change files in the PURL file…
Browse files Browse the repository at this point in the history
…system
  • Loading branch information
Darren Hardy committed Aug 15, 2016
1 parent ab1bc2f commit 5e43c01
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/dor/models/publishable.rb
@@ -1,4 +1,5 @@
require 'dor/datastreams/content_metadata_ds'
require 'fileutils'

module Dor
module Publishable
Expand Down Expand Up @@ -61,6 +62,7 @@ def publish_metadata
end
DigitalStacksService.transfer_to_document_store(pid, public_xml, 'public')
DigitalStacksService.transfer_to_document_store(pid, generate_public_desc_md, 'mods') if metadata_format == 'mods'
publish_notify_on_success
else
# Clear out the document cache for this item
DigitalStacksService.prune_purl_dir pid
Expand All @@ -74,5 +76,15 @@ def publish_metadata_remotely
endpoint.post ''
endpoint.url
end

##
# When publishing a PURL, we drop a `aa11bb2222` file into the `local_recent_changes` folder
# to notify other applications watching the filesystem (i.e., purl-fetcher).
# @param [String] `local_recent_changes` usually `/purl/recent_changes`
def publish_notify_on_success(local_recent_changes = Config.stacks.local_recent_changes)
raise ArgumentError, "Missing local_recent_changes directory: #{local_recent_changes}" unless File.directory?(local_recent_changes)
id = pid.gsub(/^druid:/, '')
FileUtils.touch(File.join(local_recent_changes, id))
end
end
end
23 changes: 23 additions & 0 deletions spec/dor/publishable_spec.rb
Expand Up @@ -327,6 +327,7 @@ class ItemizableItem < ActiveFedora::Base
expect(Dor::DigitalStacksService).to receive(:transfer_to_document_store).with('druid:ab123cd4567', /<oai_dc:dc/, 'dc')
expect(Dor::DigitalStacksService).to receive(:transfer_to_document_store).with('druid:ab123cd4567', /<publicObject/, 'public')
expect(Dor::DigitalStacksService).to receive(:transfer_to_document_store).with('druid:ab123cd4567', /<mods:mods/, 'mods')
expect(@item).to receive(:publish_notify_on_success).with(no_args)
end
it 'identityMetadta, contentMetadata, rightsMetadata, generated dublin core, and public xml' do
@item.rightsMetadata.content = "<rightsMetadata><access type='discover'><machine><world/></machine></access></rightsMetadata>"
Expand All @@ -340,6 +341,28 @@ class ItemizableItem < ActiveFedora::Base
end
end

context 'publish_notify_on_success' do
let(:dir) { '/my/dir' }
it 'writes empty file' do
Dor::Config.push! {|config| config.stacks.local_recent_changes dir}
expect(File).to receive(:directory?).with(dir).and_return(true)
expect(FileUtils).to receive(:touch).with(dir + '/ab123cd4567')
@item.publish_notify_on_success
end
it 'writes empty file even when given only the base id' do
Dor::Config.push! {|config| config.stacks.local_recent_changes dir}
expect(File).to receive(:directory?).with(dir).and_return(true)
expect(@item).to receive(:pid).and_return('aa111bb2222')
expect(FileUtils).to receive(:touch).with(dir + '/aa111bb2222')
@item.publish_notify_on_success
end
it 'raises error if not configured' do
expect(File).to receive(:directory?).with(nil).and_return(false)
expect(FileUtils).not_to receive(:touch)
expect { @item.publish_notify_on_success }.to raise_error(ArgumentError, /Missing local_recent_changes directory/)
end
end

context 'error handling' do
it 'throws an exception if any of the required datastreams are missing' do
skip 'write an error handling test'
Expand Down

0 comments on commit 5e43c01

Please sign in to comment.