Class: Dor::EmbargoService
- Inherits:
-
Object
- Object
- Dor::EmbargoService
- Defined in:
- lib/dor/services/embargo_service.rb
Overview
Sets up and removes embargos on an object This assumes the object has embargoMetadata, rightsMetadata, and events datastreams
Instance Method Summary collapse
-
#initialize(obj) ⇒ EmbargoService
constructor
A new instance of EmbargoService.
-
#release(release_agent) ⇒ Object
Lift the embargo from the object Sets embargo status to released in embargoMetadata Modifies rightsMetadata to remove embargoReleaseDate and updates/adds access from embargoMetadata/releaseAccess.
- #release_20_pct_vis(release_agent) ⇒ Object
- #update(new_date) ⇒ Object
Constructor Details
#initialize(obj) ⇒ EmbargoService
Returns a new instance of EmbargoService.
7 8 9 |
# File 'lib/dor/services/embargo_service.rb', line 7 def initialize(obj) @obj = obj end |
Instance Method Details
#release(release_agent) ⇒ Object
Note:
The caller should save the object to fedora to commit the changes
Lift the embargo from the object Sets embargo status to released in embargoMetadata Modifies rightsMetadata to remove embargoReleaseDate and updates/adds access from embargoMetadata/releaseAccess
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dor/services/embargo_service.rb', line 16 def release(release_agent) # Set status to released .status = 'released' # Remove all read acces nodes rights_xml = rightsMetadata.ng_xml rightsMetadata.ng_xml_will_change! rights_xml.xpath("//rightsMetadata/access[@type='read']").each(&:remove) # Replace rights <access> nodes with those from embargoMetadta release_access = .release_access_node release_access.xpath('//releaseAccess/access').each do |new_access| access_sibling = rights_xml.at_xpath('//rightsMetadata/access[last()]') if access_sibling access_sibling.add_next_sibling(new_access.clone) else rights_xml.root.add_child(new_access.clone) end end events.add_event('embargo', release_agent, 'Embargo released') end |
#release_20_pct_vis(release_agent) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dor/services/embargo_service.rb', line 39 def release_20_pct_vis(release_agent) # Set status to released .twenty_pct_status = 'released' # Remove all read acces nodes rights_xml = rightsMetadata.ng_xml rightsMetadata.ng_xml_will_change! rights_xml.xpath("//rightsMetadata/access[@type='read']").each(&:remove) # Replace rights <access> nodes with 1 machine/world node access_sibling = rights_xml.at_xpath('//rightsMetadata/access[last()]') if access_sibling access_sibling.add_next_sibling(world_doc.root.clone) else rights_xml.root.add_child(world_doc.root.clone) end events.add_event('embargo', release_agent, '20% Visibility Embargo released') end |
#update(new_date) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dor/services/embargo_service.rb', line 59 def update(new_date) raise ArgumentError, 'You cannot change the embargo date of an item that is not embargoed.' if .status != 'embargoed' raise ArgumentError, 'You cannot set the embargo date to a past date.' if new_date.past? updated = false rightsMetadata.ng_xml.search('//embargoReleaseDate').each do |node| node.content = new_date.beginning_of_day.utc.xmlschema updated = true end rightsMetadata.ng_xml_will_change! rightsMetadata.save raise 'No release date in rights metadata, cannot proceed!' unless updated .ng_xml.xpath('//releaseDate').each do |node| node.content = new_date.beginning_of_day.utc.xmlschema end .ng_xml_will_change! .save end |