lib/ruote/engine/process_status.rb in ruote-2.1.11 vs lib/ruote/engine/process_status.rb in ruote-2.2.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -36,10 +36,14 @@
# The expressions that compose the process instance.
#
attr_reader :expressions
+ # Returns the expression at the root of the process instance.
+ #
+ attr_reader :root_expression
+
# An array of the workitems currently in the storage participant for this
# process instance.
#
# Do not confuse with #workitems
#
@@ -53,11 +57,11 @@
# An array of schedules (open structs yielding information about the
# schedules of this process)
#
attr_reader :schedules
- def initialize (context, expressions, stored_workitems, errors, schedules)
+ def initialize(context, expressions, stored_workitems, errors, schedules)
@expressions = expressions.collect { |e|
Ruote::Exp::FlowExpression.from_h(context, e) }
@expressions.sort! { |a, b| a.fei.expid <=> b.fei.expid }
@@ -65,40 +69,32 @@
Ruote::Workitem.new(h)
}
@errors = errors.sort! { |a, b| a.fei.expid <=> b.fei.expid }
@schedules = schedules.sort! { |a, b| a['owner'].sid <=> b['owner'].sid }
- end
- # Returns the expression at the root of the process instance.
- #
- def root_expression
-
- #@expressions.find { |e| e.fei.expid == '0' && e.fei.sub_wfid == nil }
- # vanilla implementation
-
- root_expressions.first
+ @root_expression = root_expressions.first
end
# Returns a list of all the expressions that have no parent expression.
# The list is sorted with the deeper (closer to the original root) first.
#
def root_expressions
roots = @expressions.select { |e| e.h.parent_id == nil }
roots = roots.inject({}) { |h, e|
- h["#{e.h.fei['expid']}__#{e.h.fei['sub_wfid']}"] = e; h
+ h["#{e.h.fei['expid']}__#{e.h.fei['subid']}"] = e; h
}
roots.keys.sort.collect { |k| roots[k] }
end
# Given an expression id, returns the root (top ancestor) for its
# expression.
#
- def root_expression_for (fei)
+ def root_expression_for(fei)
sfei = Ruote.sid(fei)
exp = @expressions.find { |fe| sfei == Ruote.sid(fe.fei) }
@@ -110,11 +106,11 @@
# Returns the process variables set for this process instance.
#
def variables
- root_expression.variables
+ @root_expression && @root_expression.variables
end
# Returns a hash fei => variable_hash containing all the variable bindings
# (expression by expression) of the process instance.
#
@@ -129,11 +125,11 @@
# Returns a hash tagname => fei of tags set at the root of the process
# instance.
#
def tags
- variables.select { |k, v| FlowExpressionId.is_a_fei?(v) }
+ Hash[variables.select { |k, v| FlowExpressionId.is_a_fei?(v) }]
end
# Returns a hash tagname => array of feis of all the tags set in the process
# instance.
#
@@ -161,11 +157,12 @@
#
# will yield 'review'.
#
def definition_name
- root_expression.attribute('name') || root_expression.attribute_text
+ @root_expression && (
+ @root_expression.attribute('name') || @root_expression.attribute_text)
end
# For a process
#
# Ruote.process_definition :name => 'review', :revision => '0.1' do
@@ -175,11 +172,11 @@
#
# will yield '0.1'.
#
def definition_revision
- root_expression.attribute('revision')
+ @root_expression && @root_expression.attribute('revision')
end
# Returns the 'position' of the process.
#
# pdef = Ruote.process_definition do
@@ -196,13 +193,20 @@
# It uses #workitems underneath.
#
def position
workitems.collect { |wi|
+
r = [ wi.fei.sid, wi.participant_name ]
- params = wi.fields['params'].dup
+
+ params = (wi.fields['params'] || {}).dup
params.delete('ref')
+
+ if err = errors.find { |e| e.fei == wi.fei }
+ params['error'] = err.message
+ end
+
r << params
r
}
end
@@ -243,18 +247,18 @@
# Returns the process definition tree as it was when this process instance
# was launched.
#
def original_tree
- root_expression.original_tree
+ @root_expression && @root_expression.original_tree
end
# Returns a Time instance indicating when the process instance was launched.
#
def launched_time
- root_expression.created_time
+ @root_expression && @root_expression.created_time
end
def to_s
"(process_status wfid '#{wfid}', " +
@@ -265,30 +269,45 @@
")"
end
def inspect
+ vars = variables rescue nil
+ avars = all_variables.inject({}) { |h, (k, v)| h[Ruote.sid(k)] = v; h }
+
s = [ "== #{self.class} ==" ]
s << " expressions : #{@expressions.size}"
@expressions.each do |e|
- s << " #{e.fei.to_storage_id} : #{e}"
+ s << " #{e.fei.to_storage_id}"
+ s << " | #{e.name}"
+ s << " | #{e.attributes.inspect}"
+ s << " `-parent--> #{e.h.parent_id ? e.parent_id.to_storage_id : 'nil'}"
end
+ s << " schedules : #{@schedules.size}"
+ s << " stored workitems : #{@stored_workitems.size}"
+ s << " variables : #{vars.inspect}"
+ s << " all_variables : #{avars.inspect}"
s << " errors : #{@errors.size}"
@errors.each do |e|
+ s << " ***"
s << " #{e.fei.to_storage_id} :" if e.fei
- s << " #{e.inspect}"
+ s << " action : #{e.action}"
+ s << " message : #{e.message}"
+ s << " trace :"
+ e.trace.split("\n").each do |line|
+ s << " #{line}"
+ end
+ s << " fields : #{e.fields.inspect}"
end
- s << " schedules : #{@schedules.size}"
- s << " stored workitems : #{@stored_workitems.size}"
s.join("\n") + "\n"
end
# Returns a 'dot' representation of the process. A graph describing
# the tree of flow expressions that compose the process.
#
- def to_dot (opts={})
+ def to_dot(opts={})
s = [ "digraph \"process wfid #{wfid}\" {" ]
@expressions.each { |e| s.push(*e.send(:to_dot, opts)) }
@errors.each { |e| s.push(*e.send(:to_dot, opts)) }
s << "}"
@@ -345,25 +364,25 @@
Ruote.recompose_tree(h)
end
protected
- def original_tree_from_parent (e)
+ def original_tree_from_parent(e)
parent = @expressions.find { |exp| exp.fei == e.parent_id }
parent ? parent.tree[2][e.fei.child_id] : e.tree
end
end
- def self.decompose_tree (t, pos='0', h={})
+ def self.decompose_tree(t, pos='0', h={})
h[pos] = t[0, 2]
t[2].each_with_index { |c, i| decompose_tree(c, "#{pos}_#{i}", h) }
h
end
- def self.recompose_tree (h, pos='0')
+ def self.recompose_tree(h, pos='0')
t = h[pos]
return nil unless t