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
@@ -17,12 +17,12 @@ OpenWFEru is a Ruby port of the OpenWFE workflow engine
17
17
  (http://www.openwfe.org). It is a complete rewrite in Ruby
18
18
  so does not need to use the Java-based engine from OpenWFE.
19
19
 
20
- OpenWFEru was initially implemented in San Joaquin de Flores, Costa Rica.
20
+ OpenWFEru was initially implemented in San Joaquin de Flores, Costa Rica. And then in Yokohama, Japan.
21
21
 
22
22
  One project goal for OpenWFEru is compatibility with its
23
23
  Java based cousin so workflows defined for the Java engine
24
24
  should work with the Ruby implementation. There are
25
- some incompatibilities between each implementatio.
25
+ some incompatibilities between each implementation.
26
26
 
27
27
  TODO: Document implementation differences
28
28
 
@@ -37,29 +37,28 @@ Creating an workflow engine instance
37
37
 
38
38
  # Create an engine to launch the flow
39
39
  engine = OpenWFEru::Engine.new
40
- engine.register_participant('test-.*',
41
- OpenWFEru::PrintParticipant.new())
40
+ engine.register_participant('test-.*', OpenWFEru::PrintParticipant.new())
41
+
42
42
  # Create a flow definition and assign to a new instance
43
43
  flow = '''<process-definition name="equals_0" revision="0">
44
- <sequence>
44
+ <if>
45
45
  <equals value="a" other-value="a" />
46
46
  <print>${field:__result__}</print>
47
- </sequence>
47
+ </if>
48
48
  </process-definition>'''
49
- li = OpenWFE::LaunchItem.new
50
- li.workflowDefinitionUrl = "field:__definition"
51
- li.attributes['__definition'] = flow
49
+ li = OpenWFE::LaunchItem.new(flow)
50
+
52
51
  # Launch the instance
53
52
  engine.launch(li)
53
+
54
54
  # Examine it
55
- exp_storage = engine.application_context[OpenWFEru::S_EXPRESSION_STORAGE]
56
- pp exp_storage
55
+ pp engine.get_expression_storage
57
56
 
58
57
  == How to help
59
58
 
60
59
  If you want to help hacking on openwferu you'll probably want the following
61
60
  libraries:
62
- [+rake+] Handle builds, generating documentation, and running unit tests
61
+ [rake] Handle builds, generating documentation, and running unit tests
63
62
  [rubygems] Handles creation of the gems
64
63
  [rote] A framework being used to help with managing the offline written docs
65
64
  [redcloth] Openwferu uses textile-markup for its docs. Redcloth provides an engine for it.
@@ -70,6 +69,7 @@ It's best if you use gems to install these as the process can get rather
70
69
  tedious by hand.
71
70
 
72
71
  === Prerequisites
72
+
73
73
  You'll need libxml2-dev in order to compile the native libraries
74
74
  for libxml. Please check your your packaging system for the appropriate
75
75
  name.
@@ -78,6 +78,7 @@ On Ubuntu you can install libxml2 with:
78
78
  sudo apt-get install libxml2-dev
79
79
 
80
80
  === Ruby Libraries Install
81
+
81
82
  1. gem install -r rake
82
83
  2. gem install -r rote redcloth
83
84
  3. gem install -r tidy
@@ -87,9 +88,11 @@ On Ubuntu you can install libxml2 with:
87
88
 
88
89
  The main project site lives at rubyforge at:
89
90
  http://rubyforge.org/projects/openwferu
91
+ or
92
+ http://ru.openwfe.org
90
93
 
91
94
  In the meantime the old site hosted at openwfe.org is at:
92
95
  http://www.openwfe.org/openwfe-ruby.html
93
96
 
94
- If you're interested in helping : john at openwfe dot org
97
+ If you're interested in helping : http://groups.google.com/group/openwferu-dev/topics
95
98
 
@@ -4,11 +4,11 @@
4
4
  # Purpose: A helper script that validates a workflow document against
5
5
  # a XML Schema
6
6
  # Author: Alain Hoang
7
- # Version: 0.1
8
7
  # Notes: Uses Ruby's libxml library to handle the parsing
9
8
 
10
9
  # Stdlib
11
10
  require 'net/http'
11
+ require 'optparse'
12
12
  require 'uri'
13
13
  # From the gems archive
14
14
  require 'rubygems'
@@ -16,42 +16,66 @@ require 'xml/libxml'
16
16
 
17
17
 
18
18
  module OpenWFEru
19
+ FLOWDEF_URL = 'http://www.openwfe.org/flowdef.xsd'
19
20
  # Validates a workflow definition against the Workflow XML Schema
20
21
  # defined at http://www.openwfe.org/flowdef.xsd
21
22
  class WorkflowValidator
22
- OPENWFE_FLOWDEF_URL='http://www.openwfe.org/flowdef.xsd'
23
+
24
+ attr_accessor :schema_url
25
+ attr_accessor :args
23
26
 
24
- # Class method for validating a xml file against the
25
- # OpenWFE XML Schema
26
- def WorkflowValidator.validate(file)
27
- # Should only be initialized once during the lifetime
28
- # of the program
29
- if not defined? @@schema
30
- xsd_str = Net::HTTP.get URI.parse(OPENWFE_FLOWDEF_URL)
31
- @@schema = XML::Schema.from_string(xsd_str)
32
- end
27
+ # Create a validator object using a WorkflowValidatorArgs object
28
+ def initialize(args)
29
+ @args = args
30
+ @args[:schema_url] ||= FLOWDEF_URL
31
+
32
+ xsd_str = Net::HTTP.get URI.parse(@args[:schema_url])
33
+ @schema = XML::Schema.from_string(xsd_str)
34
+ end
35
+
36
+ # validates a xml file against the OpenWFE XML Schema
37
+ def validate(file)
33
38
  xmldoc = XML::Document.file(file)
34
- xmldoc.validate_schema(@@schema)
39
+ xmldoc.validate_schema(@schema)
35
40
  end
36
41
  end
37
- end
38
42
 
39
- def usage
40
- print "Usage: #{$0} <workflow def> [workflow def] [workflow def] ...\n"
41
- print " <workflow def> - workflow definition file\n"
43
+ class WorkflowValidatorArgs < Hash
44
+ # Create an arguments object to send to a WorkflowValidator object
45
+ def initialize(args)
46
+ super()
47
+ opts = OptionParser.new do |opts|
48
+ opts.banner = "Usage: #$0 [-u url] <workflow def> [workflow def] ..."
49
+
50
+ opts.on('-u', '--url URL', 'Use XML Schema at URL') do |url|
51
+ self[:schema_url] = url
52
+ end
53
+
54
+ opts.on_tail('-h', '--help', 'display this help and exit') do
55
+ puts opts
56
+ exit
57
+ end
58
+ end
59
+ opts.parse!(args)
60
+ # Check for no args and exit if so
61
+ if args.empty?
62
+ puts opts
63
+ exit 1
64
+ end
65
+ end
66
+ end
42
67
  end
43
68
 
69
+
44
70
  def main
45
- # Make sure we have at least one argument or bail
46
- if ARGV.length == 0
47
- usage
48
- exit 1
49
- end
71
+ # Create the arguments object and the validator object
72
+ args = OpenWFEru::WorkflowValidatorArgs.new(ARGV)
73
+ validator = OpenWFEru::WorkflowValidator.new(args)
50
74
 
51
75
  # Loop through all arguments and validate the file
52
76
  ARGV.each do |f|
53
77
  print "Trying to validate #{f}... "
54
- if OpenWFEru::WorkflowValidator.validate(f)
78
+ if FileTest.exists?(f) && validator.validate(f)
55
79
  print "PASSED\n"
56
80
  else
57
81
  print "FAILED\n"
@@ -0,0 +1,8 @@
1
+ = OpenWFEru examples
2
+
3
+ you can run quotereporter.rb with
4
+
5
+ ruby -r path/to/openwferu/lib/ quotereporter.rb
6
+
7
+ It will fetch a few quotes for stocks and produce an atom feed file (atom_feed.xml)
8
+
@@ -0,0 +1,66 @@
1
+
2
+ ### EXAMPLE IN PREPARATION ###
3
+
4
+ #
5
+ # an OpenWFEru example
6
+ #
7
+
8
+ require 'openwfe/engine/engine'
9
+ require 'openwfe/expressions/raw_prog'
10
+ #require 'openwfe/participants/soapparticipants'
11
+ #require 'openwfe/participants/atomparticipants'
12
+
13
+
14
+ #
15
+ # the process definition
16
+ #
17
+ # instead of using the classical OpenWFE XML process definitions, we
18
+ # define the flow as a Ruby class
19
+
20
+ class ReviewFlow < OpenWFE::ProcessDefinition
21
+ def make
22
+ process_definition :name => "homework_review", :revision => "0.1" do
23
+ sequence do
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ #
30
+ # the engine
31
+ #
32
+ # a simple in memory engine, no persistence whatsoever for now.
33
+
34
+ engine = OpenWFE::Engine.new
35
+
36
+ #
37
+ # The Participants
38
+ #
39
+ # Ideally participants are shared by more than one process definition
40
+ # (a person is usually part of more than one business process in
41
+ # his organization)
42
+
43
+ # a small debug participant, as you can see, a participant can
44
+ # directly be a ruby block (which receives the workitem)
45
+ # (it's commented out at the end of the flow)
46
+ #
47
+ engine.register_participant("puts_workitem") do |workitem|
48
+ puts
49
+ puts workitem.to_s
50
+ puts
51
+ end
52
+
53
+ #
54
+ # launching
55
+
56
+ launchitem = LaunchItem.new(QuoteLookupFlow)
57
+ #
58
+ # Passing the process definition class as the unique
59
+ # LaunchItem parameter
60
+
61
+ launchitem.symbols = "aapl, sunw, msft, lnux"
62
+ #
63
+ # directly setting the value for the field "symbols"
64
+
65
+ engine.launch(launchitem)
66
+
@@ -0,0 +1,154 @@
1
+
2
+ #
3
+ # an OpenWFEru example
4
+ #
5
+
6
+ require 'openwfe/engine/engine'
7
+ require 'openwfe/expressions/raw_prog'
8
+ require 'openwfe/participants/soapparticipants'
9
+ require 'openwfe/participants/atomparticipants'
10
+
11
+
12
+ #
13
+ # the process definition
14
+ #
15
+ # instead of using the classical OpenWFE XML process definitions, we
16
+ # define the flow as a Ruby class
17
+
18
+ class QuoteLookupFlow < OpenWFE::ProcessDefinition
19
+ def make
20
+ process_definition :name => "quote_lookup", :revision => "0.1" do
21
+ sequence do
22
+
23
+ #
24
+ # lookup quotes
25
+
26
+ iterator :on_field_value => "symbols", :to_field => "symbol" do
27
+ sequence do
28
+
29
+ set \
30
+ :field => "quote_${f:__ip__}_name",
31
+ :field_value => "symbol"
32
+
33
+ participant :quote_service
34
+
35
+ set \
36
+ :field => "quote_${f:__ip__}_value",
37
+ :field_value => "__result__"
38
+ end
39
+ end
40
+
41
+ #
42
+ # update feed
43
+
44
+ set :field => "atom_entry_title" do
45
+ "quote feed at ${r:Time.now}"
46
+ end
47
+ #
48
+ # wrapping some ruby code for eval at runtime
49
+ # with ${r: ruby code ... }
50
+
51
+ participant :feed
52
+
53
+ #participant :ref => "puts_workitem"
54
+ #participant :ref => :puts_workitem
55
+ #participant "puts_workitem"
56
+ participant :puts_workitem
57
+ #
58
+ # the four notations are equivalent
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ #
65
+ # the engine
66
+ #
67
+ # a simple in memory engine, no persistence whatsoever for now.
68
+
69
+ engine = OpenWFE::Engine.new
70
+
71
+ #
72
+ # The Participants
73
+ #
74
+ # Ideally participants are shared by more than one process definition
75
+ # (a person is usually part of more than one business process in
76
+ # his organization)
77
+
78
+ # the participant that looks up the quote values
79
+ #
80
+ quote_service = OpenWFE::SoapParticipant.new(
81
+ "http://services.xmethods.net/soap", # service URI
82
+ "urn:xmethods-delayed-quotes", # namespace
83
+ "getQuote", # operation name
84
+ [ "symbol" ]) # param arrays (workitem fields)
85
+
86
+ engine.register_participant("quote_service", quote_service)
87
+
88
+ # the feed : at most 10 feed entries are kept.
89
+ #
90
+ # The entry template is specified as a block returning the template
91
+ # (a string containing xhtml).
92
+ #
93
+ # The feed is outputted in the current working directory ./atom_feed.xml
94
+ #
95
+ feed = OpenWFE::AtomParticipant.new(10) do
96
+ | flow_expression, participant, workitem |
97
+
98
+ #
99
+ # the template (xhtml by default) is generated via a block
100
+
101
+ s = "<h3>quotes</h3>"
102
+
103
+ s << "<ul>"
104
+
105
+ workitem.__ic__.times do |i|
106
+ #
107
+ # within an iteration, the count of iterations is stored in the
108
+ # workitem field "__ic__"
109
+ #
110
+ s << "<li>"
111
+ s << workitem.attributes["quote_#{i}_name"].to_s
112
+ s << " : "
113
+ s << workitem.attributes["quote_#{i}_value"].to_s
114
+ s << "</li>\n"
115
+ end
116
+
117
+ s << "</ul>"
118
+ end
119
+ engine.register_participant("feed", feed)
120
+
121
+ # a small debug participant, as you can see, a participant can
122
+ # directly be a ruby block (which receives the workitem)
123
+ # (it's commented out at the end of the flow)
124
+ #
125
+ engine.register_participant("puts_workitem") do |workitem|
126
+ puts
127
+ puts workitem.to_s
128
+ puts
129
+ end
130
+
131
+ #
132
+ # launching (not lunching)
133
+
134
+ launchitem = LaunchItem.new(QuoteLookupFlow)
135
+ #
136
+ # Passing the process definition class as the unique
137
+ # LaunchItem parameter
138
+
139
+ launchitem.symbols = "aapl, sunw, msft, lnux"
140
+ #
141
+ # directly setting the value for the field "symbols"
142
+
143
+ engine.launch(launchitem)
144
+
145
+ # in this example, the engine is used once with only one process definition,
146
+ # but an OpenWFE engine is made to run multiple different process instances.
147
+
148
+ # as an extension example, to produce a feed for the next ten hours you would :
149
+ #
150
+ # 10.times do
151
+ # engine.launch(launchitem)
152
+ # sleep (3600) # one hour
153
+ # end
154
+
@@ -1,6 +1,6 @@
1
1
  #
2
- #<tt>
3
- # Copyright (c) 2005-2006, John Mettraux, OpenWFE.org
2
+ #--
3
+ # Copyright (c) 2005-2007, John Mettraux and Alain Hoang, OpenWFE.org
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -28,8 +28,6 @@
28
28
  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
29
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
30
  # POSSIBILITY OF SUCH DAMAGE.
31
- #</tt>
32
- #
33
31
  #++
34
32
  #
35
33
  # = openwferu -- Open Workflow Engine in Ruby
@@ -38,8 +36,8 @@
38
36
  # referenced as a library via a require statement.
39
37
  #
40
38
 
41
- require 'workitem'
42
- require 'ru/engine'
43
- require 'ru/rudefinitions'
44
- require 'ru/participants'
39
+ require 'openwfe/workitem'
40
+ require 'openwfe/engine'
41
+ require 'openwfe/rudefinitions'
42
+ require 'openwfe/participants'
45
43
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  #--
3
- # Copyright (c) 2006, John Mettraux, OpenWFE.org
3
+ # Copyright (c) 2006-2007, John Mettraux, Nicolas Modrzyk OpenWFE.org
4
4
  # All rights reserved.
5
5
  #
6
6
  # Redistribution and use in source and binary forms, with or without
@@ -37,9 +37,9 @@
37
37
  # "made in Japan"
38
38
  #
39
39
  # John Mettraux at openwfe.org
40
- #
40
+ # Nicolas Modrzyk at openwfe.org
41
41
 
42
- module OpenWFEru
42
+ module OpenWFE
43
43
 
44
44
  module Contextual
45
45
 
@@ -59,6 +59,14 @@ module OpenWFEru
59
59
  end
60
60
  return @application_context[key]
61
61
  end
62
+
63
+ #
64
+ # use reflection to instanciate the new service,and
65
+ # add it to the application context
66
+ def init_service (service_name, service_class)
67
+ @application_context[service_name] = \
68
+ service_class.new(service_name,@application_context)
69
+ end
62
70
 
63
71
  end
64
72