Module: RuoteKit::Helpers::LaunchItemParser

Defined in:
lib/ruote-kit/helpers/launch_item_parser.rb

Instance Method Summary collapse

Instance Method Details

#field_updates_and_proceed_from_putObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ruote-kit/helpers/launch_item_parser.rb', line 32

def field_updates_and_proceed_from_put
  options = {
    :fields => {},
    :proceed => false
  }

  case env['CONTENT_TYPE']

  when "application/json" then
    data = Rufus::Json.decode( env['rack.input'].read )
    options[:fields] = data['fields'] unless data['fields'].nil? || data['fields'].empty?
    options[:proceed] = data['_proceed'] unless data['_proceed'].nil? || data['_proceed'].empty?

  when "application/x-www-form-urlencoded"
    options[:fields] = Rufus::Json.decode( params[:fields] ) unless params['fields'].nil? || params['fields'].empty?
    options[:proceed] = params[:_proceed] unless params[:_proceed].nil? || params[:_proceed].empty?

  else
    raise "#{evn['CONTENT_TYPE']} is not supported for workitem fields"
  end

  return options
end

#launch_item_from_postObject

Extract the launch item parameters from a posted form or a JSON request body



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruote-kit/helpers/launch_item_parser.rb', line 6

def launch_item_from_post
  case env["CONTENT_TYPE"]

  when "application/json" then
    data = Rufus::Json.decode( env["rack.input"].read )
    launch_item = {}
    launch_item['pdef'] = data["definition"]
    launch_item['fields'] = data["fields"] || {}
    launch_item['variables'] = data["variables"] || {}
    return launch_item

  when "application/x-www-form-urlencoded"
    launch_item = { 'pdef' => params[:process_definition] }
    fields = params[:process_fields] || ""
    fields = "{}" if fields.empty?
    launch_item['fields'] = Rufus::Json.decode( fields )
    vars = params[:process_variables] || ""
    vars = "{}" if vars.empty?
    launch_item['variables'] = Rufus::Json.decode( vars )
    return launch_item

  else
    raise "#{env['CONTENT_TYPE']} not supported as a launch mechanism yet"
  end
end