Class: Camunda::Deployment

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

Overview

Note:

You must supply the paths of the BPMN files as a param titled file_names to deploy the BPMN file

Deployment is responsible for creating BPMN, DMN, and CMMN processes within Camunda. Before a process (or case, or decision) can be executed by the process engine, it has to be deployed. A deployment is a logical entity that groups multiple resources that are deployed together. Camunda offers an application called Modeler(camunda.com/download/modeler/) that allows you to create and edit BPMN diagrams and BPMN decision tables. and deploy BPMN, DMN, CMMN definitions in the Camunda engine.

Class Method Summary collapse

Methods inherited from Model

find_by!, log_details?, worker_id

Class Method Details

.create(file_names:, tenant_id: nil, deployment_source: 'Camunda Workflow Gem', deployment_name: nil) ⇒ Camunda::ProcessDefinition

Note:

Only supporting .create which uses a POST on deployment/create.

Deploys a new process definition to Camunda and returns an instance of Camunda::ProcessDefinition.

Examples:

pd = Camunda::Deployment.create(file_names: ['bpmn/resources/sample.bpmn']).first

Parameters:

  • files_names (Array<String>)

    file paths of the bpmn file for deployment

  • tenant_id (String) (defaults to: nil)

    supplied when a single Camunda installation should serve more than one tenant

  • deployment_source (String) (defaults to: 'Camunda Workflow Gem')

    the source of where the deployment occurred.

  • deployment_name (String) (defaults to: nil)

    provide the name of the deployment, otherwise the deployment name will be the bpmn file names.

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/camunda/deployment.rb', line 19

def self.create(file_names:, tenant_id: nil, deployment_source: 'Camunda Workflow Gem', deployment_name: nil)
  deployment_name ||= file_names.map { |file_name| File.basename(file_name) }.join(", ")
  tenant_id ||= Camunda::Workflow.configuration.tenant_id
  args = file_data(file_names).merge('deployment-name' => deployment_name, 'deployment-source' => deployment_source)
  args.merge!("tenant-id": tenant_id) if tenant_id
  response = post_raw('deployment/create', args)

  deployed_process_definitions(response[:parsed_data][:data][:deployed_process_definitions])
end

.deployed_process_definitions(definitions_hash) ⇒ Array<Camunda::ProcessDefinition>

Returns a new instance of Camunda::ProcessDefinition according to definitions hash returned by Camunda

Parameters:

  • definitions_hash (Hash)

Returns:

Raises:



41
42
43
44
45
46
47
48
49
# File 'lib/camunda/deployment.rb', line 41

def self.deployed_process_definitions(definitions_hash)
  # Currently only returning the process definitions. But this Deployment.create can create a DMN, CMMN also
  # It returns :deployed_process_definitions, :deployed_case_definitions, :deployed_decision_definitions,
  # :deployed_decision_requirements_definitions

  raise Camunda::ProcessEngineException, "No Process Definition created" if definitions_hash.nil?

  definitions_hash.values.map { |process_definition| Camunda::ProcessDefinition.new process_definition }
end

.file_data(file_names) ⇒ Object

Convenience method for dealing with files and IO that are to be uploaded

Parameters:

  • file_names (Array<String>)

    local files paths to be uploaded



31
32
33
34
35
# File 'lib/camunda/deployment.rb', line 31

def self.file_data(file_names)
  file_names.map do |file_name|
    [file_name, Faraday::FilePart.new(file_name, 'text/plain')]
  end.to_h
end