diff --git a/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json b/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json index b678dea..e74ad30 100644 --- a/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json +++ b/configurations/sharepoint-woo/mappings/sharepoint-woo-verzoek-to-publications.json @@ -3,9 +3,21 @@ "description": "", "version": "0.0.1", "mapping": { - "title": "Name" + "title": "d.woo_x005f_titel", + "description": "d.woo_x005f_beschrijving", + "summary": "d.woo_x005f_samenvatting", + "category": "d.woo_x005f_categorie", + "published": "d.woo_x005f_publicatiedatum", + "modified": "d.vti_x005f_nexttolasttimemodified" }, "unset": [], - "cast": [], + "cast": { + "title": "d.woo_x005f_titel", + "description": "d.woo_x005f_beschrijving", + "summary": "d.woo_x005f_samenvatting", + "category": "d.woo_x005f_categorie", + "published": "d.woo_x005f_publicatiedatum", + "modified": "d.vti_x005f_nexttolasttimemodified" + }, "passThrough": false } \ No newline at end of file diff --git a/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json b/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json index 17e38a8..c142820 100644 --- a/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json +++ b/configurations/sharepoint-woo/mappings/xxllnc-suite-to-publications.json @@ -5,8 +5,10 @@ "reference": "", "mapping": { "title": "omschrijving", - "summary": "statustoelichting", - "description": "statusomschrijving" + "summary": "zaaktypeomschrijving", + "description": "zaaktypeomschrijving", + "published" : "startdatum", + "modified" : "{{ 'now'|date(H:i:sTm-d-Y') }}" }, "unset": [], "cast": [], diff --git a/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json b/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json index e39deb8..bc53941 100644 --- a/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json +++ b/configurations/sharepoint-woo/synchronizations/sharepoint-convenanten-to-publications.json @@ -7,9 +7,11 @@ "sourceHash": "", "sourceTargetMapping": "1", "sourceConfig": { - "idPosition": "UniqueId", + "idPosition": "Properties.__deferred.uri", "resultsPosition": "d.results", "endpoint": "/Web/GetFolderByServerRelativePath(decodedurl='/WOO/Convenanten')/folders", + "singleEndpoint": "{{ originId }}", + "mergeDataSingleEndpoint": true, "headers": [], "query": [] }, diff --git a/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json b/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json index 7aa6512..f7f3e47 100644 --- a/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json +++ b/configurations/sharepoint-woo/synchronizations/sharepoint-woo-verzoeken-to-publications.json @@ -7,9 +7,11 @@ "sourceHash": "", "sourceTargetMapping": "1", "sourceConfig": { - "idPosition": "UniqueId", + "idPosition": "Properties.__deferred.uri", "resultsPosition": "d.results", "endpoint": "/Web/GetFolderByServerRelativePath(decodedurl='/WOO/Woo-verzoeken en -besluiten')/folders", + "singleEndpoint": "{{ originId }}", + "mergeDataSingleEndpoint": true, "headers": [], "query": [] }, diff --git a/lib/Service/AuthenticationService.php b/lib/Service/AuthenticationService.php index b59e41b..e433110 100644 --- a/lib/Service/AuthenticationService.php +++ b/lib/Service/AuthenticationService.php @@ -192,6 +192,35 @@ public function fetchOAuthTokens (array $configuration): string return $result['access_token']; } + /** + * Fetch an access token from the DeCOS non-implementation of OAuth 2.0 + * + * @param array $configuration The configuration of the source. + * + * @return string The access token + * + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function fetchDecosToken(array $configuration): string + { + $url = $configuration['tokenUrl']; + $tokenLocation = $configuration['tokenLocation']; + unset($configuration['tokenUrl']); + + $callConfig['json'] = $configuration; + + $client = new Client(); + $response = $client->post(uri: $url, options: $callConfig); + + $result = json_decode(json: $response->getBody()->getContents(), associative: true); + + if (isset($tokenLocation) === true) { + return $result[$tokenLocation]; + } + + return $result['token']; + } + /** * Get RSA key for RS and PS (asymmetrical) encryption. * diff --git a/lib/Service/SynchronizationService.php b/lib/Service/SynchronizationService.php index 8f88250..bba3445 100644 --- a/lib/Service/SynchronizationService.php +++ b/lib/Service/SynchronizationService.php @@ -47,6 +47,9 @@ class SynchronizationService private ObjectService $objectService; private Source $source; + const SINGLE_ENDPOINT = 'singleEndpoint'; + const MERGE_DATA_SINGLE_ENDPOINT = 'mergeDataSingleEndpoint'; + public function __construct( CallService $callService, @@ -230,16 +233,19 @@ public function getObjectFromSource(Synchronization $synchronization, string $en */ public function synchronizeContract(SynchronizationContract $synchronizationContract, Synchronization $synchronization = null, array $object = [], ?bool $isTest = false): SynchronizationContract|Exception|array { - - if ($synchronization !== null && isset($synchronization->getSourceConfig()['singleEndpoint']) === true) { + $sourceConfig = $synchronization->getSourceConfig(); + if ($synchronization !== null && isset($sourceConfig[$this::SINGLE_ENDPOINT]) === true) { // Update endpoint - $endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $synchronization->getSourceConfig()['singleEndpoint']); + $endpoint = str_replace(search: '{{ originId }}', replace: $this->getOriginId($synchronization, $object), subject: $sourceConfig[$this::SINGLE_ENDPOINT]); $endpoint = str_replace(search: '{{originId}}', replace: $this->getOriginId($synchronization, $object), subject: $endpoint); // Get object from source - $object = $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint); - + if (isset($sourceConfig[$this::MERGE_DATA_SINGLE_ENDPOINT]) === true && $sourceConfig[$this::MERGE_DATA_SINGLE_ENDPOINT] === true) { + $object = array_merge($object, $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint)); + } else { + $object = $this->getObjectFromSource(synchronization: $synchronization, endpoint: $endpoint); + } } diff --git a/lib/Twig/AuthenticationExtension.php b/lib/Twig/AuthenticationExtension.php index fed2dfb..a4cc8ec 100644 --- a/lib/Twig/AuthenticationExtension.php +++ b/lib/Twig/AuthenticationExtension.php @@ -11,6 +11,7 @@ public function getFunctions(): array { return [ new TwigFunction(name: 'oauthToken', callable: [AuthenticationRuntime::class, 'oauthToken']), + new TwigFunction(name: 'decosToken', callable: [AuthenticationRuntime::class, 'decosToken']), new TwigFunction(name: 'jwtToken', callable: [AuthenticationRuntime::class, 'jwtToken']), ]; //return parent::getFunctions(); // TODO: Change the autogenerated stub diff --git a/lib/Twig/AuthenticationRuntime.php b/lib/Twig/AuthenticationRuntime.php index 1655229..7534bcf 100644 --- a/lib/Twig/AuthenticationRuntime.php +++ b/lib/Twig/AuthenticationRuntime.php @@ -37,6 +37,25 @@ public function oauthToken(Source $source): string ); } + /** + * Add a decos non-oauth token to the configuration. + * + * @param Source $source + * @return string + * + * @throws GuzzleException + */ + public function decosToken(Source $source): string + { + $configuration = new Dot($source->getConfiguration(), true); + + $authConfig = $configuration->get('authentication'); + + return $this->authService->fetchDecosToken( + configuration: $authConfig + ); + } + /** * Add a jwt token to the configuration. *