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
@@ -39,66 +39,83 @@
39
39
  # John Mettraux at openwfe.org
40
40
  #
41
41
 
42
- require 'openwfe/rudefinitions'
42
+ #require 'openwfe/rudefinitions'
43
43
  require 'openwfe/expressions/flowexpression'
44
+ require 'openwfe/expressions/fe_sequence'
44
45
 
45
46
 
46
47
  module OpenWFE
47
48
 
48
- class DefineExpression < FlowExpression
49
+ #
50
+ # The <process-definition> expression.
51
+ #
52
+ class DefineExpression < SequenceExpression
53
+
54
+ is_definition
49
55
 
50
56
  names :define, :process_definition, :workflow_definition
51
57
 
58
+
59
+ attr_accessor :body_fei, :eval_only
60
+
61
+ #
62
+ # Evaluates the definition, but doesn't apply its body, will
63
+ # simply return the body fei.
64
+ #
52
65
  def evaluate (workitem)
66
+ @eval_only = true
67
+ apply workitem
68
+ return @body_fei
69
+ end
53
70
 
54
- #ldebug { "evaluate() #{@fei.to_s}" }
71
+ #
72
+ # Called at the end of the 'evaluation', the 'apply' operation on
73
+ # the body of the definition is done here.
74
+ #
75
+ def reply_to_parent (workitem)
55
76
 
56
- #
57
- # spot the body of this expression
58
- # define each sub-definition
77
+ return if @eval_only
59
78
 
60
- body_fei = nil
79
+ unless @body_fei
80
+ super workitem
81
+ return
82
+ end
61
83
 
62
- @children.each do |fei|
84
+ fei = @body_fei
85
+ @body_fei = nil
63
86
 
64
- #ldebug { "evaluate() looking at #{fei.to_debug_s}" }
87
+ store_itself()
65
88
 
66
- rawchild, _fei = get_expression_pool().fetch(fei)
89
+ get_expression_pool.apply fei, workitem
90
+ end
67
91
 
68
- if not rawchild.is_definition?
69
- body_fei = rawchild.fei if not body_fei
70
- next
71
- end
92
+ protected
72
93
 
73
- # then it's a definition
94
+ def get_to_next_child
74
95
 
75
- get_environment()[rawchild.definition_name()] = fei
76
- end
77
-
78
- #
79
- # store self
96
+ next_fei = super
80
97
 
81
- store_itself()
98
+ return nil unless next_fei
82
99
 
83
- #
84
- # return the id of the body
100
+ rawchild = get_expression_pool.fetch_expression next_fei
85
101
 
86
- return body_fei
87
- end
102
+ unless rawchild.is_definition?
103
+ @body_fei = next_fei unless @body_fei
104
+ return get_to_next_child
105
+ end
88
106
 
89
- #
90
- # apply / reply
107
+ exp_class = get_expression_map.get_class rawchild
91
108
 
92
- def apply (workitem)
93
- #
94
- # apply the body
109
+ if exp_class == DefineExpression
110
+ get_environment()[rawchild.definition_name()] = next_fei
111
+ return get_to_next_child
112
+ end
95
113
 
96
- body_fei = evaluate(workitem)
97
- get_expression_pool().apply(body_fei, workitem)
98
- end
114
+ #
115
+ # our next child will simply get applied
99
116
 
100
- #def reply (workitem)
101
- #end
117
+ next_fei
118
+ end
102
119
  end
103
120
 
104
121
  end
@@ -0,0 +1,129 @@
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/expressions/filter'
43
+
44
+
45
+ module OpenWFE
46
+
47
+ #
48
+ # This expression applies a filter to the workitem used by the process
49
+ # segment nested within it.
50
+ #
51
+ # class TestFilter48a0 < ProcessDefinition
52
+ # sequence do
53
+ #
54
+ # set :field => "readable", :value => "bible"
55
+ # set :field => "writable", :value => "sand"
56
+ # set :field => "randw", :value => "notebook"
57
+ # set :field => "hidden", :value => "playboy"
58
+ #
59
+ # alice
60
+ #
61
+ # filter :name => "filter0" do
62
+ # sequence do
63
+ # bob
64
+ # charly
65
+ # end
66
+ # end
67
+ #
68
+ # doug
69
+ # end
70
+ #
71
+ # filter_definition :name => "filter0" do
72
+ # field :regex => "readable", :permissions => "r"
73
+ # field :regex => "writable", :permissions => "w"
74
+ # field :regex => "randw", :permissions => "rw"
75
+ # field :regex => "hidden", :permissions => ""
76
+ # end
77
+ # end
78
+ #
79
+ # In this example, the filter 'filter0' is applied upon entering bob and
80
+ # charly's sequence.
81
+ #
82
+ # Please note that the filter will not be enforced between bob and charly,
83
+ # it is enforced just before entering the sequence and just after leaving
84
+ # it.
85
+ #
86
+ # Note also that the ParticipantExpression accepts a 'filter' attribute,
87
+ # thus :
88
+ #
89
+ # <filter name="filter0">
90
+ # <participant ref="toto" />
91
+ # </filter>
92
+ #
93
+ # can be simplified to :
94
+ #
95
+ # <participant ref="toto" filter="filter0" />
96
+ #
97
+ class FilterExpression < FlowExpression
98
+ include FilterMixin
99
+
100
+ names :filter
101
+
102
+ attr_accessor :applied_workitem, :filter
103
+
104
+
105
+ def apply workitem
106
+
107
+ if @children.length < 1
108
+ reply_to_parent workitem
109
+ return
110
+ end
111
+
112
+ @applied_workitem = workitem.dup
113
+ filter_in workitem, :name
114
+
115
+ store_itself
116
+
117
+ get_expression_pool.apply @children[0], workitem
118
+ end
119
+
120
+ def reply workitem
121
+
122
+ filter_out workitem
123
+
124
+ reply_to_parent workitem
125
+ end
126
+ end
127
+
128
+ end
129
+
@@ -0,0 +1,170 @@
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 expression binds a filter definition into a variable.
49
+ #
50
+ # class TestFilter48a0 < ProcessDefinition
51
+ # sequence do
52
+ #
53
+ # set :field => "readable", :value => "bible"
54
+ # set :field => "writable", :value => "sand"
55
+ # set :field => "randw", :value => "notebook"
56
+ # set :field => "hidden", :value => "playboy"
57
+ #
58
+ # alice
59
+ #
60
+ # filter :name => "filter0" do
61
+ # sequence do
62
+ # bob
63
+ # charly
64
+ # end
65
+ # end
66
+ #
67
+ # doug
68
+ # end
69
+ #
70
+ # filter_definition :name => "filter0" do
71
+ # field :regex => "readable", :permissions => "r"
72
+ # field :regex => "writable", :permissions => "w"
73
+ # field :regex => "randw", :permissions => "rw"
74
+ # field :regex => "hidden", :permissions => ""
75
+ # end
76
+ # end
77
+ #
78
+ # In that example, the filter definition is done for filter 'filter0'.
79
+ #
80
+ # A filter definition accepts 4 attributes :
81
+ #
82
+ # * 'name' - simply naming the filter, the filter is then bound as a variable. This is the only mandatory attribute.
83
+ #
84
+ # * 'closed' - by default, set to 'false'. A closed filter will not allow modifications to unspecified fields.
85
+ #
86
+ # * 'add' - by default, set to 'true'. When true, this filter accepts adding new fields to the filtered workitem.
87
+ #
88
+ # * 'remove' - by default, set to 'true'. When true, this filter accepts removing fields to the filtered workitem.
89
+ #
90
+ #
91
+ # Inside of the process definition, fields are identified via regular
92
+ # expressions ('regex'), a 'permissions' string is then expected with four
93
+ # possible values "rw", "w", "r" and "".
94
+ #
95
+ class FilterDefinitionExpression < FlowExpression
96
+
97
+ is_definition
98
+
99
+ names :filter_definition
100
+
101
+
102
+ #
103
+ # Will build the filter and bind it as a variable.
104
+ #
105
+ def apply (workitem)
106
+
107
+ filter = build_filter workitem
108
+ filter_name = lookup_attribute :name, workitem
109
+
110
+ set_variable filter_name, filter \
111
+ if filter_name and filter
112
+
113
+ reply_to_parent workitem
114
+ end
115
+
116
+ protected
117
+
118
+ #
119
+ # Builds the filter (as described in the process definition)
120
+ # and returns it.
121
+ #
122
+ def build_filter (workitem)
123
+
124
+ filter = FilterDefinition.new
125
+
126
+ # filter attributes
127
+
128
+ type = lookup_downcase_attribute :type, workitem
129
+ closed = lookup_downcase_attribute :closed, workitem
130
+
131
+ filter.closed = (type == "closed" or closed == "true")
132
+
133
+ add = lookup_downcase_attribute :add, workitem
134
+ remove = lookup_downcase_attribute :remove, workitem
135
+
136
+ filter.add_allowed = (add == "true")
137
+ filter.remove_allowed = (remove == "true")
138
+
139
+ # field by field
140
+
141
+ @children.each do |fei|
142
+
143
+ rawexp = get_expression_pool.fetch_expression fei
144
+ get_expression_pool.remove fei
145
+
146
+ add_field filter, rawexp, workitem
147
+ end
148
+
149
+ filter
150
+ end
151
+
152
+ #
153
+ # builds and add a field (a line) of the filter.
154
+ #
155
+ def add_field (filter, rawexp, workitem)
156
+
157
+ rawexp.load_attributes
158
+
159
+ regex = rawexp.lookup_attribute :regex, workitem
160
+ regex = rawexp.lookup_attribute :name, workitem unless regex
161
+
162
+ permissions =
163
+ rawexp.lookup_downcase_attribute :permissions, workitem
164
+
165
+ filter.add_field regex, permissions
166
+ end
167
+ end
168
+
169
+ end
170
+
@@ -39,6 +39,7 @@
39
39
  # John Mettraux at openwfe.org
40
40
  #
41
41
 
42
+ require 'openwfe/expressions/wtemplate'
42
43
  require 'openwfe/expressions/flowexpression'
43
44
 
44
45
 
@@ -57,16 +58,15 @@ module OpenWFE
57
58
  # />
58
59
  # </iterator>
59
60
  #
60
- # Within the iteration, the workitem field "__ic__" contains the number
61
- # of elements in the iteration and the field "__ip__" the index of the
61
+ # Within the iteration, the workitem field "\_\_ic__" contains the number
62
+ # of elements in the iteration and the field "\_\_ip__" the index of the
62
63
  # current iteration.
63
64
  #
64
65
  class IteratorExpression < WithTemplateExpression
65
66
 
66
67
  names :iterator
67
68
 
68
- attr_accessor \
69
- :iterator
69
+ attr_accessor :iterator
70
70
 
71
71
  def apply (workitem)
72
72
 
@@ -77,7 +77,7 @@ module OpenWFE
77
77
 
78
78
  @iterator = Iterator.new(self, workitem)
79
79
 
80
- reply(workitem)
80
+ reply workitem
81
81
  end
82
82
 
83
83
  def reply (workitem)
@@ -87,12 +87,12 @@ module OpenWFE
87
87
  return
88
88
  end
89
89
 
90
- @iterator.next(self, workitem)
90
+ vars = @iterator.next(self, workitem)
91
91
 
92
92
  store_itself()
93
93
 
94
94
  get_expression_pool.launch_template(
95
- self, @iterator.counter-1, @children[0], workitem, nil)
95
+ self, @iterator.index, @children[0], workitem, vars)
96
96
  end
97
97
  end
98
98
 
@@ -103,6 +103,9 @@ module OpenWFE
103
103
  #
104
104
  class Iterator
105
105
 
106
+ ITERATOR_COUNT = "__ic__"
107
+ ITERATOR_POSITION = "__ip__"
108
+
106
109
  attr_accessor \
107
110
  :iteration_list,
108
111
  :to_field,
@@ -129,7 +132,7 @@ module OpenWFE
129
132
 
130
133
  @iteration_list = extract_iteration_list(raw_list)
131
134
 
132
- workitem.attributes['__ic__'] = @iteration_list.length
135
+ workitem.attributes[ITERATOR_COUNT] = @iteration_list.length
133
136
  end
134
137
 
135
138
  #
@@ -145,17 +148,27 @@ module OpenWFE
145
148
  #
146
149
  def next (iterator_expression, workitem)
147
150
 
151
+ result = {}
152
+
148
153
  value = @iteration_list.pop
149
154
 
150
155
  if @to_field
151
156
  workitem.attributes[@to_field] = value
152
157
  else
153
- iterator_expression.set_variable(@to_variable, value)
158
+ #iterator_expression.set_variable(@to_variable, value)
159
+ result[@to_variable] = value
154
160
  end
155
161
 
156
- workitem.attributes['__ip__'] = @counter
162
+ workitem.attributes[ITERATOR_POSITION] = @counter
163
+ result[ITERATOR_POSITION] = @counter
157
164
 
158
165
  @counter = @counter + 1
166
+
167
+ result
168
+ end
169
+
170
+ def index
171
+ return @counter - 1
159
172
  end
160
173
 
161
174
  protected