class CPEE::Logging::Handler

Public Instance Methods

doc(topic,event_name,log_dir,template,notification) click to toggle source
# 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}"
  event["cpee:state"] = content['state'] if content['state']
  event["cpee:description"] = content['dslx'] if content['dslx']
  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
response() click to toggle source
# File lib/cpee-logging-xes-yaml/logging.rb, line 96
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