openwferu 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/{README → README.txt} +16 -13
  2. data/bin/validate-workflow.rb +46 -22
  3. data/examples/README.txt +8 -0
  4. data/examples/homeworkreview.rb +66 -0
  5. data/examples/quotereporter.rb +154 -0
  6. data/lib/{openwferu.rb → openwfe.rb} +6 -8
  7. data/lib/{ru → openwfe}/contextual.rb +11 -3
  8. data/lib/{ru → openwfe/engine}/engine.rb +50 -36
  9. data/lib/{ru/participant.rb → openwfe/engine/file_persisted_engine.rb} +21 -22
  10. data/lib/openwfe/expool/expressionpool.rb +534 -0
  11. data/lib/openwfe/expool/expstorage.rb +184 -0
  12. data/lib/openwfe/expool/journalexpstorage.rb +312 -0
  13. data/lib/openwfe/expool/yamlexpstorage.rb +127 -0
  14. data/lib/{ru → openwfe/expressions}/environment.rb +19 -14
  15. data/lib/{ru → openwfe/expressions}/expressionmap.rb +48 -21
  16. data/lib/{ru → openwfe/expressions}/fe_concurrence.rb +111 -35
  17. data/lib/openwfe/expressions/fe_cursor.rb +236 -0
  18. data/lib/{ru → openwfe/expressions}/fe_define.rb +5 -5
  19. data/lib/openwfe/expressions/fe_fqv.rb +99 -0
  20. data/lib/openwfe/expressions/fe_iterator.rb +182 -0
  21. data/lib/{ru/fe_misc.rb → openwfe/expressions/fe_losfor.rb} +14 -56
  22. data/lib/openwfe/expressions/fe_misc.rb +102 -0
  23. data/lib/{ru → openwfe/expressions}/fe_participant.rb +25 -14
  24. data/lib/{ru → openwfe/expressions}/fe_raw.rb +39 -75
  25. data/lib/{ru/fe_base.rb → openwfe/expressions/fe_sequence.rb} +40 -35
  26. data/lib/{ru → openwfe/expressions}/fe_subprocess.rb +30 -14
  27. data/lib/{ru → openwfe/expressions}/fe_time.rb +59 -31
  28. data/lib/{ru → openwfe/expressions}/fe_utils.rb +42 -26
  29. data/lib/{ru → openwfe/expressions}/fe_value.rb +20 -14
  30. data/lib/openwfe/expressions/flowexpression.rb +434 -0
  31. data/lib/openwfe/expressions/raw_prog.rb +391 -0
  32. data/lib/openwfe/expressions/raw_xml.rb +128 -0
  33. data/lib/openwfe/flowexpressionid.rb +148 -0
  34. data/lib/{ru → openwfe}/logging.rb +10 -6
  35. data/lib/{osocket.rb → openwfe/osocket.rb} +36 -35
  36. data/lib/{otime.rb → openwfe/otime.rb} +71 -21
  37. data/lib/openwfe/participants/atomparticipants.rb +144 -0
  38. data/lib/openwfe/participants/enoparticipant.rb +73 -0
  39. data/lib/openwfe/participants/participant.rb +85 -0
  40. data/lib/{ru → openwfe/participants}/participantmap.rb +40 -12
  41. data/lib/{ru → openwfe/participants}/participants.rb +41 -12
  42. data/lib/openwfe/participants/soapparticipants.rb +96 -0
  43. data/lib/{controlclient.rb → openwfe/rest/controlclient.rb} +12 -13
  44. data/lib/{definitions.rb → openwfe/rest/definitions.rb} +3 -3
  45. data/lib/{exception.rb → openwfe/rest/exception.rb} +3 -3
  46. data/lib/{restclient.rb → openwfe/rest/restclient.rb} +13 -22
  47. data/lib/{worklistclient.rb → openwfe/rest/worklistclient.rb} +33 -46
  48. data/lib/openwfe/rest/xmlcodec.rb +575 -0
  49. data/lib/{ru → openwfe}/rudefinitions.rb +32 -4
  50. data/lib/{ru → openwfe}/service.rb +20 -8
  51. data/lib/openwfe/storage/yamlfilestorage.rb +159 -0
  52. data/lib/{ru → openwfe/util}/dollar.rb +10 -8
  53. data/lib/openwfe/util/lru_cache.rb +149 -0
  54. data/lib/{ru → openwfe/util}/scheduler.rb +18 -10
  55. data/lib/{ru → openwfe/util}/schedulers.rb +7 -7
  56. data/lib/{utils.rb → openwfe/utils.rb} +93 -9
  57. data/lib/openwfe/workitem.rb +366 -0
  58. data/lib/openwfe/worklist/worklists.rb +175 -0
  59. data/test/README.txt +27 -0
  60. data/test/atomtest.rb +99 -0
  61. data/test/crontest.rb +58 -0
  62. data/test/dollartest.rb +3 -3
  63. data/test/feitest.rb +42 -14
  64. data/test/file_persistence_test.rb +93 -0
  65. data/test/flowtestbase.rb +72 -26
  66. data/test/ft_0.rb +1 -97
  67. data/test/ft_0b_sequence.rb +33 -0
  68. data/test/ft_0c_testname.rb +29 -0
  69. data/test/ft_10_loop.rb +48 -0
  70. data/test/ft_11_ppd.rb +292 -0
  71. data/test/ft_12_blockparticipant.rb +45 -0
  72. data/test/ft_13_eno.rb +51 -0
  73. data/test/ft_14_subprocess.rb +90 -0
  74. data/test/ft_14b_subprocess.rb +40 -0
  75. data/test/ft_15_iterator.rb +70 -0
  76. data/test/ft_16_fqv.rb +57 -0
  77. data/test/ft_1_unset.rb +25 -1
  78. data/test/ft_2_concurrence.rb +10 -5
  79. data/test/ft_3_equals.rb +35 -1
  80. data/test/ft_4_misc.rb +16 -1
  81. data/test/ft_5_time.rb +26 -1
  82. data/test/ft_6_lambda.rb +2 -1
  83. data/test/{ft_7_losfor.rb → ft_7_lose.rb} +41 -35
  84. data/test/ft_8_forget.rb +46 -0
  85. data/test/ft_9_cursor.rb +94 -0
  86. data/test/journal_persistence_test.rb +147 -0
  87. data/test/misctest.rb +13 -9
  88. data/test/rake_ptest.rb +18 -0
  89. data/test/rake_qtest.rb +43 -0
  90. data/test/{fulltest.rb → rake_test.rb} +2 -2
  91. data/test/raw_prog_test.rb +236 -0
  92. data/test/rest_test.rb +189 -0
  93. data/test/rutest_utils.rb +1 -1
  94. data/test/timetest.rb +42 -34
  95. metadata +125 -82
  96. data/lib/codec.rb +0 -573
  97. data/lib/flowexpressionid.rb +0 -139
  98. data/lib/ru/expressionpool.rb +0 -382
  99. data/lib/ru/expressionstorage.rb +0 -99
  100. data/lib/ru/flowexpression.rb +0 -272
  101. data/lib/ru/ruutils.rb +0 -70
  102. data/lib/test.rb +0 -222
  103. data/lib/workitem.rb +0 -249
  104. data/test/quicktest.rb +0 -21
@@ -0,0 +1,391 @@
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 'rexml/document'
43
+
44
+ require 'openwfe/expressions/fe_raw'
45
+ require 'openwfe/expressions/fe_utils'
46
+
47
+
48
+ module OpenWFE
49
+
50
+ #
51
+ # A raw representation for a process definition, programmatic
52
+ # process definitions are turned into trees of instances of this class.
53
+ #
54
+ class ProgExpRepresentation
55
+
56
+ attr_reader \
57
+ :name,
58
+ :attributes,
59
+ :children
60
+
61
+ def initialize (name, attributes)
62
+ super()
63
+ @name = name
64
+ @attributes = attributes
65
+ @children = []
66
+ end
67
+
68
+ #
69
+ # Adds a child to this expression representation.
70
+ #
71
+ def << (child)
72
+ @children << child
73
+ end
74
+
75
+ #
76
+ # Always return the ProgRawExpression class.
77
+ #
78
+ def rawExpressionClass
79
+ return ProgRawExpression
80
+ end
81
+
82
+ #
83
+ # Returns an XML string, containing the equivalent process definition
84
+ # in the classical OpenWFE process definition language.
85
+ #
86
+ def to_s
87
+ doc = REXML::Document.new()
88
+ doc << to_xml
89
+ s = ""
90
+ doc.write(s, 0)
91
+ return s
92
+ end
93
+
94
+ #
95
+ # Returns this representation tree as an XML element (and its children).
96
+ #
97
+ def to_xml
98
+
99
+ elt = REXML::Element.new(@name)
100
+
101
+ #elt.attributes.update(@attributes)
102
+ @attributes.each do |k, v|
103
+ elt.attributes[k] = v
104
+ end
105
+
106
+ @children.each do |child|
107
+ if child.kind_of? ProgExpRepresentation
108
+ elt << child.to_xml
109
+ else
110
+ elt << REXML::Text.new(child.to_s)
111
+ end
112
+ end
113
+
114
+ return elt
115
+ end
116
+
117
+ #
118
+ # Returns a string containing the ruby code that generated this
119
+ # raw representation tree.
120
+ #
121
+ def to_code_s (indentation = 0)
122
+
123
+ s = ""
124
+ tab = " "
125
+ ind = tab * indentation
126
+
127
+ s << ind
128
+ s << OpenWFE.make_safe(@name)
129
+
130
+ sa = ""
131
+ @attributes.each do |k, v|
132
+ sa << ", :#{k} => '#{v}'"
133
+ end
134
+ s << sa[1..-1] if sa.length > 0
135
+
136
+ if @children.length > 0
137
+ s << " do\n"
138
+ @children.each do |child|
139
+ if child.respond_to? :to_code_s
140
+ s << child.to_code_s(indentation + 1)
141
+ else
142
+ s << ind
143
+ s << tab
144
+ s << "'#{child.to_s}'"
145
+ end
146
+ s << "\n"
147
+ end
148
+ s << ind
149
+ s << "end"
150
+ end
151
+
152
+ return s
153
+ end
154
+ end
155
+
156
+ #
157
+ # This is the class to extend to create a programmatic process definition.
158
+ #
159
+ # A short example :
160
+ # <tt>
161
+ # class MyProcessDefinition < OpenWFE::ProcessDefinition
162
+ # def make
163
+ # process_definition :name => "test1", :revision => "0" do
164
+ # sequence do
165
+ # set :variable => "toto", :value => "nada"
166
+ # print "toto:${toto}"
167
+ # end
168
+ # end
169
+ # end
170
+ # end
171
+ #
172
+ # li = OpenWFE::LaunchItem.new(MyProcessDefinition)
173
+ # engine.launch(li)
174
+ # </tt>
175
+ #
176
+ class ProcessDefinition
177
+
178
+ def initialize (exp_names=nil)
179
+
180
+ super()
181
+
182
+ if not exp_names
183
+ exp_names = $EXPRESSION_NAMES if $EXPRESSION_NAMES
184
+ else
185
+ if exp_names.kind_of? ExpressionMap
186
+ exp_names = exp_names.expression_names
187
+ elsif exp_names.kind_of? Engine
188
+ exp_names = exp_names.get_expression_map.expression_names
189
+ elsif exp_names.kind_of? Hash
190
+ exp_names = exp_names[S_EXPRESSION_MAP].expression_names
191
+ elsif not exp_names.kind_of? Array
192
+ exp_names = $EXPRESSION_NAMES
193
+ end
194
+ end
195
+
196
+ if not exp_names
197
+ raise "no expression names found, please provide them"
198
+ end
199
+
200
+ @exp_names = exp_names
201
+
202
+ #exp_names.each do |exp_name|
203
+ # register_expression(exp_name)
204
+ #end
205
+
206
+ @previous_parent_expression = []
207
+ end
208
+
209
+ #
210
+ # previous trick
211
+ #
212
+ # kept for the record.
213
+ #
214
+ #def register_expression (expression_name)
215
+ # _exp_name = OpenWFE.make_safe(exp_name)
216
+ # self.instance_eval """
217
+ # def #{_exp_name} (params={}, &block)
218
+ # make_expression('#{exp_name}', params, &block)
219
+ # end
220
+ # """
221
+ #end
222
+
223
+ def method_missing (m, *args, &block)
224
+
225
+ methodname = m.to_s
226
+
227
+ expname = OpenWFE.to_expression_name(methodname)
228
+ if not @exp_names.include? expname
229
+ #raise "No expression named '#{methodname}' (#{expname}) found"
230
+ #raise "No expression named '#{expname}' found"
231
+ params = args[0]
232
+ params = {} if not params
233
+ params["ref"] = methodname
234
+ return make_expression("subprocess", params, &block)
235
+ end
236
+ make_expression(expname, args[0], &block)
237
+ end
238
+
239
+ #
240
+ # This method has to be overriden in order to define
241
+ # a process definition.
242
+ #
243
+ def make
244
+ raise "make() implementation is missing, please provide one"
245
+ end
246
+
247
+ def make_expression (exp_name, params, &block)
248
+
249
+ exp_name = exp_name.to_s
250
+
251
+ string_child = nil
252
+ attributes = {}
253
+
254
+ #puts " ... params.class is #{params.class}"
255
+
256
+ if params.kind_of? Hash
257
+ params.each do |k, v|
258
+ #attributes[k.to_s] = v.to_s
259
+ attributes[OpenWFE.to_dash(k.to_s)] = v.to_s
260
+ end
261
+ elsif params
262
+ string_child = params.to_s
263
+ end
264
+
265
+ exp = ProgExpRepresentation.new(exp_name, attributes)
266
+
267
+ exp.children << string_child \
268
+ if string_child
269
+
270
+ @parent_expression << exp \
271
+ if @parent_expression
272
+
273
+ return exp if not block
274
+
275
+ @previous_parent_expression.push(@parent_expression) \
276
+ if @parent_expression
277
+
278
+ @parent_expression = exp
279
+
280
+ result = block.call
281
+ #if result and result.kind_of? String and result.length > 0
282
+ # puts " ... child is >#{result}<"
283
+ # exp.children << result
284
+ #end
285
+ #exp.children << result \
286
+ # if result and not result.kind_of? ProgExpRepresentation
287
+ exp.children << result \
288
+ if result and result.kind_of? String
289
+
290
+ @parent_expression = @previous_parent_expression.pop
291
+
292
+ return exp
293
+ end
294
+
295
+ #
296
+ # A class method for actually "making" the process
297
+ # segment raw representation
298
+ #
299
+ def ProcessDefinition.do_make (exp_names=nil)
300
+ self.new(exp_names).make
301
+ end
302
+ end
303
+
304
+ #
305
+ # The actual 'programmatic' raw expression.
306
+ # Its raw_representation being an instance of ProgExpRepresentation.
307
+ #
308
+ class ProgRawExpression < RawExpression
309
+
310
+ attr_accessor \
311
+ :raw_representation
312
+
313
+ def initialize \
314
+ (fei, parent_id, env_id, application_context, raw_representation)
315
+
316
+ super(
317
+ fei,
318
+ parent_id,
319
+ env_id,
320
+ application_context,
321
+ raw_representation)
322
+ end
323
+
324
+ protected
325
+
326
+ def extract_attributes ()
327
+ return raw_representation.attributes
328
+ end
329
+
330
+ def extract_children ()
331
+
332
+ i = 0
333
+ raw_representation.children.collect do |child|
334
+
335
+ if child.kind_of? ProgExpRepresentation
336
+
337
+ cfei = @fei.dup
338
+ cfei.expression_name = child.name
339
+ cfei.expression_id = "#{cfei.expression_id}.#{i}"
340
+
341
+ efei = @environment_id
342
+
343
+ rawexp = ProgRawExpression\
344
+ .new(cfei, @fei, efei, @application_context, child)
345
+
346
+ get_expression_pool.update(rawexp)
347
+
348
+ i = i + 1
349
+
350
+ rawexp.fei
351
+ else
352
+
353
+ child
354
+ end
355
+ end
356
+ end
357
+ end
358
+
359
+ private
360
+
361
+ #
362
+ # OpenWFE process definitions do use some
363
+ # Ruby keywords... The workaround is to put an underscore
364
+ # just before the name to 'escape' it.
365
+ #
366
+ # 'undo' isn't reserved by Ruby, but lets keep it in line
367
+ # with 'do' and 'redo' that are.
368
+ #
369
+ KEYWORDS = [
370
+ :if, :do, :redo, :undo, :print
371
+ ]
372
+
373
+ #
374
+ # Ensures the method name is not conflicting with Ruby keywords
375
+ # and turn dashes to underscores.
376
+ #
377
+ def OpenWFE.make_safe (method_name)
378
+ method_name = to_underscore(method_name)
379
+ return "_" + method_name \
380
+ if KEYWORDS.include? eval(":"+method_name)
381
+ return method_name
382
+ end
383
+
384
+ def OpenWFE.to_expression_name (method_name)
385
+ method_name = method_name[1..-1] if method_name[0, 1] == "_"
386
+ method_name = to_dash(method_name)
387
+ return method_name
388
+ end
389
+
390
+ end
391
+
@@ -0,0 +1,128 @@
1
+ #
2
+ #--
3
+ # Copyright (c) 2006-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 'rexml/document'
43
+
44
+ require 'openwfe/expressions/fe_raw'
45
+
46
+
47
+ module OpenWFE
48
+
49
+ #
50
+ # Handling process definition whose representation is in XML
51
+ # (the classical OpenWFE case).
52
+ #
53
+ class XmlRawExpression < RawExpression
54
+
55
+ def initialize \
56
+ (fei, parent_id, env_id, application_context, raw_representation)
57
+
58
+ super(
59
+ fei,
60
+ parent_id,
61
+ env_id,
62
+ application_context,
63
+ raw_representation)
64
+
65
+ @raw_representation_s = raw_representation.to_s
66
+ end
67
+
68
+ def raw_representation
69
+ synchronize do
70
+ if not @raw_representation
71
+ @raw_representation = \
72
+ REXML::Document.new(@raw_representation_s).root
73
+ end
74
+ return @raw_representation
75
+ end
76
+ end
77
+
78
+ protected
79
+
80
+ def extract_attributes ()
81
+ result = {}
82
+ raw_representation.attributes.each_attribute do |a|
83
+ result[a.name] = a.value
84
+ end
85
+ return result
86
+ end
87
+
88
+ def extract_children ()
89
+
90
+ c = []
91
+ i = 0
92
+
93
+ raw_representation.each_child do |elt|
94
+
95
+ if elt.kind_of?(REXML::Element)
96
+
97
+ cfei = @fei.dup
98
+
99
+ efei = @environment_id
100
+
101
+ cfei.expression_name = elt.name
102
+ cfei.expression_id = "#{cfei.expression_id}.#{i}"
103
+
104
+ rawchild = XmlRawExpression\
105
+ .new(cfei, @fei, efei, @application_context, elt)
106
+
107
+ get_expression_pool().update(rawchild)
108
+ c << rawchild.fei
109
+
110
+ i = i+1
111
+
112
+ elsif elt.kind_of?(REXML::Comment)
113
+
114
+ next
115
+
116
+ else
117
+
118
+ s = elt.to_s.strip
119
+ c << s if s.length > 0
120
+
121
+ end
122
+ end
123
+
124
+ return c
125
+ end
126
+ end
127
+ end
128
+