Skip to content

Commit

Permalink
Preliminary fixes for blocking deletes and overriding values by defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Jul 26, 2023
1 parent 098a52a commit 2b79ec5
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 3 deletions.
75 changes: 75 additions & 0 deletions ActionHandler/DeleteHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace CommonGateway\ZGWBundle\ActionHandler;

use App\Exception\GatewayException;
use CommonGateway\CoreBundle\ActionHandler\ActionHandlerInterface;
use CommonGateway\ZGWBundle\Service\ZGWService;
use Psr\Cache\CacheException;
use Psr\Cache\InvalidArgumentException;
use Respect\Validation\Exceptions\ComponentException;

class DeleteHandler implements ActionHandlerInterface
{
private ZGWService $zgwService;

public function __construct(ZGWService $zgwService)
{
$this->zgwService = $zgwService;
}

/**
* 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://example.com/person.schema.json',
'$schema' => 'https://docs.commongateway.nl/schemas/ActionHandler.schema.json',
'title' => 'ZGW Action',
'description' => 'This handler returns a welcoming string',
'required' => [],
'properties' => [
'schema' => [
'type' => 'string',
'description' => 'The reference to the schema to block deletes for',
'example' => 'https://vng.opencatalogi.nl/schemas/ztc.zaakType.schema.json',
'nullable' => true,
],
'property' => [
'type' => 'string',
'description' => 'The property of the schema that can block deletion.',
'example' => 'concept',
'nullable' => true,
],
'value' => [
'type' => 'boolean',
'description' => 'The value that blocks deletion of an object.',
'example' => false,
'nullable' => true,
],

],
];
}

/**
* This function runs 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->zgwService->preventDeleteHandler($data, $configuration);
}
}
74 changes: 74 additions & 0 deletions ActionHandler/IdentificatieHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace CommonGateway\ZGWBundle\ActionHandler;

use App\Exception\GatewayException;
use CommonGateway\CoreBundle\ActionHandler\ActionHandlerInterface;
use CommonGateway\ZGWBundle\Service\ZGWService;
use Psr\Cache\CacheException;
use Psr\Cache\InvalidArgumentException;
use Respect\Validation\Exceptions\ComponentException;

class IdentificatieHandler implements ActionHandlerInterface
{
private ZGWService $zgwService;

public function __construct(ZGWService $zgwService)
{
$this->zgwService = $zgwService;
}

/**
* 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://example.com/person.schema.json',
'$schema' => 'https://docs.commongateway.nl/schemas/ActionHandler.schema.json',
'title' => 'ZGW Action',
'description' => 'This handler returns a welcoming string',
'required' => [],
'properties' => [
'schema' => [
'type' => 'string',
'description' => 'The reference to the schema to update.',
'example' => 'https://vng.opencatalogi.nl/schemas/zrc.zaak.schema.json',
'nullable' => true,
],
'property' => [
'type' => 'string',
'description' => 'The property to override.',
'example' => 'identificatie',
'nullable' => true,
],
'value' => [
'type' => 'string',
'description' => 'The value that should be overridden.',
'example' => '',
'nullable' => true,
],
],
];
}

/**
* This function runs 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->zgwService->overrideValueHandler($data, $configuration);
}
}
19 changes: 19 additions & 0 deletions Installation/Action/zgw.blockDeleteAction.action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"title": "ZaakZoekenAction",
"$id": "https://vng.opencatalogi.nl/action/zgw.blockDeleteAction.action.json",
"$schema": "https://docs.commongateway.nl/schemas/Action.schema.json",
"version": "0.0.1",
"listens": ["commongateway.object.pre.delete"],
"conditions":
{
"==": [
1,1
]
},
"class": "CommonGateway\\ZGWBundle\\ActionHandler\\DeleteHandler",
"configuration": {
"schema": "https://vng.opencatalogi.nl/schemas/ztc.zaakType.schema.json",
"property": "concept",
"value": false
}
}
19 changes: 19 additions & 0 deletions Installation/Action/zgw.unsetValueAction.action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"title": "ZaakZoekenAction",
"$id": "https://vng.opencatalogi.nl/action/zgw.blockDeleteAction.action.json",
"$schema": "https://docs.commongateway.nl/schemas/Action.schema.json",
"version": "0.0.1",
"listens": ["commongateway.object.pre.create"],
"conditions":
{
"==": [
1,1
]
},
"class": "CommonGateway\\ZGWBundle\\ActionHandler\\IdentificatieHandler",
"configuration": {
"schema": "https://vng.opencatalogi.nl/schemas/zrc.zaak.schema.json",
"property": "identificatie",
"value": ""
}
}
40 changes: 37 additions & 3 deletions Service/ZGWService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace CommonGateway\ZGWBundle\Service;

use App\Entity\ObjectEntity;
use App\Exception\GatewayException;
use Doctrine\ORM\EntityManagerInterface;
use Ramsey\Uuid\Uuid;;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -32,6 +33,39 @@ public function __construct(
$this->eventDispatcher = $eventDispatcher;
}

public function preventDeleteHandler(array $data, array $configuration): array
{
if ($data['object']->getEntity()->getReference() !== $configuration['schema']
|| $data['object']->getValue($configuration['property']) !== $configuration['value']) {
return $data;
}


throw new GatewayException('Cannot remove an object if it is published');
}

/**
* Sets the value of the property 'identificatie' to its default value if the value is empty
*
*
* @param array $data The object created
* @param array $configuration The configuration for the action
* @return array
*/
public function overrideValueHandler(array $data, array $configuration): array
{
if ($data['object']->getEntity()->getReference() !== $configuration['schema']
|| $data['object']->getValue($configuration['property']) !== '') {
return $data;
}

$value = $data['object']->getValueObject($configuration['property']);

$data['object']->hydrate([$configuration['property'] => $value->getAttribute()->getDefaultValue()]);

return $data;
}


/**
* Returns a new besluit, existing besluit or all besluiten of a zaak.
Expand Down Expand Up @@ -118,7 +152,7 @@ public function postZaakBesluitHandler(array $data, array $configuration): array

/**
* Handles the ZGW zaakeigenschappen subendpoint.
*
*
* @param array $data from action.
* @param array $configuration from action.
*
Expand Down Expand Up @@ -160,13 +194,13 @@ public function postZaakEigenschapHandler(array $data, array $configuration): ar
}//end if

return ['response' => new Response(json_encode($zaakeigenschap->toArray(['embedded' => true])), 201, ['Content-Type' => 'application/json'])];

}//end postZaakEigenschapHandler()


/**
* Handles the ZGW publish subendpoint.
*
*
* @param array $data from action.
* @param array $configuration from action.
*
Expand Down

0 comments on commit 2b79ec5

Please sign in to comment.