Skip to content

Commit

Permalink
Fix originId and extra fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrands02 committed Dec 19, 2024
1 parent 268db67 commit 66ddae3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"resultaat": "{% if instance.outcome|default %}{% set data = {'outcome': instance.outcome, 'resultaattypen': zaaktype.resultaattypen} %}{{ executeMapping(2, data)|json_encode }}{% endif %}",
"rollen": "[{% if instance.route.instance.role|default %}{% set dataRol = {'requestor': instance.requestor, 'role': instance.route.instance.role, 'roltypen': zaaktype.roltypen} %}{{ executeMapping(3, dataRol)|json_encode }}{% endif %}]",
"status": "{% if instance.milestone|default %}{% set data = {'milestone': instance.milestone, 'statustypen': zaaktype.statustypen} %}{{ executeMapping(4, data)|json_encode }}{% endif %}",
"zaaktype": "{% if zaaktype|default %}{{ executeMapping(7, zaaktype)|json_encode }}{% endif %}",
"eigenschappen": "[{% set index=0 %}{% if zaaktype.eigenschappen|default %}{% for key, attribute in instance.attributes %}{% if index != 0 %},{% endif %}{% set data = {'name': key, 'value': attribute, 'eigenschappen': zaaktype.eigenschappen} %}{% if attribute[0][0]|default and attribute[0][0] is iterable %}{{ attribute|json_encode }}{% else %}{{ executeMapping(5, data)|json_encode }}{% endif %}{% set index=index+1 %}{% endfor %}{% endif %}]",
"zaakinformatieobjecten": "[{% set index=0 %}{% if documents.result.instance.rows|default %}{% for document in documents.result.instance.rows %}{% if index != 0 %},{% endif %}{{ executeMapping(6, document)|json_encode }}{% set index=index+1 %}{% endfor %}{% endif %}]",
"zaaktype": "{% if casetype|default %}{{ executeMapping(5, casetype)|json_encode }}{% endif %}",
"eigenschappen": "[{% set index=0 %}{% if zaaktype.eigenschappen|default %}{% for key, attribute in instance.attributes %}{% if index != 0 %},{% endif %}{% set data = {'name': key, 'value': attribute, 'eigenschappen': zaaktype.eigenschappen} %}{% if attribute[0][0]|default and attribute[0][0] is iterable %}{{ attribute|json_encode }}{% else %}{{ executeMapping(6, data)|json_encode }}{% endif %}{% set index=index+1 %}{% endfor %}{% endif %}]",
"zaakinformatieobjecten": "[{% set index=0 %}{% if documents.result.instance.rows|default %}{% for document in documents.result.instance.rows %}{% if index != 0 %},{% endif %}{{ executeMapping(7, document)|json_encode }}{% set index=index+1 %}{% endfor %}{% endif %}]",
"bronorganisatie": "bronorganisatie",
"verantwoordelijkeOrganisatie": "bronorganisatie",
"opschorting.indicatie": "{% if instance.stalled_until|default %}true{% else %}{% endif %}",
Expand All @@ -37,7 +37,8 @@
"opschorting.indicatie": "unsetIfValue==",
"opschorting.reden": "unsetIfValue==",
"opschorting": "unsetIfValue==",
"zaakinformatieobjecten": "jsonToArray"
"zaakinformatieobjecten": "jsonToArray",
"zaaktype": "jsonToArray"
},
"passTrough": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"unset": [],
"cast": {
"indicatieLaatstGezetteStatus": "bool"
"indicatieLaatstGezetteStatus": "bool",
"statustype": "unsetIfValue=="
},
"passTrough": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"resultaattype": "{% if resultaattypen|default %}{% for resultaattype in resultaattypen %}{% if resultaattype.toelichting == outcome.instance.name %}{{ resultaattype['_self']['id'] }}{% endif %}{% endfor %}{% endif %}"
},
"unset": [],
"cast": [],
"cast": {
"resultaattype": "unsetIfValue=="
},
"passTrough": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"extraDataConfigs.0.staticEndpoint": "/case/{{ originId }}/document",
"extraDataConfigs.0.mergeExtraData": "true",
"extraDataConfigs.0.keyToSetExtraData": "documents",
"extraDataConfigs.0.resultsLocation": "result.instance.rows"
"extraDataConfigs.1.staticEndpoint": "/casetype/{{ originId }}",
"extraDataConfigs.1.endpointIdLocation": "instance.casetype.reference",
"extraDataConfigs.1.mergeExtraData": "true",
"extraDataConfigs.1.keyToSetExtraData": "casetype"
},
"currentPage": 1,
"targetId": "1\/1",
Expand Down
20 changes: 16 additions & 4 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@ public function getObjectFromSource(Synchronization $synchronization, string $en
* - KEY_FOR_EXTRA_DATA_LOCATION: The key under which the extra data should be returned.
* - MERGE_EXTRA_DATA_OBJECT_LOCATION: Boolean flag indicating whether to merge the extra data with the object.
* @param array $object The original object for which extra data needs to be fetched.
* @param string|null $originId
*
* @return array The original object merged with the extra data, or the extra data itself based on the configuration.
*
* @throws Exception If both dynamic and static endpoint configurations are missing or the endpoint cannot be determined.
*/
private function fetchExtraDataForObject(Synchronization $synchronization, array $extraDataConfig, array $object)
private function fetchExtraDataForObject(Synchronization $synchronization, array $extraDataConfig, array $object, ?string $originId = null)
{
if (isset($extraDataConfig[$this::EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION]) === false && isset($extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION]) === false) {
return $object;
Expand All @@ -253,9 +254,20 @@ private function fetchExtraDataForObject(Synchronization $synchronization, array

// Get endpoint static defined in config.
if (isset($extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION]) === true) {

if ($originId === null) {
$originId = $this->getOriginId($synchronization, $object);
}

if (isset($extraDataConfig['endpointIdLocation']) === true) {
$dotObject = new Dot($object);
$originId = $dotObject->get($extraDataConfig['endpointIdLocation']);
}


$endpoint = $extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION];
$endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint);
$endpoint = str_replace(search: '{{originId}}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint);
$endpoint = str_replace(search: '{{ originId }}', replace: $originId, subject: $endpoint);
$endpoint = str_replace(search: '{{originId}}', replace: $originId, subject: $endpoint);
}

if (!$endpoint) {
Expand All @@ -275,7 +287,7 @@ private function fetchExtraDataForObject(Synchronization $synchronization, array
$results = $dotObject->get($extraDataConfig['resultsLocation']);

foreach ($results as $key => $result) {
$results[$key] = $this->fetchExtraDataForObject($synchronization, $extraDataConfig['extraDataConfigPerResult'], $result);
$results[$key] = $this->fetchExtraDataForObject(synchronization: $synchronization, extraDataConfig: $extraDataConfig['extraDataConfigPerResult'], object: $result, originId: $originId);
}

$extraData = $results;
Expand Down

0 comments on commit 66ddae3

Please sign in to comment.