Class: Camunda::BpmnXML

Inherits:
Object
  • Object
show all
Defined in:
lib/camunda/bpmn_xml.rb

Overview

Used to parse bpmn file during bpmn_classes generator to create Camunda job class based on process id

Defined Under Namespace

Classes: Task

Instance Method Summary collapse

Constructor Details

#initialize(io_or_string) ⇒ BpmnXML

Returns a new instance of BpmnXML.

Parameters:

  • io_or_string (IO, String)

    valid xml string for bpmn file



4
5
6
# File 'lib/camunda/bpmn_xml.rb', line 4

def initialize(io_or_string)
  @doc = Nokogiri::XML(io_or_string)
end

Instance Method Details

#class_names_with_same_bpmn_id_as_topicArray<String>

We may have tasks with different topics. Returns classes with topics which are the same as the BPMN process id

Examples:

["DoSomething"]

Returns:

  • (Array<String>)

    class names which should be implemented



37
38
39
# File 'lib/camunda/bpmn_xml.rb', line 37

def class_names_with_same_bpmn_id_as_topic
  tasks_with_same_bpmn_id_as_topic.map(&:class_name)
end

#external_tasksObject

creates a new instance of Camunda::BpmnXML::Task



22
23
24
25
26
27
28
29
30
31
# File 'lib/camunda/bpmn_xml.rb', line 22

def external_tasks
  @doc.xpath('(//bpmn:serviceTask[@camunda:type="external"]|//bpmn:sendTask[@camunda:type="external"])').map do |task|
    Task.new(task)
  end +
    @doc.xpath('//bpmn:endEvent/bpmn:messageEventDefinition[@camunda:type="external"]').map do |child_node|
      task = child_node.parent.dup
      task["topic"] = child_node["topic"]
      Task.new(task)
    end
end

#modularized_class_namesArray<String>

Returns array of modularized class names.

Examples:

["CamundaWorkflow::DoSomething"]

Returns:

  • (Array<String>)

    array of modularized class names



44
45
46
# File 'lib/camunda/bpmn_xml.rb', line 44

def modularized_class_names
  class_names_with_same_bpmn_id_as_topic.map { |name| "#{module_name}::#{name}" }
end

#module_nameString

Returns Id (process definition key) of the BPMN process.

Examples:

"CamundaWorkflow"

Returns:

  • (String)

    Id (process definition key) of the BPMN process



17
18
19
# File 'lib/camunda/bpmn_xml.rb', line 17

def module_name
  @doc.xpath('/bpmn:definitions/bpmn:process').first['id']
end

#to_sString

Friendly name of this BPMN file is the module name

Returns:

  • (String)

    module name



10
11
12
# File 'lib/camunda/bpmn_xml.rb', line 10

def to_s
  module_name
end

#topicsArray<String>

Returns topics in this BPMN file.

Returns:

  • (Array<String>)

    topics in this BPMN file



49
50
51
# File 'lib/camunda/bpmn_xml.rb', line 49

def topics
  @doc.xpath('//*[@camunda:topic]').map { |node| node.attribute('topic').value }.uniq
end