openwferu 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/README +47 -0
  2. data/lib/codec.rb +571 -0
  3. data/lib/controlclient.rb +115 -0
  4. data/lib/definitions.rb +112 -0
  5. data/lib/exception.rb +60 -0
  6. data/lib/flowexpressionid.rb +137 -0
  7. data/lib/openwferu.rb +43 -0
  8. data/lib/osocket.rb +138 -0
  9. data/lib/otime.rb +171 -0
  10. data/lib/restclient.rb +155 -0
  11. data/lib/ru/contextual.rb +63 -0
  12. data/lib/ru/dollar.rb +163 -0
  13. data/lib/ru/engine.rb +130 -0
  14. data/lib/ru/environment.rb +140 -0
  15. data/lib/ru/expressionmap.rb +120 -0
  16. data/lib/ru/expressionpool.rb +339 -0
  17. data/lib/ru/expressionstorage.rb +97 -0
  18. data/lib/ru/fe_base.rb +105 -0
  19. data/lib/ru/fe_concurrence.rb +122 -0
  20. data/lib/ru/fe_define.rb +101 -0
  21. data/lib/ru/fe_misc.rb +96 -0
  22. data/lib/ru/fe_participant.rb +75 -0
  23. data/lib/ru/fe_raw.rb +173 -0
  24. data/lib/ru/fe_subprocess.rb +84 -0
  25. data/lib/ru/fe_time.rb +135 -0
  26. data/lib/ru/fe_utils.rb +123 -0
  27. data/lib/ru/fe_value.rb +225 -0
  28. data/lib/ru/flowexpression.rb +250 -0
  29. data/lib/ru/logging.rb +85 -0
  30. data/lib/ru/participant.rb +67 -0
  31. data/lib/ru/participantmap.rb +93 -0
  32. data/lib/ru/participants.rb +74 -0
  33. data/lib/ru/rudefinitions.rb +70 -0
  34. data/lib/ru/ruutils.rb +68 -0
  35. data/lib/ru/scheduler.rb +478 -0
  36. data/lib/ru/schedulers.rb +63 -0
  37. data/lib/ru/service.rb +64 -0
  38. data/lib/test.rb +220 -0
  39. data/lib/utils.rb +94 -0
  40. data/lib/workitem.rb +250 -0
  41. data/lib/worklistclient.rb +276 -0
  42. data/test/dollartest.rb +79 -0
  43. data/test/feitest.rb +130 -0
  44. data/test/flowtestbase.rb +86 -0
  45. data/test/ft_0.rb +161 -0
  46. data/test/ft_1_unset.rb +152 -0
  47. data/test/ft_2_concurrence.rb +34 -0
  48. data/test/ft_3_equals.rb +84 -0
  49. data/test/ft_4_misc.rb +128 -0
  50. data/test/ft_5_time.rb +56 -0
  51. data/test/misctest.rb +46 -0
  52. data/test/runtest.rb +21 -0
  53. data/test/rutest_utils.rb +15 -0
  54. data/test/timetest.rb +111 -0
  55. metadata +100 -0
@@ -0,0 +1,84 @@
1
+ #
2
+ # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ #require 'workitem'
41
+ #require 'ru/flowexpression'
42
+ #require 'ru/fe_utils'
43
+
44
+
45
+ #
46
+ # the subprocess expression
47
+ #
48
+
49
+ module OpenWFEru
50
+
51
+ class SubprocessRefExpression < FlowExpression
52
+
53
+ #
54
+ # apply / reply
55
+
56
+ def apply (workitem)
57
+
58
+ ref = OpenWFEru::lookup_ref(self, workitem)
59
+
60
+ raise "'subprocess' expression misses a 'ref', 'field-ref' or 'variable-ref' attribute" if not ref
61
+
62
+ template_fei = lookup_variable(ref)
63
+
64
+ raise "did not find any subprocess named '#{ref}'" \
65
+ if not template_fei
66
+
67
+ sForget = lookup_attribute(A_FORGET, workitem)
68
+
69
+ requester = @fei
70
+ requester = @fei.workflowInstanceId \
71
+ if sForget and sForget.downcase == 'true'
72
+
73
+ params = list_attributes(workitem)
74
+
75
+ get_expression_pool()\
76
+ .launch_template(requester, template_fei, workitem, params)
77
+ end
78
+
79
+ #def reply (workitem)
80
+ #end
81
+ end
82
+
83
+ end
84
+
data/lib/ru/fe_time.rb ADDED
@@ -0,0 +1,135 @@
1
+ #
2
+ # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ require 'otime'
41
+ require 'ru/scheduler'
42
+ require 'ru/rudefinitions'
43
+
44
+
45
+ #
46
+ # expressions like 'sleep' and 'cron'
47
+ #
48
+
49
+ module OpenWFEru
50
+
51
+ #
52
+ # A parent class for CronExpression and SleepExpression, is never
53
+ # used directly.
54
+ # It contains a simple get_scheduler() method simplifying the scheduler
55
+ # localization for <sleep/> and <cron/>.
56
+ #
57
+ class TimeExpression < FlowExpression
58
+
59
+ def get_scheduler
60
+ return @application_context[S_SCHEDULER]
61
+ end
62
+ end
63
+
64
+ #
65
+ # The 'sleep' expression expects one attribute, either 'for', either
66
+ # 'until'.
67
+ #
68
+ # <sequence>
69
+ # <sleep for="10m12s" />
70
+ # <participant ref="alpha" />
71
+ # </sequence>
72
+ #
73
+ # will wait for 10 minutes and 12 seconds before sending a workitem
74
+ # to participant 'alpha'.
75
+ #
76
+ class SleepExpression < TimeExpression
77
+ include Schedulable
78
+
79
+ attr_accessor \
80
+ :sleeping_workitem,
81
+ :awakening_time
82
+
83
+ def apply (workitem)
84
+
85
+ sfor = lookup_attribute("for", workitem)
86
+ suntil = lookup_attribute("until", workitem)
87
+
88
+ tuntil = nil
89
+
90
+ if suntil
91
+ tuntil = suntil
92
+ elsif sfor
93
+ tfor = OpenWFE::parse_time_string(sfor)
94
+ now = Time.new
95
+ #tuntil = now.to_f + now.gmt_offset + tfor
96
+ tuntil = now.to_f + tfor
97
+ end
98
+
99
+ if not tuntil
100
+ reply_to_parent(workitem)
101
+ return
102
+ end
103
+
104
+ @awakening_time = tuntil
105
+ @sleeping_workitem = workitem.dup
106
+
107
+ store_itself()
108
+
109
+ #ldebug do
110
+ # "apply() " +
111
+ # "will sleep until '#{tuntil}' " +
112
+ # "(#{OpenWFE::to_iso_date(tuntil)})"
113
+ #end
114
+
115
+ get_scheduler.schedule_at(tuntil, self, nil)
116
+ end
117
+
118
+ #def reply (workitem)
119
+ #end
120
+
121
+ #
122
+ # This is the method called by the Scheduler instance attached to
123
+ # the workflow engine when the 'sleep' of this expression is
124
+ # over
125
+ #
126
+ def trigger (params)
127
+ reply_to_parent(@sleeping_workitem)
128
+ end
129
+ end
130
+
131
+ class CronExpression < TimeExpression
132
+ end
133
+
134
+ end
135
+
@@ -0,0 +1,123 @@
1
+ #
2
+ # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ require 'ru/fe_raw'
41
+ require 'ru/dollar'
42
+ require 'ru/rudefinitions'
43
+
44
+ #
45
+ # a few help methods for expressions
46
+
47
+ module OpenWFEru
48
+
49
+ #
50
+ # Returns the text stored as the children of the given expression
51
+ #
52
+ def OpenWFEru.fetch_text_content (expression, workitem, escape=false)
53
+
54
+ text = ""
55
+
56
+ expression.children.each do |child|
57
+ if child.kind_of?(RawExpression)
58
+ text << child.fei.to_s
59
+ else
60
+ text << child.to_s
61
+ end
62
+ text << "\n"
63
+ end
64
+
65
+ text = dosub(text, expression, workitem) \
66
+ if not escape
67
+
68
+ return text
69
+ end
70
+
71
+ #
72
+ # looks up for 'value', 'variable-value' and then for 'field-value'
73
+ # if necessary.
74
+ #
75
+ def OpenWFEru.lookup_value (flow_expression, workitem, prefix='')
76
+
77
+ return OpenWFEru\
78
+ .lookup_vf_attribute(flow_expression, workitem, 'value', prefix)
79
+ end
80
+
81
+ #
82
+ # looks up for 'ref', 'variable-ref' and then for 'field-ref'
83
+ # if necessary.
84
+ #
85
+ def OpenWFEru.lookup_ref (flow_expression, workitem, prefix='')
86
+
87
+ return OpenWFEru\
88
+ .lookup_vf_attribute(flow_expression, workitem, 'ref', prefix)
89
+ end
90
+
91
+ #
92
+ # looks up for value attributes like 'field-ref' or 'variable-value'
93
+ #
94
+ def OpenWFEru.lookup_vf_attribute \
95
+ (flow_expression, workitem, att_name, prefix='')
96
+
97
+ prefix = "#{prefix}-" if prefix != ''
98
+
99
+ v = flow_expression.lookup_attribute("#{prefix}#{att_name}", workitem)
100
+
101
+ if not v
102
+ v = flow_expression\
103
+ .lookup_attribute("#{prefix}variable-#{att_name}", workitem)
104
+ end
105
+
106
+ if not v
107
+ v = flow_expression\
108
+ .lookup_attribute("#{prefix}field-#{att_name}", workitem)
109
+ end
110
+
111
+ return v
112
+ end
113
+
114
+ #
115
+ # sets the '__result__' field of the workitem
116
+ #
117
+ def OpenWFEru.set_result (workitem, result)
118
+
119
+ workitem.attributes[FIELD_RESULT] = result
120
+ end
121
+
122
+ end
123
+
@@ -0,0 +1,225 @@
1
+ #
2
+ # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are met:
7
+ #
8
+ # . Redistributions of source code must retain the above copyright notice, this
9
+ # list of conditions and the following disclaimer.
10
+ #
11
+ # . Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ #
15
+ # . Neither the name of the "OpenWFE" nor the names of its contributors may be
16
+ # used to endorse or promote products derived from this software without
17
+ # specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+ #
31
+ # $Id: definitions.rb 2725 2006-06-02 13:26:32Z jmettraux $
32
+ #
33
+
34
+ #
35
+ # "made in Japan"
36
+ #
37
+ # John Mettraux at openwfe.org
38
+ #
39
+
40
+ require 'workitem'
41
+ require 'flowexpressionid'
42
+ require 'ru/flowexpression'
43
+ require 'ru/fe_utils'
44
+
45
+
46
+ #
47
+ # expressions like 'set' and 'unset' and their utility methods
48
+ #
49
+
50
+ module OpenWFEru
51
+
52
+ class SetValueExpression < FlowExpression
53
+
54
+ def apply (workitem)
55
+
56
+ if @children.length < 1
57
+ workitem.attributes[FIELD_RESULT] = \
58
+ OpenWFEru::lookup_value(self, workitem)
59
+ reply(workitem)
60
+ return
61
+ end
62
+
63
+ child = @children[0]
64
+
65
+ if child.kind_of? OpenWFE::FlowExpressionId
66
+ store_itself()
67
+ get_expression_pool().apply(child, workitem)
68
+ return
69
+ end
70
+
71
+ workitem.attributes[FIELD_RESULT] = child.to_s
72
+
73
+ reply(workitem)
74
+ end
75
+
76
+ def reply (workitem)
77
+
78
+ vkey = lookup_attribute("variable", workitem)
79
+ fkey = lookup_attribute("field", workitem)
80
+
81
+ value = workitem.attributes[FIELD_RESULT]
82
+
83
+ #puts "value is '#{value}'"
84
+
85
+ if vkey
86
+ set_variable(vkey, value)
87
+ elsif fkey
88
+ workitem.attributes[fkey] = value
89
+ else
90
+ raise "'variable' or 'field' attribute missing from 'set' expression"
91
+ end
92
+
93
+ reply_to_parent(workitem)
94
+ end
95
+
96
+ protected
97
+
98
+ def determine_value (workitem)
99
+
100
+ if @children.length > 0
101
+ child = @children[0]
102
+
103
+ if child.kind_of? FlowExpressionId
104
+ return "nada"
105
+ else
106
+ return child
107
+ end
108
+ end
109
+
110
+ return OpenWFEru::lookup_value(self, workitem)
111
+ end
112
+ end
113
+
114
+ class UnsetValueExpression < FlowExpression
115
+
116
+ def apply (workitem)
117
+
118
+ vkey = lookup_attribute("variable", workitem)
119
+ fkey = lookup_attribute("field", workitem)
120
+
121
+ if vkey
122
+ delete_variable(vkey)
123
+ elsif fkey
124
+ workitem.attributes.delete(fkey)
125
+ else
126
+ raise "attribute 'variable' or 'field' is missing for 'unset' expression"
127
+ end
128
+
129
+ reply_to_parent(workitem)
130
+ end
131
+
132
+ #def reply (workitem)
133
+ #end
134
+ end
135
+
136
+ class ComparisonExpression < FlowExpression
137
+
138
+ def apply (workitem)
139
+
140
+ value_a = OpenWFEru::lookup_value(self, workitem)
141
+ value_b = OpenWFEru::lookup_value(self, workitem, 'other')
142
+
143
+ result = compare(value_a, value_b)
144
+
145
+ ldebug { "apply() result is '#{result}' #{@fei.to_debug_s}" }
146
+
147
+ OpenWFEru::set_result(workitem, result)
148
+
149
+ reply_to_parent(workitem)
150
+ end
151
+
152
+ protected
153
+
154
+ def compare (a, b)
155
+ raise "not yet implemented : '#{@fei.expressionName}'"
156
+ end
157
+ end
158
+
159
+ #
160
+ # <equals/>
161
+ #
162
+ class EqualsExpression < ComparisonExpression
163
+
164
+ protected
165
+
166
+ def compare (a, b)
167
+ return a == b
168
+ end
169
+ end
170
+
171
+ #
172
+ # <if/>
173
+ #
174
+ class IfExpression < FlowExpression
175
+
176
+ attr_accessor \
177
+ :condition_replied
178
+
179
+ def apply (workitem)
180
+
181
+ reply_to_parent(workitem) if @children.length < 1
182
+
183
+ @condition_replied = false
184
+
185
+ store_itself()
186
+
187
+ get_expression_pool.apply(@children[0], workitem)
188
+ end
189
+
190
+ def reply (workitem)
191
+
192
+ if @condition_replied
193
+ reply_to_parent(workitem)
194
+ return
195
+ end
196
+
197
+ result = workitem.attributes[FIELD_RESULT]
198
+
199
+ @condition_replied = true
200
+
201
+ if result
202
+ apply_consequence(1, workitem)
203
+ else
204
+ apply_consequence(2, workitem)
205
+ end
206
+ end
207
+
208
+ def reply_to_parent(workitem)
209
+ clean_children()
210
+ super(workitem)
211
+ end
212
+
213
+ protected
214
+
215
+ def apply_consequence (index, workitem)
216
+ if index >= @children.length
217
+ reply_to_parent(workitem)
218
+ else
219
+ get_expression_pool.apply(@children[index], workitem)
220
+ end
221
+ end
222
+ end
223
+
224
+ end
225
+