Repository: ProcessMaker/nayra (php)

Issue:
Missing declaration of methods for token persistence in Activity states

Pull request description:
Add declaration of methods for token persistence in Activity states. Resolves #100

Patch:
diff --git a/src/ProcessMaker/Nayra/Bpmn/ActivityTrait.php b/src/ProcessMaker/Nayra/Bpmn/ActivityTrait.php
index 65c65bc..beb487c 100755
--- a/src/ProcessMaker/Nayra/Bpmn/ActivityTrait.php
+++ b/src/ProcessMaker/Nayra/Bpmn/ActivityTrait.php
@@ -88,6 +88,9 @@ trait ActivityTrait
         $this->activeState->attachEvent(
             StateInterface::EVENT_TOKEN_ARRIVED,
             function (TokenInterface $token) {
+                $this->getRepository()
+                    ->getTokenRepository()
+                    ->persistActivityActivated($this, $token);
                 $this->notifyEvent(ActivityInterface::EVENT_ACTIVITY_ACTIVATED, $this, $token);
 
             }
@@ -95,6 +98,9 @@ trait ActivityTrait
         $this->failingState->attachEvent(
             StateInterface::EVENT_TOKEN_ARRIVED,
             function (TokenInterface $token) {
+                $this->getRepository()
+                    ->getTokenRepository()
+                    ->persistActivityException($this, $token);
                 $this->notifyEvent(ActivityInterface::EVENT_ACTIVITY_EXCEPTION, $this, $token);
 
             }
@@ -102,6 +108,9 @@ trait ActivityTrait
         $this->closedState->attachEvent(
             StateInterface::EVENT_TOKEN_ARRIVED,
             function (TokenInterface $token) {
+                $this->getRepository()
+                    ->getTokenRepository()
+                    ->persistActivityCompleted($this, $token);
                 $this->notifyEvent(ActivityInterface::EVENT_ACTIVITY_COMPLETED, $this, $token);
 
             }
@@ -139,6 +148,9 @@ trait ActivityTrait
             StateInterface::EVENT_TOKEN_CONSUMED,
             function (TokenInterface $token) {
                 $token->setStatus(ActivityInterface::TOKEN_STATE_CLOSED);
+                $this->getRepository()
+                    ->getTokenRepository()
+                    ->persistActivityClosed($this, $token);
                 $this->notifyEvent(ActivityInterface::EVENT_ACTIVITY_CLOSED, $this, $token);
 
             }
diff --git a/src/ProcessMaker/Nayra/Contracts/Repositories/TokenRepositoryInterface.php b/src/ProcessMaker/Nayra/Contracts/Repositories/TokenRepositoryInterface.php
index 62b030d..e452ed3 100755
--- a/src/ProcessMaker/Nayra/Contracts/Repositories/TokenRepositoryInterface.php
+++ b/src/ProcessMaker/Nayra/Contracts/Repositories/TokenRepositoryInterface.php
@@ -2,6 +2,7 @@
 
 namespace ProcessMaker\Nayra\Contracts\Repositories;
 
+use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface;
@@ -40,6 +41,46 @@ interface TokenRepositoryInterface
      */
     public function store(TokenInterface $token, $saveChildElements = false);
 
+    /**
+     * Persists instance and token data when a token arrives to an activity
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityActivated(ActivityInterface $activity, TokenInterface $token);
+
+    /**
+     * Persists instance and token data when a token within an activity change to error state
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityException(ActivityInterface $activity, TokenInterface $token);
+
+    /**
+     * Persists instance and token data when a token is completed within an activity
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityCompleted(ActivityInterface $activity, TokenInterface $token);
+
+    /**
+     * Persists instance and token data when a token is closed by an activity
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityClosed(ActivityInterface $activity, TokenInterface $token);
+
     /**
      * Persists instance and token data when a token arrives in a throw event
      *


Test patch:
diff --git a/tests/ProcessMaker/Test/Models/TokenRepository.php b/tests/ProcessMaker/Test/Models/TokenRepository.php
index 840fce8..21b78d9 100755
--- a/tests/ProcessMaker/Test/Models/TokenRepository.php
+++ b/tests/ProcessMaker/Test/Models/TokenRepository.php
@@ -2,6 +2,7 @@
 
 namespace ProcessMaker\Test\Models;
 
+use ProcessMaker\Nayra\Contracts\Bpmn\ActivityInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\CatchEventInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\GatewayInterface;
 use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface;
@@ -53,6 +54,58 @@ class TokenRepository implements TokenRepositoryInterface
 
     }
 
+    /**
+     * Persists instance and token data when a token arrives to an activity
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityActivated(ActivityInterface $activity, TokenInterface $token)
+    {
+        
+    }
+
+    /**
+     * Persists instance and token data when a token within an activity change to error state
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityException(ActivityInterface $activity, TokenInterface $token)
+    {
+        
+    }
+
+    /**
+     * Persists instance and token data when a token is completed within an activity
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityCompleted(ActivityInterface $activity, TokenInterface $token)
+    {
+        
+    }
+
+    /**
+     * Persists instance and token data when a token is closed by an activity
+     *
+     * @param ActivityInterface $activity
+     * @param TokenInterface $token
+     *
+     * @return mixed
+     */
+    public function persistActivityClosed(ActivityInterface $activity, TokenInterface $token)
+    {
+        
+    }
+
     public function getPersistCalls()
     {
         return $this->persistCalls;