Skip to content

Commit 8bb4d78

Browse files
committed
PR comments
1 parent d6b3ef2 commit 8bb4d78

File tree

3 files changed

+123
-50
lines changed

3 files changed

+123
-50
lines changed

src/ActionHandler/SynchronizeCollectionHandler.php

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@
66
use CommonGateway\VrijBRPToZGWBundle\Service\VrijBrpService;
77
use CommonGateway\CoreBundle\ActionHandler\ActionHandlerInterface;
88

9+
/**
10+
* Handler for synchronizing collections from external sources.
11+
*
12+
* @author Robert Zondervan, Barry Brands, Ruben van der Linde
13+
* @license EUPL<github.com/ConductionNL/contactcatalogus/blob/master/LICENSE.md>
14+
*
15+
* @category ActionHandler
16+
*/
917
class SynchronizeCollectionHandler implements ActionHandlerInterface
1018
{
1119

1220

1321
/**
14-
* @param NewSynchronizationService $synchronizationService
22+
* @param NewSynchronizationService $syncService
23+
* @param VrijBrpService $vrijBrpService
1524
*/
1625
public function __construct(
17-
private readonly NewSynchronizationService $synchronizationService,
18-
private readonly VrijBrpService $vrijBrpService,
19-
) {
26+
private readonly NewSynchronizationService $syncService,
27+
private readonly VrijBrpService $vrijBrpService,
28+
)
29+
{
2030

2131
}//end __construct()
2232

@@ -25,16 +35,63 @@ public function __construct(
2535
* This function returns the requered configuration as a [json-schema](https://json-schema.org/) array.
2636
*
2737
* @throws array a [json-schema](https://json-schema.org/) that this action should comply to
38+
*
39+
* @return array The configuration of the handler.
2840
*/
2941
public function getConfiguration(): array
3042
{
3143
return [
32-
'$id' => 'https://commongateway.nl/ActionHandler/SynchronizationCollectionHandler.ActionHandler.json',
33-
'$schema' => 'https://docs.commongateway.nl/schemas/ActionHandler.schema.json',
34-
'title' => 'SynchronizationCollectionHandler',
44+
'$id' => 'https://commongateway.nl/ActionHandler/SynchronizationCollectionHandler.ActionHandler.json',
45+
'$schema' => 'https://docs.commongateway.nl/schemas/ActionHandler.schema.json',
46+
'title' => 'SynchronizationCollectionHandler',
3547
'description' => '',
36-
'required' => [],
37-
'properties' => [],
48+
'required' => ['source', 'schema', 'endpoint', 'idField', 'resultsPath'],
49+
'properties' => [
50+
'source' => [
51+
'type' => 'string',
52+
'description' => 'The source where the publication belongs to.',
53+
'example' => 'https://commongateway.woo.nl/source/buren.openwoo.source.json',
54+
'required' => true,
55+
],
56+
'schema' => [
57+
'type' => 'string',
58+
'description' => 'The publication schema.',
59+
'example' => 'https://commongateway.nl/woo.publicatie.schema.json',
60+
'reference' => 'https://commongateway.nl/woo.publicatie.schema.json',
61+
'required' => true,
62+
], 'mapping' => [
63+
'type' => 'string',
64+
'description' => 'The mapping for open woo to publication.',
65+
'example' => 'https://commongateway.nl/mapping/woo.openWooToWoo.mapping.json',
66+
'reference' => 'https://commongateway.nl/mapping/woo.openWooToWoo.mapping.json',
67+
'required' => false,
68+
],
69+
'endpoint' => [
70+
'type' => 'string',
71+
'description' => 'The endpoint of the source.',
72+
'example' => '/wp-json/owc/openwoo/v1/items',
73+
'required' => true,
74+
],
75+
'idField' => [
76+
'type' => 'string',
77+
'description' => 'Dot-array location of the field that contains the id',
78+
'example' => 'dossierId',
79+
'required' => true,
80+
],
81+
'resultsPath' => [
82+
'type' => 'string',
83+
'description' => 'Dot-array location of the field that contains the results',
84+
'example' => 'dossierId',
85+
'required' => true,
86+
],
87+
'body' => [
88+
'type' => 'array',
89+
'description' => 'Body that will be sent to the source if necessary.',
90+
'example' => 'dossierId',
91+
'required' => false,
92+
],
93+
],
94+
3895
];
3996

4097
}//end getConfiguration()
@@ -43,7 +100,7 @@ public function getConfiguration(): array
43100
/**
44101
* Run the actual business logic in the appropriate server.
45102
*
46-
* @param array $data The data from the call
103+
* @param array $data The data from the call
47104
* @param array $configuration The configuration of the action
48105
*
49106
* @return array
@@ -52,7 +109,7 @@ public function run(array $data, array $configuration): array
52109
{
53110
$configuration = $this->vrijBrpService->setVrijBRPDefaults($configuration);
54111

55-
return $this->synchronizationService->synchronizeCollectionHandler($data, $configuration);
112+
return $this->syncService->synchronizeCollectionHandler($data, $configuration);
56113

57114
}//end run()
58115

src/Service/NewSynchronizationService.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class NewSynchronizationService
3737

3838
public function __construct(
3939
private readonly GatewayResourceService $resourceService,
40-
private readonly CallService $callService,
41-
private readonly SynchronizationService $synchronizationService,
42-
private readonly LoggerInterface $synchronizationLogger,
40+
private readonly CallService $callService,
41+
private readonly SynchronizationService $syncService,
42+
private readonly LoggerInterface $synchronizationLogger,
4343
private readonly EntityManagerInterface $entityManager,
44-
private readonly MappingService $mappingService,
45-
private readonly HydrationService $hydrationService,
44+
private readonly MappingService $mappingService,
45+
private readonly HydrationService $hydrationService,
4646
) {
4747

4848
}//end __construct()
@@ -79,7 +79,7 @@ public function synchronizeFromSource(Synchronization $synchronization, array $s
7979
$oldDateModified = $synchronization->getObject()->getDateModified()->getTimestamp();
8080
}
8181

82-
$sourceObject = $sourceObject ?: $this->synchronizationService->getSingleFromSource($synchronization);
82+
$sourceObject = $sourceObject ?: $this->syncService->getSingleFromSource($synchronization);
8383

8484
if ($sourceObject === null) {
8585
$this->synchronizationLogger->warning("Can not handle Synchronization with id = {$synchronization->getId()->toString()} if \$sourceObject === null");
@@ -212,7 +212,7 @@ public function synchronizeCollectionHandler(array $data, array $configuration):
212212
foreach ($dossiers as $dossier) {
213213
$dossierDot = new Dot($dossier);
214214

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

217217
if ($synchronization->getMapping() === null && isset($mapping) === true) {
218218
$synchronization->setMapping($mapping);

src/Service/VrijBrpService.php

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,42 @@
88
use DateTime;
99
use Doctrine\ORM\EntityManagerInterface;
1010

11+
/**
12+
* Service for project specific code.
13+
*
14+
* Service for project specific code. More specifically: creating notifications and setting defaults.
15+
*
16+
* @author Robert Zondervan, Barry Brands, Ruben van der Linde
17+
* @license EUPL<github.com/ConductionNL/contactcatalogus/blob/master/LICENSE.md>
18+
*
19+
* @category Service
20+
*/
1121
class VrijBrpService
1222
{
1323

1424

25+
/**
26+
* @param CacheService $cacheService
27+
* @param GatewayResourceService $resourceService
28+
* @param EntityManagerInterface $entityManager
29+
* @param NewSynchronizationService $syncService
30+
*/
1531
public function __construct(
16-
private readonly CacheService $cacheService,
17-
private readonly GatewayResourceService $resourceService,
18-
private readonly EntityManagerInterface $entityManager,
19-
private readonly NewSynchronizationService $synchronizationService,
32+
private readonly CacheService $cacheService,
33+
private readonly GatewayResourceService $resourceService,
34+
private readonly EntityManagerInterface $entityManager,
35+
private readonly NewSynchronizationService $syncService,
2036
) {
2137

2238
}//end __construct()
2339

2440

41+
/**
42+
* Set defaults for configuration of synchronize action.
43+
*
44+
* @param array $configuration Incoming configuration.
45+
* @return array
46+
*/
2547
public function setVrijBRPDefaults(array $configuration): array
2648
{
2749
if (isset($configuration['endpoint']) === false) {
@@ -45,33 +67,13 @@ public function setVrijBRPDefaults(array $configuration): array
4567

4668
}//end setVrijBRPDefaults()
4769

48-
49-
function arrayRecursiveDiff($aArray1, $aArray2)
50-
{
51-
$aReturn = [];
52-
53-
foreach ($aArray1 as $mKey => $mValue) {
54-
if (array_key_exists($mKey, $aArray2)) {
55-
if (is_array($mValue)) {
56-
$aRecursiveDiff = $this->arrayRecursiveDiff($mValue, $aArray2[$mKey]);
57-
if (count($aRecursiveDiff)) {
58-
$aReturn[$mKey] = $aRecursiveDiff;
59-
}
60-
} else {
61-
if ($mValue != $aArray2[$mKey]) {
62-
$aReturn[$mKey] = $mValue;
63-
}
64-
}
65-
} else {
66-
$aReturn[$mKey] = $mValue;
67-
}
68-
}
69-
70-
return $aReturn;
71-
72-
}//end arrayRecursiveDiff()
73-
74-
70+
/**
71+
* Creates a status notification.
72+
*
73+
* @param array $data incoming data.
74+
* @param array $config incoming configuration.
75+
* @return array
76+
*/
7577
public function createStatusNotification(array $data, array $config): array
7678
{
7779
$object = $data['object'];
@@ -102,6 +104,13 @@ public function createStatusNotification(array $data, array $config): array
102104
}//end createStatusNotification()
103105

104106

107+
/**
108+
* Specific extension: fetch second source and run mapping.
109+
*
110+
* @param ObjectEntity $object Incoming object
111+
* @param array $array Serialised incoming object
112+
* @return ObjectEntity
113+
*/
105114
public function extendSync(ObjectEntity $object, array $array): ObjectEntity
106115
{
107116
$type = $array['toelichting'];
@@ -119,13 +128,20 @@ public function extendSync(ObjectEntity $object, array $array): ObjectEntity
119128
$synchronization->setEndpoint($endpoint);
120129
$synchronization->setMapping($detailMapping);
121130

122-
$this->synchronizationService->synchronizeFromSource($synchronization);
131+
$this->syncService->synchronizeFromSource($synchronization);
123132

124133
return $synchronization->getObject();
125134

126135
}//end extendSync()
127136

128137

138+
/**
139+
* Fire notification for case creation. Also extend case with data from detail endpoint.
140+
*
141+
* @param array $data Incoming data
142+
* @param array $config Incoming configuration
143+
* @return array
144+
*/
129145
public function createCaseNotification(array $data, array $config): array
130146
{
131147
$object = $data['object'];

0 commit comments

Comments
 (0)