chg: [inboxProcessor] Renamed `RequestProcessors` into `InboxProcessors`

pull/59/head
mokaddem 2021-06-18 11:09:19 +02:00
parent ae423bfb68
commit 4080654806
12 changed files with 70 additions and 70 deletions

View File

@ -1,9 +1,9 @@
<?php
use Cake\ORM\TableRegistry;
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php');
class BroodRequestProcessor extends GenericRequestProcessor
class BroodInboxProcessor extends GenericInboxProcessor
{
protected $scope = 'Brood';
protected $action = 'not-specified'; //overriden when extending
@ -22,7 +22,7 @@ class BroodRequestProcessor extends GenericRequestProcessor
}
}
class ToolInterconnectionProcessor extends BroodRequestProcessor implements GenericProcessorActionI {
class ToolInterconnectionProcessor extends BroodInboxProcessor implements GenericProcessorActionI {
public $action = 'ToolInterconnection';
protected $description;

View File

@ -12,13 +12,13 @@ interface GenericProcessorActionI
public function discard($requestID ,$requestData);
}
class GenericRequestProcessor
class GenericInboxProcessor
{
protected $Inbox;
protected $registeredActions = [];
protected $validator;
protected $processingTemplate = '/genericTemplates/confirm';
protected $processingTemplatesDirectory = ROOT . '/libraries/default/RequestProcessors/templates';
protected $processingTemplatesDirectory = ROOT . '/libraries/default/InboxProcessors/templates';
public function __construct($registerActions=false) {
$this->Inbox = TableRegistry::getTableLocator()->get('Inbox');
@ -150,7 +150,7 @@ class GenericRequestProcessor
if ($controller->ParamHandler->isRest()) {
$response = $controller->RestResponse->viewData($processResult, 'json');
} else if ($controller->ParamHandler->isAjax()) {
$response = $controller->RestResponse->ajaxSuccessResponse('RequestProcessor', "{$scope}.{$action}", $processResult['data'], $message);
$response = $controller->RestResponse->ajaxSuccessResponse('InboxProcessor', "{$scope}.{$action}", $processResult['data'], $message);
} else {
$controller->Flash->success($message);
if (!is_null($redirect)) {
@ -164,7 +164,7 @@ class GenericRequestProcessor
if ($controller->ParamHandler->isRest()) {
$response = $controller->RestResponse->viewData($processResult, 'json');
} else if ($controller->ParamHandler->isAjax()) {
$response = $controller->RestResponse->ajaxFailResponse('RequestProcessor', "{$scope}.{$action}", $processResult['data'], $message, $processResult['errors']);
$response = $controller->RestResponse->ajaxFailResponse('InboxProcessor', "{$scope}.{$action}", $processResult['data'], $message, $processResult['errors']);
} else {
$controller->Flash->error($message);
if (!is_null($redirect)) {

View File

@ -3,9 +3,9 @@ use Cake\ORM\TableRegistry;
use Cake\Filesystem\File;
use Cake\Http\Exception\NotFoundException;
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php');
class LocalToolRequestProcessor extends GenericRequestProcessor
class LocalToolInboxProcessor extends GenericInboxProcessor
{
protected $scope = 'LocalTool';
protected $action = 'not-specified'; //overriden when extending
@ -171,7 +171,7 @@ class LocalToolRequestProcessor extends GenericRequestProcessor
}
}
class IncomingConnectionRequestProcessor extends LocalToolRequestProcessor implements GenericProcessorActionI {
class IncomingConnectionRequestProcessor extends LocalToolInboxProcessor implements GenericProcessorActionI {
public $action = 'IncomingConnectionRequest';
protected $description;
@ -283,7 +283,7 @@ class IncomingConnectionRequestProcessor extends LocalToolRequestProcessor imple
}
}
class AcceptedRequestProcessor extends LocalToolRequestProcessor implements GenericProcessorActionI {
class AcceptedRequestProcessor extends LocalToolInboxProcessor implements GenericProcessorActionI {
public $action = 'AcceptedRequest';
protected $description;
@ -356,7 +356,7 @@ class AcceptedRequestProcessor extends LocalToolRequestProcessor implements Gene
}
}
class DeclinedRequestProcessor extends LocalToolRequestProcessor implements GenericProcessorActionI {
class DeclinedRequestProcessor extends LocalToolInboxProcessor implements GenericProcessorActionI {
public $action = 'DeclinedRequest';
protected $description;

View File

@ -1,9 +1,9 @@
<?php
use Cake\ORM\TableRegistry;
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php');
class ProposalRequestProcessor extends GenericRequestProcessor
class ProposalInboxProcessor extends GenericInboxProcessor
{
protected $scope = 'Proposal';
protected $action = 'not-specified'; //overriden when extending
@ -22,7 +22,7 @@ class ProposalRequestProcessor extends GenericRequestProcessor
}
}
class ProposalEditProcessor extends ProposalRequestProcessor implements GenericProcessorActionI {
class ProposalEditProcessor extends ProposalInboxProcessor implements GenericProcessorActionI {
public $action = 'ProposalEdit';
protected $description;

View File

@ -1,9 +1,9 @@
<?php
use Cake\ORM\TableRegistry;
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php');
class SynchronisationRequestProcessor extends GenericRequestProcessor
class SynchronisationInboxProcessor extends GenericInboxProcessor
{
protected $scope = 'Synchronisation';
protected $action = 'not-specified'; //overriden when extending
@ -22,7 +22,7 @@ class SynchronisationRequestProcessor extends GenericRequestProcessor
}
}
class DataExchangeProcessor extends SynchronisationRequestProcessor implements GenericProcessorActionI {
class DataExchangeProcessor extends SynchronisationInboxProcessor implements GenericProcessorActionI {
public $action = 'DataExchange';
protected $description;

View File

@ -1,9 +1,9 @@
<?php
use Cake\ORM\TableRegistry;
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php');
class SCOPE_RequestProcessor extends GenericRequestProcessor
class SCOPE_InboxProcessor extends GenericInboxProcessor
{
protected $scope = '~to-be-defined~';
protected $action = 'not-specified'; //overriden when extending
@ -22,7 +22,7 @@ class SCOPE_RequestProcessor extends GenericRequestProcessor
}
}
class SCOPE_ACTION_Processor extends ProposalRequestProcessor implements GenericProcessorActionI {
class SCOPE_ACTION_Processor extends ProposalInboxProcessor implements GenericProcessorActionI {
public $action = 'ACTION';
protected $description;

View File

@ -1,9 +1,9 @@
<?php
use Cake\ORM\TableRegistry;
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'RequestProcessors' . DS . 'GenericRequestProcessor.php');
require_once(ROOT . DS . 'libraries' . DS . 'default' . DS . 'InboxProcessors' . DS . 'GenericInboxProcessor.php');
class UserRequestProcessor extends GenericRequestProcessor
class UserInboxProcessor extends GenericInboxProcessor
{
protected $scope = 'User';
protected $action = 'not-specified'; //overriden when extending
@ -24,7 +24,7 @@ class UserRequestProcessor extends GenericRequestProcessor
}
}
class RegistrationProcessor extends UserRequestProcessor implements GenericProcessorActionI {
class RegistrationProcessor extends UserInboxProcessor implements GenericProcessorActionI {
public $action = 'Registration';
protected $description;

View File

@ -158,8 +158,8 @@ class BroodsController extends AppController
public function interconnectTools()
{
$this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor');
$processor = $this->requestProcessor->getProcessor('Brood', 'ToolInterconnection');
$this->InboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors');
$processor = $this->InboxProcessors->getProcessor('Brood', 'ToolInterconnection');
$data = [
'origin' => '127.0.0.1',
'comment' => 'Test comment',

View File

@ -61,8 +61,8 @@ class InboxController extends AppController
{
if ($this->request->is('post')) {
$request = $this->Inbox->get($id, ['contain' => ['Users' => ['Individuals' => ['Alignments' => 'Organisations']]]]);
$this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor');
$processor = $this->requestProcessor->getProcessor($request->scope, $request->action);
$this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors');
$processor = $this->inboxProcessors->getProcessor($request->scope, $request->action);
$discardResult = $processor->discard($id, $request);
return $processor->genHTTPReply($this, $discardResult);
}
@ -81,11 +81,11 @@ class InboxController extends AppController
$request = $this->Inbox->get($id, ['contain' => ['Users' => ['Individuals' => ['Alignments' => 'Organisations']]]]);
$scope = $request->scope;
$action = $request->action;
$this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor');
$this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors');
if ($scope == 'LocalTool') {
$processor = $this->requestProcessor->getLocalToolProcessor($action, $request->local_tool_name);
$processor = $this->inboxProcessors->getLocalToolProcessor($action, $request->local_tool_name);
} else {
$processor = $this->requestProcessor->getProcessor($scope, $action);
$processor = $this->inboxProcessors->getProcessor($scope, $action);
}
if ($this->request->is('post')) {
$processResult = $processor->process($id, $this->request->getData(), $request);
@ -98,14 +98,14 @@ class InboxController extends AppController
public function listProcessors()
{
$this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor');
$requestProcessors = $this->requestProcessor->listProcessors();
$this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors');
$processors = $this->inboxProcessors->listProcessors();
if ($this->ParamHandler->isRest()) {
return $this->RestResponse->viewData($requestProcessors, 'json');
return $this->RestResponse->viewData($processors, 'json');
}
$data = [];
foreach ($requestProcessors as $scope => $processors) {
foreach ($processors as $processor) {
foreach ($processors as $scope => $scopedProcessors) {
foreach ($scopedProcessors as $processor) {
$data[] = [
'enabled' => $processor->enabled,
'scope' => $scope,
@ -129,20 +129,20 @@ class InboxController extends AppController
'user_id' => $this->ACL->getUser()['id'],
];
$entryData['data'] = $this->request->getData() ?? [];
$this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor');
$this->inboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors');
if ($scope == 'LocalTool') {
$this->validateLocalToolRequestEntry($entryData);
$entryData['origin'] = $entryData['data']['cerebrateURL'];
$processor = $this->requestProcessor->getLocalToolProcessor($action, $entryData['data']['connectorName']);
$processor = $this->inboxProcessors->getLocalToolProcessor($action, $entryData['data']['connectorName']);
$errors = $this->Inbox->checkUserBelongsToBroodOwnerOrg($this->ACL->getUser(), $entryData);
if (!empty($errors)) {
$message = __('Could not create inbox message');
return $this->RestResponse->ajaxFailResponse(Inflector::singularize($this->Inbox->getAlias()), 'createInboxEntry', [], $message, $errors);
}
} else {
$processor = $this->requestProcessor->getProcessor($scope, $action);
$processor = $this->inboxProcessors->getProcessor($scope, $action);
}
$creationResult = $this->requestProcessor->createInboxEntry($processor, $entryData);
$creationResult = $this->inboxProcessors->createInboxEntry($processor, $entryData);
return $processor->genHTTPReply($this, $creationResult);
}

View File

@ -138,8 +138,8 @@ class UsersController extends AppController
public function register()
{
$this->requestProcessor = TableRegistry::getTableLocator()->get('RequestProcessor');
$processor = $this->requestProcessor->getProcessor('User', 'Registration');
$this->InboxProcessors = TableRegistry::getTableLocator()->get('InboxProcessors');
$processor = $this->InboxProcessors->getProcessor('User', 'Registration');
$data = [
'origin' => '127.0.0.1',
'comment' => 'Hi there!, please create an account',

View File

@ -7,15 +7,15 @@ use Cake\Filesystem\Folder;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\Core\Exception\Exception;
class MissingRequestProcessorException extends Exception
class MissingInboxProcessorException extends Exception
{
protected $_defaultCode = 404;
}
class RequestProcessorTable extends AppTable
class InboxProcessors extends AppTable
{
private $processorsDirectory = ROOT . '/libraries/default/RequestProcessors';
private $requestProcessors;
private $processorsDirectory = ROOT . '/libraries/default/InboxProcessors';
private $inboxProcessors;
private $enabledProcessors = [ // to be defined in config
'Brood' => [
'ToolInterconnection' => false,
@ -40,16 +40,16 @@ class RequestProcessorTable extends AppTable
public function getProcessor($scope, $action=null)
{
if (isset($this->requestProcessors[$scope])) {
if (isset($this->inboxProcessors[$scope])) {
if (is_null($action)) {
return $this->requestProcessors[$scope];
} else if (!empty($this->requestProcessors[$scope]->{$action})) {
return $this->requestProcessors[$scope]->{$action};
return $this->inboxProcessors[$scope];
} else if (!empty($this->inboxProcessors[$scope]->{$action})) {
return $this->inboxProcessors[$scope]->{$action};
} else {
throw new \Exception(__('Processor {0}.{1} not found', $scope, $action));
}
}
throw new MissingRequestProcessorException(__('Processor not found'));
throw new MissingInboxProcessorException(__('Processor not found'));
}
public function getLocalToolProcessor($action, $connectorName)
@ -58,7 +58,7 @@ class RequestProcessorTable extends AppTable
$specificScope = "{$connectorName}LocalTool";
try { // try to get specific processor for module name or fall back to generic local tool processor
$processor = $this->getProcessor($specificScope, $action);
} catch (MissingRequestProcessorException $e) {
} catch (MissingInboxProcessorException $e) {
$processor = $this->getProcessor($scope, $action);
}
return $processor;
@ -67,12 +67,12 @@ class RequestProcessorTable extends AppTable
public function listProcessors($scope=null)
{
if (is_null($scope)) {
return $this->requestProcessors;
return $this->inboxProcessors;
} else {
if (isset($this->requestProcessors[$scope])) {
return $this->requestProcessors[$scope];
if (isset($this->inboxProcessors[$scope])) {
return $this->inboxProcessors[$scope];
} else {
throw new MissingRequestProcessorException(__('Processors for {0} not found', $scope));
throw new MissingInboxProcessorException(__('Processors for {0} not found', $scope));
}
}
}
@ -80,30 +80,30 @@ class RequestProcessorTable extends AppTable
private function loadProcessors()
{
$processorDir = new Folder($this->processorsDirectory);
$processorFiles = $processorDir->find('.*RequestProcessor\.php', true);
$processorFiles = $processorDir->find('.*InboxProcessor\.php', true);
foreach ($processorFiles as $processorFile) {
if ($processorFile == 'GenericRequestProcessor.php') {
if ($processorFile == 'GenericInboxProcessor.php') {
continue;
}
$processorMainClassName = str_replace('.php', '', $processorFile);
$processorMainClassNameShort = str_replace('RequestProcessor.php', '', $processorFile);
$processorMainClassNameShort = str_replace('InboxProcessor.php', '', $processorFile);
$processorMainClass = $this->getProcessorClass($processorDir->pwd() . DS . $processorFile, $processorMainClassName);
if (is_object($processorMainClass)) {
$this->requestProcessors[$processorMainClassNameShort] = $processorMainClass;
foreach ($this->requestProcessors[$processorMainClassNameShort]->getRegisteredActions() as $registeredAction) {
$scope = $this->requestProcessors[$processorMainClassNameShort]->getScope();
$this->inboxProcessors[$processorMainClassNameShort] = $processorMainClass;
foreach ($this->inboxProcessors[$processorMainClassNameShort]->getRegisteredActions() as $registeredAction) {
$scope = $this->inboxProcessors[$processorMainClassNameShort]->getScope();
if (!empty($this->enabledProcessors[$scope][$registeredAction])) {
$this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = true;
$this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = true;
} else {
$this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false;
$this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false;
}
}
} else {
$this->requestProcessors[$processorMainClassNameShort] = new \stdClass();
$this->requestProcessors[$processorMainClassNameShort]->{$registeredAction} = new \stdClass();
$this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->action = "N/A";
$this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false;
$this->requestProcessors[$processorMainClassNameShort]->{$registeredAction}->error = $processorMainClass;
$this->inboxProcessors[$processorMainClassNameShort] = new \stdClass();
$this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction} = new \stdClass();
$this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->action = "N/A";
$this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->enabled = false;
$this->inboxProcessors[$processorMainClassNameShort]->{$registeredAction}->error = $processorMainClass;
}
}
}

View File

@ -22,7 +22,7 @@ namespace App\View;
class MonadView extends AppView
{
private $additionalTemplatePaths = [
ROOT . '/libraries/default/RequestProcessors/templates/',
ROOT . '/libraries/default/InboxProcessors/templates/',
];
protected function _paths(?string $plugin = null, bool $cached = true): array