Skip to content

Commit

Permalink
Added code for finding the right task
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrands02 committed Oct 7, 2024
1 parent 0357366 commit 7bd7692
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Installation/Action/xxllnctoktb.syncTaskToTaak.action.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"conditions": {
"!!": { "var": "task_uuid" }
},
"class": "CommonGateway\\CoreBundle\\ActionHandler\\NotificationHandler",
"class": "CommonGateway\\XxllncToKTBBundle\\ActionHandler\\NotificationToTaakHandler",
"configuration": {
"mapping": "https://commongateway.nl/mapping/xxllnctoktb.TaskToTaak.mapping.json",
"schema": "https://commongateway.nl/klant.taak.schema.json",
"source": "https://development.zaaksysteem.nl/source/xxllnc.zaaksysteemv2.source.json",
"endpoint": "/api/v2/cm/task/get_task_list",
"sourceIdField": "task_uuid",
"pluginName": "common-gateway/xxllnc-to-ktb-bundle"
}
Expand Down
78 changes: 78 additions & 0 deletions src/ActionHandler/NotificationToTaakHandler.php
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

View workflow job for this annotation

GitHub Actions / build

The tag in position 1 should be the @category tag

Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Content of the @author tag must be in the form "Display Name <[email protected]>"

Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

The tag in position 1 should be the @category tag

Check failure on line 8 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Content of the @author tag must be in the form "Display Name <[email protected]>"
* @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

View workflow job for this annotation

GitHub Actions / build

The tag in position 2 should be the @author tag

Check failure on line 9 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

The tag in position 2 should be the @author tag
*
* @category ActionHandler

Check failure on line 11 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

The tag in position 3 should be the @license tag

Check failure on line 11 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

The tag in position 3 should be the @license tag
*/

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

View workflow job for this annotation

GitHub Actions / build

Missing parameter comment

Check failure on line 29 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Missing parameter comment
*/
public function __construct(

Check failure on line 31 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Expected 2 blank lines before function; 1 found

Check failure on line 31 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Expected 2 blank lines before function; 1 found
private readonly Service $service,
)
{

Check failure on line 34 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line

Check failure on line 34 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
}//end __construct()

Check failure on line 35 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Expected 1 blank line before closing function brace; 0 found

Check failure on line 35 in src/ActionHandler/NotificationToTaakHandler.php

View workflow job for this annotation

GitHub Actions / build

Expected 1 blank line before closing function brace; 0 found


/**
* 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
135 changes: 135 additions & 0 deletions src/Service/NotificationToTaakService.php
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

View workflow job for this annotation

GitHub Actions / build

Avoid excessively long variable names like $oldSynchronizationService. Keep variable name length under 20.

Check warning on line 45 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Avoid excessively long variable names like $oldSynchronizationService. Keep variable name length under 20.
private readonly SynchronizationService $synchronizationService,

Check warning on line 46 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Avoid excessively long variable names like $synchronizationService. Keep variable name length under 20.

Check warning on line 46 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Avoid excessively long variable names like $synchronizationService. Keep variable name length under 20.
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

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 134 characters

Check warning on line 56 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 134 characters
*
* @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

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 130 characters

Check warning on line 91 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 130 characters
$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

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 131 characters

Check warning on line 92 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 131 characters

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

View workflow job for this annotation

GitHub Actions / build

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

Check warning on line 128 in src/Service/NotificationToTaakService.php

View workflow job for this annotation

GitHub Actions / build

Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space
$this->configuration = $configuration;

return $this->synchronizeTask();
}//end execute()


}//end class

0 comments on commit 7bd7692

Please sign in to comment.