Class: Dor::ReleaseTagService

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/release_tag_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ ReleaseTagService

Returns a new instance of ReleaseTagService.



12
13
14
# File 'lib/dor/services/release_tag_service.rb', line 12

def initialize(item)
  @item = item
end

Class Method Details

.for(item) ⇒ Hash{String => Boolean}

Determine projects in which an item is released

Parameters:

  • item (Dor::Item)

    to get the release tags for

Returns:

  • (Hash{String => Boolean})

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



8
9
10
# File 'lib/dor/services/release_tag_service.rb', line 8

def self.for(item)
  new(item)
end

Instance Method Details

#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



79
80
81
# File 'lib/dor/services/release_tag_service.rb', line 79

def newest_release_tag(tags)
  Hash[tags.map { |key, val| [key, newest_release_tag_in_an_array(val)] }]
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



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dor/services/release_tag_service.rb', line 62

def release_tags
  release_tags = item..ng_xml.xpath('//release')
  return_hash = {}
  release_tags.each do |release_tag|
    hashed_node = release_tag_node_to_hash(release_tag)
    if !return_hash[hashed_node[:to]].nil?
      return_hash[hashed_node[:to]] << hashed_node[:attrs]
    else
      return_hash[hashed_node[:to]] = [hashed_node[:attrs]]
    end
  end
  return_hash
end

#release_tags_for_item_and_all_governing_setsHash

Take an item and get all of its release tags and all tags on collections it is a member of it

Returns:

  • (Hash)

    a hash of all tags



50
51
52
53
54
55
56
57
58
# File 'lib/dor/services/release_tag_service.rb', line 50

def release_tags_for_item_and_all_governing_sets
  return_tags = release_tags || {}
  item.collections.each do |collection|
    next if collection.id == item.id # recursive, so parents of parents are found, but we need to avoid an infinite loop if the collection references itself (i.e. bad data)

    return_tags = combine_two_release_tag_hashes(return_tags, collection.releases.release_tags_for_item_and_all_governing_sets)
  end
  return_tags
end

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

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

Returns:

  • (Hash{String => Boolean})

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dor/services/release_tag_service.rb', line 19

def released_for(skip_live_purl:)
  released_hash = {}

  # Get the most recent self tag for all targets and retain their result since most recent self always trumps any other non self tags
  latest_self_tags = newest_release_tag self_release_tags(release_tags)
  latest_self_tags.each do |key, payload|
    released_hash[key] = { 'release' => payload['release'] }
  end

  # With Self Tags resolved we now need to deal with tags on all sets this object is part of.
  # Get all release tags on the item and strip out the what = self ones, we've already processed all the self tags on this item.
  # This will be where we store all tags that apply, regardless of their timestamp:
  potential_applicable_release_tags = tags_for_what_value(release_tags_for_item_and_all_governing_sets, 'collection')
  administrative_tags = item.tags # Get admin tags once here and pass them down

  # We now have the keys for all potential releases, we need to check the tags: the most recent timestamp with an explicit true or false wins.
  # In a nil case, the lack of an explicit false tag we do nothing.
  (potential_applicable_release_tags.keys - released_hash.keys).each do |key| # don't bother checking if already added to the release hash, they were added due to a self tag so that has won
    latest_tag = latest_applicable_release_tag_in_array(potential_applicable_release_tags[key], administrative_tags)
    next if latest_tag.nil? # Otherwise, we have a valid tag, record it

    released_hash[key] = { 'release' => latest_tag['release'] }
  end

  # See what the application is currently released for on Purl.  If released in purl but not listed here, it needs to be added as a false
  add_tags_from_purl(released_hash) unless skip_live_purl
  released_hash
end