cpee-transformation 1.0.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.
- checksums.yaml +7 -0
- data/AUTHORS +2 -0
- data/LICENSE +165 -0
- data/README.md +1 -0
- data/Rakefile +21 -0
- data/cpee-transformation.gemspec +29 -0
- data/lib/cpee/transformation/beautiful.rb +182 -0
- data/lib/cpee/transformation/bpmn2.rb +144 -0
- data/lib/cpee/transformation/cpee.rb +309 -0
- data/lib/cpee/transformation/dataflow.rb +127 -0
- data/lib/cpee/transformation/graphviz.rb +100 -0
- data/lib/cpee/transformation/implementation.rb +144 -0
- data/lib/cpee/transformation/implementation.xml +47 -0
- data/lib/cpee/transformation/mermaid.rb +242 -0
- data/lib/cpee/transformation/ptml.rb +316 -0
- data/lib/cpee/transformation/structures.rb +570 -0
- data/lib/cpee/transformation/target.rb +58 -0
- data/lib/cpee/transformation/text-bf.rb +201 -0
- data/lib/cpee/transformation/text-df-PO-extended.rb +221 -0
- data/lib/cpee/transformation/text-df-PO-reduced.rb +211 -0
- data/lib/cpee/transformation/transformation_text_cpee.xml +49 -0
- data/lib/cpee/transformation/transformation_xml_cpee.xml +49 -0
- data/lib/cpee/transformation/transformation_xml_text.xml +49 -0
- data/lib/cpee/transformation/transformer.rb +300 -0
- data/server/trans +38 -0
- data/tools/bpmn2_to_cpee.rb +84 -0
- data/tools/bpmn2_to_mermaid.rb +85 -0
- data/tools/bpmn2_to_ptml.rb +87 -0
- data/tools/cpee-trans +74 -0
- data/tools/cpee_to_cpee.rb +83 -0
- data/tools/cpee_to_dataflow.rb +83 -0
- data/tools/cpee_to_mermaid.rb +85 -0
- data/tools/cpee_to_ptml.rb +87 -0
- data/tools/cpee_to_text_bf.rb +85 -0
- data/tools/cpee_to_text_df-poe.rb +85 -0
- data/tools/cpee_to_text_df-por.rb +85 -0
- data/tools/mermaid_to_cpee.rb +85 -0
- data/tools/ptml_to_cpee.rb +87 -0
- metadata +160 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# This file is part of CPEE-TRANSFORMATION.
|
|
4
|
+
#
|
|
5
|
+
# CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or (at your
|
|
8
|
+
# option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
|
|
11
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
13
|
+
# for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
|
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
require_relative 'target'
|
|
20
|
+
require 'xml/smart'
|
|
21
|
+
|
|
22
|
+
module CPEE
|
|
23
|
+
|
|
24
|
+
module Transformation
|
|
25
|
+
|
|
26
|
+
module Source #{{{
|
|
27
|
+
|
|
28
|
+
class CPEE
|
|
29
|
+
attr_reader :tree, :start, :dataelements, :endpoints, :graph, :traces
|
|
30
|
+
|
|
31
|
+
def initialize(text)
|
|
32
|
+
@tree = Tree.new
|
|
33
|
+
@start = nil
|
|
34
|
+
@nids = []
|
|
35
|
+
|
|
36
|
+
@dataelements = {}
|
|
37
|
+
@endpoints = {}
|
|
38
|
+
@graph = Graph.new
|
|
39
|
+
|
|
40
|
+
extract_original(text)
|
|
41
|
+
|
|
42
|
+
if @start.nil?
|
|
43
|
+
@traces = Traces.new [[]]
|
|
44
|
+
else
|
|
45
|
+
@traces = Traces.new [[@start]]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def id_find(nid)
|
|
50
|
+
nid = 'g0' unless nid
|
|
51
|
+
while @nids.include?(nid)
|
|
52
|
+
nid.next!
|
|
53
|
+
end
|
|
54
|
+
@nids << nid
|
|
55
|
+
nid
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def dive(node,n1=nil,condition=nil,otherwise=false)
|
|
59
|
+
if node.children.empty?
|
|
60
|
+
return n1
|
|
61
|
+
end
|
|
62
|
+
if n1.nil?
|
|
63
|
+
nid = id_find(node.attributes['id'] || node.attributes['eid'])
|
|
64
|
+
n1 = @start = Node.new(0,nid,:startEvent,'',0,1)
|
|
65
|
+
end
|
|
66
|
+
node.children.each do |ele|
|
|
67
|
+
case ele.qname.name
|
|
68
|
+
when 'loop'
|
|
69
|
+
if ele.attributes['mode'] == 'pre_test'
|
|
70
|
+
nid = id_find(ele.attributes['eid'])
|
|
71
|
+
nx = Node.new(0,nid,:exclusiveGateway,nil,2,2)
|
|
72
|
+
@graph.add_node nx
|
|
73
|
+
@graph.add_link Link.new(n1.id, nx.id, condition, otherwise)
|
|
74
|
+
|
|
75
|
+
condition = nil
|
|
76
|
+
bn = dive ele, nx, ele.attributes['condition']
|
|
77
|
+
|
|
78
|
+
@graph.add_link Link.new(bn.id, nx.id)
|
|
79
|
+
n1 = nx
|
|
80
|
+
else
|
|
81
|
+
nid = id_find(ele.attributes['eid'])
|
|
82
|
+
nx = Node.new(0,nid,:exclusiveGateway,nil,2,1)
|
|
83
|
+
@graph.add_node nx
|
|
84
|
+
@graph.add_link Link.new(n1.id, nx.id, condition, otherwise)
|
|
85
|
+
condition = nil
|
|
86
|
+
|
|
87
|
+
bn = dive ele, nx, ele.attributes['condition']
|
|
88
|
+
|
|
89
|
+
no = Node.new(0,nid + 'e',:exclusiveGateway,nil,1,2)
|
|
90
|
+
@graph.add_node no
|
|
91
|
+
@graph.add_link Link.new(bn.id, no.id)
|
|
92
|
+
@graph.add_link Link.new(no.id, nx.id, ele.attributes['condition'])
|
|
93
|
+
n1 = no
|
|
94
|
+
end
|
|
95
|
+
when 'call'
|
|
96
|
+
nid = id_find(ele.attributes['id'])
|
|
97
|
+
no = Node.new(0,nid,:task,ele.find("string(d:parameters/d:label)"),1,1)
|
|
98
|
+
no.methods << ele.find("string(d:parameters/d:method)")
|
|
99
|
+
no.endpoints << ele.attributes['endpoint']
|
|
100
|
+
ele.find("d:parameters/d:arguments/d:*").each do |e|
|
|
101
|
+
no.arguments[e.qname.name] = e.text
|
|
102
|
+
end
|
|
103
|
+
if (sc = ele.find("d:code/d:*")).any?
|
|
104
|
+
no.script_type = 'application/x-ruby'
|
|
105
|
+
no.script = sc.map{|e| [e.qname.name,e.text] }.to_h
|
|
106
|
+
end
|
|
107
|
+
@graph.add_link Link.new(n1.id, no.id, condition, otherwise)
|
|
108
|
+
condition = nil
|
|
109
|
+
@graph.add_node no
|
|
110
|
+
n1 = no
|
|
111
|
+
when 'manipulate'
|
|
112
|
+
nid = id_find(ele.attributes['id'])
|
|
113
|
+
no = Node.new(0,nid,:scriptTask,ele.attributes['label'].to_s,1,1)
|
|
114
|
+
no.script_type = 'application/x-ruby'
|
|
115
|
+
no.script = ele.find("string(d:code)")
|
|
116
|
+
@graph.add_link Link.new(n1.id, no.id, condition, otherwise)
|
|
117
|
+
condition = nil
|
|
118
|
+
@graph.add_node no
|
|
119
|
+
n1 = no
|
|
120
|
+
when 'parallel'
|
|
121
|
+
bra = ele.find('d:parallel_branch')
|
|
122
|
+
nid = id_find(ele.attributes['eid'])
|
|
123
|
+
ns = Node.new(0,nid,:parallelGateway,nil,1,bra.length)
|
|
124
|
+
ns.attributes[:wait] = ele.attributes['wait'] || -1
|
|
125
|
+
ns.attributes[:cancel] = ele.attributes['cancel'] || 'last'
|
|
126
|
+
@graph.add_link Link.new(n1.id, ns.id, condition, otherwise)
|
|
127
|
+
condition = nil
|
|
128
|
+
ne = Node.new(0,nid + 'e',:parallelGateway,nil,1,bra.length)
|
|
129
|
+
@graph.add_node ns
|
|
130
|
+
@graph.add_node ne
|
|
131
|
+
bra.each do |br|
|
|
132
|
+
bn = dive br, ns
|
|
133
|
+
@graph.add_link Link.new(bn.id, ne.id)
|
|
134
|
+
end
|
|
135
|
+
n1 = ne
|
|
136
|
+
when 'choose'
|
|
137
|
+
nid = id_find(ele.attributes['eid'])
|
|
138
|
+
bra = ele.find('d:alternative|d:otherwise')
|
|
139
|
+
ns = Node.new(0,nid,:exclusiveGateway,ele.attributes['label'],1,bra.length)
|
|
140
|
+
@graph.add_link Link.new(n1.id, ns.id, condition, otherwise)
|
|
141
|
+
condition = nil
|
|
142
|
+
ne = Node.new(0,nid + 'e',:exclusiveGateway,nil,1,bra.length)
|
|
143
|
+
@graph.add_node ns
|
|
144
|
+
@graph.add_node ne
|
|
145
|
+
bra.each do |br|
|
|
146
|
+
bn = dive br, ns, br.attributes['condition'], br.qname.name == 'otherwise'
|
|
147
|
+
if bn == ns
|
|
148
|
+
@graph.add_link Link.new(bn.id, ne.id, br.attributes['condition'], br.qname.name == 'otherwise')
|
|
149
|
+
else
|
|
150
|
+
@graph.add_link Link.new(bn.id, ne.id)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
n1 = ne
|
|
154
|
+
when 'escape'
|
|
155
|
+
nid = id_find(ele.attributes['eid'])
|
|
156
|
+
no = Node.new(0,nid,:break,'',1,1)
|
|
157
|
+
@graph.add_link Link.new(n1.id, no.id, condition, otherwise)
|
|
158
|
+
@graph.add_node no
|
|
159
|
+
condition = nil
|
|
160
|
+
n1 = no
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
n1
|
|
164
|
+
end
|
|
165
|
+
private :dive
|
|
166
|
+
|
|
167
|
+
def extract_original(text)
|
|
168
|
+
doc = XML::Smart::string(text)
|
|
169
|
+
doc.register_namespace :d, 'http://cpee.org/ns/description/1.0'
|
|
170
|
+
bn = dive doc.root
|
|
171
|
+
ne = Node.new(0,Digest::MD5.hexdigest(Kernel::rand().to_s),:endEvent,'',1,0)
|
|
172
|
+
@graph.add_node ne
|
|
173
|
+
@graph.add_link Link.new(bn.id, ne.id)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
end #}}}
|
|
179
|
+
|
|
180
|
+
module Target #{{{
|
|
181
|
+
|
|
182
|
+
class CPEE < Default
|
|
183
|
+
|
|
184
|
+
def generate
|
|
185
|
+
@nids = []
|
|
186
|
+
@eid = 0
|
|
187
|
+
res = XML::Smart.string("<description xmlns='http://cpee.org/ns/description/1.0' xmlns:a='http://cpee.org/ns/annotation/1.0'/>")
|
|
188
|
+
res.register_namespace 'd', 'http://cpee.org/ns/description/1.0'
|
|
189
|
+
res.register_namespace 'a', 'http://cpee.org/ns/annotation/1.0'
|
|
190
|
+
generate_in_list(@tree,res.root)
|
|
191
|
+
res.to_s
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
private
|
|
195
|
+
def print_Break(node,res)
|
|
196
|
+
res.add('escape', 'a:alt_id' => node.id)
|
|
197
|
+
res
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def print_Loop(node,res)
|
|
201
|
+
eid = "e#{(@eid += 1)}"
|
|
202
|
+
if node.sub.length == 2 && node.sub[1].condition.empty? && ((node.sub[1].length == 1 && node.sub[1][0].class.name.gsub(/\w+:+/,'') == 'Break') || node.sub[1].length == 0)
|
|
203
|
+
s1 = res.add('loop', 'mode' => node.mode, 'condition' => node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && '), 'a:alt_id' => node.id, 'eid' => eid)
|
|
204
|
+
s1.attributes['language'] = node.sub[0].condition_type unless node.sub[0].condition_type.nil?
|
|
205
|
+
node.sub[0].attributes.each do |k,v|
|
|
206
|
+
s1.attributes[k] = v
|
|
207
|
+
end
|
|
208
|
+
generate_in_list(node.sub[0],s1)
|
|
209
|
+
else
|
|
210
|
+
s1 = res.add('loop', 'mode' => node.mode, 'condition' => node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && '), 'eid' => eid)
|
|
211
|
+
if node.sub.length == 1
|
|
212
|
+
generate_in_list(node.sub[0],s1)
|
|
213
|
+
else
|
|
214
|
+
print_Conditional(node,s1)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
res
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def print_Node(node,res)
|
|
221
|
+
### make sure nids are not duplicate
|
|
222
|
+
nid = "a#{node.niceid}"
|
|
223
|
+
nic = node.niceid
|
|
224
|
+
while @nids.include?(nid)
|
|
225
|
+
nid = "a#{nic += 1}"
|
|
226
|
+
end
|
|
227
|
+
@nids << nid
|
|
228
|
+
###
|
|
229
|
+
if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
|
|
230
|
+
n = res.add('d:manipulate', 'id' => nid, 'a:alt_id' => node.id)
|
|
231
|
+
n.attributes['label'] = node.label.gsub(/"/,"\\\"")
|
|
232
|
+
nc = n.add('d:code',node.script)
|
|
233
|
+
nc.attributes['output'] = node.script_var unless node.script_var.nil?
|
|
234
|
+
nc.attributes['language'] = node.script_type unless node.script_type.nil?
|
|
235
|
+
else
|
|
236
|
+
n = res.add('d:call', 'id' => nid, 'endpoint' => node.endpoints.join(','), 'a:alt_id' => node.id)
|
|
237
|
+
p = n.add('d:parameters')
|
|
238
|
+
p.add('d:label',"#{node.label}")
|
|
239
|
+
p.add('d:method',node.methods.join(',') || 'post')
|
|
240
|
+
par = p.add('d:arguments')
|
|
241
|
+
node.arguments.each do |k,v|
|
|
242
|
+
par.add(k,v)
|
|
243
|
+
end
|
|
244
|
+
if !node.script.nil? && ((node.script.is_a?(String) && node.script.strip != '') || node.script.is_a?(Hash))
|
|
245
|
+
y = n.add('d:code')
|
|
246
|
+
if node.script.is_a?(String)
|
|
247
|
+
x = y.add('d:finalize',node.script)
|
|
248
|
+
x.attributes['output'] = node.script_var unless node.script_var.nil?
|
|
249
|
+
x.attributes['language'] = node.script_type unless node.script_type.nil?
|
|
250
|
+
else
|
|
251
|
+
node.script.each do |k,v|
|
|
252
|
+
x = y.add('d:' + k,v)
|
|
253
|
+
x.attributes['output'] = node.script_var unless node.script_var.nil? || k == 'prepare'
|
|
254
|
+
x.attributes['language'] = node.script_type unless node.script_type.nil?
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
n
|
|
259
|
+
end
|
|
260
|
+
res
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def print_Parallel(node,res)
|
|
264
|
+
eid = "e#{(@eid += 1)}"
|
|
265
|
+
s1 = res.add('parallel','wait' => node.wait, 'cancel' => node.cancel, 'a:alt_id' => node.id, 'eid' => eid)
|
|
266
|
+
node.sub.each do |branch|
|
|
267
|
+
bid = "e#{(@eid += 1)}"
|
|
268
|
+
s2 = s1.add('parallel_branch', 'eid' => bid)
|
|
269
|
+
generate_in_list(branch,s2)
|
|
270
|
+
end
|
|
271
|
+
res
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
def print_Conditional(node,res)
|
|
275
|
+
eid = "e#{(@eid += 1)}"
|
|
276
|
+
s1 = res.add('d:choose', 'label' => node.label, 'mode' => node.mode == :inclusive ? 'inclusive' : 'exclusive', 'a:alt_id' => node.id, 'eid' => eid)
|
|
277
|
+
otherwise = false
|
|
278
|
+
node.sub.each do |branch|
|
|
279
|
+
bid = "e#{(@eid += 1)}"
|
|
280
|
+
s2 = if branch.condition.any?
|
|
281
|
+
a = s1.add('d:alternative','condition' => branch.condition.join(' or '), 'eid' => bid)
|
|
282
|
+
a.attributes['language'] = branch.condition_type unless branch.condition_type.nil?
|
|
283
|
+
a
|
|
284
|
+
else
|
|
285
|
+
if branch.otherwise || !otherwise
|
|
286
|
+
otherwise = true
|
|
287
|
+
s1.add('d:otherwise', 'eid' => bid)
|
|
288
|
+
else
|
|
289
|
+
s1.add('d:alternative', 'condition' => '', 'eid' => bid)
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
branch.attributes.each do |k,v|
|
|
293
|
+
s2.attributes[k] = v
|
|
294
|
+
end
|
|
295
|
+
generate_in_list(branch,s2)
|
|
296
|
+
end
|
|
297
|
+
if (x = s1.find('d:otherwise')).any?
|
|
298
|
+
s1.add x
|
|
299
|
+
end
|
|
300
|
+
res
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
end #}}}
|
|
306
|
+
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# This file is part of cpee-transformation.
|
|
4
|
+
#
|
|
5
|
+
# cpee-transformation is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or (at your
|
|
8
|
+
# option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# cpee-transformation is distributed in the hope that it will be useful, but
|
|
11
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
13
|
+
# for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with cpee-transformation (file COPYING in the main directory). If not,
|
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
require_relative 'target'
|
|
20
|
+
require 'xml/smart'
|
|
21
|
+
|
|
22
|
+
module CPEE
|
|
23
|
+
|
|
24
|
+
module Transformation
|
|
25
|
+
|
|
26
|
+
module Target #{{{
|
|
27
|
+
|
|
28
|
+
class DataFlow < Default
|
|
29
|
+
|
|
30
|
+
def generate
|
|
31
|
+
res = {
|
|
32
|
+
"tasks" => {},
|
|
33
|
+
"gateway_conditions" => {}
|
|
34
|
+
}
|
|
35
|
+
generate_in_list(@tree,res)
|
|
36
|
+
res
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def print_Node(node,res) #{{{
|
|
42
|
+
if node.type == :scriptTask
|
|
43
|
+
res["tasks"][node.id] = {
|
|
44
|
+
"label" => node.label,
|
|
45
|
+
"url" => "script",
|
|
46
|
+
"script" => node.script
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
|
|
50
|
+
temp = {
|
|
51
|
+
"label" => node.label,
|
|
52
|
+
"url" => node.endpoints[0],
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if !node.script.nil?
|
|
56
|
+
final = node.script['finalize']
|
|
57
|
+
temp["output"] = final.split(";").to_h { |pair| pair.split("=", 2) }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if node.arguments.length > 0
|
|
61
|
+
temp["input"] = node.arguments
|
|
62
|
+
end
|
|
63
|
+
res["tasks"][node.id] = temp
|
|
64
|
+
end
|
|
65
|
+
@last = node.id
|
|
66
|
+
res
|
|
67
|
+
end #}}}
|
|
68
|
+
|
|
69
|
+
def print_Loop(node,res) #{{{
|
|
70
|
+
gid = "#{node.id}s"
|
|
71
|
+
condition = node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && ')
|
|
72
|
+
res["gateway_conditions"][gid] = {
|
|
73
|
+
"type" => "exclusive",
|
|
74
|
+
"source_task" => @last,
|
|
75
|
+
"label" => "Loop condition",
|
|
76
|
+
"branches" => {"Loop condition" => condition}
|
|
77
|
+
}
|
|
78
|
+
if node.sub.length >=2
|
|
79
|
+
node.sub.each do |branch|
|
|
80
|
+
cond = branch.condition.any? ? branch.condition[0] : nil
|
|
81
|
+
if branch.length >= 1
|
|
82
|
+
generate_in_list(branch,res)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
res
|
|
87
|
+
end #}}}
|
|
88
|
+
|
|
89
|
+
def print_Conditional(node,res) #{{{
|
|
90
|
+
gid = "#{node.id}s"
|
|
91
|
+
temp = {
|
|
92
|
+
"type" => node.mode.to_s,
|
|
93
|
+
"source_task" => @last,
|
|
94
|
+
"label" => node.label,
|
|
95
|
+
"branches" => {}
|
|
96
|
+
}
|
|
97
|
+
@last = node.id
|
|
98
|
+
node.sub.each do |branch|
|
|
99
|
+
cond = branch.condition.any? ? branch.condition[0] : nil
|
|
100
|
+
cur_id = @last.next
|
|
101
|
+
@last = cur_id
|
|
102
|
+
temp["branches"][cur_id] = cond
|
|
103
|
+
end
|
|
104
|
+
res["gateway_conditions"][gid] = temp
|
|
105
|
+
res
|
|
106
|
+
end #}}}
|
|
107
|
+
|
|
108
|
+
def print_Inclusive(node,res) #{{{
|
|
109
|
+
print_Conditional(node,res)
|
|
110
|
+
res
|
|
111
|
+
end #}}}
|
|
112
|
+
|
|
113
|
+
def print_Parallel(node,res) #{{{
|
|
114
|
+
res
|
|
115
|
+
end #}}}
|
|
116
|
+
|
|
117
|
+
def print_Break(node,res) #{{{
|
|
118
|
+
res
|
|
119
|
+
end #}}}
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end #}}}
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# This file is part of CPEE-TRANSFORMATION.
|
|
4
|
+
#
|
|
5
|
+
# CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or (at your
|
|
8
|
+
# option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
|
|
11
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
13
|
+
# for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
|
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
require_relative 'structures'
|
|
20
|
+
|
|
21
|
+
module CPEE
|
|
22
|
+
|
|
23
|
+
module Transformation
|
|
24
|
+
|
|
25
|
+
module Source
|
|
26
|
+
|
|
27
|
+
class Graphviz
|
|
28
|
+
attr_reader :tree, :start, :dataelements, :endpoints, :graph, :traces
|
|
29
|
+
|
|
30
|
+
def initialize(text) #{{{
|
|
31
|
+
Node.class_variable_set(:@@niceid, {})
|
|
32
|
+
|
|
33
|
+
@tree = Tree.new
|
|
34
|
+
@start = nil
|
|
35
|
+
|
|
36
|
+
@dataelements = {}
|
|
37
|
+
@endpoints = {}
|
|
38
|
+
@graph = Graph.new
|
|
39
|
+
|
|
40
|
+
extract_nodelink(text)
|
|
41
|
+
|
|
42
|
+
@traces = Traces.new [[@start]]
|
|
43
|
+
end #}}}
|
|
44
|
+
|
|
45
|
+
def map_nodes(shape,label)
|
|
46
|
+
case [shape,label]
|
|
47
|
+
when ['rectangle',nil]; :task
|
|
48
|
+
when ['diamond','AND']; :parallelGateway
|
|
49
|
+
when ['diamond','and']; :parallelGateway
|
|
50
|
+
when ['diamond','X']; :exclusiveGateway
|
|
51
|
+
when ['diamond','x']; :exclusiveGateway
|
|
52
|
+
when ['diamond','*']; :eventBasedGateway
|
|
53
|
+
when ['diamond','o']; :inclusiveGateway
|
|
54
|
+
when ['circle','']; :startEvent
|
|
55
|
+
when ['circle',nil]; :startEvent
|
|
56
|
+
when ['doublecircle','']; :endEvent
|
|
57
|
+
when ['doublecircle',nil]; :endEvent
|
|
58
|
+
else
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
private :map_nodes
|
|
63
|
+
|
|
64
|
+
def extract_nodelink(text) #{{{
|
|
65
|
+
text.each_line do |line|
|
|
66
|
+
if line =~ /^\s*"([^"]+)"\[shape=([a-z]+)(\slabel="([^"]*)")?\]\s*;?/
|
|
67
|
+
id = $1
|
|
68
|
+
type = map_nodes($2,$4)
|
|
69
|
+
label = id
|
|
70
|
+
|
|
71
|
+
label.sub(/^'/,'')
|
|
72
|
+
label.sub(/'$/,'')
|
|
73
|
+
label.sub(/^"/,'')
|
|
74
|
+
label.sub(/"$/,'')
|
|
75
|
+
|
|
76
|
+
n = Node.new(0,id,type,label,0,1)
|
|
77
|
+
@graph.add_node n
|
|
78
|
+
|
|
79
|
+
@start = n if n.type == :startEvent && @start == nil
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
text.each_line do |line|
|
|
83
|
+
if line =~ /^\s*"([^"]+)"\s+->\s+"([^"]+)"(\s*\[(label="([^"]*)")?\])?\s*;?/
|
|
84
|
+
lid = $1
|
|
85
|
+
rid = $2
|
|
86
|
+
cond = $5
|
|
87
|
+
|
|
88
|
+
@graph.add_link Link.new(lid, rid, cond.nil? ? nil : cond)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end #}}}
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
#
|
|
3
|
+
# This file is part of CPEE-TRANSFORMATION.
|
|
4
|
+
#
|
|
5
|
+
# CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or (at your
|
|
8
|
+
# option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
|
|
11
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
13
|
+
# for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
# along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
|
|
17
|
+
# see <http://www.gnu.org/licenses/>.
|
|
18
|
+
|
|
19
|
+
require 'riddl/server'
|
|
20
|
+
require 'json'
|
|
21
|
+
require 'timeout'
|
|
22
|
+
require_relative 'bpmn2'
|
|
23
|
+
require_relative 'mermaid'
|
|
24
|
+
require_relative 'graphviz'
|
|
25
|
+
require_relative 'transformer'
|
|
26
|
+
require_relative 'cpee'
|
|
27
|
+
|
|
28
|
+
module CPEE
|
|
29
|
+
|
|
30
|
+
module Transformation
|
|
31
|
+
|
|
32
|
+
module Service
|
|
33
|
+
|
|
34
|
+
SERVER = File.expand_path(File.join(__dir__,'implementation.xml'))
|
|
35
|
+
|
|
36
|
+
class ExtractDescription < Riddl::Implementation #{{{
|
|
37
|
+
def response
|
|
38
|
+
source = case @h['RIDDL_DECLARATION_PATH'].split('/')[-1]
|
|
39
|
+
when 'cpee'
|
|
40
|
+
CPEE::Transformation::Source::CPEE.new(@p[0].value.read)
|
|
41
|
+
when 'bpmn2'
|
|
42
|
+
CPEE::Transformation::Source::BPMN2.new(@p[0].value.read)
|
|
43
|
+
when 'mermaid'
|
|
44
|
+
CPEE::Transformation::Source::Mermaid.new(@p[0].value.read)
|
|
45
|
+
when 'graphviz'
|
|
46
|
+
CPEE::Transformation::Source::Graphviz.new(@p[0].value.read)
|
|
47
|
+
else
|
|
48
|
+
nil
|
|
49
|
+
end
|
|
50
|
+
mtype, target = case @h['RIDDL_DECLARATION_PATH'].split('/')[-2]
|
|
51
|
+
when 'cpee'
|
|
52
|
+
['text/xml', CPEE::Transformation::Target::CPEE]
|
|
53
|
+
when 'mermaid'
|
|
54
|
+
['text/plain', CPEE::Transformation::Target::Mermaid]
|
|
55
|
+
when 'text-bf'
|
|
56
|
+
['text/plain', CPEE::Transformation::Target::Text_bf]
|
|
57
|
+
when 'text-df-PO-extended'
|
|
58
|
+
['text/plain', CPEE::Transformation::Target::Text_df_PO_extended]
|
|
59
|
+
when 'text-df-PO-reduced'
|
|
60
|
+
['text/plain', CPEE::Transformation::Target::Text_df_PO_reduced]
|
|
61
|
+
else
|
|
62
|
+
[nil,nil]
|
|
63
|
+
end
|
|
64
|
+
if source.nil? || target.nil?
|
|
65
|
+
@status = 500
|
|
66
|
+
else
|
|
67
|
+
trans = nil
|
|
68
|
+
begin
|
|
69
|
+
Timeout.timeout(15) do
|
|
70
|
+
trans = CPEE::Transformation::Transformer.new(source)
|
|
71
|
+
trans.build_traces
|
|
72
|
+
trans.build_tree(false)
|
|
73
|
+
end
|
|
74
|
+
rescue Timeout::Error => err
|
|
75
|
+
puts 'broken model'
|
|
76
|
+
puts err.message
|
|
77
|
+
puts err.backtrace
|
|
78
|
+
ensure
|
|
79
|
+
if trans
|
|
80
|
+
xml = trans.generate_model(target)
|
|
81
|
+
return Riddl::Parameter::Complex.new("description",mtype,xml.to_s)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end #}}}
|
|
87
|
+
|
|
88
|
+
class ExtractDataelements < Riddl::Implementation #{{{
|
|
89
|
+
def response
|
|
90
|
+
ret = []
|
|
91
|
+
|
|
92
|
+
if @h['RIDDL_DECLARATION_PATH'].split('/')[-1] == 'bpmn2'
|
|
93
|
+
bpmn2 = CPEE::Transformation::Source::BPMN2.new(@p[0].value.read)
|
|
94
|
+
bpmn2.dataelements.each do |k,v|
|
|
95
|
+
ret << Riddl::Parameter::Simple.new("name",k)
|
|
96
|
+
ret << Riddl::Parameter::Simple.new("value",v)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
ret
|
|
101
|
+
end
|
|
102
|
+
end #}}}
|
|
103
|
+
|
|
104
|
+
class ExtractEndpoints < Riddl::Implementation #{{{
|
|
105
|
+
def response
|
|
106
|
+
ret = []
|
|
107
|
+
|
|
108
|
+
if @h['RIDDL_DECLARATION_PATH'].split('/')[-1] == 'bpmn2'
|
|
109
|
+
bpmn2 = CPEE::Transformation::Source::BPMN2.new(@p[0].value.read)
|
|
110
|
+
bpmn2.endpoints.each do |k,v|
|
|
111
|
+
ret << Riddl::Parameter::Simple.new("name",k)
|
|
112
|
+
ret << Riddl::Parameter::Simple.new("value",v)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
ret
|
|
117
|
+
end
|
|
118
|
+
end #}}}
|
|
119
|
+
|
|
120
|
+
def self::implementation(opts)
|
|
121
|
+
Proc.new do
|
|
122
|
+
interface 'xml_cpee' do
|
|
123
|
+
run ExtractDescription if post 'xmldedesc'
|
|
124
|
+
run ExtractDataelements if post 'xmldadesc'
|
|
125
|
+
run ExtractEndpoints if post 'xmlendesc'
|
|
126
|
+
end
|
|
127
|
+
interface 'text_cpee' do
|
|
128
|
+
run ExtractDescription if post 'plaindedesc'
|
|
129
|
+
run ExtractDataelements if post 'plaindadesc'
|
|
130
|
+
run ExtractEndpoints if post 'plainendesc'
|
|
131
|
+
end
|
|
132
|
+
interface 'xml_text' do
|
|
133
|
+
run ExtractDescription if post 'xmldedesc'
|
|
134
|
+
run ExtractDataelements if post 'xmldadesc'
|
|
135
|
+
run ExtractEndpoints if post 'xmlendesc'
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
end
|