Skip to content

Commit

Permalink
Merge pull request #185 from ProcessMaker/184-fix-task-with-two-or-mo…
Browse files Browse the repository at this point in the history
…re-outgoing-flows

Resolves #184 Fix task with two or more outgoing flows
  • Loading branch information
danloa authored Oct 2, 2020
2 parents 405940e + c4d3b56 commit 170e2b0
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 37 deletions.
14 changes: 8 additions & 6 deletions src/ProcessMaker/Nayra/Bpmn/ActivityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function buildTransitions(RepositoryInterface $factory)
$this->exceptionTransition = new ExceptionTransition($this, true);
$this->closeExceptionTransition = new CloseExceptionTransition($this, true);
$this->completeExceptionTransition = new CompleteExceptionTransition($this, true);
$this->transition = new Transition($this, true);
$this->transition = new Transition($this, false);
$this->closedState = new State($this, ActivityInterface::TOKEN_STATE_COMPLETED);

$this->activeState->connectTo($this->exceptionTransition);
Expand Down Expand Up @@ -155,7 +155,7 @@ function ($transition, $tokens) {
*/
public function getInputPlace(FlowInterface $targetFlow = null)
{
$ready = new State($this);
$ready = new State($this, 'INCOMING');
$transition = new Transition($this, false);
$ready->connectTo($transition);
$transition->connectTo($this->activeState);
Expand All @@ -176,10 +176,12 @@ protected function buildConnectionTo(FlowInterface $targetFlow)
$target = $targetFlow->getTarget();
$place = $target->getInputPlace($targetFlow);
$this->transition->connectTo($place);
$place->attachEvent(
StateInterface::EVENT_TOKEN_CONSUMED,
function (TokenInterface $token) {
$token->setStatus(ActivityInterface::TOKEN_STATE_CLOSED);
$this->transition->attachEvent(
TransitionInterface::EVENT_AFTER_CONSUME,
function (TransitionInterface $transition, Collection $consumedTokens) {
foreach ($consumedTokens as $token) {
$token->setStatus(ActivityInterface::TOKEN_STATE_CLOSED);
}
$this->getRepository()
->getTokenRepository()
->persistActivityClosed($this, $token);
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Engine/EventBasedGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function testDeferredChoiceChoiceOne()
EventInterface::EVENT_EVENT_TRIGGERED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
Expand Down Expand Up @@ -109,6 +109,7 @@ public function testDeferredChoiceChoiceOne()
$this->completeTask($approve, $manager);
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateCatchEventInterface::EVENT_CATCH_MESSAGE_CATCH,
ThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,
IntermediateCatchEventInterface::EVENT_CATCH_TOKEN_CONSUMED,
Expand All @@ -118,7 +119,6 @@ public function testDeferredChoiceChoiceOne()
IntermediateCatchEventInterface::EVENT_CATCH_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
ThrowEventInterface::EVENT_THROW_TOKEN_PASSED,
ThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,
ThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down Expand Up @@ -173,10 +173,10 @@ public function testDeferredChoiceChoiceTwo()
EventInterface::EVENT_EVENT_TRIGGERED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
Expand Down Expand Up @@ -210,6 +210,7 @@ public function testDeferredChoiceChoiceTwo()

$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateCatchEventInterface::EVENT_CATCH_MESSAGE_CATCH,
ThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,
IntermediateCatchEventInterface::EVENT_CATCH_TOKEN_CONSUMED,
Expand All @@ -219,7 +220,6 @@ public function testDeferredChoiceChoiceTwo()
IntermediateCatchEventInterface::EVENT_CATCH_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
ThrowEventInterface::EVENT_THROW_TOKEN_PASSED,
ThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,
ThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Engine/ExclusiveGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ public function testParallelDivergingExclusiveConverging()
//Assertion: Verify the triggered engine events. The activity is closed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
TransitionInterface::EVENT_CONDITIONED_TRANSITION,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
Expand All @@ -364,10 +364,10 @@ public function testParallelDivergingExclusiveConverging()
//Assertion: Verify the triggered engine events. The activity B is closed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
TransitionInterface::EVENT_CONDITIONED_TRANSITION,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Engine/InclusiveGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public function testInclusiveGatewayAllPaths()
//Assertion: Verify the triggered engine events. The activity is closed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
]);

Expand All @@ -174,12 +175,11 @@ public function testInclusiveGatewayAllPaths()
//Assertion: Verify the triggered engine events. The activity is closed and process is ended.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
EndEventInterface::EVENT_THROW_TOKEN_ARRIVES,
EndEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down Expand Up @@ -231,10 +231,10 @@ public function testInclusiveGatewayOnlyB()
//Assertion: Verify the triggered engine events. The activity is closed and process is ended.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
EndEventInterface::EVENT_THROW_TOKEN_ARRIVES,
EndEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Engine/IntermediateMessageEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public function testIntermediateEvent()
//Assertion: The throwing process must advances to activity B an the catching process to activity D
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateCatchEventInterface::EVENT_CATCH_MESSAGE_CATCH,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,

Expand All @@ -313,7 +314,6 @@ public function testIntermediateEvent()
EventInterface::EVENT_EVENT_TRIGGERED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED
]);
Expand Down Expand Up @@ -405,6 +405,7 @@ public function testSignalEvent()
//Assertion: The throwing process must advances to activity B an the catching process to activity D
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateCatchEventInterface::EVENT_CATCH_MESSAGE_CATCH,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,

Expand All @@ -415,7 +416,6 @@ public function testSignalEvent()
EventInterface::EVENT_EVENT_TRIGGERED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED
]);
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Engine/LoadExecutionInstancesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ public function testLoadExecutionInstanceWithMultipleTokens()
//Assertion: Second and third activity are completed and closed, the gateway is activate, and the process ends.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
EndEventInterface::EVENT_THROW_TOKEN_ARRIVES,
EndEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down Expand Up @@ -237,14 +237,14 @@ public function testLoadExecutionInstanceWithMultipleTokensStates()

//Assertion: Second activity is closed and the third activity are completed, then closed, the join gateway is activiate, and finally the process is completed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
EndEventInterface::EVENT_THROW_TOKEN_ARRIVES,
EndEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/Engine/LoadFromBPMNFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ public function testParallelGateway()
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ScriptTaskInterface::EVENT_SCRIPT_TASK_ACTIVATED,
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
Expand All @@ -129,6 +129,7 @@ public function testParallelGateway()
//Assertion: Verify the triggered engine events. The activity is closed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
]);

Expand All @@ -140,12 +141,11 @@ public function testParallelGateway()
//Assertion: Verify the triggered engine events. The activity B is closed and process is ended.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ScriptTaskInterface::EVENT_SCRIPT_TASK_ACTIVATED,
Expand Down Expand Up @@ -222,10 +222,10 @@ public function testInclusiveGatewayWithDefault()
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ScriptTaskInterface::EVENT_SCRIPT_TASK_ACTIVATED,
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
Expand All @@ -242,6 +242,7 @@ public function testInclusiveGatewayWithDefault()
//Assertion: Verify the triggered engine events. The activity is closed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
]);

Expand All @@ -253,12 +254,11 @@ public function testInclusiveGatewayWithDefault()
//Assertion: Verify the triggered engine events. The activity is closed and process is ended.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
ActivityInterface::EVENT_ACTIVITY_ACTIVATED,
ScriptTaskInterface::EVENT_SCRIPT_TASK_ACTIVATED,
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Engine/MessageStartEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ public function testMessageStartEvent()
//Assertion: The process1 activity should be finished and a new instance of the second process must be created
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
ProcessInterface::EVENT_PROCESS_INSTANCE_CREATED,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_ARRIVES,

//events triggered when the catching event runs
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
IntermediateThrowEventInterface::EVENT_THROW_TOKEN_PASSED,

//Actibity activated in the first process
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Engine/NayraModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function testProcessWithInclusiveGateway()
//Assertion: Verify the triggered engine events. The activity is closed.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
]);

Expand All @@ -119,12 +120,11 @@ public function testProcessWithInclusiveGateway()
//Assertion: Verify the triggered engine events. The activity is closed and process is ended.
$this->assertEvents([
ActivityInterface::EVENT_ACTIVITY_COMPLETED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_ARRIVES,
GatewayInterface::EVENT_GATEWAY_ACTIVATED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_CONSUMED,
ActivityInterface::EVENT_ACTIVITY_CLOSED,
GatewayInterface::EVENT_GATEWAY_TOKEN_PASSED,
EndEventInterface::EVENT_THROW_TOKEN_ARRIVES,
EndEventInterface::EVENT_THROW_TOKEN_CONSUMED,
Expand Down
Loading

0 comments on commit 170e2b0

Please sign in to comment.