Class: CPEE::ProcessTransformation::Source::BPMN2

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee/processtransformation/bpmn2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ BPMN2

{{{



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cpee/processtransformation/bpmn2.rb', line 35

def initialize(xml) #{{{
  @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"

  @dataelements = {}
  @endpoints = {}
  @graph = Graph.new

  extract_dataelements(doc)
  extract_endpoints(doc)
  extract_nodelink(doc)

  @traces = Traces.new [[@start]]
end

Instance Attribute Details

#dataelementsObject (readonly)

Returns the value of attribute dataelements.



33
34
35
# File 'lib/cpee/processtransformation/bpmn2.rb', line 33

def dataelements
  @dataelements
end

#endpointsObject (readonly)

Returns the value of attribute endpoints.



33
34
35
# File 'lib/cpee/processtransformation/bpmn2.rb', line 33

def endpoints
  @endpoints
end

#graphObject (readonly)

Returns the value of attribute graph.



33
34
35
# File 'lib/cpee/processtransformation/bpmn2.rb', line 33

def graph
  @graph
end

#startObject (readonly)

Returns the value of attribute start.



33
34
35
# File 'lib/cpee/processtransformation/bpmn2.rb', line 33

def start
  @start
end

Instance Method Details

#build_tracesObject

}}}



134
135
136
137
# File 'lib/cpee/processtransformation/bpmn2.rb', line 134

def build_traces #{{{
  build_extraces @traces, @start
  @traces
end

#build_tree(debug = false) ⇒ Object

}}}



138
139
140
141
142
# File 'lib/cpee/processtransformation/bpmn2.rb', line 138

def build_tree(debug=false) #{{{
  build_ttree @tree, @traces.dup, nil, debug
  debug_print debug, 'Tree finished'
  @tree
end

#extract_dataelements(doc) ⇒ Object

}}}



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cpee/processtransformation/bpmn2.rb', line 54

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
    else
      @dataelements[ref.attributes['name']] = ''
    end
  end
end

#extract_endpoints(doc) ⇒ Object

}}}



66
67
68
69
70
71
72
# File 'lib/cpee/processtransformation/bpmn2.rb', line 66

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

}}}



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cpee/processtransformation/bpmn2.rb', line 74

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']
    end

    e.find("bm:property[@name='cpee:endpoint']/@itemSubjectRef").each do |ep|
      n.endpoints << ep.value
    end
    e.find("bm:property[@name='cpee:method']/@itemSubjectRef").each do |m|
      n.methods << m.value
    end
    e.find("bm:script").each do |s|
      n.script ||= ''
      n.script << s.text.strip
    end
    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
        n.parameters[name] = value
      end
    end
    e.find("bm:ioSpecification/bm:dataOutput").each do |a|
      ref = a.attributes['id']
      e.find("bm:dataOutputAssociation[bm:sourceRef=\"#{ref}\"]").each do |d|
        n.script_var = ref
        n.script_id = d.find("string(bm:targetRef)")
      end
    end

    @graph.add_node n
    @start = n if n.type == :startEvent && @start == nil
  end

  # extract all sequences to a links
  doc.find("/bm:definitions/bm:process/bm:sequenceFlow").each do |e|
    source = e.attributes['sourceRef']
    target = e.attributes['targetRef']
    cond = e.find('bm:conditionExpression')
    @graph.add_link Link.new(source, target, cond.empty? ? nil : cond.first.text.strip)
  end

  @graph.clean_up do |node|
    if node.type == :scriptTask && (x = @graph.find_script_id(node.id)).any?
      x.each do |k,n|
        n.script = node.script
        n.script_type = node.script_type
      end
      true
    else
      false
    end
  end
end

#generate_model(formater) ⇒ Object

{{{



287
288
289
# File 'lib/cpee/processtransformation/bpmn2.rb', line 287

def generate_model(formater) #{{{
  formater.new(@tree).generate
end


176
177
178
# File 'lib/cpee/processtransformation/bpmn2.rb', line 176

def print_node(niceid)
  @graph.find_node(niceid)
end