Sha256: 8cce05baf7509f3372c5df94e5c96fe54cbdf1824b145c1b3d0068d9d41d9c5f
Contents?: true
Size: 1.91 KB
Versions: 3
Compression:
Stored size: 1.91 KB
Contents
# frozen_string_literal: true module Dor module Workflow module Response # The response from asking the server about a workflow for an item class Workflow extend Deprecation self.deprecation_horizon = '4.x' def initialize(xml:) @xml = xml end def pid workflow['objectId'] end def workflow_name workflow['id'] end def repository workflow['repository'] end deprecation_deprecate :repository # @param [Integer] version the version we are checking for. def active_for?(version:) result = ng_xml.at_xpath("/workflow/process[@version=#{version}]") result ? true : false end # Returns the process, for the most recent version that matches the given name: def process_for_recent_version(name:) nodes = process_nodes_for(name: name) node = nodes.max { |a, b| a.attr('version').to_i <=> b.attr('version').to_i } attributes = node ? Hash[node.attributes.collect { |k, v| [k.to_sym, v.value] }] : {} Process.new(parent: self, **attributes) end def empty? ng_xml.xpath('/workflow/process').empty? end def complete? ng_xml.xpath("/workflow/process[@version=#{version}]/@status").map(&:value).all? { |p| %w[skipped completed].include?(p) } end attr_reader :xml private # Return the max version in this workflow document def version ng_xml.xpath('/workflow/process/@version').map { |attr| attr.value.to_i }.max end def workflow ng_xml.at_xpath('workflow') end def process_nodes_for(name:) ng_xml.xpath("/workflow/process[@name = '#{name}']") end def ng_xml @ng_xml ||= Nokogiri::XML(@xml) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems