Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetching an endpoint with id in sub object #156

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"extraDataConfigs.0.mergeExtraData": "true",
"extraDataConfigs.0.keyToSetExtraData": "files",
"extraDataConfigs.0.resultsLocation": "results",
"extraDataConfigs.0.extraDataConfigPerResult.idPosition": "identificatie",
"extraDataConfigs.0.extraDataConfigPerResult.staticEndpoint": "/tlb/zaaksysteem/api/v1/informatieobjecten/{{ originId }}"
},
"targetId": "1/1",
Expand Down
13 changes: 7 additions & 6 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class SynchronizationService
const EXTRA_DATA_CONFIGS_LOCATION = 'extraDataConfigs';
const EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION = 'dynamicEndpointLocation';
const EXTRA_DATA_STATIC_ENDPOINT_LOCATION = 'staticEndpoint';
const EXTRA_DATA_ID_POSITION_LOCATION = 'idPosition';
const KEY_FOR_EXTRA_DATA_LOCATION = 'keyToSetExtraData';
const MERGE_EXTRA_DATA_OBJECT_LOCATION = 'mergeExtraData';

Expand Down Expand Up @@ -303,10 +304,6 @@ 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']);
Expand All @@ -315,8 +312,12 @@ private function fetchExtraDataForObject(Synchronization $synchronization, array

$endpoint = $extraDataConfig[$this::EXTRA_DATA_STATIC_ENDPOINT_LOCATION];

if ($originId === null) {
$originId = $this->getOriginId($synchronization, $object);
if ($originId === null || isset($extraDataConfig[$this::EXTRA_DATA_ID_POSITION_LOCATION]) === true) {
if (isset($extraDataConfig[$this::EXTRA_DATA_ID_POSITION_LOCATION]) === true) {
$synchronization->setSourceConfig(array_merge($synchronization->getSourceConfig(), ['idPosition' => $extraDataConfig[$this::EXTRA_DATA_ID_POSITION_LOCATION]]));
}

$originId = $this->getOriginId(synchronization: $synchronization, object: $object);
}

$endpoint = str_replace(search: '{{ originId }}', replace: $originId, subject: $endpoint);
Expand Down
Loading