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
data/README.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  = OpenWFEru, Standard Library Documentation
2
2
 
3
3
  == Prerequisites
4
- Ruby 1.8.0 or later
4
+ Ruby 1.8.4 or later
5
5
 
6
6
  == Supported platforms
7
7
  TODO
@@ -61,9 +61,8 @@ libraries:
61
61
  [rake] Handle builds, generating documentation, and running unit tests
62
62
  [rubygems] Handles creation of the gems
63
63
  [rote] A framework being used to help with managing the offline written docs
64
- [redcloth] Openwferu uses textile-markup for its docs. Redcloth provides an engine for it.
64
+ [redcloth] OpenWFEru uses textile-markup for its docs. Redcloth provides an engine for it.
65
65
  [tidy] General cleanup
66
- [libxml-ruby] Allows XSD validation
67
66
 
68
67
  It's best if you use gems to install these as the process can get rather
69
68
  tedious by hand.
@@ -89,10 +88,10 @@ On Ubuntu you can install libxml2 with:
89
88
  The main project site lives at rubyforge at:
90
89
  http://rubyforge.org/projects/openwferu
91
90
  or
92
- http://ru.openwfe.org
91
+ http://openwferu.rubyforge.org
93
92
 
94
93
  In the meantime the old site hosted at openwfe.org is at:
95
94
  http://www.openwfe.org/openwfe-ruby.html
96
95
 
97
- If you're interested in helping : http://groups.google.com/group/openwferu-dev/topics
96
+ If you're interested in helping : http://groups.google.com/group/openwferu-users/topics
98
97
 
@@ -136,29 +136,29 @@ module OpenWFE
136
136
  #
137
137
  def launch (launch_object, async=false)
138
138
 
139
- launchitem = nil
139
+ launchitem = if launch_object.kind_of?(OpenWFE::LaunchItem)
140
140
 
141
- if launch_object.kind_of? OpenWFE::LaunchItem
141
+ launch_object
142
142
 
143
- launchitem = launch_object
143
+ elsif launch_object.kind_of?(Class)
144
144
 
145
- elsif launch_object.kind_of? Class
146
-
147
- launchitem = LaunchItem.new(launch_object)
145
+ LaunchItem.new launch_object
148
146
 
149
147
  elsif launch_object.kind_of? String
150
148
 
151
- launchitem = OpenWFE::LaunchItem.new
149
+ li = OpenWFE::LaunchItem.new
152
150
 
153
- if launch_object[0] == '<'
154
- launchitem.workflowDefinitionUrl = "field:__definition"
155
- launchitem['definition'] = launch_object
151
+ if launch_object[0, 1] == '<'
152
+ li.workflowDefinitionUrl = "field:__definition"
153
+ li['definition'] = launch_object
156
154
  else
157
- launchitem.workflowDefinitionUrl = launch_object
155
+ li.workflowDefinitionUrl = launch_object
158
156
  end
157
+
158
+ li
159
159
  end
160
160
 
161
- get_expression_pool.launch(launchitem, async)
161
+ get_expression_pool.launch launchitem, async
162
162
  end
163
163
 
164
164
  #
@@ -170,11 +170,11 @@ module OpenWFE
170
170
  #
171
171
  def reply (workitem)
172
172
 
173
- if workitem.kind_of? InFlowWorkItem
173
+ if workitem.kind_of?(InFlowWorkItem)
174
174
 
175
175
  get_expression_pool.reply(workitem.flow_expression_id, workitem)
176
176
 
177
- elsif workitem.kind_of? LaunchItem
177
+ elsif workitem.kind_of?(LaunchItem)
178
178
 
179
179
  get_expression_pool.launch(workitem, false)
180
180
 
@@ -183,7 +183,7 @@ module OpenWFE
183
183
 
184
184
  definition = if wfdurl.match "^field:"
185
185
  wfdfield = wfdurl[6..-1]
186
- launchitem.attributes.delete(wfdfield)
186
+ launchitem.attributes.delete wfdfield
187
187
  else
188
188
  read_uri(wfdurl)
189
189
  end
@@ -191,9 +191,9 @@ module OpenWFE
191
191
  raise "didn't find process definition at '#{wfdurl}'" \
192
192
  unless definition
193
193
 
194
- raw_expression = build_raw_expression(launchitem, definition)
194
+ raw_expression = build_raw_expression launchitem, definition
195
195
 
196
- raw_expression.check_parameters(launchitem)
196
+ raw_expression.check_parameters launchitem
197
197
  #
198
198
  # will raise an exception if there are requirements
199
199
  # and one of them is not met
@@ -246,10 +246,14 @@ module OpenWFE
246
246
  end
247
247
 
248
248
  #
249
- # launches a subprocess
249
+ # Prepares a raw expression from a template.
250
+ # Returns that raw expression.
250
251
  #
251
- def launch_template (
252
- requesting_expression, sub_id, template, workitem, params=nil)
252
+ # Used in the concurrent-iterator when building up the children list
253
+ # and of course used by the launch_template() method.
254
+ #
255
+ def prepare_from_template (
256
+ requesting_expression, sub_id, template, params=nil)
253
257
 
254
258
  rawexp = if template.is_a? RawExpression
255
259
  template
@@ -293,34 +297,34 @@ module OpenWFE
293
297
  "#{requesting_expression.fei.workflow_instance_id}.#{sub_id}"
294
298
  end
295
299
 
296
- #ldebug do
297
- # p = ""
298
- # p = rawexp.parent_id.to_debug_s if rawexp.parent_id
299
- # "launch_template()\n"+
300
- # " rawexp.fei is #{rawexp.fei.to_debug_s}\n"+
301
- # " rawexp.parent_id is #{p}"
302
- #end
303
-
304
300
  #ldebug do
305
301
  # "launch_template() spawning wfid " +
306
302
  # "#{rawexp.fei.workflow_instance_id.to_s}"
307
303
  #end
308
304
 
309
- env = rawexp.new_environment()
310
- #
311
- params.each { |k, v| env[k] = v } if params
305
+ env = rawexp.new_environment(params)
312
306
  #
313
307
  # the new scope gets its own environment
314
308
 
315
309
  rawexp.store_itself()
316
310
 
317
- workitem.flow_expression_id = rawexp.fei
311
+ rawexp
312
+ end
318
313
 
319
- fei = rawexp.fei
314
+ #
315
+ # launches a subprocess
316
+ #
317
+ def launch_template (
318
+ requesting_expression, sub_id, template, workitem, params=nil)
320
319
 
321
- apply(rawexp, workitem)
320
+ rawexp = prepare_from_template(
321
+ requesting_expression, sub_id, template, params)
322
322
 
323
- return fei
323
+ workitem.flow_expression_id = rawexp.fei
324
+
325
+ apply rawexp, workitem
326
+
327
+ rawexp.fei
324
328
  end
325
329
 
326
330
  #
@@ -329,15 +333,15 @@ module OpenWFE
329
333
  #
330
334
  def evaluate (rawExpression, workitem)
331
335
 
332
- exp = rawExpression.instantiate_real_expression(workitem)
333
- fei = exp.evaluate(workitem)
336
+ exp = rawExpression.instantiate_real_expression workitem
337
+ fei = exp.evaluate workitem
334
338
 
335
339
  #remove(rawExpression)
336
340
  #
337
341
  # not necessary, the raw expression gets overriden by
338
342
  # the real expression
339
343
 
340
- return fei
344
+ fei
341
345
  end
342
346
 
343
347
  #
@@ -408,16 +412,23 @@ module OpenWFE
408
412
  # Forgets the given expression (makes sure to substitute its
409
413
  # parent_id with the GONE_PARENT_ID constant)
410
414
  #
411
- def forget (exp)
415
+ def forget (parent_exp, exp)
412
416
 
413
417
  exp, fei = fetch(exp)
414
418
 
419
+ #ldebug { "forget() forgetting #{fei}" }
420
+
415
421
  return if not exp
416
422
 
417
423
  onotify :forget, fei
418
424
 
425
+ parent_exp.children.delete(fei)
426
+
419
427
  exp.parent_id = GONE_PARENT_ID
428
+ exp.dup_environment
420
429
  exp.store_itself()
430
+
431
+ ldebug { "forget() forgot #{fei}" }
421
432
  end
422
433
 
423
434
  #
@@ -479,7 +490,7 @@ module OpenWFE
479
490
  #
480
491
  # parent still present, reply to it
481
492
 
482
- reply(exp.parent_id, workitem)
493
+ reply exp.parent_id, workitem
483
494
  end
484
495
 
485
496
  #
@@ -558,7 +569,7 @@ module OpenWFE
558
569
  #
559
570
  def fetch_expression (exp)
560
571
  exp, _fei = fetch(exp)
561
- return exp
572
+ exp
562
573
  end
563
574
 
564
575
  #
@@ -568,12 +579,13 @@ module OpenWFE
568
579
  def fetch_root (exp_or_wfid)
569
580
 
570
581
  return fetch_expression_with_wfid(exp_or_wfid) \
571
- if exp_or_wfid.is_a? String
582
+ if exp_or_wfid.is_a?(String)
572
583
 
573
584
  exp = fetch_expression(exp_or_wfid)
574
585
 
575
586
  return exp unless exp.parent_id
576
- return fetch_root(fetch_expression(exp.parent_id))
587
+
588
+ fetch_root(fetch_expression(exp.parent_id))
577
589
  end
578
590
 
579
591
  #
@@ -591,7 +603,7 @@ module OpenWFE
591
603
  ee.store_itself()
592
604
  end
593
605
 
594
- return ee
606
+ ee
595
607
  end
596
608
  end
597
609
 
@@ -602,7 +614,7 @@ module OpenWFE
602
614
  def remove (exp)
603
615
 
604
616
  exp, _fei = fetch(exp) \
605
- if exp.kind_of? FlowExpressionId
617
+ if exp.kind_of?(FlowExpressionId)
606
618
 
607
619
  return if not exp
608
620
 
@@ -682,8 +694,8 @@ module OpenWFE
682
694
 
683
695
  get_expression_storage.real_each do |fei, fexp|
684
696
 
685
- next if fexp.kind_of? Environment
686
- next if fexp.kind_of? RawExpression
697
+ next if fexp.kind_of?(Environment)
698
+ next if fexp.kind_of?(RawExpression)
687
699
  next unless fexp.apply_time
688
700
 
689
701
  pi = fei.parent_wfid
@@ -756,7 +768,7 @@ module OpenWFE
756
768
 
757
769
  env, fei = fetch(environment_id)
758
770
 
759
- env.unbind()
771
+ env.unbind
760
772
 
761
773
  #get_expression_storage().delete(environment_id)
762
774
 
@@ -769,11 +781,11 @@ module OpenWFE
769
781
  #
770
782
  def build_workitem (launchitem)
771
783
 
772
- wi = InFlowWorkItem.new()
784
+ wi = InFlowWorkItem.new
773
785
 
774
- wi.attributes = launchitem.attributes.dup()
786
+ wi.attributes = launchitem.attributes.dup
775
787
 
776
- return wi
788
+ wi
777
789
  end
778
790
 
779
791
  #
@@ -815,9 +827,11 @@ module OpenWFE
815
827
  # "param of class #{param.class.name}"
816
828
  #end
817
829
 
818
- return param if param.is_a? SimpleExpRepresentation
819
- return param.make if param.is_a? ProcessDefinition
820
- return param.do_make if param.is_a? Class
830
+ return param \
831
+ if param.is_a?(SimpleExpRepresentation)
832
+
833
+ return param.do_make \
834
+ if param.is_a?(ProcessDefinition) or param.is_a?(Class)
821
835
 
822
836
  raise "cannot handle definition of class #{param.class.name}" \
823
837
  unless param.is_a? String
@@ -844,8 +858,8 @@ module OpenWFE
844
858
 
845
859
  o = OpenWFE::eval_safely(param, SAFETY_LEVEL)
846
860
 
847
- return o.make if o.is_a? ProcessDefinition
848
- return o.do_make if o.kind_of? Class
861
+ return o.do_make \
862
+ if o.is_a?(ProcessDefinition) or o.is_a?(Class)
849
863
 
850
864
  o
851
865
  end
@@ -873,7 +887,8 @@ module OpenWFE
873
887
  fei.wfid = get_wfid_generator.generate launchitem
874
888
  fei.expression_id = "0"
875
889
  fei.expression_name = exp_name
876
- return fei
890
+
891
+ fei
877
892
  end
878
893
 
879
894
  #
@@ -898,8 +913,8 @@ module OpenWFE
898
913
  #puts procdef.raw_expression_class
899
914
  #puts procdef.raw_expression_class.public_methods
900
915
 
901
- return procdef.raw_expression_class\
902
- .new(fei, nil, nil, @application_context, procdef)
916
+ procdef.raw_expression_class.new(
917
+ fei, nil, nil, @application_context, procdef)
903
918
  end
904
919
 
905
920
  end
@@ -100,7 +100,7 @@ module OpenWFE
100
100
  def [] (fei)
101
101
 
102
102
  #ldebug { "[] size is #{@cache.size}" }
103
- ldebug { "[] (sz #{@cache.size}) for #{fei.to_debug_s}" }
103
+ #ldebug { "[] (sz #{@cache.size}) for #{fei.to_debug_s}" }
104
104
 
105
105
  fe = @cache[fei]
106
106
  return fe if fe
@@ -79,22 +79,23 @@ module OpenWFE
79
79
  return nil \
80
80
  unless conditional
81
81
 
82
- #ldebug { "eval_condition() 0 for '#{conditional}'" }
82
+ ldebug { "eval_condition() 0 for '#{conditional}'" }
83
83
 
84
- conditional = from_xml(conditional)
84
+ conditional = from_xml conditional
85
85
 
86
- #ldebug { "eval_condition() 1 for '#{conditional}'" }
86
+ ldebug { "eval_condition() 1 for '#{conditional}'" }
87
+
88
+ begin
89
+ return to_boolean(do_eval(conditional))
90
+ rescue Exception => e
91
+ # probably needs some quoting...
92
+ end
87
93
 
88
94
  conditional = do_quote(conditional)
89
95
 
90
96
  ldebug { "eval_condition() 2 for '#{conditional}'" }
91
97
 
92
- #result = instance_eval(conditional)
93
- result = do_eval(conditional)
94
-
95
- ldebug { "eval_condition() 3 result is '#{result}'" }
96
-
97
- return (result == "true" or result == true)
98
+ to_boolean(do_eval(conditional))
98
99
  end
99
100
 
100
101
  #
@@ -121,21 +122,16 @@ module OpenWFE
121
122
 
122
123
  protected
123
124
 
125
+ private
126
+
124
127
  #
125
- # If the attribute name is a list of attribute names, pick
126
- # the first one present.
128
+ # Returns true if result is the "true" String or the true
129
+ # boolean value. Returns false else.
127
130
  #
128
- #def pick_attribute (attnames)
129
- # attnames.each do |attname|
130
- # return attname if has_attribute(attname)
131
- # return attname if has_attribute("r" + attname.to_s)
132
- # end
133
- # return attnames[0]
134
- # #
135
- # # some kind of a default (for error messages)
136
- #end
137
-
138
- private
131
+ def to_boolean (result)
132
+ ldebug { "to_boolean() result is '#{result}'" }
133
+ (result == "true" or result == true)
134
+ end
139
135
 
140
136
  def from_xml (string)
141
137
 
@@ -145,22 +141,39 @@ module OpenWFE
145
141
  s
146
142
  end
147
143
 
144
+ #
145
+ # Quotes the given string so that it can easily get evaluated
146
+ # as Ruby code (a string comparison actually).
147
+ #
148
148
  def do_quote (string)
149
149
 
150
- i = string.index("==")
151
- i = string.index("!=") unless i
152
- i = string.index("<") unless i
153
- i = string.index(">") unless i
150
+ op = find_operator string
151
+
152
+ return '"' + string + '"' unless op
153
+
154
+ op, i = op
154
155
 
155
- return '"' + string + '"' unless i
156
+ s = '"'
157
+ s << string[0..i-1].strip
158
+ s << '" '
159
+ s << string[i, op.length]
160
+ s << ' "'
161
+ s << string[i+op.length..-1].strip
162
+ s << '"'
163
+ s
164
+ end
156
165
 
157
- '"' +
158
- string[0..i-1].strip +
159
- '" ' +
160
- string[i..i+2] +
161
- ' "' +
162
- string[i+2..-1].strip +
163
- '"'
166
+ #
167
+ # Returns the operator and its index (position) in the string.
168
+ # Returns nil if not operator was found in the string.
169
+ #
170
+ def find_operator (string)
171
+ [ "==", "!=", "<=", ">=", "<", ">" ].each do |op|
172
+ i = string.index op
173
+ next unless i
174
+ return [ op, i ]
175
+ end
176
+ nil
164
177
  end
165
178
 
166
179
  #