Skip to content

Commit

Permalink
add action, make some variables more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Sep 25, 2024
1 parent 76788b9 commit f0157ca
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
34 changes: 34 additions & 0 deletions Installation/Action/synczaken.action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"title": "ZgwToVrijbrpBirthAction",
"$id": "https://vrijbrp.nl/action/vrijbrp.synczaken.action.json",
"$schema": "https://json-schema.org/draft/2020-12/action",
"version": "0.0.2",
"listens": [
"vrijbrp.zaken.sync"
],
"throws": [],
"conditions": {
"==": [
1,
1
]
},
"class": "CommonGateway\\VrijBRPToZGWBundle\\ActionHandler\\SynchronizeCollectionHandler",
"configuration": {
"source": "https://vrijbrp.nl/source/vrijbrp.dossiers.source.json",
"schema": "https://vng.opencatalogi.nl/schemas/zrc.zaak.schema.json",
"mapping": "https://commongateway.nl/mapping/vrijbrp.dossierToZaak.mapping.json",
"endpoint": "/api/v1/dossiers/search",
"idField": "dossierId",
"resultsPath": "result.content",
"method": "POST",
"body": {
"types": [
"intra_mun_relocation",
"inter_mun_relocation"
]
}
},
"isLockable": false,
"isEnabled": true
}
54 changes: 54 additions & 0 deletions src/ActionHandler/SynchronizeCollectionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

Check failure on line 2 in src/ActionHandler/SynchronizeCollectionHandler.php

View workflow job for this annotation

GitHub Actions / build

Missing file doc comment
namespace CommonGateway\VrijBRPToZGWBundle\ActionHandler;

use App\ActionHandler\ActionHandlerInterface;
use CommonGateway\VrijBRPToZGWBundle\Service\NewSynchronizationService;
use CommonGateway\VrijBRPToZGWBundle\Service\VrijBrpService;

class SynchronizeCollectionHandler implements ActionHandlerInterface
{

/**

Check failure on line 12 in src/ActionHandler/SynchronizeCollectionHandler.php

View workflow job for this annotation

GitHub Actions / build

Missing short description in doc comment

Check failure on line 12 in src/ActionHandler/SynchronizeCollectionHandler.php

View workflow job for this annotation

GitHub Actions / build

Doc comment for parameter "$vrijBrpService" missing
* @param NewSynchronizationService $synchronizationService

Check failure on line 13 in src/ActionHandler/SynchronizeCollectionHandler.php

View workflow job for this annotation

GitHub Actions / build

Missing parameter comment
*/
public function __construct(

Check failure on line 15 in src/ActionHandler/SynchronizeCollectionHandler.php

View workflow job for this annotation

GitHub Actions / build

Expected 2 blank lines before function; 1 found
private readonly NewSynchronizationService $synchronizationService,

Check warning on line 16 in src/ActionHandler/SynchronizeCollectionHandler.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 VrijBrpService $vrijBrpService,

Check failure on line 17 in src/ActionHandler/SynchronizeCollectionHandler.php

View workflow job for this annotation

GitHub Actions / build

Expected 1 space between type hint and argument "$vrijBrpService"; 12 found
)
{

Check failure on line 19 in src/ActionHandler/SynchronizeCollectionHandler.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
}

/**
* This function returns the requered configuration as a [json-schema](https://json-schema.org/) array.
*
* @throws array a [json-schema](https://json-schema.org/) that this action should comply to
*/
public function getConfiguration(): array
{
return [
'$id' => 'https://commongateway.nl/ActionHandler/SynchronizationCollectionHandler.ActionHandler.json',
'$schema' => 'https://docs.commongateway.nl/schemas/ActionHandler.schema.json',
'title' => 'SynchronizationCollectionHandler',
'description' => '',
'required' => [],
'properties' => [
],
];
}

/**
* Run the actual business logic in the appropriate server.
*
* @param array $data The data from the call
* @param array $configuration The configuration of the action
*
* @return array
*/
public function run(array $data, array $configuration): array
{
$configuration = $this->vrijBrpService->setVrijBRPDefaults($configuration);

return $this->synchronizationService->synchronizeCollectionHandler($data, $configuration);
}
}
4 changes: 2 additions & 2 deletions src/Service/NewSynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function synchronizeFromSource(Synchronization $synchronization, array $s
*/
public function getResults(array $configuration, Source $source): array
{
$response = $this->callService->call(source: $source, endpoint: $configuration['endpoint'], method: $configuration['method'], config: ['json' => ['types' => $configuration['types']]]);
$response = $this->callService->call(source: $source, endpoint: $configuration['endpoint'], method: $configuration['method'], config: ['json' => $configuration['body']]);

$result = $this->callService->decodeResponse(source: $source, response: $response, contentType: ($configuration['content-type'] ?? 'application/json'));

Expand Down Expand Up @@ -197,7 +197,7 @@ public function synchronizeCollectionHandler(array $data, array $configuration):
foreach ($dossiers as $dossier) {
$dossierDot = new Dot($dossier);

$synchronization = $this->synchronizationService->findSyncBySource(source: $source, entity: $schema, sourceId: $dossierDot[$configuration['idLocation']], endpoint: $configuration['endpoint']);
$synchronization = $this->synchronizationService->findSyncBySource(source: $source, entity: $schema, sourceId: $dossierDot[$configuration['idField']], endpoint: $configuration['endpoint']);

if ($synchronization->getMapping() === null && isset($mapping) === true) {
$synchronization->setMapping($mapping);
Expand Down
10 changes: 6 additions & 4 deletions src/Service/VrijBrpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public function setVrijBRPDefaults(array $configuration): array
$configuration['method'] = 'POST';
}

if (isset($configuration['types']) === false) {
$configuration['types'] = [
'intra_mun_relocation',
'inter_mun_relocation',
if (isset($configuration['body']) === false) {
$configuration['body'] = [
'types' => [

Check failure on line 21 in src/Service/VrijBrpService.php

View workflow job for this annotation

GitHub Actions / build

Each line in an array declaration must end in a comma
'intra_mun_relocation',
'inter_mun_relocation',
]
];
}

Expand Down

0 comments on commit f0157ca

Please sign in to comment.