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



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 17

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

Instance Method Details

#ensure_non_versionableObject



40
41
42
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 40

def ensure_non_versionable
  self.versionable = 'false'
end

#prefixObject

maintain AF < 8 indexing behavior



109
110
111
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 109

def prefix
  ''
end

#release_access_nodeNokogiri::XML::Element

Returns The releaseAccess node.

Returns:

  • (Nokogiri::XML::Element)

    The releaseAccess node



92
93
94
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 92

def release_access_node
  find_by_terms(:release_access).first
end

#release_access_node=(new_doc) ⇒ Object

Sets the embargaAccess node

Parameters:



98
99
100
101
102
103
104
105
106
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 98

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

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

#release_dateTime

Current releaseDate value

Returns:

  • (Time)


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

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

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

Sets the release date. Does NOT convert to beginning-of-day.

Parameters:

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

    the release date object



59
60
61
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 59

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

#statusObject



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

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



49
50
51
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 49

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

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



30
31
32
33
34
35
36
37
38
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 30

def to_solr(solr_doc = {}, *args)
  solr_doc = super
  #::Solrizer.insert_field(solr_doc, field_name, value, *index_types)
  rd1  = release_date
  rd20 = twenty_pct_release_date
  ::Solrizer.insert_field(solr_doc, 'embargo_release', rd1.utc.strftime('%FT%TZ'), :dateable) unless rd1.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)


86
87
88
89
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 86

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



80
81
82
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 80

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



74
75
76
# File 'lib/dor/datastreams/embargo_metadata_ds.rb', line 74

def twenty_pct_status
  term_values(:twenty_pct_status).first
end

#twenty_pct_status=(new_status) ⇒ Object



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

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