lib/cpee/processtransformation/bpmn2.rb in cpee-1.3.221 vs lib/cpee/processtransformation/bpmn2.rb in cpee-1.3.222
- old
+ new
@@ -1,19 +1,19 @@
# encoding: UTF-8
#
# This file is part of CPEE.
#
# Apache License, Version 2.0
-#
+#
# Copyright (c) 2013 Juergen Mangler
-#
+#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@@ -36,11 +36,11 @@
@tree = Tree.new
@hl = HighLine.new
@start = nil
doc = XML::Smart.string(xml)
- doc.register_namespace 'bm', "http://www.omg.org/spec/BPMN/20100524/MODEL"
+ doc.register_namespace 'bm', "http://www.omg.org/spec/BPMN/20100524/MODEL"
@dataelements = {}
@endpoints = {}
@graph = Graph.new
@@ -49,31 +49,31 @@
extract_nodelink(doc)
@traces = Traces.new [[@start]]
end #}}}
- def extract_dataelements(doc)
+ def extract_dataelements(doc) #{{{
doc.find("/bm:definitions/bm:process/bm:property[bm:dataState/@name='cpee:dataelement']").each do |ref|
if ref.attributes['itemSubjectRef']
doc.find("/bm:definitions/bm:itemDefinition[@id=\"" + ref.attributes['itemSubjectRef'] + "\"]").each do |sref|
@dataelements[ref.attributes['name']] = sref.attributes['structureRef'].to_s
- end
+ end
else
@dataelements[ref.attributes['name']] = ''
- end
+ end
end
- end
+ end #}}}
- def extract_endpoints(doc)
+ def extract_endpoints(doc) #{{{
doc.find("/bm:definitions/bm:process/bm:property[bm:dataState/@name='cpee:endpoint']/@itemSubjectRef").each do |ref|
doc.find("/bm:definitions/bm:itemDefinition[@id=\"" + ref.value + "\"]/@structureRef").each do |sref|
@endpoints[ref.value] = sref.value
- end
+ end
end
- end
+ end #}}}
- def extract_nodelink(doc)
+ def extract_nodelink(doc) #{{{
doc.find("/bm:definitions/bm:process/bm:*[@id and @name and not(@itemSubjectRef) and not(name()='sequenceFlow')]").each do |e|
n = Node.new(self.object_id,e.attributes['id'],e.qname.name.to_sym,e.attributes['name'].strip,e.find('count(bm:incoming)'),e.find('count(bm:outgoing)'))
if e.attributes['scriptFormat'] != ''
n.script_type = e.attributes['scriptFormat']
@@ -92,11 +92,11 @@
e.find("bm:ioSpecification/bm:dataInput").each do |a|
name = a.attributes['name']
value = a.attributes['itemSubjectRef']
if @dataelements.keys.include?(value)
n.parameters[name] = 'data.' + value
- else
+ else
n.parameters[name] = value
end
end
e.find("bm:ioSpecification/bm:dataOutput").each do |a|
ref = a.attributes['id']
@@ -125,31 +125,31 @@
n.script_type = node.script_type
end
true
else
false
- end
+ end
end
- end
+ end #}}}
def build_traces #{{{
build_extraces @traces, @start
@traces
end #}}}
def build_tree(debug=false) #{{{
build_ttree @tree, @traces.dup, nil, debug
debug_print debug, 'Tree finished'
@tree
end #}}}
-
+
def build_extraces(traces, node) #{{{
dupt = traces.last.dup
@graph.next_nodes(node).each_with_index do |n,i|
traces << dupt.dup if i > 0
if traces.last.include?(n)
traces.last << n
- else
+ else
traces.last << n
build_extraces(traces,n)
end
end
end #}}}
@@ -197,16 +197,16 @@
end
unless li.nil?
if branch.condition?
branch.condition << li.condition unless li.condition.nil?
branch.condition_type = "text/javascript"
- end
+ end
if branch.respond_to?(:attributes)
- branch.attributes.merge!(li.attributes)
+ branch.attributes.merge!(li.attributes)
li.attributes.delete_if{true}
- end
- end
+ end
+ end
end
if node == enode
traces.shift_all
elsif traces.incoming(node) == 1
traces.shift_all
@@ -226,17 +226,21 @@
loops.add_breaks(self.object_id,node.type == :exclusiveGateway)
### remove the exclusive gateway because we no longer need it
### if there is non (tail controlled, remove the loop target (last)
if node.type == :exclusiveGateway
loops.shift_all
- traces.shift_all
+ traces.shift_all
else
loops.pop_all
end
### add the blank conditional to get a break
puts '--> down head_loop to ' + (down + 1).to_s if debug
- build_ttree branch, loops, nil, debug, down + 1
+ if loops.same_first
+ build_ttree branch.last.new_branch, loops, nil, debug, down + 1
+ else
+ build_ttree branch, loops, nil, debug, down + 1
+ end
puts '--> up head_loop from ' + (down + 1).to_s if debug
else
### throw away the loop traces, remove loop traces from front of all other traces
traces.remove(loops)
traces.eliminate(loops)
@@ -250,41 +254,42 @@
else
endnode = traces.find_endnode || enode
puts "--> endnode #{endnode.nil? ? 'nil' : endnode.niceid}" if debug
tracesgroup, endnode = traces.segment_by endnode
tracesgroup.each do |trcs|
+ next unless branch.last.respond_to?(:new_branch)
nb = branch.last.new_branch
unless trcs.finished?
puts '--> branch down to ' + (down + 1).to_s if debug
build_ttree nb, trcs, endnode, debug, down + 1
puts '--> branch up from ' + (down + 1).to_s if debug
- end
+ end
end
# remove all traces that don't start with endnode to account for loops
if endnode.nil?
traces.empty!
- else
+ else
traces.remove_by_endnode(endnode)
- end
+ end
end
end
end
private :build_ttree
def debug_print(debug,traces) #{{{
if debug
puts '-' * @hl.output_cols, @tree.to_s
puts traces.to_s
@hl.ask('Continue ... '){ |q| q.echo = false }
- end
+ end
end #}}}
private :debug_print
def generate_model(formater) #{{{
formater.new(@tree).generate
end #}}}
- end
+ end
end
end