Module: Dor::Embargoable

Extended by:
ActiveSupport::Concern
Included in:
Item
Defined in:
lib/dor/models/embargoable.rb

Instance Method Summary collapse

Instance Method Details

#release_20_pct_vis_embargo(release_agent = 'unknown') ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dor/models/embargoable.rb', line 42

def release_20_pct_vis_embargo(release_agent = 'unknown')
  # Set status to released
  embargo_md = datastreams['embargoMetadata']
  embargo_md.twenty_pct_status = 'released'

  # Remove all read acces nodes
  rights_md = datastreams['rightsMetadata']
  rights_xml = rights_md.ng_xml
  rights_md.ng_xml_will_change!
  rights_xml.xpath("//rightsMetadata/access[@type='read']").each { |n| n.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

  datastreams['events'].add_event('embargo', release_agent, '20% Visibility Embargo released')
end

#release_embargo(release_agent = 'unknown') ⇒ Object

Note:

The caller should save the object to fedora to commit the changes

Manipulates datastreams in the object when embargo is lifted: Sets embargo status to released in embargoMetadata Modifies rightsMetadata to remove embargoReleaseDate and updates/adds access from embargoMetadata/releaseAccess



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dor/models/embargoable.rb', line 17

def release_embargo(release_agent = 'unknown')
  # Set status to released
  embargo_md = datastreams['embargoMetadata']
  embargo_md.status = 'released'

  # Remove all read acces nodes
  rights_md = datastreams['rightsMetadata']
  rights_xml = rights_md.ng_xml
  rights_md.ng_xml_will_change!
  rights_xml.xpath("//rightsMetadata/access[@type='read']").each { |n| n.remove }

  # Replace rights <access> nodes with those from embargoMetadta
  release_access = embargo_md.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

  datastreams['events'].add_event('embargo', release_agent, 'Embargo released')
end

#update_embargo(new_date) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/dor/models/embargoable.rb', line 64

def update_embargo(new_date)
  if .status != 'embargoed'
    raise ArgumentError, 'You cannot change the embargo date of an item that is not embargoed.'
  end
  if new_date.past?
    raise ArgumentError, 'You cannot set the embargo date to a past date.'
  end
  updated = false
  .ng_xml.search('//embargoReleaseDate').each do |node|
    node.content = new_date.beginning_of_day.utc.xmlschema
    updated = true
  end
  .ng_xml_will_change!
  .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