-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from ProcessMaker/feature/multiinstance
Implement Activity MultiInstance. Resolves #191
- Loading branch information
Showing
35 changed files
with
3,202 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Nayra\Bpmn; | ||
|
||
use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\StateInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; | ||
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; | ||
|
||
/** | ||
* Transition rule that always pass the token. | ||
* | ||
* @package ProcessMaker\Nayra\Bpmn | ||
*/ | ||
class DataInputTransition implements TransitionInterface | ||
{ | ||
use TransitionTrait; | ||
|
||
/** | ||
* Condition required to transit the element. | ||
* | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface|null $token | ||
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance | ||
* | ||
* @return bool | ||
*/ | ||
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get transition owner element | ||
* | ||
* @return ActivityInterface | ||
*/ | ||
public function getOwner() | ||
{ | ||
return $this->owner; | ||
} | ||
|
||
/** | ||
* Activate the next state. | ||
* | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface $flow | ||
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $consumeTokens | ||
* @param array $properties | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface|null $source | ||
* | ||
* @return TokenInterface | ||
*/ | ||
protected function activateNextState(ConnectionInterface $flow, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) | ||
{ | ||
$nextState = $flow->targetState(); | ||
$loop = $this->getOwner()->getLoopCharacteristics(); | ||
if ($loop && $loop->isExecutable()) { | ||
$loop->iterateNextState($nextState, $instance, $consumeTokens, $properties, $source); | ||
} else { | ||
$nextState->addNewToken($instance, $properties, $source); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Nayra\Bpmn; | ||
|
||
use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface; | ||
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; | ||
|
||
/** | ||
* Transition rule that always pass the token. | ||
* | ||
* @package ProcessMaker\Nayra\Bpmn | ||
*/ | ||
class DataOutputTransition implements TransitionInterface | ||
{ | ||
use TransitionTrait; | ||
|
||
/** | ||
* Initialize the transition. | ||
* | ||
* @param FlowNodeInterface $owner | ||
* @param bool $preserveToken | ||
*/ | ||
protected function initDataOutputTransition() | ||
{ | ||
$this->setTokensConsumedPerIncoming(-1); | ||
} | ||
|
||
/** | ||
* Condition required to transit the element. | ||
* | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface|null $token | ||
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface|null $executionInstance | ||
* | ||
* @return bool | ||
*/ | ||
public function assertCondition(TokenInterface $token = null, ExecutionInstanceInterface $executionInstance = null) | ||
{ | ||
$loop = $this->getOwner()->getLoopCharacteristics(); | ||
return !$loop || !$loop->isExecutable() || $loop->isLoopCompleted($executionInstance, $token); | ||
} | ||
|
||
/** | ||
* Get transition owner element | ||
* | ||
* @return ActivityInterface | ||
*/ | ||
public function getOwner() | ||
{ | ||
return $this->owner; | ||
} | ||
|
||
/** | ||
* Activate the next state. | ||
* | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\ConnectionInterface $flow | ||
* @param \ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface $instance | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\CollectionInterface $consumeTokens | ||
* @param array $properties | ||
* @param \ProcessMaker\Nayra\Contracts\Bpmn\TransitionInterface|null $source | ||
* | ||
* @return TokenInterface | ||
*/ | ||
protected function activateNextState(ConnectionInterface $flow, ExecutionInstanceInterface $instance, CollectionInterface $consumeTokens, array $properties = [], TransitionInterface $source = null) | ||
{ | ||
$loop = $this->getOwner()->getLoopCharacteristics(); | ||
if ($loop && $loop->isExecutable()) { | ||
$loop->mergeOutputData($consumeTokens, $instance); | ||
} | ||
$nextState = $flow->targetState(); | ||
$nextState->addNewToken($instance, $properties, $source); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace ProcessMaker\Nayra\Bpmn; | ||
|
||
use ProcessMaker\Nayra\Contracts\Bpmn\LoopCharacteristicsInterface; | ||
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; | ||
|
||
/** | ||
* Base implementation for LoopCharacteristicsInterface | ||
* | ||
* @package ProcessMaker\Nayra\Bpmn | ||
*/ | ||
trait LoopCharacteristicsTrait | ||
{ | ||
use BaseTrait; | ||
|
||
/** | ||
* Prepare Loop Instance properties for execution | ||
* | ||
* @param TokenInterface $token | ||
* @param array $properties | ||
* | ||
* @return array | ||
*/ | ||
private function prepareLoopInstanceProperties(TokenInterface $token, array $properties = []) | ||
{ | ||
$loopCharacteristics = $token->getProperty( | ||
LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, | ||
$properties[LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY] ?? [] | ||
); | ||
if (empty($loopCharacteristics['sourceToken'])) { | ||
$loopCharacteristics['sourceToken'] = $token->getId(); | ||
} | ||
$properties[LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY] = $loopCharacteristics; | ||
$token->setProperty( | ||
LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, | ||
$properties[LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY] | ||
); | ||
return $properties; | ||
} | ||
|
||
/** | ||
* Set Loop Instance property during execution | ||
* | ||
* @param TokenInterface $token | ||
* @param string $key | ||
* @param mixed $value | ||
* | ||
* @return self | ||
*/ | ||
private function setLoopInstanceProperty(TokenInterface $token, $key, $value) | ||
{ | ||
$loopCharacteristics = $token->getProperty(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); | ||
$outerInstance = $loopCharacteristics['sourceToken']; | ||
$ds = $token->getInstance()->getDataStore(); | ||
$data = $ds->getData(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); | ||
$data[$outerInstance] = $data[$outerInstance] ?? []; | ||
$data[$outerInstance][$key] = $value; | ||
$ds->putData(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, $data); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get Loop Instance property during execution | ||
* | ||
* @param TokenInterface $token | ||
* @param string $key | ||
* @param mixed $defaultValue | ||
* | ||
* @return mixed | ||
*/ | ||
private function getLoopInstanceProperty(TokenInterface $token, $key, $defaultValue = null) | ||
{ | ||
$loopCharacteristics = $token->getProperty(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); | ||
$outerInstance = $loopCharacteristics['sourceToken']; | ||
$ds = $token->getInstance()->getDataStore(); | ||
$data = $ds->getData(LoopCharacteristicsInterface::BPMN_LOOP_INSTANCE_PROPERTY, []); | ||
$data[$outerInstance] = $data[$outerInstance] ?? []; | ||
return $data[$outerInstance][$key] ?? $defaultValue; | ||
} | ||
} |
Oops, something went wrong.