class VcoWorkflows::WorkflowPresentation

WorkflowPresentation is a helper class for Workflow and is primarily used internally to apply additional constraints to WorkflowParameters. Currently WorkflowPresentation examines the presentation JSON from vCO to determine whether input parameters for the workflow are required or not.

Attributes

presentation_data[R]

Accessor for the data structure @return [Hash] parsed JSON

required[R]

Get the list of required parameters for the workflow @return [String Array of strings (names of parameters)

Public Class Methods

new(workflow_service, workflow_id) click to toggle source

Create a new WorkflowPresentation @param [VcoWorkflows::WorkflowService] workflow_service workflow service to use @param [String] workflow_id workflow GUID @return [VcoWorkflows::WorkflowPresentation]

# File lib/vcoworkflows/workflowpresentation.rb, line 29
def initialize(workflow_service, workflow_id)
  @required = []
  @presentation_data = JSON.parse(workflow_service.get_presentation(workflow_id))

  # Determine if there are any required input parameters
  # We're parsing this because we specifically want to know if any of
  # the input parameters are marked as required. This is very specifically
  # in the array of hashes in:
  # presentation_data[:steps][0][:step][:elements][0][:fields]
  fields = @presentation_data['steps'][0]['step']['elements'][0]['fields']
  fields.each do |attribute|
    next unless attribute.key?('constraints')
    attribute['constraints'].each do |const|
      if const.key?('@type') && const['@type'].eql?('mandatory')
        @required << attribute['id']
      end
    end
  end
end

Public Instance Methods

to_json() click to toggle source

JSON document @return [String] JSON Document

# File lib/vcoworkflows/workflowpresentation.rb, line 57
def to_json
  JSON.pretty_generate(@presentation_data)
end
to_s() click to toggle source

String representation of the presentation @return [String]

# File lib/vcoworkflows/workflowpresentation.rb, line 51
def to_s
  @presentation_data.to_s
end