Class: CPEE::Logging::Handler

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee-logging-xes-yaml/logging.rb

Instance Method Summary collapse

Instance Method Details

#responseObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cpee-logging-xes-yaml/logging.rb', line 32

def response
  opts       = @a[0]
  type       = @p[0].value
  topic      = @p[1].value
  event_name = @p[2].value
  payload    = @p[3].value.read

  unless File.exist? File.join(opts[:log_dir],@h['CPEE_INSTANCE_UUID'] + '.xes.yaml')
    notification = JSON.parse(payload)
    log = YAML::load(File.read(opts[:template]))
    log['log']['trace']['concept:name']                    ||= notification['instance']
    log['log']['trace']['cpee:name']                       ||= notification['instance-name'] if notification['instance-name']
    log['log']['trace']['cpee:instance']                   ||= notification['instance-uuid']
    log['log']['trace']['cpee:parent_instance']            ||= notification.dig('content','attributes','parent_instance').to_i       if notification.dig('content','attributes','parent_instance')
    log['log']['trace']['cpee:parent_instance_uuid']       ||= notification.dig('content','attributes','parent_instance_uuid')       if notification.dig('content','attributes','parent_instance_uuid')
    log['log']['trace']['cpee:parent_instance_model']      ||= notification.dig('content','attributes','parent_instance_model')      if notification.dig('content','attributes','parent_instance_model')
    log['log']['trace']['cpee:parent_instance_task_id']    ||= notification.dig('content','attributes','parent_instance_task_id')    if notification.dig('content','attributes','parent_instance_task_id')
    log['log']['trace']['cpee:parent_instance_task_label'] ||= notification.dig('content','attributes','parent_instance_task_label') if notification.dig('content','attributes','parent_instance_task_label')
    File.open(File.join(opts[:log_dir],@h['CPEE_INSTANCE_UUID']+'.xes.yaml'),'w'){|f| f.puts log.to_yaml}
  end

  EM.defer do
    CPEE::Logging::forward opts, topic, event_name, payload
  end if type == 'event'
  EM.defer do
    CPEE::Logging::doc opts, topic, event_name, payload
  end
  nil
end