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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/AUTHORS +2 -0
  3. data/LICENSE +165 -0
  4. data/README.md +1 -0
  5. data/Rakefile +21 -0
  6. data/cpee-transformation.gemspec +29 -0
  7. data/lib/cpee/transformation/beautiful.rb +182 -0
  8. data/lib/cpee/transformation/bpmn2.rb +144 -0
  9. data/lib/cpee/transformation/cpee.rb +309 -0
  10. data/lib/cpee/transformation/dataflow.rb +127 -0
  11. data/lib/cpee/transformation/graphviz.rb +100 -0
  12. data/lib/cpee/transformation/implementation.rb +144 -0
  13. data/lib/cpee/transformation/implementation.xml +47 -0
  14. data/lib/cpee/transformation/mermaid.rb +242 -0
  15. data/lib/cpee/transformation/ptml.rb +316 -0
  16. data/lib/cpee/transformation/structures.rb +570 -0
  17. data/lib/cpee/transformation/target.rb +58 -0
  18. data/lib/cpee/transformation/text-bf.rb +201 -0
  19. data/lib/cpee/transformation/text-df-PO-extended.rb +221 -0
  20. data/lib/cpee/transformation/text-df-PO-reduced.rb +211 -0
  21. data/lib/cpee/transformation/transformation_text_cpee.xml +49 -0
  22. data/lib/cpee/transformation/transformation_xml_cpee.xml +49 -0
  23. data/lib/cpee/transformation/transformation_xml_text.xml +49 -0
  24. data/lib/cpee/transformation/transformer.rb +300 -0
  25. data/server/trans +38 -0
  26. data/tools/bpmn2_to_cpee.rb +84 -0
  27. data/tools/bpmn2_to_mermaid.rb +85 -0
  28. data/tools/bpmn2_to_ptml.rb +87 -0
  29. data/tools/cpee-trans +74 -0
  30. data/tools/cpee_to_cpee.rb +83 -0
  31. data/tools/cpee_to_dataflow.rb +83 -0
  32. data/tools/cpee_to_mermaid.rb +85 -0
  33. data/tools/cpee_to_ptml.rb +87 -0
  34. data/tools/cpee_to_text_bf.rb +85 -0
  35. data/tools/cpee_to_text_df-poe.rb +85 -0
  36. data/tools/cpee_to_text_df-por.rb +85 -0
  37. data/tools/mermaid_to_cpee.rb +85 -0
  38. data/tools/ptml_to_cpee.rb +87 -0
  39. metadata +160 -0
@@ -0,0 +1,47 @@
1
+ <!--
2
+ This file is part of CPEE-TRANSFORMATION.
3
+
4
+ CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or (at your
7
+ option) any later version.
8
+
9
+ CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
10
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12
+ for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with CPEE-TRANSFORMATION (file COPYING in the main directory). If not,
16
+ see <http://www.gnu.org/licenses/>.
17
+ -->
18
+
19
+ <declaration xmlns="http://riddl.org/ns/declaration/1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
20
+ <interface name="xml_cpee">
21
+ <xi:include href="transformation_xml_cpee.xml"/>
22
+ </interface>
23
+ <interface name="text_cpee">
24
+ <xi:include href="transformation_text_cpee.xml"/>
25
+ </interface>
26
+ <interface name="xml_text">
27
+ <xi:include href="transformation_xml_text.xml"/>
28
+ </interface>
29
+
30
+ <facade>
31
+ <tile>
32
+ <layer name="xml_cpee">
33
+ <apply-to>/cpee/bpmn2</apply-to>
34
+ </layer>
35
+ <layer name="text_cpee">
36
+ <apply-to>/cpee/mermaid</apply-to>
37
+ <apply-to>/cpee/graphviz</apply-to>
38
+ </layer>
39
+ <layer name="xml_text">
40
+ <apply-to>/mermaid/cpee</apply-to>
41
+ <apply-to>/text-bf/cpee</apply-to>
42
+ <apply-to>/text-df-PO-extended/cpee</apply-to>
43
+ <apply-to>/text-df-PO-reduced/cpee</apply-to>
44
+ </layer>
45
+ </tile>
46
+ </facade>
47
+ </declaration>
@@ -0,0 +1,242 @@
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
+
21
+ module CPEE
22
+
23
+ module Transformation
24
+
25
+ module Source #{{{
26
+
27
+ class Mermaid
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
+ if @start.nil?
43
+ @traces = Traces.new [[]]
44
+ else
45
+ @traces = Traces.new [[@start]]
46
+ end
47
+ end #}}}
48
+
49
+ def map_nodes(node)
50
+ case node
51
+ when 'task'; :task
52
+ when 'script'; :scriptTask
53
+ when 'parallelgateway'; :parallelGateway
54
+ when 'exclusivegateway'; :exclusiveGateway
55
+ when 'eventbasedgateway'; :eventBasedGateway
56
+ when 'inclusivegateway'; :inclusiveGateway
57
+ when 'endevent'; :endEvent
58
+ when 'startevent'; :startEvent
59
+ else
60
+ nil
61
+ end
62
+ end
63
+ private :map_nodes
64
+
65
+ def extract_nodelink(text) #{{{
66
+ first = nil
67
+ text.each_line do |line|
68
+ if line =~ /-->/
69
+ a = line.strip.split(/-->\s*(\|([^|]+)\|)?/)
70
+ if a.length == 2
71
+ l, r = a
72
+ else
73
+ l, _, c, r = a
74
+ end
75
+
76
+ lid, ltype, llabel = l.strip.split(':',3)
77
+ rid, rtype, rlabel = r.strip.split(':',3)
78
+
79
+ ltype = 'task' if ltype.nil?
80
+ rtype = 'task' if rtype.nil?
81
+
82
+ if lid =~ /^([a-zA-Z\d]+)(\[([^\]]+)\])/
83
+ lid = $1
84
+ llabel = $3
85
+ end
86
+
87
+ if rid =~ /^([a-zA-Z\d]+)(\[([^\]]+)\])/
88
+ rid = $1
89
+ rlabel = $3
90
+ end
91
+
92
+ llabel = '' if llabel.nil?
93
+ rlabel = '' if rlabel.nil?
94
+ llabel.sub(/^'/,'')
95
+ llabel.sub(/'$/,'')
96
+ llabel.sub(/^"/,'')
97
+ llabel.sub(/"$/,'')
98
+ rlabel.sub(/^'/,'')
99
+ rlabel.sub(/'$/,'')
100
+ rlabel.sub(/^"/,'')
101
+ rlabel.sub(/"$/,'')
102
+
103
+ # every line contains a link
104
+ @graph.add_link Link.new(lid, rid, c.nil? ? nil : c.to_s.gsub(/(^"|"$)/, ''))
105
+
106
+ n1 = Node.new(0,lid,map_nodes(ltype),llabel.sub(/^\(/,'').sub(/\)$/,''),0,1)
107
+ n2 = Node.new(0,rid,map_nodes(rtype),rlabel.sub(/^\(/,'').sub(/\)$/,''),1,0)
108
+
109
+ @graph.add_node n1, :outgoing
110
+ @graph.add_node n2, :incoming
111
+
112
+ first = n1 if first.nil?
113
+ @start = n1 if n1.type == :startEvent && @start.nil?
114
+ end
115
+ @start = first if @start.nil?
116
+ end
117
+ end #}}}
118
+
119
+ end
120
+
121
+ end #}}}
122
+
123
+ module Target #{{{
124
+
125
+ class Mermaid < Default
126
+
127
+ def generate
128
+ @nids = []
129
+ @labels = {}
130
+ @fromto = []
131
+ @labels['se'] = "se:startevent:((startevent))"
132
+ @labels['ee'] = "ee:endevent:((endevent))"
133
+ pn = generate_in_list(@tree,'se')
134
+ set_fromto pn, 'ee'
135
+ "flowchart LR\n" + @fromto.map{ |e| "#{@labels[e[0]]}-->#{e.length == 3 ? e[2] : ''}#{@labels[e[1]]}"}.join("\n")
136
+ end
137
+
138
+ def id_find(nid)
139
+ nid = 'g0' unless nid
140
+ while @nids.include?(nid)
141
+ nid.next!
142
+ end
143
+ @nids << nid
144
+ nid
145
+ end
146
+
147
+ private
148
+
149
+ def set_fromto(pn,nid)
150
+ if pn.is_a?(Array) && pn.length > 1
151
+ @fromto << [pn[0],nid,pn[1]]
152
+ else
153
+ @fromto << [pn,nid]
154
+ end
155
+ end
156
+
157
+ def print_Node(node,pn)
158
+ nid = node.id
159
+ if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
160
+ @labels[nid] = "#{nid}:script:(#{node.label.gsub(/\(/,"\\(").gsub(/\)/,"\\)")})"
161
+ else
162
+ @labels[nid] = "#{nid}:task:(#{node.label.gsub(/\(/,"\\(").gsub(/\)/,"\\)")})"
163
+ end
164
+ set_fromto pn, nid
165
+ nid
166
+ end
167
+
168
+ def print_Break(node,pn)
169
+ nid = node.id
170
+ @labels[nid] = "#{nid}:escalate:((^))"
171
+ set_fromto pn, nid
172
+ nid
173
+ end
174
+
175
+ def print_Parallel(node,pn)
176
+ nid = id_find(node.id)
177
+ set_fromto pn, "#{nid}s"
178
+ @labels["#{nid}s"] = "#{nid}s:parallelgateway:{AND}"
179
+ @labels["#{nid}e"] = "#{nid}e:parallelgateway:{AND}"
180
+ node.sub.each do |branch|
181
+ pn = generate_in_list(branch,"#{nid}s")
182
+ set_fromto pn, "#{nid}e"
183
+ end
184
+ "#{nid}e"
185
+ end
186
+
187
+ def print_Conditional(node,pn)
188
+ nid = id_find(node.id)
189
+ set_fromto pn, "#{nid}s"
190
+ @labels["#{nid}s"] = "#{nid}s:exclusivegateway:{x}"
191
+ @labels["#{nid}e"] = "#{nid}e:exclusivegateway:{x}"
192
+ node.sub.each do |branch|
193
+ pn = if branch.condition.any?
194
+ generate_in_list(branch,["#{nid}s","|\"#{branch.condition.join(' or ')}\"|"])
195
+ else
196
+ if branch.otherwise
197
+ generate_in_list(branch,["#{nid}s","|\"|\"|"])
198
+ else
199
+ generate_in_list(branch,"#{nid}s")
200
+ end
201
+ end
202
+ set_fromto pn, "#{nid}e"
203
+ end
204
+ "#{nid}e"
205
+ end
206
+
207
+ def print_Loop(node,pn)
208
+ nid = id_find(node.id)
209
+ set_fromto pn, "#{nid}s"
210
+
211
+ @labels["#{nid}s"] = "#{nid}s:exclusivegateway:{x}"
212
+ @labels["#{nid}e"] = "#{nid}e:exclusivegateway:{x}"
213
+
214
+ cn = if node.mode == :pre_test
215
+ set_fromto "#{nid}s", "#{nid}e"
216
+ [ ["#{nid}e", "|\"#{node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && ')}\"|"], "#{nid}s"]
217
+ else
218
+ set_fromto ["#{nid}e","|\"#{node.sub[0].condition.empty? ? 'true' : node.sub[0].condition.join(' && ')}\"|"], "#{nid}s"
219
+ ["#{nid}s", "#{nid}e"]
220
+ end
221
+
222
+ pn = 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)
223
+ generate_in_list(node.sub[0],cn[0])
224
+ else
225
+ if node.sub.length == 1
226
+ generate_in_list(node.sub[0],cn[0])
227
+ else
228
+ print_Conditional(node,cn[0])
229
+ end
230
+ end
231
+ set_fromto pn, cn[1]
232
+
233
+ "#{nid}e"
234
+ end
235
+
236
+ end
237
+
238
+ end #}}}
239
+
240
+ end
241
+
242
+ end
@@ -0,0 +1,316 @@
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 PTML
29
+ attr_reader :tree, :start, :dataelements, :endpoints, :graph, :traces
30
+
31
+ def initialize(xml) #{{{
32
+ Node.class_variable_set(:@@niceid, {})
33
+
34
+ @tree = Tree.new
35
+ @start = nil
36
+
37
+ doc = XML::Smart.string(xml)
38
+
39
+ @graph = Graph.new
40
+ extract_nodelink(doc)
41
+
42
+ if @start.nil?
43
+ @traces = Traces.new [[]]
44
+ else
45
+ @traces = Traces.new [[@start]]
46
+ end
47
+ end #}}}
48
+
49
+ def map_nodes(node) #{{{
50
+ case node
51
+ when :sequence; :sequence
52
+ when :manualTask; :task
53
+ when :automaticTask; :task
54
+ when :and; :parallelGateway
55
+ when :xor; :exclusiveGateway
56
+ when :xorLoop; :exclusiveGateway
57
+ #when :eventbasedgateway; :eventBasedGateway
58
+ when :or; :inclusiveGateway
59
+ #when 'endevent'; :endEvent
60
+ #when 'startevent'; :startEvent
61
+ else
62
+ nil
63
+ end
64
+ end
65
+ private :map_nodes #}}}
66
+
67
+ def iterate_ptml(sid,doc) #{{{
68
+ # get node and get type
69
+ se = doc.find("//processTree/*[@id='#{sid}']").first
70
+ stype = map_nodes(se.qname.name.to_sym)
71
+ print '============current', ' ', sid, ' ', @last,' ', stype, ';'
72
+ pp ' '
73
+ if stype == :sequence
74
+ #get al outgoing elements
75
+ outgoings = doc.find("//parentsNode[@sourceId='#{sid}']")
76
+ outgoings.each_with_index do |e, i|
77
+ iterate_ptml(e.attributes['targetId'],doc)
78
+ end
79
+ elsif stype == :exclusiveGateway || stype == :parallelGateway || stype == :inclusiveGateway
80
+ outgoings = doc.find("//parentsNode[@sourceId='#{sid}']")
81
+ if @graph.nodes.length == 0 #if first element
82
+ n = Node.new(self.object_id,sid,stype,"",1,outgoings.length)
83
+ @start = n
84
+ else
85
+ n = Node.new(self.object_id,sid,stype,"",0,outgoings.length)
86
+ @graph.add_link Link.new(@last, sid, nil)
87
+ end
88
+ @graph.add_node n
89
+ print '***********test ', @last, " ", sid
90
+ pp ' '
91
+ @last = sid
92
+ final = []
93
+ outgoings.each_with_index do |e, i|
94
+ iterate_ptml(e.attributes['targetId'],doc)
95
+ final << @last
96
+ @last = sid
97
+ end
98
+ pp final
99
+ rid = rand.to_s[2..11]
100
+ n = Node.new(self.object_id,rid,stype,"",outgoings.length,1)
101
+ @graph.add_node n
102
+ final.each do |f|
103
+ @graph.add_link Link.new(f, rid, nil)
104
+ end
105
+ @last = rid
106
+ elsif stype == :task
107
+ pp se.attributes['name']
108
+ # write node
109
+ if @graph.nodes.length == 0 #if first element
110
+ n = Node.new(self.object_id,sid,stype,se.attributes['name'],0,1)
111
+ @start = n
112
+ else #other elements
113
+ n = Node.new(self.object_id,sid,stype,se.attributes['name'],1,1)
114
+ @graph.add_link Link.new(@last, sid, nil)
115
+ end
116
+ @graph.add_node n
117
+ @last = sid
118
+ end
119
+ #@last = sid
120
+ end
121
+ private :iterate_ptml
122
+ #}}}
123
+
124
+ def extract_nodelink(doc) #{{{
125
+ #extract nodes
126
+ sid = doc.find("//processTree/@root").first.value
127
+ @last = 0
128
+ iterate_ptml(sid,doc)
129
+ pp @last
130
+ pp @graph
131
+ end #}}}
132
+
133
+ end
134
+
135
+ end #}}}
136
+
137
+ module Target #{{{
138
+
139
+ class PTML < Default
140
+
141
+ def generate
142
+ start_id = "rootid"
143
+ @last = start_id
144
+ res = XML::Smart.string("<ptml><processTree id='tree01' name='ptml-tree' root='#{start_id}'/></ptml>")
145
+ pp "start"
146
+ generate_in_list(@tree,res.root.children[0])
147
+ res.to_s
148
+ end
149
+
150
+ private
151
+
152
+ def set_edges(source,target,res)
153
+ rid = rand.to_s[2..11]
154
+ res.add('parentsNode','id'=> rid, 'sourceId' => source, 'targetId' => target)
155
+ res
156
+ end
157
+
158
+ def set_edges_condition(source,target,res,cond,default)
159
+ rid = rand.to_s[2..11]
160
+ if default
161
+ res.add('parentsNode','id'=> rid, 'sourceId' => source, 'targetId' => target, 'default' => default)
162
+ else
163
+ res.add('parentsNode','id'=> rid, 'sourceId' => source, 'targetId' => target, 'condition' => cond)
164
+ end
165
+ res
166
+ end
167
+
168
+
169
+ def print_Break(node,res)
170
+ rid = rand.to_s[2..11]
171
+ n = res.add('manualTask','id' => rid, 'name' => node.label)
172
+ set_edges(@last,rid,res)
173
+ res
174
+ end
175
+
176
+ def print_Loop(node,res)
177
+ if node.mode == :pre_test
178
+ original_last = @last
179
+ nid = "a#{node.id}"
180
+ res.add('xorLoop','id' => nid, 'name' => nil)
181
+ set_edges(@last,nid,res)
182
+ @last = nid
183
+ if node.sub.length == 2
184
+ node.sub.reverse.each do |branch|
185
+ cond = branch.condition.any? ? branch.condition[0] : nil
186
+ if branch[0].type == :break
187
+ rid = rand.to_s[2..11]
188
+ res.add('automaticTask', 'id' => rid, 'name' => 'tau')
189
+ set_edges(@last,rid,res)
190
+ elsif branch.length == 1
191
+ generate_in_list(branch,res)
192
+ res.find("//parentsNode[@sourceId='#{@last}']").last.attributes['condition'] = cond
193
+ elsif branch.length >1
194
+ branch_last = @last
195
+ rid = rand.to_s[2..11]
196
+ res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
197
+ set_edges_condition(@last,nid,res,cond,false)
198
+ @last = rid
199
+ generate_in_list(branch,res)
200
+ @last = branch_last
201
+ end
202
+ end
203
+ elsif node.sub.length > 2
204
+ node.sub.reverse.each do |branch|
205
+ if branch[0].type == :break
206
+ rid = rand.to_s[2..11]
207
+ res.add('automaticTask', 'id' => rid, 'name' => 'tau')
208
+ set_edges(@last,rid,res)
209
+ #Add new xor
210
+ xor_id = rand.to_s[2..11]
211
+ res.add('xor', 'id' => xor_id, 'name' => 'help-xor')
212
+ set_edges(@last,xor_id,res)
213
+ escape_id = rand.to_s[2..11]
214
+ res.add('manualTask', 'id' => escape_id, 'name' => 'escape')
215
+ set_edges(xor_id,escape_id,res)
216
+ @last = xor_id
217
+ else
218
+ if branch.length == 1
219
+ generate_in_list(branch,res)
220
+ elsif branch.length >1
221
+ branch_last = @last
222
+ rid = rand.to_s[2..11]
223
+ res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
224
+ set_edges(@last,rid,res)
225
+ @last = rid
226
+ generate_in_list(branch,res)
227
+ @last = branch_last
228
+ end
229
+ end
230
+ end
231
+ end
232
+ end
233
+ @last = original_last
234
+ res
235
+ end
236
+
237
+ def print_Node(node,res) #{{{
238
+ #if the first element in the process models is task
239
+ if res.children.length == 0
240
+ res.add('sequence', 'id' => @last, 'name' => 'main-sequence')
241
+ end
242
+ nid = "a#{node.niceid}"
243
+ if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
244
+ n = res.add('automaticTask','id' => nid, 'name' => node.label)
245
+ else
246
+ n = res.add('manualTask', 'id' => nid, 'name' => node.label)
247
+ end
248
+ set_edges(@last,nid,res)
249
+ res
250
+ end #}}}
251
+
252
+ def print_Parallel(node,res) #{{{
253
+ print_Conditional(node,res)
254
+ res
255
+ end #}}}
256
+
257
+ def print_Inclusive(node,res) #{{{
258
+ print_Conditional(node,res)
259
+ res
260
+ end #}}}
261
+
262
+ def print_Conditional(node,res) #{{{
263
+ original_last = @last
264
+ nid = "a#{node.id}"
265
+
266
+ if node.type == :exclusiveGateway
267
+ res.add('xor','id' => nid, 'name' => nil)
268
+ elsif node.type == :parallelGateway
269
+ res.add('and','id' => nid, 'name' => nil)
270
+ elsif node.type == :inclusiveGateway
271
+ res.add('or','id' => nid, 'name' => nil)
272
+ end
273
+
274
+ #if first element in model
275
+ if res.children.length == 1
276
+ res.attributes['root'] = nid
277
+ else
278
+ set_edges(@last,nid,res)
279
+ end
280
+ @last = nid
281
+ node.sub.each do |branch|
282
+ #get conditions and default
283
+ cond = branch.condition.any? ? branch.condition[0] : nil
284
+ default = branch.otherwise ? true : nil
285
+ if branch.length == 0
286
+ rid = rand.to_s[2..11]
287
+ res.add('automaticTask', 'id' => rid, 'name' => 'tau')
288
+ set_edges_condition(@last,rid,res,cond,default)
289
+ elsif branch.length == 1
290
+ generate_in_list(branch,res)
291
+ if default
292
+ res.find("//parentsNode[@sourceId='#{@last}']").last.attributes['default'] = default
293
+ else
294
+ res.find("//parentsNode[@sourceId='#{@last}']").last.attributes['condition'] = cond
295
+ end
296
+ elsif branch.length >1
297
+ branch_last = @last
298
+ rid = rand.to_s[2..11]
299
+ res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
300
+ set_edges_condition(@last,rid,res,cond,default)
301
+ @last = rid
302
+ generate_in_list(branch,res)
303
+ @last = branch_last
304
+ end
305
+ end
306
+ @last = original_last
307
+ res
308
+ end #}}}
309
+
310
+ end
311
+
312
+ end #}}}
313
+
314
+ end
315
+
316
+ end