Class: VcoWorkflows::WorkflowPresentation

Inherits:
Object
  • Object
show all
Defined in:
lib/vcoworkflows/workflowpresentation.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_service, workflow_id) ⇒ VcoWorkflows::WorkflowPresentation

Create a new WorkflowPresentation

Parameters:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vcoworkflows/workflowpresentation.rb', line 31

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

Instance Attribute Details

#presentation_dataHash (readonly)

Accessor for the data structure

Returns:

  • (Hash)

    parsed JSON



19
20
21
# File 'lib/vcoworkflows/workflowpresentation.rb', line 19

def presentation_data
  @presentation_data
end

#requiredString[] (readonly)

Get the list of required parameters for the workflow

Returns:

  • (String[])

    Array of strings (names of parameters)



23
24
25
# File 'lib/vcoworkflows/workflowpresentation.rb', line 23

def required
  @required
end

Instance Method Details

#to_jsonString

JSON document

Returns:

  • (String)

    JSON Document



59
60
61
# File 'lib/vcoworkflows/workflowpresentation.rb', line 59

def to_json
  JSON.pretty_generate(@presentation_data)
end

#to_sString

String representation of the presentation

Returns:

  • (String)


53
54
55
# File 'lib/vcoworkflows/workflowpresentation.rb', line 53

def to_s
  @presentation_data.to_s
end