Skip to content

Commit

Permalink
Notifications first draft
Browse files Browse the repository at this point in the history
warning: this will cause infinite loops. Working on that
  • Loading branch information
rjzondervan committed Sep 26, 2024
1 parent 6cb974a commit e347b94
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Installation/Action/vrijbrp.createStatusNotification.action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"title": "CreateStatusNotification",
"$id": "https://example.com/action/vrijbrp.createStatusNotification.action.json",
"$schema": "https://docs.commongateway.nl/schemas/Action.schema.json",
"version": "0.0.1",
"description": "This is an example Action. This action is triggered when commongateway.object.create event is thrown and the data (object) of the event has entity = https://example.com/schema/example.schema.json. In order for this condition to work the ref https://example.com/schema/example.schema.json has to be translated to an id, see installation.json['actions']['fixConfigRef'] for how to do this.",
"listens": [
"commongateway.object.pre.update"
],
"conditions":
{
"==": [
{
"var": "entity.reference"
}, "https://vng.opencatalogi.nl/schemas/zrc.zaak.schema.json"
]
},
"class": "CommonGateway\\VrijBRPToZGWBundle\\ActionHandler\\NotificationUpdateHandler",
"configuration": {
}
}
53 changes: 53 additions & 0 deletions src/ActionHandler/NotificationUpdateHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

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

View workflow job for this annotation

GitHub Actions / build

Missing file doc comment
namespace CommonGateway\VrijBRPToZGWBundle\ActionHandler;

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

class NotificationUpdateHandler implements ActionHandlerInterface
{

public function __construct(

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

View workflow job for this annotation

GitHub Actions / build

Missing doc comment for function __construct()

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

View workflow job for this annotation

GitHub Actions / build

Expected 2 blank lines before function; 1 found
private readonly VrijBrpService $vrijBrpService,
) {

}//end __construct()


/**
* 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
*/

Check failure on line 23 in src/ActionHandler/NotificationUpdateHandler.php

View workflow job for this annotation

GitHub Actions / build

Missing @return tag in function comment
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' => [],
];

}//end getConfiguration()


/**
* 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
{
return $this->vrijBrpService->createNotification($data, $configuration);

}//end run()


}//end class
71 changes: 71 additions & 0 deletions src/Service/VrijBrpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

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

View workflow job for this annotation

GitHub Actions / build

Missing file doc comment
namespace CommonGateway\VrijBRPToZGWBundle\Service;

use App\Entity\ObjectEntity;
use CommonGateway\CoreBundle\Service\CacheService;
use CommonGateway\CoreBundle\Service\GatewayResourceService;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;

class VrijBrpService
{


public function __construct(
private readonly CacheService $cacheService,
private readonly GatewayResourceService $resourceService,
private readonly EntityManagerInterface $entityManager,
) {

}

public function setVrijBRPDefaults(array $configuration): array
{
if (isset($configuration['endpoint']) === false) {
Expand All @@ -29,5 +43,62 @@ public function setVrijBRPDefaults(array $configuration): array

}//end setVrijBRPDefaults()

function arrayRecursiveDiff($aArray1, $aArray2) {
$aReturn = array();

foreach ($aArray1 as $mKey => $mValue) {
if (array_key_exists($mKey, $aArray2)) {
if (is_array($mValue)) {
$aRecursiveDiff = $this->arrayRecursiveDiff($mValue, $aArray2[$mKey]);
if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff; }
} else {
if ($mValue != $aArray2[$mKey]) {
$aReturn[$mKey] = $mValue;
}
}
} else {
$aReturn[$mKey] = $mValue;
}
}
return $aReturn;
}

public function createNotification(array $data, array $config): array
{
var_dump('hello');


$object = $data['object'];

if($object instanceof ObjectEntity) {
$data = $object->toArray(['embedded' => true, 'user' => $this->cacheService->getObjectUser(objectEntity: $object)]);

Check warning on line 74 in src/Service/VrijBrpService.php

View workflow job for this annotation

GitHub Actions / build

Line exceeds 125 characters; contains 131 characters
$oldData = $this->cacheService->getObject($object->getId());

$diff = $this->arrayRecursiveDiff($data, $oldData);

if(array_key_exists(key: 'status', array: $diff) === true) {
$now = new DateTime();

Check warning on line 80 in src/Service/VrijBrpService.php

View workflow job for this annotation

GitHub Actions / build

Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
$message = [

Check warning on line 81 in src/Service/VrijBrpService.php

View workflow job for this annotation

GitHub Actions / build

Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space
'kanaal' => 'zaak.status.created',
'hoofdobject' => $data['url'],
'resource' => 'Zaak',
'resourceUrl' => $data['url'],
'actie' => 'create',
'aanmaakdatum' => $now->format('c'),
];
$schema = $this->resourceService->getSchema(
reference:'https://zgw.opencatalogi.nl/schema/nrc.message.schema.json',
pluginName: 'common-gateway/vrijbrp-to-zgw-bundle'
);
$messageObject = new ObjectEntity(entity: $schema);
$messageObject->hydrate($message);
$this->entityManager->persist($messageObject);
}
}

return $data;

}


}//end class

0 comments on commit e347b94

Please sign in to comment.