log/server.rb in cpee-1.3.204 vs log/server.rb in cpee-1.3.205

- old
+ new

@@ -16,88 +16,94 @@ <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"/> + <global scope="trace"> + <string key="concept:name" value="__INVALID__"/> + </global> + <global scope="event"> + <string key="concept:name" value="__INVALID__"/> + <string key="concept:endpoint" value=""/> + <string key="id:id" value=""/> + <string key="lifecycle:transition" value="complete" /> + <date key="time:timestamp" value=""/> + </global> + <classifier name="Data" keys="data_send data_received"/> + <classifier name="Data_Received" keys="data_received"/> + <classifier name="Data_Send" keys="data_send"/> <trace/> </log> END - def response - topic = @p[1].value - event_name = @p[2].value - 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" - 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 => activity + def doc(event_name,log_dir,instancenr,notification) + uuid = notification['instance_uuid'] + activity = notification["activity"] + parameters = notification['parameters'] + receiving = notification['received'] + pp notification + 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" + 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:endpoint", :value => notification["endpoint"] if notification["endpoint"] + event.add 'string', :key => "id:id", :value => activity + unless event_name=='receiving' 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 + else + event.add 'string', :key => "lifecycle:transition", :value => "unknown" + end + data_send = ((parameters[:arguments].nil? ? [] : parameters[:arguments]) rescue []) + if data_send && data_send.any? + list = event.add 'list', :key => "data_send" + data_send.each do |k,v| + list.add 'string', :key => k , :value => v end - 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 + if receiving && receiving.any? + list = event.add 'list', :key => "data_received" + if receiving.is_a? Array + receiving.each do |e| + e.each do |k,v| + case v['mimetype'] + when /\/xml$/ + node = list.add 'string', :key => k + node.add XML::Smart.string(v['content']).root + else + list.add 'string', :key => k, :value => v['content'] + end + end end + else + pp receiving end - event.add 'date', :key => "time:timestamp", :value => Time.now.iso8601 unless time_added - rescue => e - puts e.message - puts e.backtrace end - end - else - pp "Something wrong" + event.add 'date', :key => "time:timestamp", :value => Time.now.iso8601 unless time_added + rescue => e + puts e.message + puts e.backtrace + end end end + def response + topic = @p[1].value + event_name = @p[2].value + log_dir = ::File.dirname(__FILE__) + "/logs" + instancenr = @h['CPEE_INSTANCE'].split('/').last + notification = JSON.parse(@p[3].value) + doc(event_name,log_dir,instancenr,notification) + end end #}}} -Riddl::Server.new(::File.dirname(__FILE__) + '/log.xml', :host => "cpee.org", :port => 9299) do #{{{ +Riddl::Server.new(::File.dirname(__FILE__) + '/log.xml', :host => "coruscant.wst.univie.ac.at", :port => 9299) do #{{{ accessible_description true cross_site_xhr true log_path = "/home/demo/Projects/cpee-helpers/log/logs" interface 'events' do