openwferu 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/README.txt +4 -5
  2. data/lib/openwfe/engine/engine.rb +14 -14
  3. data/lib/openwfe/expool/expressionpool.rb +60 -45
  4. data/lib/openwfe/expool/expstorage.rb +1 -1
  5. data/lib/openwfe/expressions/condition.rb +47 -34
  6. data/lib/openwfe/expressions/environment.rb +29 -7
  7. data/lib/openwfe/expressions/expressionmap.rb +16 -1
  8. data/lib/openwfe/expressions/fe_concurrence.rb +142 -55
  9. data/lib/openwfe/expressions/fe_cursor.rb +146 -41
  10. data/lib/openwfe/expressions/fe_define.rb +52 -35
  11. data/lib/openwfe/expressions/fe_filter.rb +129 -0
  12. data/lib/openwfe/expressions/fe_filter_definition.rb +170 -0
  13. data/lib/openwfe/expressions/fe_iterator.rb +23 -10
  14. data/lib/openwfe/expressions/fe_losfor.rb +7 -6
  15. data/lib/openwfe/expressions/fe_participant.rb +19 -9
  16. data/lib/openwfe/expressions/fe_raw.rb +11 -16
  17. data/lib/openwfe/expressions/fe_save.rb +225 -0
  18. data/lib/openwfe/expressions/fe_sequence.rb +15 -10
  19. data/lib/openwfe/expressions/fe_subprocess.rb +0 -6
  20. data/lib/openwfe/expressions/fe_value.rb +7 -19
  21. data/lib/openwfe/expressions/filter.rb +104 -0
  22. data/lib/openwfe/expressions/flowexpression.rb +102 -36
  23. data/lib/openwfe/expressions/merge.rb +80 -0
  24. data/lib/openwfe/expressions/raw_prog.rb +21 -18
  25. data/lib/openwfe/filterdef.rb +259 -0
  26. data/lib/openwfe/flowexpressionid.rb +36 -3
  27. data/lib/openwfe/participants/participants.rb +7 -1
  28. data/lib/openwfe/rest/xmlcodec.rb +1 -1
  29. data/lib/openwfe/util/dollar.rb +4 -2
  30. data/lib/openwfe/util/scheduler.rb +3 -1
  31. data/lib/openwfe/util/sqs.rb +1 -2
  32. data/lib/openwfe/utils.rb +13 -0
  33. data/lib/openwfe/version.rb +1 -1
  34. data/lib/openwfe/workitem.rb +1 -1
  35. data/test/filter_test.rb +109 -0
  36. data/test/flowtestbase.rb +12 -1
  37. data/test/ft_11_ppd.rb +13 -1
  38. data/test/ft_11b_ppd.rb +45 -0
  39. data/test/ft_17_condition.rb +1 -1
  40. data/test/ft_2b_concurrence.rb +24 -0
  41. data/test/ft_2c_concurrence.rb +22 -1
  42. data/test/ft_3_equals.rb +26 -0
  43. data/test/ft_42_environments.rb +78 -0
  44. data/test/ft_43_pat10.rb +109 -0
  45. data/test/ft_44_save.rb +81 -0
  46. data/test/ft_44b_restore.rb +159 -0
  47. data/test/ft_45_citerator.rb +104 -0
  48. data/test/ft_46_pparams.rb +62 -0
  49. data/test/ft_47_filter.rb +165 -0
  50. data/test/ft_48_fe_filter.rb +91 -0
  51. data/test/ft_49_condition.rb +65 -0
  52. data/test/ft_50_xml_attribute.rb +89 -0
  53. data/test/ft_9_cursor.rb +36 -6
  54. data/test/ft_tests.rb +11 -1
  55. data/test/misc_test.rb +8 -0
  56. data/test/rake_qtest.rb +2 -2
  57. data/test/rutest_utils.rb +6 -1
  58. data/test/sec_test.rb +2 -2
  59. metadata +20 -2
@@ -155,28 +155,31 @@ module OpenWFE
155
155
 
156
156
  context.pop_parent_expression
157
157
 
158
- return exp
158
+ exp
159
+ end
160
+
161
+ def do_make
162
+ ProcessDefinition.do_make(self)
159
163
  end
160
164
 
161
165
  #
162
166
  # A class method for actually "making" the process
163
167
  # segment raw representation
164
168
  #
165
- def ProcessDefinition.do_make ()
166
-
167
- context = nil
168
-
169
- if @ccontext
170
- context = @ccontext
171
- else
169
+ def ProcessDefinition.do_make (instance=nil)
170
+
171
+ context = if @ccontext
172
+ @ccontext
173
+ elsif instance
174
+ instance.make
175
+ instance.context
176
+ else
172
177
  pdef = self.new
173
178
  pdef.make
174
- context = pdef.context
179
+ pdef.context
175
180
  end
176
181
 
177
- exp = context.top_expression
178
-
179
- return exp if exp
182
+ return context.top_expression if context.top_expression
180
183
 
181
184
  name, revision =
182
185
  extract_name_and_revision(self.metaclass.to_s[8..-2])
@@ -190,7 +193,7 @@ module OpenWFE
190
193
 
191
194
  top_expression.children = context.top_expressions
192
195
 
193
- return top_expression
196
+ top_expression
194
197
  end
195
198
 
196
199
  protected
@@ -218,13 +221,13 @@ module OpenWFE
218
221
  m = Regexp.compile(".*::(.*$)").match(s)
219
222
  return [ as_name(m[1]), '0' ] if m
220
223
 
221
- return [ as_name(s), '0' ]
224
+ [ as_name(s), '0' ]
222
225
  end
223
226
 
224
227
  def ProcessDefinition.as_name (s)
225
228
 
226
229
  return s[0..-11] if s.match(".*Definition$")
227
- return s
230
+ s
228
231
  end
229
232
 
230
233
  def ProcessDefinition.as_revision (s)
@@ -269,7 +272,7 @@ module OpenWFE
269
272
  return nil if @top_expressions.size > 1
270
273
  exp = @top_expressions[0]
271
274
  return exp if exp.name == "process-definition"
272
- return nil
275
+ nil
273
276
  end
274
277
  end
275
278
  end
@@ -402,14 +405,14 @@ module OpenWFE
402
405
  method_name = OpenWFE::to_underscore(method_name)
403
406
  return "_" + method_name \
404
407
  if KEYWORDS.include? eval(":"+method_name)
405
- return method_name
408
+ method_name
406
409
  end
407
410
 
408
411
  def OpenWFE.to_expression_name (method_name)
409
412
  method_name = method_name.to_s
410
413
  method_name = method_name[1..-1] if method_name[0, 1] == "_"
411
414
  method_name = OpenWFE::to_dash(method_name)
412
- return method_name
415
+ method_name
413
416
  end
414
417
 
415
418
  end
@@ -0,0 +1,259 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, Nicolas Modrzyk OpenWFE.org
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # . Redistributions of source code must retain the above copyright notice, this
10
+ # list of conditions and the following disclaimer.
11
+ #
12
+ # . Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ #
16
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
17
+ # used to endorse or promote products derived from this software without
18
+ # specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ #++
32
+ #
33
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
34
+ #
35
+
36
+ #
37
+ # "made in Japan"
38
+ #
39
+ # John Mettraux at openwfe.org
40
+ #
41
+
42
+ require 'openwfe/utils'
43
+
44
+
45
+ module OpenWFE
46
+
47
+ #
48
+ # A 'filter' is used to restrict what a participant / user / segment
49
+ # of a process may see of a workitem (filter_in) and also enforces
50
+ # restrictions on modifications (filter_out).
51
+ #
52
+ class FilterDefinition
53
+
54
+ attr_accessor \
55
+ :closed,
56
+ :add_ok,
57
+ :remove_ok,
58
+ :fields
59
+
60
+ def initialize
61
+ @closed = false
62
+ @add_ok = true
63
+ @remove_ok = true
64
+ @fields = []
65
+ end
66
+
67
+ def add_allowed= (b)
68
+ @add_ok = b
69
+ end
70
+ def remove_allowed= (b)
71
+ @remove_ok = b
72
+ end
73
+
74
+ def may_add?
75
+ return @add_ok
76
+ end
77
+ def may_remove?
78
+ return @remove_ok
79
+ end
80
+
81
+ #
82
+ # Adds a field to the filter definition
83
+ #
84
+ # filterdef.add_field("readonly", "r")
85
+ # filterdef.add_field("hidden", nil)
86
+ # filterdef.add_field("writable", :w)
87
+ # filterdef.add_field("read_write", :rw)
88
+ # filterdef.add_field("^toto_.*", :r)
89
+ #
90
+ def add_field (regex, permissions)
91
+ f = Field.new
92
+ f.regex = regex
93
+ f.permissions = permissions
94
+ @fields << f
95
+ end
96
+
97
+ #
98
+ # Takes a hash as input and returns a hash. The result will
99
+ # contain only the readable fields.
100
+ #
101
+ # Consider the following test cases to see this
102
+ # 'constraining' in action :
103
+ #
104
+ # f0 = OpenWFE::FilterDefinition.new
105
+ # f0.closed = true
106
+ # f0.add_field("a", "r")
107
+ # f0.add_field("b", "rw")
108
+ # f0.add_field("c", "")
109
+ #
110
+ # m0 = {
111
+ # "a" => "A",
112
+ # "b" => "B",
113
+ # "c" => "C",
114
+ # "d" => "D",
115
+ # }
116
+ #
117
+ # m1 = f0.filter_in m0
118
+ # assert_equal m1, { "a" => "A", "b" => "B" }
119
+ #
120
+ # f0.closed = false
121
+ #
122
+ # m2 = f0.filter_in m0
123
+ # assert_equal m2, { "a" => "A", "b" => "B", "d" => "D" }
124
+ #
125
+ def filter_in (map)
126
+
127
+ result = {}
128
+
129
+ map.each do |key, value|
130
+
131
+ field = get_field key
132
+
133
+ if @closed
134
+ result[key] = value if field and field.may_read?
135
+ else
136
+ result[key] = value if (not field) or field.may_read?
137
+ end
138
+ end
139
+
140
+ result
141
+ end
142
+
143
+ def filter_out (original_map, map)
144
+
145
+ # method with a high cyclomatic score :)
146
+
147
+ result = {}
148
+
149
+ build_out_map(original_map, map).each do |key, v|
150
+
151
+ field, ovalue, nvalue = v
152
+
153
+ #
154
+ # adding a brand new field...
155
+
156
+ isnew = ((not field) and (ovalue == nil) and (nvalue != nil))
157
+
158
+ if isnew
159
+ result[key] = nvalue if @add_ok
160
+ next
161
+ end
162
+
163
+ #
164
+ # removing a field
165
+
166
+ isremoval = ((ovalue != nil) and (nvalue == nil))
167
+
168
+ if isremoval
169
+ result[key] = ovalue unless @remove_ok
170
+ next
171
+ end
172
+
173
+ #
174
+ # no modification
175
+
176
+ haschanged = (ovalue != nvalue)
177
+
178
+ #puts "haschanged ? #{haschanged}"
179
+
180
+ if haschanged
181
+
182
+ result[key] = unless field
183
+ if @closed
184
+ ovalue
185
+ else
186
+ nvalue
187
+ end
188
+ else
189
+ if field.may_write?
190
+ nvalue
191
+ else
192
+ ovalue
193
+ end
194
+ end
195
+
196
+ next
197
+ end
198
+
199
+ # else, just use, the old value
200
+
201
+ result[key] = ovalue
202
+ end
203
+
204
+ result
205
+ end
206
+
207
+ #
208
+ # Returns a deep copy of this filter instance.
209
+ #
210
+ def dup
211
+ OpenWFE::fulldup self
212
+ end
213
+
214
+ protected
215
+
216
+ #
217
+ # pre-digesting the two maps
218
+ #
219
+ def build_out_map (original_map, map)
220
+
221
+ keys = {}
222
+ keys.merge! original_map
223
+ keys.merge! map
224
+
225
+ m = {}
226
+ keys.keys.each do |k|
227
+ m[k] = [ get_field(k), original_map[k], map[k] ]
228
+ end
229
+
230
+ #require 'pp'; pp m
231
+ m
232
+ end
233
+
234
+ #
235
+ # Returns the first field mapping a given key
236
+ #
237
+ def get_field (key)
238
+ @fields.detect do |f|
239
+ key.match f.regex
240
+ end
241
+ end
242
+
243
+ class Field
244
+ attr_accessor :regex, :permissions
245
+
246
+ def may_read?
247
+ @permissions.to_s.index("r") != nil
248
+ end
249
+
250
+ def may_write?
251
+ @permissions.to_s.index("w") != nil
252
+ end
253
+
254
+ def no_rights?
255
+ @permissions.to_s == ""
256
+ end
257
+ end
258
+ end
259
+ end
@@ -143,6 +143,7 @@ module OpenWFE
143
143
  #def to_debug_s
144
144
  # "#{to_s} (h#{hash}) (i#{object_id})"
145
145
  #end
146
+
146
147
  def to_debug_s
147
148
  "(fei #{@workflow_definition_name} #{@workflow_definition_revision} #{@workflow_instance_id} #{@expression_id} #{@expression_name})"
148
149
  end
@@ -151,6 +152,14 @@ module OpenWFE
151
152
  "(fei #{@workflow_instance_id} #{@expression_id} #{@expression_name})"
152
153
  end
153
154
 
155
+ #
156
+ # Yet another debugging method. Just returns the sub_instance_id and
157
+ # the expression_id, in a string.
158
+ #
159
+ def to_env_s
160
+ "i#{sub_instance_id} #{@expression_id}"
161
+ end
162
+
154
163
  #
155
164
  # Returns the workflow instance id without any subflow indices.
156
165
  # For example, if the wfid is "1234.0.1", this method will
@@ -158,13 +167,37 @@ module OpenWFE
158
167
  #
159
168
  def parent_workflow_instance_id
160
169
  i = workflow_instance_id.index(".")
161
- return workflow_instance_id if not i
162
- #return workflow_instance_id[0..i]
163
- return workflow_instance_id[0..i-1]
170
+ return workflow_instance_id unless i
171
+ workflow_instance_id[0..i-1]
164
172
  end
165
173
 
166
174
  alias :parent_wfid :parent_workflow_instance_id
167
175
 
176
+ #
177
+ # Returns "" if this expression id belongs to a top process,
178
+ # returns something like ".0" or ".1.3" if this exp id belongs to
179
+ # an expression in a subprocess.
180
+ # (Only used in some unit tests for now)
181
+ #
182
+ def sub_instance_id
183
+ i = workflow_instance_id.index(".")
184
+ return "" unless i
185
+ workflow_instance_id[i..-1]
186
+ end
187
+
188
+ #
189
+ # Returns the last part of the expression_id. For example, if
190
+ # the expression_id is "0.1.0.4", "4" will be returned.
191
+ #
192
+ # This method is used in "concurrence" when merging workitems coming
193
+ # backing from the children expressions.
194
+ #
195
+ def child_id
196
+ i = @expression_id.rindex(".")
197
+ return @expression_id unless i
198
+ @expression_id[i+1..-1]
199
+ end
200
+
168
201
  #
169
202
  # This class method parses a string into a FlowExpressionId instance
170
203
  #
@@ -156,6 +156,12 @@ module OpenWFE
156
156
  # Having the FlowExpression instance at hand allows for advanced tricks,
157
157
  # beware...
158
158
  #
159
+ # It's also OK to register a block participant without params :
160
+ #
161
+ # engine.register_participant :alice do
162
+ # puts "Alice received a workitem"
163
+ # end
164
+ #
159
165
  class BlockParticipant
160
166
  include LocalParticipant
161
167
 
@@ -180,7 +186,7 @@ module OpenWFE
180
186
  end
181
187
 
182
188
  if result
183
- ldebug { "consume() result is of class #{result.class.name}" }
189
+ #ldebug { "consume() result is of class #{result.class.name}" }
184
190
  workitem.set_result(result)
185
191
  end
186
192
 
@@ -413,7 +413,7 @@ module OpenWFE
413
413
 
414
414
  # add filter ? no
415
415
 
416
- encode_history(item, root)
416
+ encode_history(item, root) if item.history
417
417
 
418
418
  doc << root
419
419
 
@@ -48,7 +48,7 @@ require 'openwfe/util/safe'
48
48
 
49
49
  module OpenWFE
50
50
 
51
- SAFETY_LEVEL = 3
51
+ DSUB_SAFETY_LEVEL = 3
52
52
  #
53
53
  # Ruby code ${ruby:...} will be evaluated with this
54
54
  # safety level.
@@ -215,7 +215,9 @@ module OpenWFE
215
215
 
216
216
  #eval(ruby_code, binding).to_s
217
217
  #eval(ruby_code).to_s
218
- OpenWFE::eval_safely(ruby_code, SAFETY_LEVEL, binding()).to_s
218
+
219
+ OpenWFE::eval_safely(
220
+ ruby_code, DSUB_SAFETY_LEVEL, binding()).to_s
219
221
  end
220
222
  end
221
223