BpmListener   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 86
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B postPersist() 0 49 6
1
<?php
2
3
namespace App\EventListener\Submission\Transfer;
4
5
use App\Entity\Submission;
6
use App\Entity\Scenario;
7
use App\Service\SubmissionService;
8
use Ds\Component\Api\Api\Api;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Api\Api\Api was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Ds\Component\Camunda\Model\Variable;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Camunda\Model\Variable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Ds\Component\Camunda\Query\ProcessDefinitionParameters;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Camunda\Que...essDefinitionParameters was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Ds\Component\Config\Service\ConfigService;
0 ignored issues
show
Bug introduced by
The type Ds\Component\Config\Service\ConfigService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
/**
15
 * Class BpmListener
16
 */
17
final class BpmListener
18
{
19
    /**
20
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
21
     */
22
    private $container;
23
24
    /**
25
     * @var \Ds\Component\Api\Api\Api
26
     */
27
    private $api;
28
29
    /**
30
     * @var \Ds\Component\Config\Service\ConfigService
31
     */
32
    private $configService;
33
34
    /**
35
     * @var \App\Service\SubmissionService
36
     */
37
    private $submissionService;
38
39
    /**
40
     * Constructor
41
     *
42
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
43
     */
44
    public function __construct(ContainerInterface $container)
45
    {
46
        $this->container = $container;
47
    }
48
49
    /**
50
     * Forward the submission to the bpm service
51
     *
52
     * @param \App\Entity\Submission $submission
53
     */
54
    public function postPersist(Submission $submission)
55
    {
56
        // Circular reference error workaround
57
        // @todo Look into fixing this
58
        $this->api = $this->container->get(Api::class);
59
        $this->configService = $this->container->get(ConfigService::class);
60
        $this->submissionService = $this->container->get(SubmissionService::class);
61
        //
62
63
        $scenario = $submission->getScenario();
64
65
        if (Scenario::TYPE_BPM !== $scenario->getType()) {
66
            return;
67
        }
68
69
//        $parameters = new ProcessDefinitionParameters;
70
//        $parameters->setKey($scenario->getConfig()['process_definition_key']);
71
//        $xml = $this->api->camunda->processDefinition->getXml(null, $parameters);
72
        $service = $scenario->getService();
73
        $parameters = new ProcessDefinitionParameters;
74
        $variables = [];
75
        $variables[] = new Variable($this->configService->get('app.bpm.variables.api_url'), '');
76
        $variables[] = new Variable($this->configService->get('app.bpm.variables.api_user'), '');
77
        $variables[] = new Variable($this->configService->get('app.bpm.variables.api_key'), '');
78
        $variables[] = new Variable($this->configService->get('app.bpm.variables.service_uuid'), $service->getUuid());
79
        $variables[] = new Variable($this->configService->get('app.bpm.variables.scenario_uuid'), $scenario->getUuid());
80
        $config = $scenario->getConfig();
81
82
        if (array_key_exists('process_custom_data', $config)
83
            && array_key_exists('enabled', $config['process_custom_data'])
84
            && $config['process_custom_data']['enabled']
85
            && array_key_exists('value', $config['process_custom_data'])
86
        ) {
87
            $variables[] = new Variable($this->configService->get('app.bpm.variables.scenario_custom_data'), $config['process_custom_data']['value'], Variable::TYPE_JSON);
88
        }
89
90
        $variables[] = new Variable($this->configService->get('app.bpm.variables.identity'), $submission->getIdentity());
91
        $variables[] = new Variable($this->configService->get('app.bpm.variables.identity_uuid'), $submission->getIdentityUuid());
92
        $variables[] = new Variable($this->configService->get('app.bpm.variables.submission_uuid'), $submission->getUuid());
93
        $variables[] = new Variable($this->configService->get('app.bpm.variables.start_data'), $submission->getData(), Variable::TYPE_JSON);
94
        $parameters
95
            ->setVariables($variables)
96
            ->setKey($scenario->getConfig()['process_definition_key'])
97
            ->setTenantId($scenario->getTenant());
98
        $this->api->get('workflow.process_definition')->start(null, $parameters);
99
        $submission->setState(Submission::STATE_TRANSFERRED);
100
        $manager = $this->submissionService->getManager();
101
        $manager->persist($submission);
102
        $manager->flush();
103
    }
104
}
105