From 66ddae31340dbc3ae600c452a9bddcaeb188773b Mon Sep 17 00:00:00 2001 From: Barry Brands Date: Thu, 19 Dec 2024 10:47:04 +0100 Subject: [PATCH] Fix originId and extra fetching --- .../mappings/xxllnc-v1-case-to-zgw-zaak.json | 9 +++++---- .../xxllnc-v1-milestone-to-zgw-status.json | 3 ++- .../xxllnc-v1-outcome-to-zgw-resultaat.json | 4 +++- .../xxllnc-v1-cases-to-zgw-zaken.json | 5 ++++- lib/Service/SynchronizationService.php | 20 +++++++++++++++---- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/configurations/xxllnc-zgw/mappings/xxllnc-v1-case-to-zgw-zaak.json b/configurations/xxllnc-zgw/mappings/xxllnc-v1-case-to-zgw-zaak.json index 62fe4e9..a86c02b 100644 --- a/configurations/xxllnc-zgw/mappings/xxllnc-v1-case-to-zgw-zaak.json +++ b/configurations/xxllnc-zgw/mappings/xxllnc-v1-case-to-zgw-zaak.json @@ -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 %}", @@ -37,7 +37,8 @@ "opschorting.indicatie": "unsetIfValue==", "opschorting.reden": "unsetIfValue==", "opschorting": "unsetIfValue==", - "zaakinformatieobjecten": "jsonToArray" + "zaakinformatieobjecten": "jsonToArray", + "zaaktype": "jsonToArray" }, "passTrough": false } \ No newline at end of file diff --git a/configurations/xxllnc-zgw/mappings/xxllnc-v1-milestone-to-zgw-status.json b/configurations/xxllnc-zgw/mappings/xxllnc-v1-milestone-to-zgw-status.json index b740959..ce2564d 100644 --- a/configurations/xxllnc-zgw/mappings/xxllnc-v1-milestone-to-zgw-status.json +++ b/configurations/xxllnc-zgw/mappings/xxllnc-v1-milestone-to-zgw-status.json @@ -9,7 +9,8 @@ }, "unset": [], "cast": { - "indicatieLaatstGezetteStatus": "bool" + "indicatieLaatstGezetteStatus": "bool", + "statustype": "unsetIfValue==" }, "passTrough": false } \ No newline at end of file diff --git a/configurations/xxllnc-zgw/mappings/xxllnc-v1-outcome-to-zgw-resultaat.json b/configurations/xxllnc-zgw/mappings/xxllnc-v1-outcome-to-zgw-resultaat.json index 4ff8c3e..ea9754a 100644 --- a/configurations/xxllnc-zgw/mappings/xxllnc-v1-outcome-to-zgw-resultaat.json +++ b/configurations/xxllnc-zgw/mappings/xxllnc-v1-outcome-to-zgw-resultaat.json @@ -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 } \ No newline at end of file diff --git a/configurations/xxllnc-zgw/synchronizations/xxllnc-v1-cases-to-zgw-zaken.json b/configurations/xxllnc-zgw/synchronizations/xxllnc-v1-cases-to-zgw-zaken.json index 0d1dc77..660461e 100644 --- a/configurations/xxllnc-zgw/synchronizations/xxllnc-v1-cases-to-zgw-zaken.json +++ b/configurations/xxllnc-zgw/synchronizations/xxllnc-v1-cases-to-zgw-zaken.json @@ -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", diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 255079b..b00daf8 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -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; @@ -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) { @@ -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;