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.
- data/README +47 -0
- data/lib/codec.rb +571 -0
- data/lib/controlclient.rb +115 -0
- data/lib/definitions.rb +112 -0
- data/lib/exception.rb +60 -0
- data/lib/flowexpressionid.rb +137 -0
- data/lib/openwferu.rb +43 -0
- data/lib/osocket.rb +138 -0
- data/lib/otime.rb +171 -0
- data/lib/restclient.rb +155 -0
- data/lib/ru/contextual.rb +63 -0
- data/lib/ru/dollar.rb +163 -0
- data/lib/ru/engine.rb +130 -0
- data/lib/ru/environment.rb +140 -0
- data/lib/ru/expressionmap.rb +120 -0
- data/lib/ru/expressionpool.rb +339 -0
- data/lib/ru/expressionstorage.rb +97 -0
- data/lib/ru/fe_base.rb +105 -0
- data/lib/ru/fe_concurrence.rb +122 -0
- data/lib/ru/fe_define.rb +101 -0
- data/lib/ru/fe_misc.rb +96 -0
- data/lib/ru/fe_participant.rb +75 -0
- data/lib/ru/fe_raw.rb +173 -0
- data/lib/ru/fe_subprocess.rb +84 -0
- data/lib/ru/fe_time.rb +135 -0
- data/lib/ru/fe_utils.rb +123 -0
- data/lib/ru/fe_value.rb +225 -0
- data/lib/ru/flowexpression.rb +250 -0
- data/lib/ru/logging.rb +85 -0
- data/lib/ru/participant.rb +67 -0
- data/lib/ru/participantmap.rb +93 -0
- data/lib/ru/participants.rb +74 -0
- data/lib/ru/rudefinitions.rb +70 -0
- data/lib/ru/ruutils.rb +68 -0
- data/lib/ru/scheduler.rb +478 -0
- data/lib/ru/schedulers.rb +63 -0
- data/lib/ru/service.rb +64 -0
- data/lib/test.rb +220 -0
- data/lib/utils.rb +94 -0
- data/lib/workitem.rb +250 -0
- data/lib/worklistclient.rb +276 -0
- data/test/dollartest.rb +79 -0
- data/test/feitest.rb +130 -0
- data/test/flowtestbase.rb +86 -0
- data/test/ft_0.rb +161 -0
- data/test/ft_1_unset.rb +152 -0
- data/test/ft_2_concurrence.rb +34 -0
- data/test/ft_3_equals.rb +84 -0
- data/test/ft_4_misc.rb +128 -0
- data/test/ft_5_time.rb +56 -0
- data/test/misctest.rb +46 -0
- data/test/runtest.rb +21 -0
- data/test/rutest_utils.rb +15 -0
- data/test/timetest.rb +111 -0
- metadata +100 -0
data/lib/otime.rb
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2005-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: otime.rb 3509 2006-10-21 12:00:52Z jmettraux $
|
32
|
+
#
|
33
|
+
|
34
|
+
#
|
35
|
+
# "hecho en Costa Rica"
|
36
|
+
#
|
37
|
+
# john.mettraux@openwfe.org
|
38
|
+
#
|
39
|
+
|
40
|
+
require 'parsedate'
|
41
|
+
|
42
|
+
|
43
|
+
module OpenWFE
|
44
|
+
|
45
|
+
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
46
|
+
|
47
|
+
#
|
48
|
+
# Returns the current time as an ISO date string
|
49
|
+
#
|
50
|
+
def OpenWFE.now ()
|
51
|
+
return to_iso_date(Time.new())
|
52
|
+
end
|
53
|
+
|
54
|
+
def OpenWFE.to_iso_date (date)
|
55
|
+
|
56
|
+
if date.kind_of?(Float)
|
57
|
+
date = Time.at(date)
|
58
|
+
end
|
59
|
+
|
60
|
+
s = date.getutc().strftime(TIME_FORMAT)
|
61
|
+
o = date.utc_offset / 3600
|
62
|
+
o = o.to_s() + "00"
|
63
|
+
o = "0" + o if o.length < 4
|
64
|
+
o = "+" + o unless o[0..1] == '-'
|
65
|
+
return s + " " + o.to_s()
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Returns a Ruby time
|
70
|
+
#
|
71
|
+
def OpenWFE.toRubyTime (isoDate)
|
72
|
+
|
73
|
+
res = ParseDate.parsedate(isoDate)
|
74
|
+
return Time.local(*res)
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# An Ruby-friendly alias for toRubyTime()
|
79
|
+
#
|
80
|
+
def OpenWFE.to_ruby_time (iso_date)
|
81
|
+
|
82
|
+
return toRubyTime(iso_date)
|
83
|
+
end
|
84
|
+
|
85
|
+
#def OpenWFE.parse_date (date)
|
86
|
+
#end
|
87
|
+
|
88
|
+
#
|
89
|
+
# equivalent to java.lang.System.currentTimeMillis()
|
90
|
+
#
|
91
|
+
def OpenWFE.current_time_millis ()
|
92
|
+
t = Time.new()
|
93
|
+
t = t.to_f * 1000
|
94
|
+
return t.to_i
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# turns a string like '1m10s' into a float like '70.0'
|
99
|
+
#
|
100
|
+
# w -> week
|
101
|
+
# d -> day
|
102
|
+
# h -> hour
|
103
|
+
# m -> minute
|
104
|
+
# s -> second
|
105
|
+
# M -> month
|
106
|
+
# y -> year
|
107
|
+
# 'nada' -> millisecond
|
108
|
+
#
|
109
|
+
def OpenWFE.parse_time_string (string)
|
110
|
+
|
111
|
+
string = string.strip
|
112
|
+
|
113
|
+
index = -1
|
114
|
+
result = 0.0
|
115
|
+
|
116
|
+
number = ""
|
117
|
+
|
118
|
+
while true
|
119
|
+
index = index + 1
|
120
|
+
|
121
|
+
if index >= string.length
|
122
|
+
if number.length > 0
|
123
|
+
result = result + (Integer(number) / 1000)
|
124
|
+
end
|
125
|
+
break
|
126
|
+
end
|
127
|
+
|
128
|
+
c = string[index, 1]
|
129
|
+
|
130
|
+
if is_digit?(c)
|
131
|
+
number = number + c
|
132
|
+
next
|
133
|
+
end
|
134
|
+
|
135
|
+
value = Integer(number)
|
136
|
+
number = ""
|
137
|
+
|
138
|
+
multiplier = DURATIONS[c]
|
139
|
+
|
140
|
+
raise "unknown time char '#{c}'" \
|
141
|
+
if not multiplier
|
142
|
+
|
143
|
+
result = result + (value * multiplier)
|
144
|
+
end
|
145
|
+
|
146
|
+
return result
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# returns true if the character c is a digit
|
151
|
+
#
|
152
|
+
def OpenWFE.is_digit? (c)
|
153
|
+
return false if not c.kind_of?(String)
|
154
|
+
return false if c.length > 1
|
155
|
+
return (c >= "0" and c <= "9")
|
156
|
+
end
|
157
|
+
|
158
|
+
protected
|
159
|
+
|
160
|
+
DURATIONS = {
|
161
|
+
"y" => 365 * 24 * 3600,
|
162
|
+
"M" => 30 * 24 * 3600,
|
163
|
+
"w" => 7 * 24 * 3600,
|
164
|
+
"d" => 24 * 3600,
|
165
|
+
"h" => 3600,
|
166
|
+
"m" => 60,
|
167
|
+
"s" => 1
|
168
|
+
}
|
169
|
+
|
170
|
+
end
|
171
|
+
|
data/lib/restclient.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2005-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: restclient.rb 3454 2006-10-08 16:51:00Z jmettraux $
|
32
|
+
#
|
33
|
+
|
34
|
+
#
|
35
|
+
# "hecho en Costa Rica"
|
36
|
+
#
|
37
|
+
|
38
|
+
require 'base64'
|
39
|
+
require 'net/http'
|
40
|
+
require 'rexml/document'
|
41
|
+
|
42
|
+
|
43
|
+
module OpenWFE
|
44
|
+
|
45
|
+
class RestClient
|
46
|
+
|
47
|
+
attr_reader :host, :port, :resource, :sessionId
|
48
|
+
|
49
|
+
def initialize (url, username, password)
|
50
|
+
|
51
|
+
splitUrl(url)
|
52
|
+
@username = username
|
53
|
+
|
54
|
+
connect(password)
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Closes this REST client
|
59
|
+
#
|
60
|
+
def close ()
|
61
|
+
|
62
|
+
post('endWorkSession', nil, {}, nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def get (action, subResourceName, params)
|
68
|
+
|
69
|
+
return @httpclient\
|
70
|
+
.get(computeResource(action, subResourceName, params))
|
71
|
+
end
|
72
|
+
|
73
|
+
def post (action, subResourceName, params, data)
|
74
|
+
|
75
|
+
data = data.to_s()
|
76
|
+
|
77
|
+
return @httpclient\
|
78
|
+
.post(computeResource(action, subResourceName, params), data)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def splitUrl (url)
|
84
|
+
|
85
|
+
@host = nil
|
86
|
+
@port = nil
|
87
|
+
@resource = nil
|
88
|
+
|
89
|
+
url = url[7..-1] if url[0..6] == 'http://'
|
90
|
+
|
91
|
+
i = url.index('/')
|
92
|
+
if i < 0
|
93
|
+
@resource = '/defaultrestresource'
|
94
|
+
else
|
95
|
+
@resource = url[i..-1]
|
96
|
+
url = url[0..i]
|
97
|
+
end
|
98
|
+
|
99
|
+
@host, @port = url.split(':')
|
100
|
+
|
101
|
+
if @port == nil
|
102
|
+
@port = 5080
|
103
|
+
else
|
104
|
+
@port = Integer(@port[0..-2])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def connect (password)
|
109
|
+
|
110
|
+
@httpclient = Net::HTTP.new(@host, @port)
|
111
|
+
|
112
|
+
hs = {}
|
113
|
+
hs['Authorization'] = \
|
114
|
+
'Basic ' + Base64.encode64(@username+":"+password)
|
115
|
+
hs['RestClient'] = 'openwfe-ruby'
|
116
|
+
|
117
|
+
r = @httpclient.get(@resource, hs)
|
118
|
+
|
119
|
+
xml = REXML::Document.new(r.body)
|
120
|
+
|
121
|
+
@sessionId = Integer(xml.root.attributes["id"])
|
122
|
+
end
|
123
|
+
|
124
|
+
def computeResource (action, subResourceName, params)
|
125
|
+
|
126
|
+
resource = @resource
|
127
|
+
resource = resource+'/'+subResourceName if subResourceName
|
128
|
+
|
129
|
+
resource = resource+\
|
130
|
+
'?session='+@sessionId.to_s()+'&action='+action
|
131
|
+
|
132
|
+
if params
|
133
|
+
params.keys.each do |k|
|
134
|
+
resource = resource+'&'+k.to_s()+'='+params[k].to_s()
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
return resource
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
# for test purposes
|
145
|
+
#
|
146
|
+
#client = RestClient::RestClient\
|
147
|
+
# .new("127.0.0.1:5080/worklist", "alice", "alice")
|
148
|
+
#client = OpenWFE::RestClient\
|
149
|
+
# .new("http://127.0.0.1:5080/worklist", "alice", "alice")
|
150
|
+
#
|
151
|
+
#puts "sessionId : #{client.sessionId}"
|
152
|
+
#
|
153
|
+
#puts client.get('getstorenames', nil, nil)
|
154
|
+
#puts client.get('getheaders', 'Store.alpha', nil)
|
155
|
+
|
@@ -0,0 +1,63 @@
|
|
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
|
+
module OpenWFEru
|
41
|
+
|
42
|
+
module Contextual
|
43
|
+
|
44
|
+
attr_accessor :application_context
|
45
|
+
|
46
|
+
#
|
47
|
+
# Looks up something in the application context, if the given
|
48
|
+
# key is a class, then the first value in the context of that
|
49
|
+
# class is returned.
|
50
|
+
#
|
51
|
+
def lookup (key)
|
52
|
+
if key.kind_of? Class
|
53
|
+
@application_context.each do |k, value|
|
54
|
+
return value if value.class == key
|
55
|
+
end
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
return @application_context[key]
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/lib/ru/dollar.rb
ADDED
@@ -0,0 +1,163 @@
|
|
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/flowexpression'
|
41
|
+
|
42
|
+
#
|
43
|
+
# 'dollar notation' implementation in Ruby
|
44
|
+
#
|
45
|
+
|
46
|
+
module OpenWFEru
|
47
|
+
|
48
|
+
def OpenWFEru.dsub (text, dict)
|
49
|
+
|
50
|
+
#puts "### text is >#{text}<"
|
51
|
+
|
52
|
+
j = text.index("}")
|
53
|
+
|
54
|
+
return text if not j
|
55
|
+
|
56
|
+
t = text[0, j]
|
57
|
+
|
58
|
+
i = t.rindex("${")
|
59
|
+
ii = t.rindex("\\${")
|
60
|
+
|
61
|
+
#puts "i is #{i}"
|
62
|
+
#puts "ii is #{ii}"
|
63
|
+
|
64
|
+
return text if not i
|
65
|
+
|
66
|
+
return unescape(text) if (i) and (i != 0) and (ii == i-1)
|
67
|
+
#
|
68
|
+
# found "\${"
|
69
|
+
|
70
|
+
key = text[i+2..j-1]
|
71
|
+
|
72
|
+
#puts "### key is '#{key}'"
|
73
|
+
|
74
|
+
value = dict[key]
|
75
|
+
|
76
|
+
#puts "### value 0 is '#{value}'"
|
77
|
+
|
78
|
+
if value
|
79
|
+
value = value.to_s
|
80
|
+
else
|
81
|
+
if dict.has_key? key
|
82
|
+
value = "false"
|
83
|
+
else
|
84
|
+
value = ""
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#puts "### value 1 is '#{value}'"
|
89
|
+
|
90
|
+
#puts "pre is >#{text[0..i-1]}<"
|
91
|
+
#puts "post is >#{text[j+1..-1]}<"
|
92
|
+
|
93
|
+
pre = ""
|
94
|
+
if i > 0
|
95
|
+
pre = text[0..i-1]
|
96
|
+
end
|
97
|
+
|
98
|
+
return dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
|
99
|
+
end
|
100
|
+
|
101
|
+
def OpenWFEru.unescape (text)
|
102
|
+
return text.gsub("\\\\\\$\\{", "\\${")
|
103
|
+
end
|
104
|
+
|
105
|
+
def OpenWFEru.dosub (text, flow_expression, workitem)
|
106
|
+
return dsub(text, FlowDict.new(flow_expression, workitem))
|
107
|
+
end
|
108
|
+
|
109
|
+
class FlowDict < Hash
|
110
|
+
|
111
|
+
def initialize (flow_expression, workitem)
|
112
|
+
@flow_expression = flow_expression
|
113
|
+
@workitem = workitem
|
114
|
+
end
|
115
|
+
|
116
|
+
def [] (key)
|
117
|
+
p, k = extract_prefix(key)
|
118
|
+
|
119
|
+
#puts "### p, k is '#{p}', '#{k}'"
|
120
|
+
|
121
|
+
return '' if k == ''
|
122
|
+
|
123
|
+
return @workitem.attributes[k] if p == 'f'
|
124
|
+
return @flow_expression.lookup_variable(k) if p == 'v'
|
125
|
+
return call_function(k) if p == 'c'
|
126
|
+
return call_ruby(k) if p == 'r'
|
127
|
+
# TODO : implement constant lookup
|
128
|
+
|
129
|
+
return @workitem.attributes[key]
|
130
|
+
end
|
131
|
+
|
132
|
+
def has_key? (key)
|
133
|
+
p, k = extract_prefix(key)
|
134
|
+
|
135
|
+
return false if k == ''
|
136
|
+
|
137
|
+
return @workitem.attributes.has_key?(k) if p == 'f'
|
138
|
+
return (@flow_expression.lookup_variable(k) != nil) if p == 'v'
|
139
|
+
return true if p == 'c'
|
140
|
+
return true if p == 'r'
|
141
|
+
# TODO : implement constant lookup
|
142
|
+
|
143
|
+
return @workitem.attributes.has_key?(key)
|
144
|
+
end
|
145
|
+
|
146
|
+
protected
|
147
|
+
|
148
|
+
def extract_prefix (key)
|
149
|
+
i = key.index(':')
|
150
|
+
return 'v', key if not i
|
151
|
+
return key[0..0], key[i+1..-1]
|
152
|
+
end
|
153
|
+
|
154
|
+
def call_function (function_name)
|
155
|
+
end
|
156
|
+
|
157
|
+
def call_ruby (ruby_code)
|
158
|
+
eval(ruby_code).to_s
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
data/lib/ru/engine.rb
ADDED
@@ -0,0 +1,130 @@
|
|
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 'rexml/document'
|
41
|
+
|
42
|
+
require 'workitem'
|
43
|
+
require 'ru/rudefinitions'
|
44
|
+
require 'ru/service'
|
45
|
+
require 'ru/expressionmap'
|
46
|
+
require 'ru/expressionpool'
|
47
|
+
require 'ru/expressionstorage'
|
48
|
+
require 'ru/participantmap'
|
49
|
+
require 'ru/schedulers'
|
50
|
+
|
51
|
+
|
52
|
+
module OpenWFEru
|
53
|
+
|
54
|
+
class Engine < Service
|
55
|
+
|
56
|
+
#attr_accessor \
|
57
|
+
# :application_context
|
58
|
+
|
59
|
+
def initialize()
|
60
|
+
|
61
|
+
super('engine', {})
|
62
|
+
|
63
|
+
@application_context[@service_name] = self
|
64
|
+
|
65
|
+
@application_context[S_EXPRESSION_MAP] = build_expression_map()
|
66
|
+
@application_context[S_EXPRESSION_POOL] = build_expression_pool()
|
67
|
+
@application_context[S_EXPRESSION_STORAGE] = build_expression_storage()
|
68
|
+
@application_context[S_PARTICIPANT_MAP] = build_participant_map()
|
69
|
+
|
70
|
+
@application_context[S_SCHEDULER] = \
|
71
|
+
SchedulerService.new(S_SCHEDULER, @application_context)
|
72
|
+
|
73
|
+
init_default_logging('engine.log')
|
74
|
+
end
|
75
|
+
|
76
|
+
def launch(object)
|
77
|
+
|
78
|
+
launchitem = nil
|
79
|
+
|
80
|
+
#ldebug { "launch() param is #{object.class}" }
|
81
|
+
|
82
|
+
if object.kind_of? OpenWFE::LaunchItem
|
83
|
+
launchitem = object
|
84
|
+
#elsif object.kind_of? REXML::Element
|
85
|
+
#nada
|
86
|
+
elsif object.kind_of? String
|
87
|
+
launchitem = OpenWFE::LaunchItem.new
|
88
|
+
if object[0] == '<'
|
89
|
+
launchitem.workflowDefinitionUrl = "field:__definition"
|
90
|
+
launchitem['definition'] = object
|
91
|
+
else
|
92
|
+
launchitem.workflowDefinitionUrl = object
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
return @application_context[S_EXPRESSION_POOL].launch(launchitem)
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# registers a participant in this [embedded] engine
|
101
|
+
#
|
102
|
+
def register_participant (regex, participant)
|
103
|
+
|
104
|
+
@application_context[S_PARTICIPANT_MAP]\
|
105
|
+
.register_participant(regex, participant)
|
106
|
+
end
|
107
|
+
|
108
|
+
protected
|
109
|
+
|
110
|
+
def build_expression_map ()
|
111
|
+
ExpressionMap.new(S_EXPRESSION_MAP, @application_context)
|
112
|
+
end
|
113
|
+
|
114
|
+
def build_expression_pool ()
|
115
|
+
ExpressionPool.new(S_EXPRESSION_POOL, @application_context)
|
116
|
+
end
|
117
|
+
|
118
|
+
def build_expression_storage ()
|
119
|
+
InMemoryExpressionStorage \
|
120
|
+
.new(S_EXPRESSION_STORAGE, @application_context)
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_participant_map ()
|
124
|
+
ParticipantMap.new(S_PARTICIPANT_MAP, @application_context)
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|