Skip to content

Commit 5494e16

Browse files
authored
Merge pull request #234 from ProcessMaker/feature/FOUR-26791
FOUR-26791 Implement Throw/Catch Event Message Mapping
2 parents efd8797 + 66b1106 commit 5494e16

27 files changed

+1156
-31
lines changed

.github/workflows/sonarqube.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
- name: Run PHPUnit tests
4545
run: ./vendor/bin/phpunit -d memory_limit=-1
4646

47-
- name: List coverage files
48-
run: ls -l coverage
47+
- name: Check coverage
48+
run: ./check_coverage.php
4949

5050
- uses: sonarsource/sonarqube-scan-action@master
5151
env:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace ProcessMaker\Nayra\Bpmn;
4+
5+
use ProcessMaker\Nayra\Contracts\Bpmn\AssignmentInterface;
6+
use ProcessMaker\Nayra\Contracts\Bpmn\FormalExpressionInterface;
7+
8+
/**
9+
* Assignment class that implements AssignmentInterface
10+
*/
11+
class Assignment implements AssignmentInterface
12+
{
13+
use BaseTrait;
14+
15+
/**
16+
* Get the 'from' formal expression.
17+
*
18+
* @return FormalExpressionInterface|callable
19+
*/
20+
public function getFrom()
21+
{
22+
return $this->getProperty(self::BPMN_PROPERTY_FROM);
23+
}
24+
25+
/**
26+
* Get the 'to' formal expression.
27+
*
28+
* @return FormalExpressionInterface|callable
29+
*/
30+
public function getTo()
31+
{
32+
return $this->getProperty(self::BPMN_PROPERTY_TO);
33+
}
34+
}

src/ProcessMaker/Nayra/Bpmn/CatchEventTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ protected function initCatchEventTrait()
3030
{
3131
$this->setProperty(CatchEventInterface::BPMN_PROPERTY_EVENT_DEFINITIONS, new Collection);
3232
$this->setProperty(CatchEventInterface::BPMN_PROPERTY_PARALLEL_MULTIPLE, false);
33+
$this->setProperty(CatchEventInterface::BPMN_PROPERTY_DATA_OUTPUT_ASSOCIATION, new Collection);
3334
}
3435

3536
/**
@@ -42,6 +43,11 @@ public function getEventDefinitions()
4243
return $this->getProperty(CatchEventInterface::BPMN_PROPERTY_EVENT_DEFINITIONS);
4344
}
4445

46+
public function getDataOutputAssociations()
47+
{
48+
return $this->getProperty(CatchEventInterface::BPMN_PROPERTY_DATA_OUTPUT_ASSOCIATION);
49+
}
50+
4551
/**
4652
* Register catch events.
4753
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace ProcessMaker\Nayra\Bpmn;
4+
5+
use ProcessMaker\Nayra\Contracts\Bpmn\DataInputAssociationInterface;
6+
7+
/**
8+
* Transition to check if the activity is a loop not yet completed or a single instance
9+
*/
10+
class DataInputAssociation implements DataInputAssociationInterface
11+
{
12+
use BaseTrait;
13+
14+
protected function initDataInputAssociation()
15+
{
16+
$this->properties[static::BPMN_PROPERTY_ASSIGNMENT] = new Collection;
17+
}
18+
19+
public function getSource()
20+
{
21+
return $this->getProperty(static::BPMN_PROPERTY_SOURCES_REF);
22+
}
23+
24+
public function getTarget()
25+
{
26+
return $this->getProperty(static::BPMN_PROPERTY_TARGET_REF);
27+
}
28+
29+
public function getTransformation()
30+
{
31+
return $this->getProperty(static::BPMN_PROPERTY_TRANSFORMATION);
32+
}
33+
34+
public function getAssignments()
35+
{
36+
return $this->getProperty(static::BPMN_PROPERTY_ASSIGNMENT);
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace ProcessMaker\Nayra\Bpmn;
4+
5+
use ProcessMaker\Nayra\Contracts\Bpmn\DataOutputAssociationInterface;
6+
7+
/**
8+
* DataOutputAssociation class for handling data output associations in BPMN processes
9+
*/
10+
class DataOutputAssociation implements DataOutputAssociationInterface
11+
{
12+
use BaseTrait;
13+
14+
protected function initDataOutputAssociation()
15+
{
16+
$this->properties[static::BPMN_PROPERTY_ASSIGNMENT] = new Collection;
17+
}
18+
19+
public function getSource()
20+
{
21+
return $this->getProperty(static::BPMN_PROPERTY_SOURCES_REF);
22+
}
23+
24+
public function getTarget()
25+
{
26+
return $this->getProperty(static::BPMN_PROPERTY_TARGET_REF);
27+
}
28+
29+
public function getTransformation()
30+
{
31+
return $this->getProperty(static::BPMN_PROPERTY_TRANSFORMATION);
32+
}
33+
34+
public function getAssignments()
35+
{
36+
return $this->getProperty(static::BPMN_PROPERTY_ASSIGNMENT);
37+
}
38+
}

src/ProcessMaker/Nayra/Bpmn/DataStoreTrait.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,76 @@ public function getItemSubject()
100100
{
101101
return $this->itemSubject;
102102
}
103+
104+
/**
105+
* Get data using dot notation.
106+
*
107+
* @param string $path Dot notation path (e.g., 'user.profile.name')
108+
* @param mixed $default Default value if path doesn't exist
109+
*
110+
* @return mixed
111+
*/
112+
public function getDotData($path, $default = null)
113+
{
114+
$keys = explode('.', $path);
115+
$current = $this->data;
116+
117+
// Navigate through the path
118+
foreach ($keys as $key) {
119+
// Handle numeric keys for arrays
120+
if (is_numeric($key)) {
121+
$key = (int) $key;
122+
}
123+
124+
if (!isset($current[$key])) {
125+
return $default;
126+
}
127+
128+
$current = $current[$key];
129+
}
130+
131+
return $current;
132+
}
133+
134+
/**
135+
* Set data using dot notation.
136+
*
137+
* @param string $path Dot notation path (e.g., 'user.profile.name')
138+
* @param mixed $value Value to set
139+
*
140+
* @return $this
141+
*/
142+
public function setDotData($path, $value)
143+
{
144+
$keys = explode('.', $path);
145+
$firstKey = $keys[0];
146+
$current = &$this->data;
147+
148+
// Navigate to the parent of the target key
149+
for ($i = 0; $i < count($keys) - 1; $i++) {
150+
$key = $keys[$i];
151+
152+
// Handle numeric keys for arrays
153+
if (is_numeric($key)) {
154+
$key = (int) $key;
155+
}
156+
157+
if (!isset($current[$key]) || !is_array($current[$key])) {
158+
$current[$key] = [];
159+
}
160+
$current = &$current[$key];
161+
}
162+
163+
// Set the final value
164+
$finalKey = $keys[count($keys) - 1];
165+
if (is_numeric($finalKey)) {
166+
$finalKey = (int) $finalKey;
167+
}
168+
169+
$current[$finalKey] = $value;
170+
// Keep compatibility with putData method (required by PM Core)
171+
$this->putData($firstKey, $this->data[$firstKey]);
172+
173+
return $this;
174+
}
103175
}

src/ProcessMaker/Nayra/Bpmn/Models/EndEvent.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ProcessMaker\Nayra\Bpmn\Models;
44

5+
use ProcessMaker\Nayra\Bpmn\Collection;
56
use ProcessMaker\Nayra\Bpmn\EndEventTrait;
67
use ProcessMaker\Nayra\Contracts\Bpmn\EndEventInterface;
78
use ProcessMaker\Nayra\Model\DataInputAssociationInterface;
@@ -19,12 +20,18 @@ class EndEvent implements EndEventInterface
1920
{
2021
use EndEventTrait;
2122

22-
private $dataInputs;
23-
24-
private $dataInputAssociations;
25-
2623
private $inputSet;
2724

25+
/**
26+
* Initialize intermediate throw event.
27+
*/
28+
protected function initEndEvent()
29+
{
30+
$this->properties[static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION] = new Collection();
31+
$this->properties[static::BPMN_PROPERTY_DATA_INPUT] = new Collection;
32+
$this->setProperty(static::BPMN_PROPERTY_EVENT_DEFINITIONS, new Collection);
33+
}
34+
2835
/**
2936
* Array map of custom event classes for the bpmn element.
3037
*
@@ -52,7 +59,7 @@ public function getTargetInstances(EventDefinitionInterface $message, TokenInter
5259
*/
5360
public function getDataInputs()
5461
{
55-
return $this->dataInputs;
62+
return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT);
5663
}
5764

5865
/**
@@ -62,7 +69,7 @@ public function getDataInputs()
6269
*/
6370
public function getDataInputAssociations()
6471
{
65-
return $this->getDataInputAssociations();
72+
return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION);
6673
}
6774

6875
/**

src/ProcessMaker/Nayra/Bpmn/Models/IntermediateThrowEvent.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ class IntermediateThrowEvent implements IntermediateThrowEventInterface
1313
{
1414
use IntermediateThrowEventTrait;
1515

16-
/**
17-
* @var \ProcessMaker\Nayra\Contracts\Bpmn\DataInputAssociationInterface[]
18-
*/
19-
private $dataInputAssociations;
20-
21-
/**
22-
* @var \ProcessMaker\Nayra\Contracts\Bpmn\DataInputInterface[]
23-
*/
24-
private $dataInputs;
25-
2616
/**
2717
* @var \ProcessMaker\Nayra\Contracts\Bpmn\InputSetInterface
2818
*/
@@ -38,8 +28,8 @@ class IntermediateThrowEvent implements IntermediateThrowEventInterface
3828
*/
3929
protected function initIntermediateThrowEvent()
4030
{
41-
$this->dataInputAssociations = new Collection;
42-
$this->dataInputs = new Collection;
31+
$this->properties[static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION] = new Collection;
32+
$this->properties[static::BPMN_PROPERTY_DATA_INPUT] = new Collection;
4333
$this->setProperty(static::BPMN_PROPERTY_EVENT_DEFINITIONS, new Collection);
4434
}
4535

@@ -60,7 +50,7 @@ protected function getBpmnEventClasses()
6050
*/
6151
public function getDataInputAssociations()
6252
{
63-
return $this->dataInputAssociations;
53+
return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT_ASSOCIATION);
6454
}
6555

6656
/**
@@ -70,7 +60,7 @@ public function getDataInputAssociations()
7060
*/
7161
public function getDataInputs()
7262
{
73-
return $this->dataInputs;
63+
return $this->getProperty(static::BPMN_PROPERTY_DATA_INPUT);
7464
}
7565

7666
/**

0 commit comments

Comments
 (0)