From b8bb23c8d53f9f6de93a20511f92582ade42043a Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Mon, 10 Jul 2023 13:00:32 -0400 Subject: [PATCH 1/3] Implement sub processes with nayra service --- ProcessMaker/Console/Commands/Consumer.php | 4 +++- .../Nayra/Managers/WorkflowManagerRabbitMq.php | 10 +++++++++- .../Nayra/Repositories/PersistenceHandler.php | 6 +++++- .../Repositories/PersistenceTokenTrait.php | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ProcessMaker/Console/Commands/Consumer.php b/ProcessMaker/Console/Commands/Consumer.php index 660b2107cb..8adaed13f6 100644 --- a/ProcessMaker/Console/Commands/Consumer.php +++ b/ProcessMaker/Console/Commands/Consumer.php @@ -4,6 +4,7 @@ use Exception; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Log; use ProcessMaker\Facades\MessageBrokerService; class Consumer extends Command @@ -40,7 +41,8 @@ public function handle() try { MessageBrokerService::worker(); } catch (Exception $e) { - $this->warn($e->getMessage()); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); } } } diff --git a/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php b/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php index 53247c6ef6..828b0fe84c 100644 --- a/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php +++ b/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php @@ -480,17 +480,25 @@ private function serializeState(ProcessRequest $instance) $tokensRows = []; $tokens = $request->tokens()->where('status', '!=', 'CLOSED')->where('status', '!=', 'TRIGGERED')->get(); foreach ($tokens as $token) { - $tokensRows[] = array_merge($token->token_properties ?: [], [ + $tokenRow = array_merge($token->token_properties ?: [], [ 'id' => $token->uuid, 'status' => $token->status, 'index' => $token->element_index, 'element_id' => $token->element_id, 'created_at' => $token->created_at->getTimestamp(), ]); + if ($token->subprocess_request_id) { + $subRequest = ProcessRequest::select(['process_version_id', 'uuid']) + ->find($token->subprocess_request_id); + $tokenRow['subprocess_request_id'] = $subRequest->uuid; + $tokenRow['subprocess_request_version'] = $subRequest->process_version_id; + } + $tokensRows[] = $tokenRow; } return [ 'id' => $request->uuid, + 'process_version_id' => $request->process_version_id, 'callable_id' => $request->callable_id, 'collaboration_uuid' => $request->collaboration_uuid, 'data' => $request->data, diff --git a/ProcessMaker/Nayra/Repositories/PersistenceHandler.php b/ProcessMaker/Nayra/Repositories/PersistenceHandler.php index d66b07ded5..b2a247051d 100644 --- a/ProcessMaker/Nayra/Repositories/PersistenceHandler.php +++ b/ProcessMaker/Nayra/Repositories/PersistenceHandler.php @@ -116,6 +116,9 @@ public function save(array $transaction) case 'instance_updated': $this->persistInstanceUpdated($transaction); break; + case 'call_activity_activated': + $this->persistCallActivityActivated($transaction); + break; case 'schedule_date': $this->persistScheduleDate($transaction); break; @@ -139,7 +142,8 @@ public function save(array $transaction) } } catch (Exception $error) { Log::error($error->getMessage()); - if ($transaction['token']) { + Log::error($error->getTraceAsString()); + if (!empty($transaction['token'])) { $token = $this->deserializer->unserializeToken($transaction['token']); $request = $token->getInstance(); if ($request && $request instanceof ProcessRequest) { diff --git a/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php b/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php index c05cc193cb..ba1d4d4c20 100644 --- a/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php +++ b/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php @@ -2,8 +2,12 @@ namespace ProcessMaker\Nayra\Repositories; +use ProcessMaker\Repositories\TokenRepository; + trait PersistenceTokenTrait { + protected TokenRepository $tokenRepository; + /** * Persists instance and token data when a token arrives to an activity * @@ -208,4 +212,17 @@ public function persistEventBasedGatewayActivated(array $transaction) $consumedTokens = $this->deserializer->unserializeTokensCollection($transaction['consumed_tokens']); $this->tokenRepository->persistEventBasedGatewayActivated($gateway, $passedToken, $consumedTokens); } + + /** + * Persists a Call Activity Activated + * + * @param array $transaction + */ + public function persistCallActivityActivated(array $transaction) + { + $token = $this->deserializer->unserializeToken($transaction['token']); + $subprocessInstance = $this->deserializer->unserializeInstance($transaction['subprocess']); + $startId = $transaction['start_id']; + $this->tokenRepository->persistCallActivityActivated($token, $subprocessInstance, $startId); + } } From f971cbd16c45407ed5bd0dc908fe46964cea1928 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 11 Jul 2023 08:46:33 -0400 Subject: [PATCH 2/3] Fix deserialize for CallActivity --- ProcessMaker/Nayra/Repositories/Deserializer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ProcessMaker/Nayra/Repositories/Deserializer.php b/ProcessMaker/Nayra/Repositories/Deserializer.php index 002f7031ad..33b8952336 100644 --- a/ProcessMaker/Nayra/Repositories/Deserializer.php +++ b/ProcessMaker/Nayra/Repositories/Deserializer.php @@ -12,6 +12,7 @@ use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface; use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface; use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface; +use ProcessMaker\Nayra\Contracts\Storage\BpmnDocumentInterface; use ProcessMaker\Repositories\BpmnDocument; use ProcessMaker\Repositories\DefinitionsRepository; use ProcessMaker\Repositories\ExecutionInstanceRepository; @@ -56,7 +57,7 @@ private function findProcessDefinition($modelId): BpmnDocument $version = ProcessVersion::find($modelId); $model = $version->process; - $definition = new BpmnDocument($model); + $definition = app(BpmnDocumentInterface::class, ['process' => $model]); $definition->setFactory($this->factory); $definition->loadXML($version->bpmn); From d4de12b1ecfe1f3aa5625a9c657cf1750041ef00 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Tue, 11 Jul 2023 08:48:18 -0400 Subject: [PATCH 3/3] Get errors from tokens instead of errors property --- ProcessMaker/Models/ProcessRequest.php | 14 ++++++++++++++ ProcessMaker/Models/ProcessRequestToken.php | 2 +- ProcessMaker/Repositories/TokenRepository.php | 3 ++- resources/js/requests/components/RequestErrors.vue | 2 +- resources/views/requests/show.blade.php | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ProcessMaker/Models/ProcessRequest.php b/ProcessMaker/Models/ProcessRequest.php index f963d47589..0a33689a78 100644 --- a/ProcessMaker/Models/ProcessRequest.php +++ b/ProcessMaker/Models/ProcessRequest.php @@ -907,4 +907,18 @@ public function getMedia(string $collectionName = 'default', $filters = []): Col { return \ProcessMaker\Models\Media::getFilesRequest($this); } + + public function getErrors() + { + if ($this->errors) { + return $this->errors; + } + // select tokens with errors + return $this->tokens() + ->select('token_properties->error as message', 'created_at', 'element_name') + ->where('status', '=', ActivityInterface::TOKEN_STATE_FAILING) + ->limit(10) + ->get() + ->toArray(); + } } diff --git a/ProcessMaker/Models/ProcessRequestToken.php b/ProcessMaker/Models/ProcessRequestToken.php index c81a46d41f..bede518863 100644 --- a/ProcessMaker/Models/ProcessRequestToken.php +++ b/ProcessMaker/Models/ProcessRequestToken.php @@ -823,7 +823,7 @@ public function logError(Throwable $error, FlowElementInterface $bpmnElement) public function updateTokenProperties() { - $allowed = ['conditionals', 'loopCharacteristics', 'data']; + $allowed = ['conditionals', 'loopCharacteristics', 'data', 'error']; $this->token_properties = array_filter( $this->getProperties(), function ($key) use ($allowed) { diff --git a/ProcessMaker/Repositories/TokenRepository.php b/ProcessMaker/Repositories/TokenRepository.php index a839075a91..19e693da23 100644 --- a/ProcessMaker/Repositories/TokenRepository.php +++ b/ProcessMaker/Repositories/TokenRepository.php @@ -8,6 +8,7 @@ use ProcessMaker\Models\ProcessCollaboration; use ProcessMaker\Models\ProcessRequest as Instance; use ProcessMaker\Models\ProcessRequestToken as Token; +use ProcessMaker\Models\ProcessRequestToken; use ProcessMaker\Models\User; use ProcessMaker\Nayra\Bpmn\Collection; use ProcessMaker\Nayra\Bpmn\Models\EndEvent; @@ -201,7 +202,7 @@ private function assignTaskUser(ActivityInterface $activity, TokenInterface $tok * Persists instance and token data when a token within an activity change to error state * * @param ActivityInterface $activity - * @param TokenInterface $token + * @param TokenInterface|ProcessRequestToken $token * * @return mixed */ diff --git a/resources/js/requests/components/RequestErrors.vue b/resources/js/requests/components/RequestErrors.vue index db79a66dbb..e060f804a1 100644 --- a/resources/js/requests/components/RequestErrors.vue +++ b/resources/js/requests/components/RequestErrors.vue @@ -63,7 +63,7 @@