Module: Dor::Releaseable

Extended by:
ActiveSupport::Concern, Deprecation
Included in:
Collection, Item
Defined in:
lib/dor/models/concerns/releaseable.rb

Instance Method Summary collapse

Instance Method Details

#add_release_node(release, attrs = {}) ⇒ Nokogiri::XML::Element

Add a release node for the item Will use the current time if timestamp not supplied. You can supply a timestap for correcting history, etc if desired Timestamp will be calculated by the function

Examples:

item.add_release_node(true,{:what=>'self',:to=>'Searchworks',:who=>'petucket'})

Parameters:

  • release (Boolean)

    True or false for the release node

  • attrs (hash) (defaults to: {})

    A hash of any attributes to be placed onto the tag

Returns:

  • (Nokogiri::XML::Element)

    the tag added if successful

Raises:

  • (ArgumentError)

    Raised if attributes are improperly supplied



89
90
91
92
93
94
95
96
# File 'lib/dor/models/concerns/releaseable.rb', line 89

def add_release_node(release, attrs = {})
  allowed_release_attributes = %i[what to who when] # any other release attributes sent in will be rejected and not stored
   = 
  attrs.delete_if { |key, _value| !allowed_release_attributes.include?(key) }
  attrs[:when] = Time.now.utc.iso8601 if attrs[:when].nil? # add the timestamp
  valid_release_attributes(release, attrs)
  .add_value(:release, release.to_s, attrs)
end

#add_release_nodes_and_start_releaseWF(release_tags) ⇒ Object

Add release tags to an item and initialize the item release workflow Each tag should be of the form {:tag => ‘Fitch : Batch2’, :what => ‘self’, :to => ‘Searchworks’, :who => ‘petucket’, :release => true}

Parameters:

  • release_tags (Hash, Array<Hash>)

    hash of a single release tag or an array of many such hashes

Raises:

  • (ArgumentError)

    Raised if the tags are improperly supplied



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dor/models/concerns/releaseable.rb', line 16

def add_release_nodes_and_start_releaseWF(release_tags)
  release_tags = [release_tags] unless release_tags.is_a?(Array)

  # Add in each tag
  release_tags.each do |r_tag|
    add_release_node(r_tag[:release], r_tag)
  end

  # Save item to dor so the robots work with the latest data
  save
  create_workflow('releaseWF')
end

#get_newest_release_tag(tags) ⇒ Hash

Take a hash of tags as obtained via Dor::Item.release_tags and returns the newest tag for each namespace

Parameters:

  • tags (Hash)

    a hash of tags obtained via Dor::Item.release_tags or matching format

Returns:

  • (Hash)

    a hash of latest tags for each to value



46
47
48
# File 'lib/dor/models/concerns/releaseable.rb', line 46

def get_newest_release_tag(tags)
  releases.newest_release_tag(tags)
end

#release_tagsNokogiri::XML::NodeSet

Helper method to get the release tags as a nodeset

Returns:

  • (Nokogiri::XML::NodeSet)

    all release tags and their attributes



40
# File 'lib/dor/models/concerns/releaseable.rb', line 40

delegate :release_tags, to: :releases

#released_for(skip_live_purl = false) ⇒ Hash{String => Boolean}

Called in Dor::UpdateMarcRecordService (in dor-services-app too) Determine projects in which an item is released

Parameters:

  • skip_live_purl (Boolean) (defaults to: false)

    set true to skip requesting from purl backend

Returns:

  • (Hash{String => Boolean})

    all namespaces, keys are Project name Strings, values are Boolean



34
35
36
# File 'lib/dor/models/concerns/releaseable.rb', line 34

def released_for(skip_live_purl = false)
  releases.released_for(skip_live_purl: skip_live_purl)
end

#releasesObject



51
52
53
# File 'lib/dor/models/concerns/releaseable.rb', line 51

def releases
  @releases ||= ReleaseTagService.for(self)
end

#valid_release_attributes(tag, attrs = {}) ⇒ Boolean

Determine if the supplied tag is a valid release node that meets all requirements

Parameters:

  • tag (Boolean)

    True or false for the release node

  • attrs (hash) (defaults to: {})

    A hash of attributes for the tag, must contain :when, a ISO 8601 timestamp and :who to identify who or what added the tag, :to,

Returns:

  • (Boolean)

    Returns true if no errors found

Raises:

  • (ArgumentError)

    Raises an error of the first fault in the release tag



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/dor/models/concerns/releaseable.rb', line 105

def valid_release_attributes(tag, attrs = {})
  raise ArgumentError, ':when is not iso8601' if attrs[:when].match('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z').nil?

  %i[who to what].each do |check_attr|
    raise ArgumentError, "#{check_attr} not supplied as a String" if attrs[check_attr].class != String
  end
  raise ArgumentError, ':what must be self or collection' unless %w(self collection).include? attrs[:what]
  raise ArgumentError, 'the value set for this tag is not a boolean' unless [true, false].include? tag

  true
end

#valid_release_attributes_and_tag(tag, attrs = {}) ⇒ Boolean

Determine if the supplied tag is a valid release tag that meets all requirements

Parameters:

  • attrs (hash) (defaults to: {})

    A hash of attributes for the tag, must contain: :when, a ISO 8601 timestamp; :who, to identify who or what added the tag; and :to, a string identifying the release target

Returns:

  • (Boolean)

    Returns true if no errors found

Raises:

  • (RuntimeError)

    Raises an error of the first fault in the release tag



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dor/models/concerns/releaseable.rb', line 60

def valid_release_attributes_and_tag(tag, attrs = {})
  raise ArgumentError, ':when is not iso8601' if attrs[:when].match('\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z').nil?

  %i[who to what].each do |check_attr|
    raise ArgumentError, "#{check_attr} not supplied as a String" if attrs[check_attr].class != String
  end

  what_correct = false
  %w(self collection).each do |allowed_what_value|
    what_correct = true if attrs[:what] == allowed_what_value
  end
  raise ArgumentError, ':what must be self or collection' unless what_correct
  raise ArgumentError, 'the value set for this tag is not a boolean' if !!tag != tag # rubocop:disable Style/DoubleNegation

  true
end