Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
85ddb65
FOUR-8841 Improve start and complete events using the existing main c…
julceslauhub Jun 7, 2023
50cc1cd
Merge branch 'FOUR-8177' into FOUR-8841
caleeli Jun 12, 2023
ee3732c
Refactor Persistance Handler
caleeli Jun 12, 2023
a1e87fa
Install Message Queue Extension dependency
caleeli Jun 13, 2023
8698988
FOUR-8841 Improve start and complete events using the existing main c…
julceslauhub Jun 13, 2023
2fe1acf
Merge pull request #4861 from ProcessMaker/FOUR-8841
caleeli Jun 13, 2023
e9fc5f4
Fix DDL tests with transactions (Mysql)
caleeli Jun 15, 2023
1473c0e
Use stored data table to increase the performance of the search
caleeli Jun 16, 2023
313da6a
FOUR-8558 Refactor Trigger Intermediate Event functions to use Nayra …
julceslauhub Jun 16, 2023
d3b7d9d
Merge pull request #4887 from ProcessMaker/FOUR-8558
caleeli Jun 16, 2023
1067af4
Remove unused class
caleeli Jun 16, 2023
f688df9
Merge remote-tracking branch 'origin/develop' into FOUR-8177
caleeli Jun 16, 2023
229eb89
FOUR-8555 Refactor runScriptTask function to use Nayra BPMN engine
julceslauhub Jun 20, 2023
30f181b
Add environment variables to script tasks
caleeli Jun 20, 2023
1129531
Merge pull request #4904 from ProcessMaker/FOUR-8555
caleeli Jun 20, 2023
91e6b38
Merge pull request #4886 from ProcessMaker/FOUR-8600
caleeli Jun 21, 2023
139b1ec
Update query to check if the column 'asset_type' exists
sanjacornelius Jun 16, 2023
3707534
Update request when running
caleeli Jun 21, 2023
151cc6d
Validate data store table is not empty
caleeli Jun 21, 2023
df5ed39
Merge remote-tracking branch 'origin/develop' into FOUR-8177
caleeli Jun 22, 2023
d9b6afc
Merge remote-tracking branch 'origin/develop' into FOUR-8177-IT4
caleeli Jun 23, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ public function index(Request $request, $getTotal = false, User $user = null)
if (!empty($filter)) {
$query->filter($filter);
}


$query->nonSystem();

$pmql = $request->input('pmql', '');
if (!empty($pmql)) {
try {
$query->getModel()->useDataStoreTable($query, $request->input('data_store_table', ''), $request->input('data_store_columns', []));
$query->pmql($pmql);
} catch (SyntaxError $e) {
return response(['message' => __('Your PMQL contains invalid syntax.')], 400);
} catch (PmqlMethodException $e) {
return response(['message' => $e->getMessage(), 'field' => $e->getField()], 400);
}
}

$query->nonSystem();

try {
if ($getTotal === true) {
return $query->count();
Expand Down
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
200 changes: 168 additions & 32 deletions ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use ProcessMaker\Contracts\WorkflowManagerInterface;
use ProcessMaker\Facades\MessageBrokerService;
use ProcessMaker\GenerateAccessToken;
use ProcessMaker\Models\EnvironmentVariable;
use ProcessMaker\Models\Process as Definitions;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\User;
use ProcessMaker\Nayra\Contracts\Bpmn\ScriptTaskInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\StartEventInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
Expand All @@ -17,6 +22,8 @@ class WorkflowManagerRabbitMq extends WorkflowManagerDefault implements Workflow
const ACTION_START_PROCESS = 'START_PROCESS';

const ACTION_COMPLETE_TASK = 'COMPLETE_TASK';
const ACTION_TRIGGER_INTERMEDIATE_EVENT = 'TRIGGER_INTERMEDIATE_EVENT';
const ACTION_RUN_SCRIPT = 'RUN_SCRIPT';

/**
* Trigger a start event and return the process request instance.
Expand Down Expand Up @@ -49,8 +56,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 @@ -60,25 +67,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 @@ -100,10 +102,109 @@ 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,
],
]);
}

/**
* Complete a catch event.
*
* @param Definitions $definitions
* @param ExecutionInstanceInterface $instance
* @param TokenInterface $token
* @param array $data
*
* @return void
*/
public function completeCatchEvent(Definitions $definitions, ExecutionInstanceInterface $instance, TokenInterface $token, array $data)
{
// Validate data
$element = $token->getDefinition(true);
$this->validateData($data, $definitions, $element);

// 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_TRIGGER_INTERMEDIATE_EVENT,
'params' => [
'request_id' => $token->process_request_id,
'token_id' => $token->uuid,
'element_id' => $token->element_id,
'data' => $data,
],
'state' => $state,
'session' => [
'user_id' => $userId,
],
]);
}

/**
* Run a script task.
*
* @param ScriptTaskInterface $scriptTask
* @param TokenInterface $token
*/
public function runScripTask(ScriptTaskInterface $scriptTask, TokenInterface $token)
{
// Log execution
Log::info('Dispatch a script task: ' . $scriptTask->getId() . ' #' . $token->getId());

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

// Dispatch complete task action
$this->dispatchAction([
'bpmn' => $version->getKey(),
'action' => self::ACTION_RUN_SCRIPT,
'params' => [
'request_id' => $token->process_request_id,
'token_id' => $token->uuid,
'element_id' => $token->element_id,
'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 @@ -113,27 +214,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 All @@ -150,15 +240,61 @@ private function getCurrentUserId(): ? int
return $webGuardId ?? $apiGuardId;
}

/**
* Get the ID of the currently authenticated user.
*
* @return int|null
*/
private function getCurrentUser(): ? User
{
// Get the id from the current user
$webGuard = Auth::user();
$apiGuard = Auth::guard('api')->user();

return $webGuard ?: $apiGuard;
}

/**
* Send payload
*
* @param array $action
*/
private function dispatchAction(array $action): void
{
// add environment variables to session
$environmentVariables = $this->getEnvironmentVariables();
$action['session']['env'] = $environmentVariables;
$subject = 'requests';
$thread = $action['collaboration_id'] ?? 0;
MessageBrokerService::sendMessage($subject, $thread, $action);
}

/**
* Get the environment variables.
*
* @return array
*/
private function getEnvironmentVariables()
{
$variablesParameter = [];
EnvironmentVariable::chunk(50, function ($variables) use (&$variablesParameter) {
foreach ($variables as $variable) {
$variablesParameter[$variable['name']] = $variable['value'];
}
});

// Add the url to the host
$variablesParameter['HOST_URL'] = config('app.docker_host_url');

$user = $this->getCurrentUser();
if ($user) {
$token = new GenerateAccessToken($user);
$environmentVariables['API_TOKEN'] = $token->getToken();
$environmentVariables['API_HOST'] = config('app.url') . '/api/1.0';
$environmentVariables['APP_URL'] = config('app.url');
$environmentVariables['API_SSL_VERIFY'] = (config('app.api_ssl_verify') ? '1' : '0');
}

return $variablesParameter;
}
}
9 changes: 5 additions & 4 deletions ProcessMaker/Nayra/MessageBrokers/ServiceKafka.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace ProcessMaker\Nayra\MessageBrokers;

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

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 @@ -124,8 +124,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