Class: CPEE::Logging::Handler

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

Overview

{{{

Instance Method Summary collapse

Instance Method Details

#doc(topic, event_name, log_dir, template, notification) ⇒ Object



30
31
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cpee-logging-xes-yaml/logging.rb', line 30

def doc(topic,event_name,log_dir,template,notification)
  instance = notification['instance-uuid']
  return unless instance

  instancenr = notification['instance']
  content = notification['content']
  activity = content['activity']
  parameters = content['parameters']
  receiving = content['received']

  log = YAML::load(File.read(template))
  log["log"]["trace"]["concept:name"] ||= instancenr
  log["log"]["trace"]["cpee:name"] ||= notification['instance-name'] if notification['instance-name']
  log["log"]["trace"]["cpee:instance"] ||= instance
  File.open(File.join(log_dir,instance+'.xes.yaml'),'w'){|f| f.puts log.to_yaml} unless File.exists? File.join(log_dir,instance+'.xes.yaml')
  event = {}
  event["concept:instance"] = instancenr
  event["concept:name"] = content["label"] if content["label"]
  if notification["endpoint"]
    event["concept:endpoint"] = content["endpoint"]
  end
  event["id:id"] = (activity.nil? || activity == "") ? 'external' : activity
  event["cpee:activity"] = event["id:id"]
  event["cpee:activity_uuid"] = content['activity-uuid'] if content['activity-uuid']
  event["cpee:instance"] = instance
  case event_name
    when 'receiving', 'change', 'instantiation'
      event["lifecycle:transition"] = "unknown"
    when 'done'
      event["lifecycle:transition"] = "complete"
    else
      event["lifecycle:transition"] = "start"
  end
  event["cpee:lifecycle:transition"] = "#{topic}/#{event_name}"
  data_send = ((parameters["arguments"].nil? ? [] : parameters["arguments"]) rescue [])
  event["data"] = {"data_send" => data_send} unless data_send.empty?
  if content['changed']&.any?
    if event.has_key? "data"
      event["data"]["data_changed"] ||= content['changed']
    else
      event["data"] = {"data_changer" => content['changed']}
    end
  end
  if content['values']&.any?
    if event.has_key? "data"
      event["data"]["data_values"] ||= content['values']
    else
      event["data"] = {"data_values" => content['values']}
    end
  end
  if receiving && !receiving.empty?
    if event.has_key? "data"
      event["data"]["data_received"] ||= receiving
    else
      event["data"] = {"data_receiver" => receiving}
    end
  end
  event["time:timestamp"]= event['cpee:timestamp'] || Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z")
  File.open(File.join(log_dir,instance+'.xes.yaml'),'a') do |f|
    f << {'event' => event}.to_yaml
  end
  nil
end

#responseObject



94
95
96
97
98
99
100
101
# File 'lib/cpee-logging-xes-yaml/logging.rb', line 94

def response
  topic         = @p[1].value
  event_name    = @p[2].value
  log_dir       = @a[0]
  template      = @a[1]
  notification  = JSON.parse(@p[3].value.read)
  doc topic, event_name, log_dir, template, notification
end