log/server.rb in cpee-1.3.196 vs log/server.rb in cpee-1.3.197

- old
+ new

@@ -7,18 +7,19 @@ require 'riddl/utils/notifications_producer' require 'riddl/utils/properties' require 'riddl/utils/fileserve' require 'riddl/utils/downloadify' require 'riddl/utils/turtle' +require 'time' - class Logging < Riddl::Implementation #{{{ LOGTEMPLATE = <<-END <log xmlns="http://www.xes-standard.org/" xes.version="2.0" xes.features="nested-attributes"> <extension name="Time" prefix="time" uri="http://www.xes-standard.org/time.xesext"/> <extension name="Concept" prefix="concept" uri="http://www.xes-standard.org/concept.xesext"/> <extension name="Organizational" prefix="org" uri="http://www.xes-standard.org/org.xesext"/> + <extension name="Lifecycle" prefix="lifecycle" uri="http://www.xes-standard.org/lifecycle.xesext"/> <trace/> </log> END def response topic = @p[1].value @@ -26,57 +27,64 @@ if(topic == 'activity' && (event_name=='done' || event_name == 'calling')) log_dir = ::File.dirname(__FILE__) + "/logs" instancenr = @h['CPEE_INSTANCE'].split('/').last notification = JSON.parse(@p[3].value) uuid = notification['instance_uuid'] + activity = notification["activity"] parameters = notification['parameters'] Dir.mkdir(log_dir+'/'+uuid) unless Dir.exist?(log_dir+'/'+uuid) time_added=false XML::Smart.modify(log_dir+'/'+uuid+'/log.xes',LOGTEMPLATE) do |xml| begin trace = xml.find("/xmlns:log/xmlns:trace").first trace.add 'string', :key => "concept:name", :value => "Instance #{instancenr}" if trace.find('xmlns:string').empty? event = trace.add "event" - event.add 'string', :key => "concept:name", :value => parameters["label"] if parameters && parameters.has_key?('label') + if parameters && parameters.has_key?('label') + event.add 'string', :key => "concept:name", :value => parameters["label"] + else + event.add 'string', :key => "concept:name", :value => trace.find("string(xmlns:event[xmlns:string[@key='id:id' and @value='#{activity}']]/xmlns:string[@key='concept:name']/@value)") + end event.add 'string', :key => "concept:instance", :value => notification["endpoint"] if notification["endpoint"] - event.add 'string', :key => "id:id", :value => notification["activity"] + event.add 'string', :key => "id:id", :value => activity event.add 'string', :key => "lifecycle:transition", :value => event_name=='done'?"complete":"start" data_send = ((parameters[:arguments].nil? ? [] : parameters[:arguments]) rescue []) if data_send.any? list = event.add 'list', :key => "data_send" data_send.each do |k,v| list.add 'string', :key => k , :value => v end end - event.add 'date', :key => "time:timestamp", :value => Time.now unless time_added + event.add 'date', :key => "time:timestamp", :value => Time.now.iso8601 unless time_added rescue => e puts e.message puts e.backtrace end end elsif(event_name=='receiving') log_dir = ::File.dirname(__FILE__) + "/logs" instancenr = @h['CPEE_INSTANCE'].split('/').last notification = JSON.parse(@p[3].value) uuid = notification['instance_uuid'] + activity = notification["activity"] receiving = notification['received'] Dir.mkdir(log_dir+'/'+uuid) unless Dir.exist?(log_dir+'/'+uuid) time_added=false XML::Smart.modify(log_dir+'/'+uuid+'/log.xes',LOGTEMPLATE) do |xml| begin trace = xml.find("/xmlns:log/xmlns:trace").first trace.add 'string', :key => "concept:name", :value => "Instance #{instancenr}" if trace.find('xmlns:string').empty? event = trace.add "event" + event.add 'string', :key => "concept:name", :value => trace.find("string(xmlns:event[xmlns:string[@key='id:id' and @value='#{activity}']]/xmlns:string[@key='concept:name']/@value)") event.add 'string', :key => "concept:instance", :value => notification["endpoint"] if notification["endpoint"] event.add 'string', :key => "id:id", :value => notification["activity"] event.add 'string', :key => "lifecycle:transition", :value => "unknown" if receiving.any? list = event.add 'list', :key => "data_received" receiving.each do |k,v| list.add 'string', :key => k, :value => v end end - event.add 'date', :key => "time:timestamp", :value => Time.now unless time_added + event.add 'date', :key => "time:timestamp", :value => Time.now.iso8601 unless time_added rescue => e puts e.message puts e.backtrace end end