Module: Dor::Embargoable

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

Instance Method Summary collapse

Instance Method Details

#embargoed?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/dor/models/concerns/embargoable.rb', line 66

def embargoed?
  .status == 'embargoed'
end

#release_20_pct_vis_embargo(release_agent = 'unknown') ⇒ Object



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

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(&: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

#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

Parameters:

  • release_agent (String) (defaults to: 'unknown')

    name of the person, application or thing that released embargo



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

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(&: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

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

#update_embargo(new_date) ⇒ Object

Raises:

  • (ArgumentError)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dor/models/concerns/embargoable.rb', line 70

def update_embargo(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
  .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