cpee-transformation 1.0.3 → 1.0.6
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 +4 -4
- data/README.md +68 -1
- data/cpee-transformation.gemspec +10 -2
- data/lib/cpee/transformation/bpmn2.rb +30 -0
- data/lib/cpee/transformation/cpee.rb +43 -1
- data/lib/cpee/transformation/implementation.rb +4 -0
- data/lib/cpee/transformation/implementation.xml +3 -0
- data/lib/cpee/transformation/ptml.rb +71 -68
- data/lib/cpee/transformation/structures.rb +41 -6
- data/lib/cpee/transformation/target.rb +12 -0
- data/server/trans.conf +1 -0
- data/server/trans.pid +1 -0
- data/tools/bpmn2_to_ptml.rb +1 -3
- data/tools/cpee_to_bpmn2.rb +92 -0
- data/tools/cpee_to_ptml.rb +1 -3
- metadata +11 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e864c92b6f08671c7597c20f38324a63aabfaf8c4fb4a0faf13bf0673ffede3a
|
|
4
|
+
data.tar.gz: ff4e121e613c2cfa9989febfe4ef347d48771349769f57d3f473d83893b7d444
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 005ccfff1028e4f76549c4fb02e8c45a99aab234ab29e6c314066e772d12e798eaf8b67c5598c1d447ae31fd00a8894afa5ed6a30e4bc9a78818ed31a65a18c0
|
|
7
|
+
data.tar.gz: 343c9853cbb58c160fe6883f5f94e96cf6484010139aef4309e310d506728ec5d3bb7600767919b10c622a8ca9e6e84d9eedd43153c4069bb35b93d26604af1f
|
data/README.md
CHANGED
|
@@ -1 +1,68 @@
|
|
|
1
|
-
# cpee-transformation
|
|
1
|
+
# cpee-transformation
|
|
2
|
+
|
|
3
|
+
## Dependencies
|
|
4
|
+
|
|
5
|
+
The Ruby dependencies (riddl, xml-smart, ...) are installed with the gem. The
|
|
6
|
+
BPMN2 target additionally needs
|
|
7
|
+
[cpee-layout](https://github.com/etm/cpee-layout) (Node.js >= 22.22), which is
|
|
8
|
+
not a gem dependency. By default it is run through `npx`, which fetches it on
|
|
9
|
+
first use (so the first BPMN2 request needs network access and is slow). To
|
|
10
|
+
avoid that, install it and point `trans.conf` to it (see BPMN2 target):
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install -g cpee-layout
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Without Node.js, everything except the `/bpmn2/...` routes works.
|
|
17
|
+
|
|
18
|
+
## Service
|
|
19
|
+
|
|
20
|
+
`cpee-trans new DIR` scaffolds the service into `DIR`: the server `trans` and
|
|
21
|
+
its config `trans.conf`, which is read from the same directory.
|
|
22
|
+
|
|
23
|
+
`trans` (port 9295) transforms process models. Routes are
|
|
24
|
+
`/TARGET/SOURCE`, POSTed with the model as `description` and `type` set to
|
|
25
|
+
`description` (the transformed model), `dataelements` or `endpoints` (lists of
|
|
26
|
+
name/value pairs, from BPMN2 sources only).
|
|
27
|
+
|
|
28
|
+
| Route | Source | Target |
|
|
29
|
+
| --------------------------- | -------- | -------------------------- |
|
|
30
|
+
| `/cpee/bpmn2` | BPMN2 | CPEE |
|
|
31
|
+
| `/cpee/mermaid` | mermaid | CPEE |
|
|
32
|
+
| `/cpee/graphviz` | graphviz | CPEE |
|
|
33
|
+
| `/bpmn2/cpee` | CPEE | BPMN2 |
|
|
34
|
+
| `/bpmn2/mermaid` | mermaid | BPMN2 |
|
|
35
|
+
| `/bpmn2/graphviz` | graphviz | BPMN2 |
|
|
36
|
+
| `/mermaid/cpee` | CPEE | mermaid |
|
|
37
|
+
| `/text-bf/cpee` | CPEE | text, text-bf |
|
|
38
|
+
| `/text-df-PO-extended/cpee` | CPEE | text, text-df-PO-extended |
|
|
39
|
+
| `/text-df-PO-reduced/cpee` | CPEE | text, text-df-PO-reduced |
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
curl -F 'description=@model.xml;type=text/xml' -F 'type=description' http://localhost:9295/bpmn2/cpee
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### BPMN2 target
|
|
46
|
+
|
|
47
|
+
The BPMN2 target generates the CPEE model and lays it out with `bpmnexport`
|
|
48
|
+
from [cpee-layout](https://github.com/etm/cpee-layout), so the result is BPMN
|
|
49
|
+
with diagram interchange, laid out as drawn by cpee-layout. How `bpmnexport` is
|
|
50
|
+
run is set in `trans.conf`. The default (also without a setting) is
|
|
51
|
+
|
|
52
|
+
```yaml
|
|
53
|
+
:bpmnexport: npx -y -p cpee-layout@^1.2.0 bpmnexport
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
and after `npm install -g cpee-layout` it can be
|
|
57
|
+
|
|
58
|
+
```yaml
|
|
59
|
+
:bpmnexport: bpmnexport
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
A command name is searched in `PATH`, a path (containing `/`) is relative to
|
|
63
|
+
the directory of `trans`, `~` works too, e.g.
|
|
64
|
+
`~/Projects/cpee-layout/bin/bpmnexport` for a checkout. Arguments may follow, e.g. `bpmnexport -lr` for a left to
|
|
65
|
+
right layout.
|
|
66
|
+
|
|
67
|
+
`tools/cpee_to_bpmn2.rb FNAME` does the same on the command line, using the
|
|
68
|
+
`server/trans.conf` of the gem. If `bpmnexport` can't be run or fails, the request returns 500.
|
data/cpee-transformation.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "cpee-transformation"
|
|
3
|
-
s.version = "1.0.
|
|
3
|
+
s.version = "1.0.6"
|
|
4
4
|
s.platform = Gem::Platform::RUBY
|
|
5
5
|
s.license = "LGPL-3.0-or-later"
|
|
6
6
|
s.summary = "CPEE Transformation between different formats"
|
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
s.require_path = 'lib'
|
|
12
12
|
s.extra_rdoc_files = ['README.md']
|
|
13
13
|
s.bindir = 'tools'
|
|
14
|
-
s.executables = ['bpmn2_to_cpee.rb', 'bpmn2_to_mermaid.rb', 'bpmn2_to_ptml.rb', 'cpee_to_cpee.rb', 'cpee_to_mermaid.rb', 'cpee_to_ptml.rb', 'cpee_to_text_bf.rb', 'cpee_to_text_df-poe.rb', 'cpee_to_text_df-por.rb', 'cpee-trans', 'mermaid_to_cpee.rb', 'ptml_to_cpee.rb']
|
|
14
|
+
s.executables = ['bpmn2_to_cpee.rb', 'bpmn2_to_mermaid.rb', 'bpmn2_to_ptml.rb', 'cpee_to_bpmn2.rb', 'cpee_to_cpee.rb', 'cpee_to_mermaid.rb', 'cpee_to_ptml.rb', 'cpee_to_text_bf.rb', 'cpee_to_text_df-poe.rb', 'cpee_to_text_df-por.rb', 'cpee-trans', 'mermaid_to_cpee.rb', 'ptml_to_cpee.rb']
|
|
15
15
|
|
|
16
16
|
s.required_ruby_version = '>=3.2'
|
|
17
17
|
|
|
@@ -25,5 +25,13 @@ Gem::Specification.new do |s|
|
|
|
25
25
|
s.add_runtime_dependency 'xml-smart', '~> 0.4'
|
|
26
26
|
s.add_runtime_dependency 'typhoeus', '~> 1.4'
|
|
27
27
|
s.add_runtime_dependency 'highline', '~> 2.0'
|
|
28
|
+
|
|
29
|
+
s.post_install_message = <<~MSG
|
|
30
|
+
The BPMN2 target uses bpmnexport from cpee-layout (Node.js >= 22.22). By
|
|
31
|
+
default npx fetches it on first use. To avoid that, run
|
|
32
|
+
npm install -g cpee-layout
|
|
33
|
+
and set ":bpmnexport: bpmnexport" in trans.conf of your service
|
|
34
|
+
(scaffolded with cpee-trans new DIR).
|
|
35
|
+
MSG
|
|
28
36
|
end
|
|
29
37
|
|
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
# see <http://www.gnu.org/licenses/>.
|
|
18
18
|
|
|
19
19
|
require_relative 'structures'
|
|
20
|
+
require_relative 'target'
|
|
21
|
+
require_relative 'cpee'
|
|
20
22
|
require 'xml/smart'
|
|
23
|
+
require 'open3'
|
|
24
|
+
require 'shellwords'
|
|
21
25
|
|
|
22
26
|
module CPEE
|
|
23
27
|
|
|
@@ -142,6 +146,32 @@ module CPEE
|
|
|
142
146
|
|
|
143
147
|
end
|
|
144
148
|
|
|
149
|
+
module Target #{{{
|
|
150
|
+
|
|
151
|
+
# bpmnexport from cpee-layout (npm install -g cpee-layout) lays out the
|
|
152
|
+
# generated CPEE model as drawn and writes it as BPMN with diagram
|
|
153
|
+
# interchange. opts[:bpmnexport] (trans.conf) is a command name, searched
|
|
154
|
+
# in PATH, or a path, relative to the server dir, optionally followed by
|
|
155
|
+
# arguments (e.g. -lr). By default npx fetches cpee-layout on first use.
|
|
156
|
+
class BPMN2 < Default
|
|
157
|
+
BPMNEXPORT = 'npx -y -p cpee-layout@^1.2.0 bpmnexport'
|
|
158
|
+
|
|
159
|
+
class << self
|
|
160
|
+
attr_accessor :opts
|
|
161
|
+
end
|
|
162
|
+
@opts = {}
|
|
163
|
+
|
|
164
|
+
def generate
|
|
165
|
+
opts = self.class.opts
|
|
166
|
+
cmd, *args = Shellwords.split(opts[:bpmnexport] || BPMNEXPORT)
|
|
167
|
+
cmd = File.expand_path(cmd, opts[:basepath] || Dir.pwd) if cmd.include?('/')
|
|
168
|
+
out, err, st = Open3.capture3(cmd, *args, '-', stdin_data: Target::CPEE.new(@tree).generate)
|
|
169
|
+
raise "#{cmd}: #{err}" unless st.success?
|
|
170
|
+
out
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end #}}}
|
|
145
175
|
|
|
146
176
|
end
|
|
147
177
|
|
|
@@ -119,6 +119,12 @@ module CPEE
|
|
|
119
119
|
n1 = no
|
|
120
120
|
when 'parallel'
|
|
121
121
|
bra = ele.find('d:parallel_branch')
|
|
122
|
+
if bra.empty? && ele.find('d:*').length == 1
|
|
123
|
+
### e.g. branches created in a loop: content is a sequence
|
|
124
|
+
n1 = dive_single(SingleParallel, ele, n1, condition, otherwise)
|
|
125
|
+
condition = nil
|
|
126
|
+
next
|
|
127
|
+
end
|
|
122
128
|
nid = id_find(ele.attributes['eid'])
|
|
123
129
|
ns = Node.new(self.object_id,nid,:parallelGateway,nil,1,bra.length)
|
|
124
130
|
ns.attributes[:wait] = ele.attributes['wait'] || -1
|
|
@@ -151,6 +157,10 @@ module CPEE
|
|
|
151
157
|
end
|
|
152
158
|
end
|
|
153
159
|
n1 = ne
|
|
160
|
+
when 'parallel_branch'
|
|
161
|
+
### only reached when not a direct child of a parallel
|
|
162
|
+
n1 = dive_single(SingleParallelBranch, ele, n1, condition, otherwise)
|
|
163
|
+
condition = nil
|
|
154
164
|
when 'escape'
|
|
155
165
|
nid = id_find(ele.attributes['eid'])
|
|
156
166
|
no = Node.new(self.object_id,nid,:break,'',1,1)
|
|
@@ -171,10 +181,27 @@ module CPEE
|
|
|
171
181
|
end
|
|
172
182
|
private :dive
|
|
173
183
|
|
|
184
|
+
### open marker, content as a sequence, close marker
|
|
185
|
+
def dive_single(klass,ele,n1,condition,otherwise)
|
|
186
|
+
attrs = {}
|
|
187
|
+
ele.attributes.each { |a| attrs[a.qname.name] = a.value unless a.qname.name == 'eid' }
|
|
188
|
+
nid = id_find(ele.attributes['eid'])
|
|
189
|
+
ns = klass.new(self.object_id,nid,true,attrs)
|
|
190
|
+
@graph.add_node ns
|
|
191
|
+
@graph.add_link Link.new(n1.id, ns.id, condition, otherwise)
|
|
192
|
+
bn = dive ele, ns
|
|
193
|
+
ne = klass.new(self.object_id,nid + 'e',false)
|
|
194
|
+
@graph.add_node ne
|
|
195
|
+
@graph.add_link Link.new(bn.id, ne.id)
|
|
196
|
+
ne
|
|
197
|
+
end
|
|
198
|
+
private :dive_single
|
|
199
|
+
|
|
174
200
|
def extract_original(text)
|
|
175
201
|
doc = XML::Smart::string(text)
|
|
176
202
|
doc.register_namespace :d, 'http://cpee.org/ns/description/1.0'
|
|
177
|
-
|
|
203
|
+
# a model (root description) or a testset, which contains it
|
|
204
|
+
bn = dive(doc.find('//d:description').first || doc.root)
|
|
178
205
|
ne = Node.new(self.object_id,Digest::MD5.hexdigest(Kernel::rand().to_s),:endEvent,'',1,0)
|
|
179
206
|
@graph.add_node ne
|
|
180
207
|
@graph.add_link Link.new(bn.id, ne.id)
|
|
@@ -199,6 +226,21 @@ module CPEE
|
|
|
199
226
|
end
|
|
200
227
|
|
|
201
228
|
private
|
|
229
|
+
### open: everything up to the close marker goes inside
|
|
230
|
+
def print_single(name,node,res)
|
|
231
|
+
if node.open?
|
|
232
|
+
res.add(name, node.attributes.merge('a:alt_id' => node.id, 'eid' => "e#{(@eid += 1)}"))
|
|
233
|
+
else
|
|
234
|
+
res.parent
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
def print_SingleParallel(node,res)
|
|
238
|
+
print_single('parallel',node,res)
|
|
239
|
+
end
|
|
240
|
+
def print_SingleParallelBranch(node,res)
|
|
241
|
+
print_single('parallel_branch',node,res)
|
|
242
|
+
end
|
|
243
|
+
|
|
202
244
|
def print_Break(node,res)
|
|
203
245
|
res.add('escape', 'a:alt_id' => node.id)
|
|
204
246
|
res
|
|
@@ -50,6 +50,8 @@ module CPEE
|
|
|
50
50
|
mtype, target = case @h['RIDDL_DECLARATION_PATH'].split('/')[-2]
|
|
51
51
|
when 'cpee'
|
|
52
52
|
['text/xml', CPEE::Transformation::Target::CPEE]
|
|
53
|
+
when 'bpmn2'
|
|
54
|
+
['text/xml', CPEE::Transformation::Target::BPMN2]
|
|
53
55
|
when 'mermaid'
|
|
54
56
|
['text/plain', CPEE::Transformation::Target::Mermaid]
|
|
55
57
|
when 'text-bf'
|
|
@@ -118,6 +120,8 @@ module CPEE
|
|
|
118
120
|
end #}}}
|
|
119
121
|
|
|
120
122
|
def self::implementation(opts)
|
|
123
|
+
# the hash itself, as --config is merged into it only afterwards
|
|
124
|
+
CPEE::Transformation::Target::BPMN2.opts = opts
|
|
121
125
|
Proc.new do
|
|
122
126
|
interface 'xml_cpee' do
|
|
123
127
|
run ExtractDescription if post 'xmldedesc'
|
|
@@ -31,10 +31,13 @@
|
|
|
31
31
|
<tile>
|
|
32
32
|
<layer name="xml_cpee">
|
|
33
33
|
<apply-to>/cpee/bpmn2</apply-to>
|
|
34
|
+
<apply-to>/bpmn2/cpee</apply-to>
|
|
34
35
|
</layer>
|
|
35
36
|
<layer name="text_cpee">
|
|
36
37
|
<apply-to>/cpee/mermaid</apply-to>
|
|
37
38
|
<apply-to>/cpee/graphviz</apply-to>
|
|
39
|
+
<apply-to>/bpmn2/mermaid</apply-to>
|
|
40
|
+
<apply-to>/bpmn2/graphviz</apply-to>
|
|
38
41
|
</layer>
|
|
39
42
|
<layer name="xml_text">
|
|
40
43
|
<apply-to>/mermaid/cpee</apply-to>
|
|
@@ -141,14 +141,21 @@ module CPEE
|
|
|
141
141
|
def generate
|
|
142
142
|
start_id = "rootid"
|
|
143
143
|
@last = start_id
|
|
144
|
+
@ids = Hash.new(0)
|
|
144
145
|
res = XML::Smart.string("<ptml><processTree id='tree01' name='ptml-tree' root='#{start_id}'/></ptml>")
|
|
145
|
-
|
|
146
|
+
res.root.children[0].add('sequence', 'id' => start_id, 'name' => 'main-sequence')
|
|
146
147
|
generate_in_list(@tree,res.root.children[0])
|
|
147
148
|
res.to_s
|
|
148
149
|
end
|
|
149
150
|
|
|
150
151
|
private
|
|
151
152
|
|
|
153
|
+
### nodes can occur more than once in the tree (e.g. unrolled loops)
|
|
154
|
+
def uid(id)
|
|
155
|
+
n = (@ids[id] += 1)
|
|
156
|
+
n == 1 ? id : "#{id}_#{n}"
|
|
157
|
+
end
|
|
158
|
+
|
|
152
159
|
def set_edges(source,target,res)
|
|
153
160
|
rid = rand.to_s[2..11]
|
|
154
161
|
res.add('parentsNode','id'=> rid, 'sourceId' => source, 'targetId' => target)
|
|
@@ -181,60 +188,61 @@ module CPEE
|
|
|
181
188
|
end
|
|
182
189
|
|
|
183
190
|
def print_Loop(node,res)
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
191
|
+
### post_test loops are written like pre_test loops
|
|
192
|
+
original_last = @last
|
|
193
|
+
nid = uid("a#{node.id}")
|
|
194
|
+
res.add('xorLoop','id' => nid, 'name' => nil)
|
|
195
|
+
set_edges(@last,nid,res)
|
|
196
|
+
@last = nid
|
|
197
|
+
if node.sub.length == 2
|
|
198
|
+
node.sub.reverse.each do |branch|
|
|
199
|
+
cond = branch.condition.any? ? branch.condition[0] : nil
|
|
200
|
+
items = visible(branch)
|
|
201
|
+
if items[0]&.type == :break
|
|
202
|
+
rid = rand.to_s[2..11]
|
|
203
|
+
res.add('automaticTask', 'id' => rid, 'name' => 'tau')
|
|
204
|
+
set_edges(@last,rid,res)
|
|
205
|
+
elsif items.length == 1
|
|
206
|
+
generate_in_list(branch,res)
|
|
207
|
+
res.find("//parentsNode[@sourceId='#{@last}']").last.attributes['condition'] = cond
|
|
208
|
+
elsif items.length >1
|
|
209
|
+
branch_last = @last
|
|
210
|
+
rid = rand.to_s[2..11]
|
|
211
|
+
res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
|
|
212
|
+
set_edges_condition(@last,rid,res,cond,false)
|
|
213
|
+
@last = rid
|
|
214
|
+
generate_in_list(branch,res)
|
|
215
|
+
@last = branch_last
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
elsif node.sub.length > 2
|
|
219
|
+
node.sub.reverse.each do |branch|
|
|
220
|
+
items = visible(branch)
|
|
221
|
+
if items[0]&.type == :break
|
|
222
|
+
rid = rand.to_s[2..11]
|
|
223
|
+
res.add('automaticTask', 'id' => rid, 'name' => 'tau')
|
|
224
|
+
set_edges(@last,rid,res)
|
|
225
|
+
#Add new xor
|
|
226
|
+
xor_id = rand.to_s[2..11]
|
|
227
|
+
res.add('xor', 'id' => xor_id, 'name' => 'help-xor')
|
|
228
|
+
set_edges(@last,xor_id,res)
|
|
229
|
+
escape_id = rand.to_s[2..11]
|
|
230
|
+
res.add('manualTask', 'id' => escape_id, 'name' => 'escape')
|
|
231
|
+
set_edges(xor_id,escape_id,res)
|
|
232
|
+
@last = xor_id
|
|
233
|
+
else
|
|
234
|
+
if items.length == 1
|
|
198
235
|
generate_in_list(branch,res)
|
|
199
|
-
|
|
200
|
-
elsif branch.length >1
|
|
236
|
+
elsif items.length >1
|
|
201
237
|
branch_last = @last
|
|
202
238
|
rid = rand.to_s[2..11]
|
|
203
239
|
res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
|
|
204
|
-
|
|
240
|
+
set_edges(@last,rid,res)
|
|
205
241
|
@last = rid
|
|
206
242
|
generate_in_list(branch,res)
|
|
207
243
|
@last = branch_last
|
|
208
244
|
end
|
|
209
245
|
end
|
|
210
|
-
elsif node.sub.length > 2
|
|
211
|
-
node.sub.reverse.each do |branch|
|
|
212
|
-
if branch[0].type == :break
|
|
213
|
-
rid = rand.to_s[2..11]
|
|
214
|
-
res.add('automaticTask', 'id' => rid, 'name' => 'tau')
|
|
215
|
-
set_edges(@last,rid,res)
|
|
216
|
-
#Add new xor
|
|
217
|
-
xor_id = rand.to_s[2..11]
|
|
218
|
-
res.add('xor', 'id' => xor_id, 'name' => 'help-xor')
|
|
219
|
-
set_edges(@last,xor_id,res)
|
|
220
|
-
escape_id = rand.to_s[2..11]
|
|
221
|
-
res.add('manualTask', 'id' => escape_id, 'name' => 'escape')
|
|
222
|
-
set_edges(xor_id,escape_id,res)
|
|
223
|
-
@last = xor_id
|
|
224
|
-
else
|
|
225
|
-
if branch.length == 1
|
|
226
|
-
generate_in_list(branch,res)
|
|
227
|
-
elsif branch.length >1
|
|
228
|
-
branch_last = @last
|
|
229
|
-
rid = rand.to_s[2..11]
|
|
230
|
-
res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
|
|
231
|
-
set_edges(@last,rid,res)
|
|
232
|
-
@last = rid
|
|
233
|
-
generate_in_list(branch,res)
|
|
234
|
-
@last = branch_last
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
end
|
|
238
246
|
end
|
|
239
247
|
end
|
|
240
248
|
@last = original_last
|
|
@@ -242,11 +250,7 @@ module CPEE
|
|
|
242
250
|
end
|
|
243
251
|
|
|
244
252
|
def print_Node(node,res) #{{{
|
|
245
|
-
|
|
246
|
-
if res.children.length == 0
|
|
247
|
-
res.add('sequence', 'id' => @last, 'name' => 'main-sequence')
|
|
248
|
-
end
|
|
249
|
-
nid = "a#{node.niceid}"
|
|
253
|
+
nid = uid("a#{node.niceid}")
|
|
250
254
|
if node.endpoints.empty? && ((!node.script.nil? && node.script.strip != '') || node.type == :scriptTask)
|
|
251
255
|
n = res.add('automaticTask','id' => nid, 'name' => node.label)
|
|
252
256
|
else
|
|
@@ -268,9 +272,10 @@ module CPEE
|
|
|
268
272
|
|
|
269
273
|
def print_Conditional(node,res) #{{{
|
|
270
274
|
original_last = @last
|
|
271
|
-
nid = "a#{node.id}"
|
|
275
|
+
nid = uid("a#{node.id}")
|
|
272
276
|
|
|
273
|
-
|
|
277
|
+
### process trees have no deferred choice, xor is closest
|
|
278
|
+
if node.type == :exclusiveGateway || node.type == :eventBasedGateway
|
|
274
279
|
res.add('xor','id' => nid, 'name' => nil)
|
|
275
280
|
elsif node.type == :parallelGateway
|
|
276
281
|
res.add('and','id' => nid, 'name' => nil)
|
|
@@ -278,33 +283,31 @@ module CPEE
|
|
|
278
283
|
res.add('or','id' => nid, 'name' => nil)
|
|
279
284
|
end
|
|
280
285
|
|
|
281
|
-
|
|
282
|
-
if res.children.length == 1
|
|
283
|
-
res.attributes['root'] = nid
|
|
284
|
-
else
|
|
285
|
-
set_edges(@last,nid,res)
|
|
286
|
-
end
|
|
286
|
+
set_edges(@last,nid,res)
|
|
287
287
|
@last = nid
|
|
288
288
|
node.sub.each do |branch|
|
|
289
|
-
#get conditions and default
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
#get conditions and default (parallel branches have none)
|
|
290
|
+
conditional = branch.condition?
|
|
291
|
+
cond = conditional && branch.condition.any? ? branch.condition[0] : nil
|
|
292
|
+
default = conditional && branch.otherwise ? true : nil
|
|
293
|
+
items = visible(branch)
|
|
294
|
+
if items.length == 0
|
|
293
295
|
rid = rand.to_s[2..11]
|
|
294
296
|
res.add('automaticTask', 'id' => rid, 'name' => 'tau')
|
|
295
|
-
set_edges_condition(@last,rid,res,cond,default)
|
|
296
|
-
elsif
|
|
297
|
+
conditional ? set_edges_condition(@last,rid,res,cond,default) : set_edges(@last,rid,res)
|
|
298
|
+
elsif items.length == 1
|
|
297
299
|
generate_in_list(branch,res)
|
|
298
|
-
if
|
|
300
|
+
if !conditional
|
|
301
|
+
elsif default
|
|
299
302
|
res.find("//parentsNode[@sourceId='#{@last}']").last.attributes['default'] = default
|
|
300
303
|
else
|
|
301
304
|
res.find("//parentsNode[@sourceId='#{@last}']").last.attributes['condition'] = cond
|
|
302
305
|
end
|
|
303
|
-
elsif
|
|
306
|
+
elsif items.length >1
|
|
304
307
|
branch_last = @last
|
|
305
308
|
rid = rand.to_s[2..11]
|
|
306
309
|
res.add('sequence', 'id' => rid, 'name' => 'just-sequence')
|
|
307
|
-
set_edges_condition(@last,rid,res,cond,default)
|
|
310
|
+
conditional ? set_edges_condition(@last,rid,res,cond,default) : set_edges(@last,rid,res)
|
|
308
311
|
@last = rid
|
|
309
312
|
generate_in_list(branch,res)
|
|
310
313
|
@last = branch_last
|
|
@@ -91,6 +91,26 @@ module CPEE
|
|
|
91
91
|
super context, '-2', :terminate, 'TERMINATE', 1, []
|
|
92
92
|
end
|
|
93
93
|
end #}}}
|
|
94
|
+
### a cpee parallel whose branches are not direct children (e.g. created
|
|
95
|
+
### in a loop). Its content is a sequence between an open and a close
|
|
96
|
+
### marker, so that cpee in and cpee out can be the same. Targets without a
|
|
97
|
+
### print method for it ignore it.
|
|
98
|
+
class SingleParallel < Node #{{{
|
|
99
|
+
def initialize(context,id,open,attributes={})
|
|
100
|
+
super context, id, :singleParallel, '', 1, 1
|
|
101
|
+
@open = open
|
|
102
|
+
@attributes.merge!(attributes)
|
|
103
|
+
end
|
|
104
|
+
def open?; @open; end
|
|
105
|
+
end #}}}
|
|
106
|
+
### a cpee parallel_branch that is not a direct child of a parallel, see
|
|
107
|
+
### SingleParallel.
|
|
108
|
+
class SingleParallelBranch < SingleParallel #{{{
|
|
109
|
+
def initialize(context,id,open,attributes={})
|
|
110
|
+
super
|
|
111
|
+
@type = :singleParallelBranch
|
|
112
|
+
end
|
|
113
|
+
end #}}}
|
|
94
114
|
|
|
95
115
|
class Alternative < Array #{{{
|
|
96
116
|
include Container
|
|
@@ -299,6 +319,8 @@ module CPEE
|
|
|
299
319
|
ret << print_tree(e,indent + (last ? ' ' : '│ '),verbose)
|
|
300
320
|
elsif e.is_a?(Break) || e.is_a?(Terminate)
|
|
301
321
|
ret << indent + pchar + ' ' + e.class.to_s.gsub(/[^:]*::/,'') + "\n"
|
|
322
|
+
elsif e.is_a?(SingleParallel)
|
|
323
|
+
ret << indent + pchar + ' ' + e.class.to_s.gsub(/[^:]*::/,'') + (e.open? ? '' : ' End') + "\n"
|
|
302
324
|
else
|
|
303
325
|
ret << indent + pchar + ' ' + e.niceid.to_s + (verbose ? " (#{e.label})" : "") + "\n"
|
|
304
326
|
end
|
|
@@ -315,9 +337,9 @@ module CPEE
|
|
|
315
337
|
end
|
|
316
338
|
|
|
317
339
|
def remove(trcs)
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
340
|
+
### a set, deleting one by one is quadratic for many traces
|
|
341
|
+
rem = trcs.to_set
|
|
342
|
+
self.reject!{ |t| rem.include?(t) }
|
|
321
343
|
end
|
|
322
344
|
def remove_by_endnode(enode)
|
|
323
345
|
self.delete_if do |t|
|
|
@@ -419,8 +441,19 @@ module CPEE
|
|
|
419
441
|
|
|
420
442
|
def add_breaks(context,front=true)
|
|
421
443
|
### traces that are a prefix of another trace were cut short at an earlier
|
|
422
|
-
### visited node, they do not leave the loop, so they get no break
|
|
423
|
-
|
|
444
|
+
### visited node, they do not leave the loop, so they get no break.
|
|
445
|
+
### sorted, all extensions of a trace directly follow it, so comparing
|
|
446
|
+
### with the next different trace is enough
|
|
447
|
+
keys = self.map{ |t| t.map{ |n| n.object_id } }
|
|
448
|
+
prefix = {}
|
|
449
|
+
last = nextdiff = nil
|
|
450
|
+
(0...self.length).sort_by{ |i| keys[i] }.reverse_each do |i|
|
|
451
|
+
k = keys[i]
|
|
452
|
+
nextdiff = last unless k == last
|
|
453
|
+
prefix[i] = true if nextdiff && nextdiff.length > k.length && nextdiff[0...k.length] == k
|
|
454
|
+
last = k
|
|
455
|
+
end
|
|
456
|
+
self.reject!.with_index{ |t,i| prefix[i] }
|
|
424
457
|
### a trace whose last node occurs earlier in it is a loop (to the head or to
|
|
425
458
|
### an inner loop), not a way out. a trace ending in terminate needs no break
|
|
426
459
|
trueloops = self.find_all{ |t| t[0..-2].include?(t.last) || t.last&.type == :terminate }.length
|
|
@@ -441,8 +474,10 @@ module CPEE
|
|
|
441
474
|
end
|
|
442
475
|
def loops_and_partial_loops
|
|
443
476
|
lo = Traces.new self.find_all{ |t| t.first == t.last }
|
|
477
|
+
### computed once, traces added below share their second node anyway
|
|
478
|
+
sn = lo.second_nodes.to_set
|
|
444
479
|
self.each do |t|
|
|
445
|
-
lo << t if
|
|
480
|
+
lo << t if sn.include?(t[1])
|
|
446
481
|
end
|
|
447
482
|
lo.uniq!
|
|
448
483
|
lo
|
|
@@ -27,9 +27,20 @@ module CPEE
|
|
|
27
27
|
@tree = tree
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
### SingleParallel markers are only printed by targets that know them
|
|
31
|
+
def ignore?(e,nam)
|
|
32
|
+
e.is_a?(SingleParallel) && !respond_to?("print_#{nam}".to_sym,true)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
### the elements of a list this target prints (e.g. to count them)
|
|
36
|
+
def visible(list)
|
|
37
|
+
list.reject { |e| ignore?(e,e.class.name.gsub(/\w+:+/,'')) }
|
|
38
|
+
end
|
|
39
|
+
|
|
30
40
|
def generate_in_list(list,res)
|
|
31
41
|
list.each do |e|
|
|
32
42
|
nam = e.class.name.gsub(/\w+:+/,'')
|
|
43
|
+
next if ignore?(e,nam)
|
|
33
44
|
res = send("print_#{nam}".to_sym,e,res) # always save last node
|
|
34
45
|
end
|
|
35
46
|
res
|
|
@@ -39,6 +50,7 @@ module CPEE
|
|
|
39
50
|
post = []
|
|
40
51
|
list.each do |e|
|
|
41
52
|
nam = e.class.name.gsub(/\w+:+/,'')
|
|
53
|
+
next if ignore?(e,nam)
|
|
42
54
|
post += send("print_#{nam}".to_sym,e,res)
|
|
43
55
|
end
|
|
44
56
|
post.compact!
|
data/server/trans.conf
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:bpmnexport: npx -y -p cpee-layout@^1.2.0 bpmnexport
|
data/server/trans.pid
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1235950
|
data/tools/bpmn2_to_ptml.rb
CHANGED
|
@@ -54,7 +54,7 @@ ARGV.options { |opt|
|
|
|
54
54
|
opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
|
|
55
55
|
opt.on("--tree", "-t", "Print tree") { printtree = true }
|
|
56
56
|
opt.on("")
|
|
57
|
-
opt.on(wrap("[FNAME]","convert
|
|
57
|
+
opt.on(wrap("[FNAME]","convert bpmn2 in file FNAME to ptml and output to console."))
|
|
58
58
|
opt.parse!
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -78,8 +78,6 @@ else
|
|
|
78
78
|
tree = trans.build_tree(false)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
pp tree
|
|
82
|
-
|
|
83
81
|
if printtree
|
|
84
82
|
puts tree.to_s
|
|
85
83
|
else
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
# encoding: UTF-8
|
|
3
|
+
#
|
|
4
|
+
# This file is part of CPEE-TRANSFORMATION.
|
|
5
|
+
#
|
|
6
|
+
# CPEE-TRANSFORMATION is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or (at your
|
|
9
|
+
# option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# CPEE-TRANSFORMATION is distributed in the hope that it will be useful, but
|
|
12
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
14
|
+
# for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
# along with CPEE-TRANSFORMATION (file LICENSE in the main directory). If not,
|
|
18
|
+
# see <http://www.gnu.org/licenses/>.
|
|
19
|
+
|
|
20
|
+
def wrap(s1, s2, width=78, indent=ARGV.options.summary_width + 3)
|
|
21
|
+
lines = []
|
|
22
|
+
s = ARGV.options.summary_indent + s1 + ' ' * (indent - s1.length - ARGV.options.summary_indent.length) + s2
|
|
23
|
+
line, s = s[0..indent-2], s[indent..-1]
|
|
24
|
+
s.split(/\n/).each do |ss|
|
|
25
|
+
ss.split(/[ \t]+/).each do |word|
|
|
26
|
+
if line.size + word.size >= width
|
|
27
|
+
lines << line
|
|
28
|
+
line = (" " * (indent)) + word
|
|
29
|
+
else
|
|
30
|
+
line << " " << word
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
lines << line if line
|
|
34
|
+
line = (" " * (indent-1))
|
|
35
|
+
end
|
|
36
|
+
return lines.join("\n")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
require 'optparse'
|
|
40
|
+
require 'psych'
|
|
41
|
+
|
|
42
|
+
require_relative '../lib/cpee/transformation/transformer' rescue nil
|
|
43
|
+
require_relative '../lib/cpee/transformation/cpee' rescue nil
|
|
44
|
+
require_relative '../lib/cpee/transformation/bpmn2' rescue nil
|
|
45
|
+
|
|
46
|
+
# bpmnexport from cpee-layout, configured as for the server, see Target::BPMN2
|
|
47
|
+
conf = File.join(__dir__,'..','server','trans.conf')
|
|
48
|
+
CPEE::Transformation::Target::BPMN2.opts = {
|
|
49
|
+
:basepath => File.dirname(conf)
|
|
50
|
+
}.merge(File.exist?(conf) ? Psych::load_file(conf) || {} : {})
|
|
51
|
+
|
|
52
|
+
interactive = false
|
|
53
|
+
printtree = false
|
|
54
|
+
|
|
55
|
+
ARGV.options { |opt|
|
|
56
|
+
opt.summary_indent = ' ' * 2
|
|
57
|
+
opt.summary_width = 18
|
|
58
|
+
opt.banner = "Usage:\n#{opt.summary_indent}#{File.basename($0)} FNAME\n"
|
|
59
|
+
opt.on("Options:")
|
|
60
|
+
opt.on("--help", "-h", "This text") { puts opt; exit }
|
|
61
|
+
opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
|
|
62
|
+
opt.on("--tree", "-t", "Print tree") { printtree = true }
|
|
63
|
+
opt.on("")
|
|
64
|
+
opt.on(wrap("[FNAME]","convert cpee tree in file FNAME to bpmn2 and output to console."))
|
|
65
|
+
opt.parse!
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if ARGV.length != 1
|
|
69
|
+
puts ARGV.options
|
|
70
|
+
exit
|
|
71
|
+
else
|
|
72
|
+
f = ARGV[0]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
model = CPEE::Transformation::Source::CPEE.new(File.read(f))
|
|
76
|
+
|
|
77
|
+
trans = CPEE::Transformation::Transformer.new(model)
|
|
78
|
+
traces = trans.build_traces
|
|
79
|
+
|
|
80
|
+
if interactive
|
|
81
|
+
puts traces.legend
|
|
82
|
+
puts
|
|
83
|
+
tree = trans.build_tree(true)
|
|
84
|
+
else
|
|
85
|
+
tree = trans.build_tree(false)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
if printtree
|
|
89
|
+
puts tree.to_s
|
|
90
|
+
else
|
|
91
|
+
puts trans.generate_model(CPEE::Transformation::Target::BPMN2)
|
|
92
|
+
end
|
data/tools/cpee_to_ptml.rb
CHANGED
|
@@ -54,7 +54,7 @@ ARGV.options { |opt|
|
|
|
54
54
|
opt.on("--interactive", "-i", "Interactive mode") { interactive = true }
|
|
55
55
|
opt.on("--tree", "-t", "Print tree") { printtree = true }
|
|
56
56
|
opt.on("")
|
|
57
|
-
opt.on(wrap("[FNAME]","convert cpee tree in file FNAME to
|
|
57
|
+
opt.on(wrap("[FNAME]","convert cpee tree in file FNAME to ptml and output to console."))
|
|
58
58
|
opt.parse!
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -78,8 +78,6 @@ else
|
|
|
78
78
|
tree = trans.build_tree(false)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
pp tree
|
|
82
|
-
|
|
83
81
|
if printtree
|
|
84
82
|
puts tree.to_s
|
|
85
83
|
else
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cpee-transformation
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juergen eTM Mangler
|
|
@@ -87,6 +87,7 @@ executables:
|
|
|
87
87
|
- bpmn2_to_mermaid.rb
|
|
88
88
|
- bpmn2_to_ptml.rb
|
|
89
89
|
- cpee-trans
|
|
90
|
+
- cpee_to_bpmn2.rb
|
|
90
91
|
- cpee_to_cpee.rb
|
|
91
92
|
- cpee_to_mermaid.rb
|
|
92
93
|
- cpee_to_ptml.rb
|
|
@@ -123,10 +124,13 @@ files:
|
|
|
123
124
|
- lib/cpee/transformation/transformation_xml_text.xml
|
|
124
125
|
- lib/cpee/transformation/transformer.rb
|
|
125
126
|
- server/trans
|
|
127
|
+
- server/trans.conf
|
|
128
|
+
- server/trans.pid
|
|
126
129
|
- tools/bpmn2_to_cpee.rb
|
|
127
130
|
- tools/bpmn2_to_mermaid.rb
|
|
128
131
|
- tools/bpmn2_to_ptml.rb
|
|
129
132
|
- tools/cpee-trans
|
|
133
|
+
- tools/cpee_to_bpmn2.rb
|
|
130
134
|
- tools/cpee_to_cpee.rb
|
|
131
135
|
- tools/cpee_to_dataflow.rb
|
|
132
136
|
- tools/cpee_to_mermaid.rb
|
|
@@ -140,6 +144,12 @@ homepage: http://github.com/etm/cpee-transformation/
|
|
|
140
144
|
licenses:
|
|
141
145
|
- LGPL-3.0-or-later
|
|
142
146
|
metadata: {}
|
|
147
|
+
post_install_message: |
|
|
148
|
+
The BPMN2 target uses bpmnexport from cpee-layout (Node.js >= 22.22). By
|
|
149
|
+
default npx fetches it on first use. To avoid that, run
|
|
150
|
+
npm install -g cpee-layout
|
|
151
|
+
and set ":bpmnexport: bpmnexport" in trans.conf of your service
|
|
152
|
+
(scaffolded with cpee-trans new DIR).
|
|
143
153
|
rdoc_options: []
|
|
144
154
|
require_paths:
|
|
145
155
|
- lib
|