-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* This class handles the execution of the NotificationToTaakService. | ||
* | ||
* This ActionHandler executes the | ||
* NotificationToTaak->syncNotificationToTaak. | ||
* | ||
* @author Conduction BV <[email protected]>, Barry Brands <[email protected]> | ||
Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 | ||
Check failure on line 9 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
Check failure on line 9 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
* | ||
* @category ActionHandler | ||
Check failure on line 11 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
Check failure on line 11 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
*/ | ||
|
||
namespace CommonGateway\XxllncToKTBBundle\ActionHandler; | ||
|
||
use App\Exception\GatewayException; | ||
use CommonGateway\CoreBundle\ActionHandler\ActionHandlerInterface; | ||
use CommonGateway\XxllncToKTBBundle\Service\NotificationToTaakService as Service; | ||
use Psr\Cache\CacheException; | ||
use Psr\Cache\InvalidArgumentException; | ||
use Respect\Validation\Exceptions\ComponentException; | ||
|
||
class NotificationToTaakHandler implements ActionHandlerInterface | ||
{ | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
* @param Service $service | ||
Check failure on line 29 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
*/ | ||
public function __construct( | ||
Check failure on line 31 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
private readonly Service $service, | ||
) | ||
{ | ||
Check failure on line 34 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
}//end __construct() | ||
Check failure on line 35 in src/ActionHandler/NotificationToTaakHandler.php GitHub Actions / build
|
||
|
||
|
||
/** | ||
* This function returns the required configuration as | ||
* a [json-schema](https://json-schema.org/) array. | ||
* | ||
* @return array a [json-schema](https://json-schema.org/) that this action should comply to | ||
*/ | ||
public function getConfiguration(): array | ||
{ | ||
return [ | ||
'$id' => 'https://development.zaaksysteem.nl/schemas/NotificationToTaak.ActionHandler.schema.json', | ||
'$schema' => 'https://docs.commongateway.nl/schemas/ActionHandler.schema.json', | ||
'title' => 'NotificationToTaak', | ||
'description' => 'This handler gets throught the notification the task and syncs it to taak', | ||
'required' => [], | ||
'properties' => [], | ||
]; | ||
|
||
}//end getConfiguration() | ||
|
||
|
||
/** | ||
* This function executes the service | ||
* | ||
* @param array $data The data from the call | ||
* @param array $configuration The configuration of the action | ||
* | ||
* @throws GatewayException | ||
* @throws CacheException | ||
* @throws InvalidArgumentException | ||
* @throws ComponentException | ||
* | ||
* @return array | ||
*/ | ||
public function run(array $data, array $configuration): array | ||
{ | ||
return $this->service->execute($data, $configuration); | ||
|
||
}//end run() | ||
|
||
|
||
}//end class |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
/** | ||
* This class handles the synchronization of a notification of a zaaksysteem task taken to a customerinteractionbundle taak. | ||
* | ||
* Fetches all tasks of the case of the notification. | ||
* | ||
* @author Conduction BV <[email protected]>, Barry Brands <[email protected]> | ||
* @license EUPL-1.2 https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 | ||
* | ||
* @category Service | ||
*/ | ||
|
||
namespace CommonGateway\XxllncToKTBBundle\Service; | ||
|
||
use App\Service\SynchronizationService as OldSynchronizationService; | ||
use CommonGateway\CoreBundle\Service\SynchronizationService; | ||
use CommonGateway\CoreBundle\Service\CallService; | ||
use CommonGateway\CoreBundle\Service\MappingService; | ||
use App\Service\GatewayResourceService as ResourceService; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use App\Entity\Gateway as Source; | ||
use Psr\Log\LoggerInterface; | ||
use Ramsay\Uuid; | ||
|
||
class NotificationToTaakService | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private array $configuration; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private array $data; | ||
|
||
/** | ||
* __construct. | ||
*/ | ||
public function __construct( | ||
private readonly EntityManagerInterface $entityManager, | ||
private readonly ResourceService $resourceService, | ||
private readonly CallService $callService, | ||
private readonly OldSynchronizationService $oldSynchronizationService, | ||
Check warning on line 45 in src/Service/NotificationToTaakService.php GitHub Actions / build
|
||
private readonly SynchronizationService $synchronizationService, | ||
Check warning on line 46 in src/Service/NotificationToTaakService.php GitHub Actions / build
|
||
private readonly MappingService $mappingService, | ||
private readonly LoggerInterface $pluginLogger, | ||
) { | ||
}//end __construct() | ||
|
||
|
||
/** | ||
* Synchronizes a CustomerInteractionBundle taak to the zaaksysteem v2 task equilevant. | ||
* | ||
* Can handle create, update and delete. Prerequisite is that the taak has a zaak that is synchronized as case in the zaaksysteem. | ||
Check warning on line 56 in src/Service/NotificationToTaakService.php GitHub Actions / build
|
||
* | ||
* @return array $this->data | ||
*/ | ||
private function synchronizeTask(): array | ||
{ | ||
$this->pluginLogger->debug('NotificationToTaakService -> synchronizeTask'); | ||
$pluginName = 'common-gateway/xxllnc-to-ktb-bundle'; | ||
|
||
// Get Source zaaksysteem v2. | ||
$source = $this->resourceService->getSource(reference: $this->configuration['source'], pluginName: $pluginName); | ||
if ($source === null) { | ||
return $this->data; | ||
} | ||
|
||
// Get taak schema. | ||
$schema = $this->resourceService->getSchema(reference: $this->configuration['schema'], pluginName: $pluginName); | ||
if ($schema === null) { | ||
return $this->data; | ||
} | ||
|
||
// Get task to taak mapping. | ||
$mapping = $this->resourceService->getMapping(reference: $this->configuration['mapping'], pluginName: $pluginName); | ||
if ($mapping === null) { | ||
return $this->data; | ||
} | ||
|
||
$endpoint = $this->configuration['endpoint'] . "?filter[relationships.case.id]=" . $this->data['case_uuid']; | ||
|
||
// Fetch all tasks of the case | ||
try { | ||
$this->pluginLogger->info("Fetching tasks for case id: {$this->data['case_uuid']}.."); | ||
$response = $this->callService->call($source, $endpoint, 'GET', [], false, false); | ||
$tasks = $this->callService->decodeResponse(source: $source, response: $response); | ||
} catch (Exception $e) { | ||
// isset($this->style) === true && $this->style->error("Failed to fetch case: $caseID, message: {$e->getMessage()}"); | ||
Check warning on line 91 in src/Service/NotificationToTaakService.php GitHub Actions / build
|
||
$this->pluginLogger->error("Failed to fetch tasks for case: {$this->data['case_uuid']}, message: {$e->getMessage()}"); | ||
Check warning on line 92 in src/Service/NotificationToTaakService.php GitHub Actions / build
|
||
|
||
return null; | ||
}//end try | ||
|
||
// Check if the entity_id is equal to task id | ||
foreach ($tasks as $task) { | ||
if ($this->data['entity_id'] === $task['id']) { | ||
$taskWeNeed = $task; | ||
} | ||
} | ||
|
||
if (isset($taskWeNeed) === false) { | ||
$this->pluginLogger->error("Could not find the correct task ({$this->data['entity_id']}) in the tasks of the case ({$this->data['case_uuid']})"); | ||
|
||
return $this->data; | ||
} | ||
|
||
// Synchronize correct task. | ||
$synchronization = $this->oldSynchronizationService->findSyncBySource(source: $source, entity: $schema, sourceId: $taskWeNeed['id'], endpoint: $endpoint); | ||
$synchronization = $this->oldSynchronizationService->synchronize(synchronization: $synchronization, sourceObject: $taskWeNeed, unsafe: false, mapping: $mapping); | ||
|
||
return $this->data; | ||
}//end synchronizeTask() | ||
|
||
|
||
/** | ||
* Executes synchronizeTaak | ||
* | ||
* @param array $configuration | ||
* @param array $data | ||
* | ||
* @return array $this->synchronizeTaak() | ||
*/ | ||
public function execute(array $configuration, array $data): array | ||
{ | ||
$this->data = $data; | ||
Check warning on line 128 in src/Service/NotificationToTaakService.php GitHub Actions / build
|
||
$this->configuration = $configuration; | ||
|
||
return $this->synchronizeTask(); | ||
}//end execute() | ||
|
||
|
||
}//end class |