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

Refactor publish service #438

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions lib/dor/services/publish_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@ def initialize(item)

# Appends contentMetadata file resources from the source objects to this object
def publish
if world_discoverable?
dc_xml = item.generate_dublin_core.to_xml(&:no_declaration)
transfer_to_document_store(dc_xml, 'dc')
%w(identityMetadata contentMetadata rightsMetadata).each do |stream|
transfer_to_document_store(item.datastreams[stream].content.to_s, stream) if item.datastreams[stream]
end
transfer_to_document_store(item.public_xml, 'public')
transfer_to_document_store(item.generate_public_desc_md, 'mods')
publish_notify_on_success
else
# Clear out the document cache for this item
purl_druid.prune!
publish_delete_on_success
end
return unpublish unless world_discoverable?

transfer_metadata
publish_notify_on_success
end

private

attr_reader :item

def transfer_metadata
dc_xml = item.generate_dublin_core.to_xml(&:no_declaration)
transfer_to_document_store(dc_xml, 'dc')
%w(identityMetadata contentMetadata rightsMetadata).each do |stream|
transfer_to_document_store(item.datastreams[stream].content.to_s, stream) if item.datastreams[stream]
end
transfer_to_document_store(item.public_xml, 'public')
transfer_to_document_store(item.generate_public_desc_md, 'mods')
end

# Clear out the document cache for this item
def unpublish
purl_druid.prune!
publish_delete_on_success
end

def world_discoverable?
rights = item.rightsMetadata.ng_xml.clone.remove_namespaces!
rights.at_xpath("//rightsMetadata/access[@type='discover']/machine/world")
Expand Down