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
@@ -44,10 +44,6 @@ require 'openwfe/flowexpressionid'
44
44
  require 'openwfe/expressions/flowexpression'
45
45
 
46
46
 
47
- #
48
- # expressions like 'set' and 'unset' and their utility methods
49
- #
50
-
51
47
  module OpenWFE
52
48
 
53
49
  #
@@ -61,10 +57,17 @@ module OpenWFE
61
57
  #
62
58
  # (Notice the usage of the dollar notation in the last exemple).
63
59
  #
60
+ # 'set' expressions may be placed outside of a process-definition body,
61
+ # they will be evaluated sequentially before the body gets applied
62
+ # (executed).
63
+ #
64
64
  class SetValueExpression < FlowExpression
65
65
 
66
+ is_definition
67
+
66
68
  names :set
67
69
 
70
+
68
71
  def apply (workitem)
69
72
 
70
73
  if @children.length < 1
@@ -120,18 +123,6 @@ module OpenWFE
120
123
  get_expression_pool().apply(child, workitem)
121
124
  end
122
125
  end
123
-
124
- #def determine_value (workitem)
125
- # if @children.length > 0
126
- # child = @children[0]
127
- # if child.kind_of? FlowExpressionId
128
- # return "nada"
129
- # else
130
- # return child
131
- # end
132
- # end
133
- # return lookup_value(workitem)
134
- #end
135
126
  end
136
127
 
137
128
  #
@@ -159,9 +150,6 @@ module OpenWFE
159
150
 
160
151
  reply_to_parent(workitem)
161
152
  end
162
-
163
- #def reply (workitem)
164
- #end
165
153
  end
166
154
 
167
155
  end
@@ -0,0 +1,104 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, 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/filterdef'
43
+
44
+
45
+ module OpenWFE
46
+
47
+ #
48
+ # This mixin adds filtering capabilities to a FlowExpression.
49
+ #
50
+ # It's used by the 'participant' and 'filter' expressions.
51
+ #
52
+ module FilterMixin
53
+
54
+ attr_accessor :filter
55
+
56
+ #
57
+ # Used when the workitem enters the 'filtered zone'. Will replace
58
+ # the attributes of the workitem with filtered ones.
59
+ # Assumes the original workitem is kept under @applied_workitem.
60
+ #
61
+ def filter_in workitem, filter_attribute_name=:filter
62
+
63
+ @filter = get_filter filter_attribute_name, workitem
64
+
65
+ return unless @filter
66
+
67
+ workitem.attributes = @filter.filter_in workitem.attributes
68
+ workitem.filter = @filter.dup
69
+ end
70
+
71
+ #
72
+ # Prepares the workitem for leaving the 'filtered zone'. Makes sure
73
+ # hidden and unwritable fields haven't been tampered with. Enforces
74
+ # the 'add_ok', 'remove_ok', 'closed' filter directives.
75
+ # Assumes the original workitem is kept under @applied_workitem.
76
+ #
77
+ def filter_out incoming_workitem
78
+
79
+ return unless @filter
80
+
81
+ incoming_workitem.filter = nil
82
+
83
+ incoming_workitem.attributes = @filter.filter_out(
84
+ @applied_workitem.attributes, incoming_workitem.attributes)
85
+ end
86
+
87
+ protected
88
+
89
+ #
90
+ # Fetches the filter pointed at via the 'filter' attribute
91
+ # of the including expression class.
92
+ #
93
+ def get_filter filter_attribute_name, workitem
94
+
95
+ filter_name = lookup_attribute filter_attribute_name, workitem
96
+
97
+ return nil unless filter_name
98
+
99
+ lookup_variable filter_name
100
+ end
101
+ end
102
+
103
+ end
104
+
@@ -148,9 +148,10 @@ module OpenWFE
148
148
  # Returns the parent expression (not as a FlowExpressionId but directly
149
149
  # as the FlowExpression instance it is).
150
150
  #
151
- def get_parent ()
152
- parent, parent_fei = get_expression_pool().fetch(@parent_id)
153
- parent
151
+ def get_parent
152
+ #parent, parent_fei = get_expression_pool.fetch @parent_id
153
+ #parent
154
+ get_expression_pool.fetch_expression @parent_id
154
155
  end
155
156
 
156
157
  #
@@ -160,10 +161,10 @@ module OpenWFE
160
161
  # Else this information would be lost at engine restart or
161
162
  # simply if the expression got swapped out of memory and reloaded later.
162
163
  #
163
- def store_itself ()
164
+ def store_itself
164
165
  ldebug { "store_itself() for #{@fei.to_debug_s}" }
165
166
  #ldebug { "store_itself() \n#{OpenWFE::caller_to_s(0, 6)}" }
166
- get_expression_pool().update(self)
167
+ get_expression_pool.update self
167
168
  end
168
169
 
169
170
  #
@@ -172,17 +173,47 @@ module OpenWFE
172
173
  # definition.
173
174
  # Environments themselves are FlowExpression instances.
174
175
  #
175
- def get_environment ()
176
- return nil if not @environment_id
177
- env, fei = get_expression_pool().fetch(@environment_id)
176
+ def get_environment
177
+
178
+ #return nil if not @environment_id
179
+ #env, fei = get_expression_pool().fetch(@environment_id)
180
+ #env
181
+
182
+ env = fetch_environment
183
+ env = get_expression_pool.fetch_engine_environment unless env
178
184
  env
179
185
  end
180
186
 
187
+ #
188
+ # A shortcut for fetch_environment.get_root_environment
189
+ #
190
+ # Returns the environment of the top process (the environement
191
+ # just before the engine environment in the hierarchy).
192
+ #
193
+ def get_root_environment
194
+ fetch_environment.get_root_environment
195
+ end
196
+
197
+ #
198
+ # A shortcut for fetch_environment.get_process_environment
199
+ #
200
+ #def get_subprocess_environment
201
+ # fetch_environment.get_subprocess_environment
202
+ #end
203
+
204
+ #
205
+ # Just fetches the environment for this expression.
206
+ #
207
+ def fetch_environment
208
+ #return nil unless @environment_id
209
+ get_expression_pool.fetch_expression @environment_id
210
+ end
211
+
181
212
  #
182
213
  # Returns true if the expression's environment was generated
183
214
  # for itself (usually DefineExpression do have such envs)
184
215
  #
185
- def owns_its_environment? ()
216
+ def owns_its_environment?
186
217
 
187
218
  #ldebug do
188
219
  # "owns_its_environment?()\n" +
@@ -192,8 +223,8 @@ module OpenWFE
192
223
 
193
224
  return false if not @environment_id
194
225
 
195
- ei = @fei.dup()
196
- vi = @environment_id.dup()
226
+ ei = @fei.dup
227
+ vi = @environment_id.dup
197
228
 
198
229
  ei.expression_name = "neutral"
199
230
  vi.expression_name = "neutral"
@@ -216,9 +247,13 @@ module OpenWFE
216
247
  #
217
248
  def set_variable (varname, value)
218
249
 
219
- #get_environment()[varname] = value
220
-
221
250
  env, var = lookup_environment(varname)
251
+
252
+ #ldebug do
253
+ # "set_variable() '#{varname}' to '#{value}' " +
254
+ # "in #{env.fei.to_debug_s}"
255
+ #end
256
+
222
257
  env[var] = value
223
258
  end
224
259
 
@@ -232,8 +267,6 @@ module OpenWFE
232
267
  #
233
268
  def lookup_variable (varname)
234
269
 
235
- #get_environment()[varname]
236
-
237
270
  env, var = lookup_environment(varname)
238
271
  env[var]
239
272
  end
@@ -246,8 +279,6 @@ module OpenWFE
246
279
  #
247
280
  def delete_variable (varname)
248
281
 
249
- #get_environment().delete(varname)
250
-
251
282
  env, var = lookup_environment(varname)
252
283
  env.delete var
253
284
  end
@@ -285,6 +316,16 @@ module OpenWFE
285
316
  OpenWFE::dosub(text, self, workitem)
286
317
  end
287
318
 
319
+ #
320
+ # Like lookup_attribute() but returns the value downcased.
321
+ # Returns nil if no such attribute was found.
322
+ #
323
+ def lookup_downcase_attribute (attname, workitem, default=nil)
324
+ result = lookup_attribute attname, workitem, default
325
+ result = result.downcase if result
326
+ result
327
+ end
328
+
288
329
  #
289
330
  # Returns true if the expression has the given attribute.
290
331
  # The attname parameter can be a String or a Symbol.
@@ -369,7 +410,7 @@ module OpenWFE
369
410
  #
370
411
  # creates a new environment just for this expression
371
412
  #
372
- def new_environment ()
413
+ def new_environment (initial_vars=nil)
373
414
 
374
415
  ldebug { "new_environment() for #{@fei.to_debug_s}" }
375
416
 
@@ -384,14 +425,31 @@ module OpenWFE
384
425
 
385
426
  parent_fei = parent.environment_id if parent
386
427
 
387
- env = Environment\
388
- .new(@environment_id, parent_fei, nil, @application_context, nil)
428
+ env = Environment.new(
429
+ @environment_id, parent_fei, nil, @application_context, nil)
430
+
431
+ env.variables.merge!(initial_vars) if initial_vars
389
432
 
390
433
  ldebug { "new_environment() is #{env.fei.to_debug_s}" }
391
434
 
392
435
  return env.store_itself()
393
436
  end
394
437
 
438
+ #
439
+ # This method is called in expressionpool.forget(). It duplicates
440
+ # the expression's current environment (deep copy) and attaches
441
+ # it as the expression own environment.
442
+ # Returns the duplicated environment.
443
+ #
444
+ def dup_environment
445
+ env = fetch_environment
446
+ env = env.dup
447
+ env.fei = @fei.dup
448
+ env.fei.expression_name = EN_ENVIRONMENT
449
+ @environment_id = env.fei
450
+ return env.store_itself
451
+ end
452
+
395
453
  #
396
454
  # Takes care of removing all the children of this expression, if any.
397
455
  #
@@ -501,26 +559,24 @@ module OpenWFE
501
559
 
502
560
  s = "* #{@fei.to_debug_s}"
503
561
 
504
- if @parent_id
505
- s << "\n `--p--> #{@parent_id.to_debug_s}"
506
- end
562
+ s << "\n `--p--> #{@parent_id.to_debug_s}" \
563
+ if @parent_id
507
564
 
508
- if @environment_id
509
- s << "\n `--e--> #{@environment_id.to_debug_s}"
510
- end
565
+ s << "\n `--e--> #{@environment_id.to_debug_s}" \
566
+ if @environment_id
511
567
 
512
- if @children
513
- @children.each do |c|
514
- sc = if c.kind_of?(OpenWFE::FlowExpressionId)
515
- c.to_debug_s
516
- else
517
- ">#{c.to_s}<"
518
- end
519
- s << "\n `--c--> #{sc}"
568
+ return s unless @children
569
+
570
+ @children.each do |c|
571
+ sc = if c.kind_of?(OpenWFE::FlowExpressionId)
572
+ c.to_debug_s
573
+ else
574
+ ">#{c.to_s}<"
520
575
  end
576
+ s << "\n `--c--> #{sc}"
521
577
  end
522
578
 
523
- return s
579
+ s
524
580
  end
525
581
 
526
582
  #
@@ -528,6 +584,7 @@ module OpenWFE
528
584
  # Expression classes.
529
585
  #
530
586
  def self.names (*exp_names)
587
+
531
588
  exp_names = exp_names.collect do |n|
532
589
  n.to_s
533
590
  end
@@ -536,6 +593,15 @@ module OpenWFE
536
593
  end
537
594
  end
538
595
 
596
+ def self.is_definition?
597
+ false
598
+ end
599
+ def self.is_definition
600
+ meta_def :is_definition? do
601
+ true
602
+ end
603
+ end
604
+
539
605
  protected
540
606
 
541
607
  #
@@ -560,7 +626,7 @@ module OpenWFE
560
626
  ]
561
627
  end
562
628
 
563
- return [ get_environment, varname]
629
+ [ get_environment, varname]
564
630
  end
565
631
 
566
632
  #
@@ -0,0 +1,80 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2007, John Mettraux, 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
+ # Gathering methods for mixing (merging) workitems.
49
+ #
50
+ module MergeMixin
51
+
52
+ #
53
+ # Merges a source workitem into a target workitem (the fields
54
+ # of the source will overwrite the fields in the target).
55
+ #
56
+ # Returns the resulting (merged) workitem.
57
+ #
58
+ def merge_workitems (wiTarget, wiSource, override=false)
59
+
60
+ return wiSource unless wiTarget
61
+ return wiTarget unless wiSource
62
+
63
+ return wiSource if override
64
+
65
+ wiSource.attributes.each do |k, v|
66
+
67
+ #puts "merge() '#{k}' => '#{v}'"
68
+
69
+ nk = OpenWFE::fulldup(k)
70
+ nv = OpenWFE::fulldup(v)
71
+
72
+ wiTarget.attributes[nk] = nv
73
+ end
74
+
75
+ wiTarget
76
+ end
77
+ end
78
+
79
+ end
80
+