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

Commit

Permalink
Refactor publish service
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 21, 2018
1 parent 34513bc commit ea8664d
Showing 1 changed file with 20 additions and 14 deletions.
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

0 comments on commit ea8664d

Please sign in to comment.