Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ProcessMaker/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class Kernel extends HttpKernel
// API Middleware is defined with routeMiddleware below.
// See routes/api.php
],
'engine' => [
'auth:api',
'setlocale',
'bindings',
'sanitize',
],
];

/**
Expand Down
77 changes: 44 additions & 33 deletions ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function triggerStartEvent(Definitions $definitions, StartEventInterface
'signal_events' => [],
]);

// Create triggered
// TO DO:
// Serialize instance
$state = $this->serializeState($request);

// Dispatch start process action
$this->dispatchAction([
Expand All @@ -59,25 +59,20 @@ public function triggerStartEvent(Definitions $definitions, StartEventInterface
'instance_id' => $request->uuid,
'request_id' => $request->getKey(),
'element_id' => $event->getId(),
'data'=> $data,
'data' => $data,
'extra_properties' => [
'user_id' => $userId,
'process_id' => $definitions->id,
'request_id' => $request->getKey(),
],
],
'state' => [
'requests' => [
$request->uuid => [
'id' => $request->uuid,
'callable_id' => $request->callable_id,
'data' => $request->data,
'tokens' => [],
]
],
'state' => $state,
'session' => [
'user_id' => $userId,
],
]);

//Return the instance created
return $request;
}

Expand All @@ -99,10 +94,37 @@ public function completeTask(Definitions $definitions, ExecutionInstanceInterfac

// Get complementary information
$version = $definitions->getLatestVersion();
$userId = $this->getCurrentUserId();
$state = $this->serializeState($instance);

// Dispatch complete task action
$this->dispatchAction([
'bpmn' => $version->getKey(),
'action' => self::ACTION_COMPLETE_TASK,
'params' => [
'request_id' => $token->process_request_id,
'token_id' => $token->uuid,
'element_id' => $token->element_id,
'data' => $data,
],
'state' => $state,
'session' => [
'user_id' => $userId,
],
]);
}

/**
* Build a state object
*
* @param ProcessRequest $instance
* @return array
*/
private function serializeState(ProcessRequest $instance)
{
// Get open tokens
$tokensRows = [];
$tokens = $instance->tokens()->where('status', '!=', 'CLOSED')->get();
$tokens = $instance->tokens()->where('status', '!=', 'CLOSED')->where('status', '!=', 'TRIGGERED')->get();
foreach ($tokens as $token) {
$tokensRows[] = array_merge($token->token_properties ?: [], [
'id' => $token->uuid,
Expand All @@ -112,27 +134,16 @@ public function completeTask(Definitions $definitions, ExecutionInstanceInterfac
]);
}

// Dispatch complete task action
$this->dispatchAction([
'bpmn' => $version->getKey(),
'action' => self::ACTION_COMPLETE_TASK,
'params' => [
'request_id' => $token->process_request_id,
'token_id' => $token->uuid,
'element_id' => $token->element_id,
'data'=> $data,
],
'state' => [
'requests' => [
[
'id' => $instance->uuid,
'callable_id' => $instance->callable_id,
'data' => $instance->data,
'tokens' => $tokensRows,
]
return [
'requests' => [
[
'id' => $instance->uuid,
'callable_id' => $instance->callable_id,
'data' => $instance->data,
'tokens' => $tokensRows,
],
]
]);
],
];
}

/**
Expand Down
9 changes: 5 additions & 4 deletions ProcessMaker/Nayra/MessageBrokers/ServiceKafka.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Junges\Kafka\Facades\Kafka;
use Junges\Kafka\Contracts\KafkaConsumerMessage;
use ProcessMaker\Nayra\Repositories\EntityRepositoryFactory;
use ProcessMaker\Nayra\Repositories\PersistenceHandler;

class ServiceKafka
{
Expand Down Expand Up @@ -65,11 +65,11 @@ public function worker()
// Get transactions
$transactions = $message->getBody();

// Store transsactions
// Store transactions
$this->storeData($transactions);
})->build();

// Consume incomming messages
// Consume incoming messages
$consumer->consume();
}

Expand All @@ -80,8 +80,9 @@ public function worker()
*/
private function storeData(array $transactions)
{
$handler = new PersistenceHandler();
foreach ($transactions as $transaction) {
EntityRepositoryFactory::createRepository($transaction['entity'])->save($transaction);
$handler->save($transaction);
}
}
}
5 changes: 3 additions & 2 deletions ProcessMaker/Nayra/MessageBrokers/ServiceRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use ProcessMaker\Nayra\Repositories\EntityRepositoryFactory;
use ProcessMaker\Nayra\Repositories\PersistenceHandler;

class ServiceRabbitMq
{
Expand Down Expand Up @@ -123,8 +123,9 @@ public function worker(): void
*/
private function storeData(array $transactions): void
{
$handler = new PersistenceHandler();
foreach ($transactions as $transaction) {
EntityRepositoryFactory::createRepository($transaction['entity'])->save($transaction);
$handler->save($transaction);
}
}
}
Loading