Class: Dor::ReleaseTags::IdentityMetadata
- Inherits:
-
Object
- Object
- Dor::ReleaseTags::IdentityMetadata
- Defined in:
- lib/dor/release_tags/identity_metadata.rb
Class Method Summary collapse
-
.for(item) ⇒ Hash{String => Boolean}
Determine projects in which an item is released.
Instance Method Summary collapse
-
#initialize(item) ⇒ IdentityMetadata
constructor
A new instance of IdentityMetadata.
-
#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.
-
#release_tags ⇒ Nokogiri::XML::NodeSet
Helper method to get the release tags as a nodeset.
-
#release_tags_for_item_and_all_governing_sets ⇒ Hash
Take an item and get all of its release tags and all tags on collections it is a member of it.
-
#released_for(released_hash) ⇒ Hash{String => Boolean}
Called in Dor::UpdateMarcRecordService (in dor-services-app too) Determine projects in which an item is released.
Constructor Details
#initialize(item) ⇒ IdentityMetadata
Returns a new instance of IdentityMetadata.
13 14 15 |
# File 'lib/dor/release_tags/identity_metadata.rb', line 13 def initialize(item) @item = item end |
Class Method Details
.for(item) ⇒ Hash{String => Boolean}
Determine projects in which an item is released
9 10 11 |
# File 'lib/dor/release_tags/identity_metadata.rb', line 9 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
78 79 80 |
# File 'lib/dor/release_tags/identity_metadata.rb', line 78 def newest_release_tag() Hash[.map { |key, val| [key, newest_release_tag_in_an_array(val)] }] end |
#release_tags ⇒ Nokogiri::XML::NodeSet
Helper method to get the release tags as a nodeset
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dor/release_tags/identity_metadata.rb', line 61 def = item.identityMetadata.ng_xml.xpath('//release') return_hash = {} .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_sets ⇒ Hash
Take an item and get all of its release tags and all tags on collections it is a member of it
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dor/release_tags/identity_metadata.rb', line 48 def = || {} 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) release_service = self.class.for(collection) = combine_two_release_tag_hashes(, release_service.) end end |
#released_for(released_hash) ⇒ Hash{String => Boolean}
Called in Dor::UpdateMarcRecordService (in dor-services-app too) Determine projects in which an item is released
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dor/release_tags/identity_metadata.rb', line 21 def released_for(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 = newest_release_tag () .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: = (, 'collection') = item. # 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. # Don't bother checking if already added to the release hash, they were added due to a self tag so that has won (.keys - released_hash.keys).each do |key| latest_tag = latest_applicable_release_tag_in_array([key], ) next if latest_tag.nil? # Otherwise, we have a valid tag, record it released_hash[key] = { 'release' => latest_tag['release'] } end released_hash end |