public
Description: the [OpenWFEru] workflow and BPM engine (ruby)
Homepage: http://openwferu.rubyforge.org
Clone URL: git://github.com/jmettraux/ruote.git
step implementation over, ready for merging
jmettraux (author)
Sat May 10 20:55:27 -0700 2008
commit  f0845a92b83d42cfe1ed839a118eb6c1cd356a50
tree    6541631ffe35860c2a92d336c0eba0eeecc3dca2
parent  bbfd912ef3b7073131424b0b9cdeb3c92f0a9ccf
...
43
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48
49
...
61
62
63
64
65
66
67
 
 
 
 
 
 
 
68
69
70
 
 
71
72
73
 
 
74
75
76
...
84
85
86
87
 
 
88
89
90
 
 
 
 
91
92
93
 
94
95
96
97
98
 
99
100
101
...
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
...
102
103
104
 
 
 
 
105
106
107
108
109
110
111
112
113
114
115
116
117
 
 
118
119
120
121
122
...
130
131
132
 
133
134
135
 
 
136
137
138
139
140
141
 
142
143
144
145
146
 
147
148
149
150
0
@@ -43,7 +43,48 @@ require 'openwfe/expressions/flowexpression'
0
 module OpenWFE
0
 
0
     #
0
- # TODO : document me
0
+ # This expression takes its root in this "trouble ticket blog post" :
0
+ #
0
+ # http://jmettraux.wordpress.com/2008/01/04/the-trouble-ticket-process/
0
+ #
0
+ # In this post, the "step" was implemented directly in the OpenWFEru
0
+ # process definition language.
0
+ #
0
+ # It's been turned into an expression and it's not limited anymore to
0
+ # the concept "state is a participant, transition points to a subprocess",
0
+ # state can now point to a subprocess as well as to a participant, idem
0
+ # for a transition.
0
+ #
0
+ # In other words, this "step" expression allows you to write
0
+ # state-transition process definitions in OpenWFEru (the Ruote workflow
0
+ # engine). But don't abuse it. Classical OpenWFEru constructs can
0
+ # do most of the job.
0
+ #
0
+ # An interesting aspect of the "step" expression is that it can remove
0
+ # the need for some "if" expression constructs (well the fact
0
+ #
0
+ # class ProcDef0 < OpenWFE::ProcessDefinition
0
+ #
0
+ # sequence do
0
+ #
0
+ # step "Alfred", :outcomes => [ 'blue_pen', 'red_pen' ]
0
+ # # Alfred gets to choose between a blue pen and a red pen
0
+ #
0
+ # participant "Bob"
0
+ # # flow resumes with Bob in a classical way (sequence)
0
+ # end
0
+ #
0
+ # define "blue_pen" do
0
+ # # ... Alfred buying a blue pen
0
+ # end
0
+ # define "red_pen" do
0
+ # # ... Alfred buying a red pen
0
+ # end
0
+ # end
0
+ #
0
+ # For some more discussions about Ruote and state-transition see
0
+ #
0
+ # http://groups.google.com/group/openwferu-dev/t/16e713c1313cb2fa
0
     #
0
     class StepExpression < FlowExpression
0
 
0
@@ -61,16 +102,21 @@ module OpenWFE
0
 
0
             @out = false
0
 
0
- @outcomes = lookup_array_attribute :outcomes, workitem
0
- @default = lookup_attribute :default, workitem
0
- #
0
- # keeping track of outcomes and default as found at apply time
0
+ # keeping track of outcomes and default as found at apply time
0
+
0
+ @outcomes = lookup_array_attribute(
0
+ :outcomes, workitem, :to_s => true)
0
+
0
+ @default = lookup_attribute(
0
+ :default, workitem, :to_s => true)
0
 
0
             store_itself
0
 
0
+ # launching the 'step' itself
0
+
0
             template = [
0
- step, # expression name
0
- { :outcomes => @outcomes, :default => @default }, # attributes
0
+ step.to_s, # expression name
0
+ lookup_attributes(workitem), # attributes
0
                 [], # children
0
             ]
0
 
0
@@ -84,18 +130,21 @@ module OpenWFE
0
 
0
             @out = true
0
 
0
- outcome = workitem.fields['outcome'] || @default
0
+ outcome = workitem.fields.delete 'outcome'
0
+ outcome = outcome.to_s if outcome
0
 
0
- return reply_to_parent(workitem) \
0
- unless outcome
0
+ #p [ outcome, @outcomes, @default ]
0
+
0
+ outcome = @default \
0
+ if @outcomes and (not @outcomes.include?(outcome))
0
 
0
             return reply_to_parent(workitem) \
0
- if @outcomes and ( ! @outcomes.include?(outcome))
0
+ unless outcome
0
 
0
             store_itself
0
 
0
             template = [
0
- outcome, # expression name
0
+ outcome.to_s, # expression name
0
                 {}, # attributes
0
                 [], # children
0
             ]
...
379
380
381
 
382
383
384
...
387
388
389
390
 
391
392
 
393
394
395
 
396
397
 
 
 
 
 
 
 
 
 
 
398
399
400
...
449
450
451
 
 
452
453
454
455
456
 
 
 
 
 
457
458
 
459
460
461
...
473
474
475
476
 
477
478
479
...
481
482
483
484
485
486
 
487
488
489
490
 
491
492
493
494
495
 
496
497
498
499
 
500
501
502
503
504
505
...
379
380
381
382
383
384
385
...
388
389
390
 
391
392
 
393
394
 
 
395
396
 
397
398
399
400
401
402
403
404
405
406
407
408
409
...
458
459
460
461
462
463
464
465
466
 
467
468
469
470
471
472
 
473
474
475
476
...
488
489
490
 
491
492
493
494
...
496
497
498
 
 
 
499
500
 
 
 
501
502
503
504
505
 
506
507
 
 
 
508
509
 
 
510
511
512
0
@@ -379,6 +379,7 @@ module OpenWFE
0
 
0
             default = options[:default]
0
             escape = options[:escape]
0
+ tostring = options[:to_s]
0
 
0
             attname = OpenWFE::symbol_to_name(attname) \
0
                 if attname.kind_of?(Symbol)
0
@@ -387,14 +388,22 @@ module OpenWFE
0
 
0
             text = @attributes[attname]
0
 
0
- return default if text == nil
0
+ text = if text == nil
0
 
0
- #return text unless text.is_a?(String)
0
+ default
0
 
0
- return text if escape == true
0
- # returns text if escape is set and is set to true
0
+ elsif escape == true
0
 
0
- OpenWFE::dosub text, self, workitem
0
+ text
0
+
0
+ else
0
+
0
+ OpenWFE::dosub text, self, workitem
0
+ end
0
+
0
+ text = text.to_s if text and tostring
0
+
0
+ text
0
         end
0
 
0
         #
0
@@ -449,13 +458,19 @@ module OpenWFE
0
         #
0
         def lookup_array_attribute (attname, workitem, options={})
0
 
0
+ tostring = options.delete :to_s
0
+
0
             v = lookup_attribute attname, workitem, options
0
 
0
             return nil unless v
0
 
0
- return v if v.is_a?(Array)
0
+ v = v.to_s.split(",").collect { |e| e.strip } \
0
+ unless v.is_a?(Array)
0
+
0
+ v = v.collect { |e| e.to_s } \
0
+ if tostring
0
 
0
- v.to_s.split(",").collect { |e| e.strip }
0
+ v
0
         end
0
 
0
         #
0
@@ -473,7 +488,7 @@ module OpenWFE
0
         #
0
         # Returns a hash of all the FlowExpression attributes with their
0
         # values having undergone dollar variable substitution.
0
- # If the attributes parameter is set (to an Array instance) then
0
+ # If the _attributes parameter is set (to an Array instance) then
0
         # only the attributes named in that list will be looked up.
0
         #
0
         # It's ok to pass an array of Symbol instances for the attributes
0
@@ -481,25 +496,17 @@ module OpenWFE
0
         #
0
         def lookup_attributes (workitem, _attributes=nil)
0
 
0
- result = {}
0
-
0
- return result if not @attributes
0
+ return {} unless @attributes
0
 
0
- _attributes = @attributes.keys if not _attributes
0
-
0
- _attributes.each do |k|
0
+ (_attributes || @attributes.keys).inject({}) do |r, k|
0
 
0
                 k = k.to_s
0
                 v = @attributes[k]
0
 
0
- result[k] = OpenWFE::dosub v, self, workitem
0
+ r[k] = OpenWFE::dosub v, self, workitem
0
 
0
- #ldebug do
0
- # "lookup_attributes() added '#{k}' -> '#{result[k]}'"
0
- #end
0
+ r
0
             end
0
-
0
- result
0
         end
0
 
0
         #
...
176
177
178
179
 
180
181
182
...
176
177
178
 
179
180
181
182
0
@@ -176,7 +176,7 @@ class FlowTest79b < Test::Unit::TestCase
0
 
0
         assert_equal expected_trace, p.trace
0
 
0
- sleep 0.350 # c tests reply too fast, have to wait a bit
0
+ sleep 0.400 # c tests reply too fast, have to wait a bit
0
 
0
         assert(
0
             (@engine.process_status(fei) == nil),
...
16
17
18
19
 
 
 
 
 
20
21
22
 
 
 
 
 
 
23
24
 
 
 
 
 
 
 
 
 
 
25
26
27
28
29
30
31
32
 
 
 
 
33
34
 
35
36
37
...
16
17
18
 
19
20
21
22
23
24
25
 
26
27
28
29
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
0
@@ -16,22 +16,41 @@ class FlowTest79c < Test::Unit::TestCase
0
     class Test0 < OpenWFE::ProcessDefinition
0
 
0
         sequence do
0
- step :alpha
0
+ step :a0, :outcomes => [ :a1, :a2 ], :default => :a2
0
+ _print "-"
0
+ step :a1, :outcomes => [ :a1, :a2 ], :default => :whatever
0
+ _print "-"
0
+ step :a2, :outcomes => [ :a1, :a2 ]
0
         end
0
 
0
- define "ichi" do
0
+ define "a0" do
0
+ sequence do
0
+ _print "a0"
0
+ #set :f => "outcome", :val => "a1"
0
+ set :f => "outcome", :val => "whatever"
0
+ end
0
         end
0
- define "ni" do
0
+ define "a1" do
0
+ sequence do
0
+ _print "a1"
0
+ set :f => "outcome", :val => "a2"
0
+ end
0
+ end
0
+ define "a2" do
0
+ sequence do
0
+ _print "a2"
0
+ end
0
         end
0
     end
0
 
0
     def test_0
0
 
0
- @engine.register_participant :alpha do |wi|
0
- @tracer << "alpha"
0
- end
0
+ #log_level_to_debug
0
+
0
+ #@engine.register_participant :alpha do |wi|
0
+ #end
0
 
0
- dotest Test0, ""
0
+ dotest Test0, %w{ a0 a2 - a1 a2 - a2 }.join("\n")
0
     end
0
 end
0
 
...
110
111
112
 
113
114
115
...
110
111
112
113
114
115
116
0
@@ -110,6 +110,7 @@ require 'ft_77_segments'
0
 require 'ft_78_eval'
0
 require 'ft_79_tticket'
0
 require 'ft_79b_tticket'
0
+require 'ft_79c_outcome'
0
 require 'ft_80_spname'
0
 require 'ft_81_exp'
0
 

Comments

    No one has commented yet.