Class: Dor::EmbargoMetadataDS

Inherits:
ActiveFedora::OmDatastream
  • Object
show all
Defined in:
lib/dor/datastreams/embargo_metadata_ds.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.xml_templateObject

Default EmbargoMetadataDS xml



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 23

def self.xml_template
  builder = Nokogiri::XML::Builder.new do |xml|
    xml. do
      xml.status
      xml.releaseDate
      xml.releaseAccess
      xml.twentyPctVisibilityStatus
      xml.twentyPctVisibilityReleaseDate
    end
  end
  builder.doc
end

Instance Method Details

#ensure_non_versionableObject



44
45
46
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 44

def ensure_non_versionable
  self.versionable = 'false'
end

#prefixObject

maintain AF < 8 indexing behavior



98
99
100
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 98

def prefix
  ''
end

#release_access_nodeNokogiri::XML::Element

Returns The releaseAccess node.

Returns:

  • (Nokogiri::XML::Element)

    The releaseAccess node



83
84
85
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 83

def release_access_node
  find_by_terms(:release_access).first
end

#release_access_node=(new_doc) ⇒ Object

Sets the embargaAccess node

Parameters:



89
90
91
92
93
94
95
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 89

def release_access_node=(new_doc)
  raise 'Trying to replace releaseAccess with a non-releaseAccess document' if new_doc.root.name != 'releaseAccess'

  term_value_delete(select: '//embargoMetadata/releaseAccess')
  ng_xml_will_change!
  ng_xml.root.add_child(new_doc.root.clone)
end

#statusObject



57
58
59
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 57

def status
  term_values(:status).first
end

#status=(new_status) ⇒ Object

Convenience methods to get and set embargo properties Hides complexity/verbosity of OM TermOperators for simple, non-repeating values



53
54
55
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 53

def status=(new_status)
  update_values([:status] => new_status)
end

#to_solr(solr_doc = {}, *args) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 36

def to_solr(solr_doc = {}, *args)
  solr_doc = super
  rd20 = twenty_pct_release_date
  ::Solrizer.insert_field(solr_doc, 'embargo_release', release_date.first.utc.strftime('%FT%TZ'), :dateable) unless release_date.first.blank?
  ::Solrizer.insert_field(solr_doc, 'twenty_pct_visibility_release', rd20.utc.strftime('%FT%TZ'), :dateable) unless rd20.blank?
  solr_doc
end

#twenty_pct_release_dateTime

Current twentyPctVisibilityReleaseDate value

Returns:

  • (Time)


77
78
79
80
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 77

def twenty_pct_release_date
  rd = term_values(:twenty_pct_release_date).first
  rd.nil? || rd.empty? ? nil : Time.parse(rd)
end

#twenty_pct_release_date=(rd = Time.now.utc) ⇒ Object

Sets the 20% visibility release date. Converts the date to beginning-of-day, UTC to help with Solr indexing

Parameters:

  • rd (Time) (defaults to: Time.now.utc)

    A Time object represeting the release date. By default, it is set to now



71
72
73
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 71

def twenty_pct_release_date=(rd = Time.now.utc)
  update_values([:twenty_pct_release_date] => rd.beginning_of_day.utc.xmlschema)
end

#twenty_pct_statusObject



65
66
67
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 65

def twenty_pct_status
  term_values(:twenty_pct_status).first
end

#twenty_pct_status=(new_status) ⇒ Object



61
62
63
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 61

def twenty_pct_status=(new_status)
  update_values([:twenty_pct_status] => new_status)
end