From 1e40081927550669997b1b2990d7bc9269ad74f5 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 4 Feb 2020 14:29:08 -0400 Subject: [PATCH 1/3] Add reference to ownerDocument --- src/ProcessMaker/Nayra/Bpmn/BaseTrait.php | 32 ++++++++++++++++++- .../Nayra/Contracts/Bpmn/EntityInterface.php | 15 ++++++++- .../Contracts/Engine/EngineInterface.php | 18 ++--------- src/ProcessMaker/Nayra/Engine/EngineTrait.php | 26 ++------------- .../Nayra/Storage/BpmnElement.php | 1 + .../Engine/LoadExecutionInstancesTest.php | 20 ++++-------- 6 files changed, 57 insertions(+), 55 deletions(-) diff --git a/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php b/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php index 3723cbcd..ca0acdde 100755 --- a/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php +++ b/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php @@ -19,10 +19,17 @@ trait BaseTrait /** * Factory used to build this element. * - * @var StorageInterface $factory + * @var RepositoryInterface $factory */ private $repository; + /** + * BPMN document of this object. + * + * @var StorageInterface $ownerDocument + */ + private $ownerDocument; + /** * BaseTrait constructor. * @@ -72,6 +79,29 @@ public function setRepository(RepositoryInterface $repository) return $this; } + /** + * Get the owner BPMN document of this object. + * + * @return \ProcessMaker\Nayra\Contracts\StorageInterface + */ + public function getOwnerDocument() + { + return $this->ownerDocument; + } + + /** + * Set the owner BPMN document of this object. + * + * @param \ProcessMaker\Nayra\Contracts\StorageInterface $ownerDocument + * + * @return $this + */ + public function setOwnerDocument(StorageInterface $ownerDocument) + { + $this->ownerDocument = $ownerDocument; + return $this; + } + /** * Get properties. * diff --git a/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php b/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php index 5d0494b3..2bcc8752 100755 --- a/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php +++ b/src/ProcessMaker/Nayra/Contracts/Bpmn/EntityInterface.php @@ -2,6 +2,7 @@ namespace ProcessMaker\Nayra\Contracts\Bpmn; +use ProcessMaker\Nayra\Contracts\Repositories\StorageInterface; use ProcessMaker\Nayra\Contracts\RepositoryInterface; /** @@ -56,7 +57,7 @@ public function getProperty($name, $default = null); public function addProperty($name, $value); /** - * @return \ProcessMaker\Nayra\Contracts\Repositories\StorageInterface + * @return \ProcessMaker\Nayra\Contracts\RepositoryInterface */ public function getRepository(); @@ -98,4 +99,16 @@ public function getName(); * @return $this */ public function setName($name); + + /** + * @return \ProcessMaker\Nayra\Contracts\Repositories\StorageInterface + */ + public function getOwnerDocument(); + + /** + * @param StorageInterface $ownerDocument + * + * @return $this + */ + public function setOwnerDocument(StorageInterface $ownerDocument); } diff --git a/src/ProcessMaker/Nayra/Contracts/Engine/EngineInterface.php b/src/ProcessMaker/Nayra/Contracts/Engine/EngineInterface.php index 6c15c54b..05eef9c8 100755 --- a/src/ProcessMaker/Nayra/Contracts/Engine/EngineInterface.php +++ b/src/ProcessMaker/Nayra/Contracts/Engine/EngineInterface.php @@ -86,11 +86,11 @@ public function createExecutionInstance(ProcessInterface $process, DataStoreInte * Load an execution instance from the storage. * * @param string $id - * @param DataStoreInterface $data + * @param StorageInterface $storage * * @return ExecutionInstanceInterface */ - public function loadExecutionInstance($id); + public function loadExecutionInstance($id, StorageInterface $storage); /** * Close all the execution instances. @@ -115,13 +115,6 @@ public function getDataStore(); */ public function setDataStore(DataStoreInterface $dataStore); - /** - * Set the repository storage of the engine. - * - * @param StorageInterface $repository - */ - public function setStorage(StorageInterface $repository); - /** * Get the engine job manager for timer tasks and events. * @@ -171,11 +164,4 @@ public function loadBpmnDocument(BpmnDocumentInterface $document); * @return EngineInterface */ public function loadCollaboration(CollaborationInterface $collaboration); - - /** - * Get the repository storage of the engine. - * - * @return StorageInterface - */ - public function getStorage(); } diff --git a/src/ProcessMaker/Nayra/Engine/EngineTrait.php b/src/ProcessMaker/Nayra/Engine/EngineTrait.php index b3b85963..126b90ec 100755 --- a/src/ProcessMaker/Nayra/Engine/EngineTrait.php +++ b/src/ProcessMaker/Nayra/Engine/EngineTrait.php @@ -45,8 +45,6 @@ trait EngineTrait */ private $dataStore; - private $storage; - protected $jobManager; /** @@ -153,7 +151,7 @@ public function createExecutionInstance(ProcessInterface $process, DataStoreInte * * @return ExecutionInstanceInterface|null */ - public function loadExecutionInstance($id) + public function loadExecutionInstance($id, StorageInterface $storage) { // If exists return the already loaded instance by id foreach($this->executionInstances as $executionInstance) { @@ -163,7 +161,7 @@ public function loadExecutionInstance($id) } // Create and load an instance by id $repository = $this->getRepository()->createExecutionInstanceRepository(); - $executionInstance = $repository->loadExecutionInstanceByUid($id, $this->getStorage()); + $executionInstance = $repository->loadExecutionInstanceByUid($id, $storage); if (!$executionInstance) { return; } @@ -279,26 +277,6 @@ private function registerCatchEvents(ProcessInterface $process) } } - /** - * Get the repository storage of the engine. - * - * @return StorageInterface - */ - public function getStorage() - { - return $this->storage; - } - - /** - * Set the repository storage of the engine. - * - * @param StorageInterface $storage - */ - public function setStorage(StorageInterface $storage) - { - $this->storage = $storage; - } - /** * Get the engine job manager for timer tasks and events. * diff --git a/src/ProcessMaker/Nayra/Storage/BpmnElement.php b/src/ProcessMaker/Nayra/Storage/BpmnElement.php index 2fc2d603..63aff08e 100644 --- a/src/ProcessMaker/Nayra/Storage/BpmnElement.php +++ b/src/ProcessMaker/Nayra/Storage/BpmnElement.php @@ -59,6 +59,7 @@ public function getBpmnElementInstance($owner = null) } } else { $bpmnElement = $this->ownerDocument->getFactory()->create($classInterface); + $bpmnElement->setOwnerDocument($this->ownerDocument); $id ? $this->ownerDocument->indexBpmnElement($id, $bpmnElement) : null; $bpmnElement->setRepository($this->ownerDocument->getFactory()); if ($bpmnElement instanceof CallableElementInterface) { diff --git a/tests/Feature/Engine/LoadExecutionInstancesTest.php b/tests/Feature/Engine/LoadExecutionInstancesTest.php index 881a11ff..c81a1393 100644 --- a/tests/Feature/Engine/LoadExecutionInstancesTest.php +++ b/tests/Feature/Engine/LoadExecutionInstancesTest.php @@ -127,14 +127,13 @@ public function testLoadExecutionInstanceWithOneToken() $bpmnRepository->setEngine($this->engine); $bpmnRepository->setFactory($this->repository); $this->engine->setRepository($this->repository); - $this->engine->setStorage($bpmnRepository); $bpmnRepository->load(__DIR__ . '/files/LoadTokens.bpmn'); //Set test data to load the sequential process $this->prepareSequentialProcess($bpmnRepository); //Load the execution instance - $instance = $this->engine->loadExecutionInstance('executionInstanceId'); + $instance = $this->engine->loadExecutionInstance('executionInstanceId', $bpmnRepository); //Get References by id $secondActivity = $bpmnRepository->getScriptTask('second'); @@ -166,14 +165,13 @@ public function testLoadExecutionInstanceWithMultipleTokens() $bpmnRepository->setEngine($this->engine); $bpmnRepository->setFactory($this->repository); $this->engine->setRepository($this->repository); - $this->engine->setStorage($bpmnRepository); $bpmnRepository->load(__DIR__ . '/files/LoadTokens.bpmn'); //Set test data to load the sequential process $this->prepareParallelProcess($bpmnRepository); //Load the execution instance - $instance = $this->engine->loadExecutionInstance('otherExecutionInstanceId'); + $instance = $this->engine->loadExecutionInstance('otherExecutionInstanceId', $bpmnRepository); //Get References by id $secondActivity = $bpmnRepository->getScriptTask('task2'); @@ -220,14 +218,13 @@ public function testLoadExecutionInstanceWithMultipleTokensStates() $bpmnRepository->setEngine($this->engine); $bpmnRepository->setFactory($this->repository); $this->engine->setRepository($this->repository); - $this->engine->setStorage($bpmnRepository); $bpmnRepository->load(__DIR__ . '/files/LoadTokens.bpmn'); //Set test data to load the sequential process $this->prepareParallelProcessWithActivityCompleted($bpmnRepository); //Load the execution instance - $instance = $this->engine->loadExecutionInstance('otherExecutionInstanceId'); + $instance = $this->engine->loadExecutionInstance('otherExecutionInstanceId', $bpmnRepository); //Get References by id $secondActivity = $bpmnRepository->getScriptTask('task2'); @@ -267,14 +264,13 @@ public function testLoadExecutionInstanceWithMultipleTokensFallingState() $bpmnRepository = new BpmnDocument(); $bpmnRepository->setEngine($this->engine); $bpmnRepository->setFactory($this->repository); - $this->engine->setStorage($bpmnRepository); $bpmnRepository->load(__DIR__ . '/files/LoadTokens.bpmn'); //Set test data to load the sequential process $this->prepareParallelProcessWithException($bpmnRepository); //Load the execution instance - $instance = $this->engine->loadExecutionInstance('otherExecutionInstanceId'); + $instance = $this->engine->loadExecutionInstance('otherExecutionInstanceId', $bpmnRepository); //Get References by id $thirdActivity = $bpmnRepository->getActivity('task3'); @@ -294,11 +290,10 @@ public function testLoadNonExistingInstance() $bpmnRepository = new BpmnDocument(); $bpmnRepository->setEngine($this->engine); $bpmnRepository->setFactory($this->repository); - $this->engine->setStorage($bpmnRepository); $bpmnRepository->load(__DIR__ . '/files/LoadTokens.bpmn'); //Load the execution instance - $instance = $this->engine->loadExecutionInstance('nonExistingInstance'); + $instance = $this->engine->loadExecutionInstance('nonExistingInstance', $bpmnRepository); //Assertion: The returned value must be null $this->assertNull($instance); @@ -315,15 +310,14 @@ public function testLoadTheSameExistingInstanceTwice() $bpmnRepository->setEngine($this->engine); $bpmnRepository->setFactory($this->repository); $this->engine->setRepository($this->repository); - $this->engine->setStorage($bpmnRepository); $bpmnRepository->load(__DIR__ . '/files/LoadTokens.bpmn'); //Set test data to load the sequential process $this->prepareSequentialProcess($bpmnRepository); //Load the execution instance twice - $instance1 = $this->engine->loadExecutionInstance('executionInstanceId'); - $instance2 = $this->engine->loadExecutionInstance('executionInstanceId'); + $instance1 = $this->engine->loadExecutionInstance('executionInstanceId', $bpmnRepository); + $instance2 = $this->engine->loadExecutionInstance('executionInstanceId', $bpmnRepository); //Assertion: Both variables point to the same instance $this->assertEquals($instance1, $instance2); From 6d8554761482dcc39b3b09d61c454735b7e2e01e Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 4 Feb 2020 14:36:19 -0400 Subject: [PATCH 2/3] Method documentation correction --- src/ProcessMaker/Nayra/Bpmn/BaseTrait.php | 2 +- src/ProcessMaker/Nayra/Engine/EngineTrait.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php b/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php index ca0acdde..39152699 100755 --- a/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php +++ b/src/ProcessMaker/Nayra/Bpmn/BaseTrait.php @@ -92,7 +92,7 @@ public function getOwnerDocument() /** * Set the owner BPMN document of this object. * - * @param \ProcessMaker\Nayra\Contracts\StorageInterface $ownerDocument + * @param \ProcessMaker\Nayra\Contracts\Repositories\StorageInterface $ownerDocument * * @return $this */ diff --git a/src/ProcessMaker/Nayra/Engine/EngineTrait.php b/src/ProcessMaker/Nayra/Engine/EngineTrait.php index 126b90ec..924d9337 100755 --- a/src/ProcessMaker/Nayra/Engine/EngineTrait.php +++ b/src/ProcessMaker/Nayra/Engine/EngineTrait.php @@ -147,7 +147,7 @@ public function createExecutionInstance(ProcessInterface $process, DataStoreInte * Load an execution instance from the storage. * * @param string $id - * @param DataStoreInterface $data + * @param StorageInterface $storage * * @return ExecutionInstanceInterface|null */ From 138f86402cb48068f219720041c2bda6bdbefc6a Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 4 Feb 2020 14:46:42 -0400 Subject: [PATCH 3/3] Complete test to refer to the owner document --- tests/Feature/Engine/LoadFromBPMNFileTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Feature/Engine/LoadFromBPMNFileTest.php b/tests/Feature/Engine/LoadFromBPMNFileTest.php index a2f7739c..ac99d41e 100644 --- a/tests/Feature/Engine/LoadFromBPMNFileTest.php +++ b/tests/Feature/Engine/LoadFromBPMNFileTest.php @@ -77,6 +77,13 @@ public function testParallelGateway() $activityB = $bpmnRepository->getScriptTask('ScriptTask_2'); $endActivity = $bpmnRepository->getScriptTask('end'); + //Assertion: Check reference to BpmnDocument + $this->assertEquals($bpmnRepository, $start->getOwnerDocument()); + $this->assertEquals($bpmnRepository, $startActivity->getOwnerDocument()); + $this->assertEquals($bpmnRepository, $activityA->getOwnerDocument()); + $this->assertEquals($bpmnRepository, $activityB->getOwnerDocument()); + $this->assertEquals($bpmnRepository, $endActivity->getOwnerDocument()); + //Start the process $start->start($instance); $this->engine->runToNextState();