From 6c230573e020e1a0698a5e485a83a678ff8f907d Mon Sep 17 00:00:00 2001 From: Mark West <66728126+MWest2020@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:15:42 +0200 Subject: [PATCH 1/2] Update SyncXxllncCasesService.php https://chatgpt.com/share/e/66f855ba-6eb0-800b-8070-7ac12fe7f3e1 --- src/Service/SyncXxllncCasesService.php | 71 +++++++++++++++++++------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/src/Service/SyncXxllncCasesService.php b/src/Service/SyncXxllncCasesService.php index f3a77b1..b3930e0 100644 --- a/src/Service/SyncXxllncCasesService.php +++ b/src/Service/SyncXxllncCasesService.php @@ -25,8 +25,8 @@ /** * Service responsible for synchronizing xxllnc cases to woo objects. * - * @author Conduction BV , Barry Brands , Wilco Louwerse . - * @license EUPL + * @author + * @license * * @package CommonGateway\WOOBundle * @category Service @@ -137,7 +137,7 @@ public function __construct( $this->cacheService = $cacheService; $this->wooService = $wooService; - }//end __construct() + } /** @@ -155,7 +155,7 @@ public function setStyle(SymfonyStyle $style): self return $this; - }//end setStyle() + } /** @@ -208,7 +208,7 @@ private function retrieveFile(array $result, array $documentMeta, array $config) return $this->mappingService->mapping($config['mapping'], array_merge($documentMeta, ['url' => $url, 'documentText' => $documentText])); - }//end retrieveFile() + } /** @@ -236,8 +236,8 @@ private function getBijlagen(array $result, array $config, array &$fileURLS): ar $documentMeta = $result['values']["attribute.woo_$field"][0]; $fileURLS[$field] = $this->retrieveFile($result, $documentMeta, $config); $fileNames[] = $result['values']["attribute.woo_$field"][0]['filename']; - }//end if - }//end foreach + } + } $bijlagen = []; if (isset($result['values']["attribute.woo_publicatie"]) === true) { @@ -246,12 +246,12 @@ private function getBijlagen(array $result, array $config, array &$fileURLS): ar $bijlagen[] = $this->retrieveFile($result, $documentMeta, $config); $fileNames[] = $documentMeta['filename']; } - }//end foreach - }//end if + } + } return $bijlagen; - }//end getBijlagen() + } /** @@ -276,7 +276,7 @@ private function handleCustomLogic(array $objectArray, array $result, Endpoint $ return $this->mappingService->mapping($customFieldsMapping, array_merge($objectArray, $fileURLS, ["bijlagen" => $bijlagen, "portalUrl" => $portalURL, "id" => $result['id']])); - }//end handleCustomLogic() + } /** @@ -310,7 +310,32 @@ private function fetchObjects(Source $source, ?int $page=1, array $results=[]): return $results; - }//end fetchObjects() + } + + + /** + * Valideert de OIN-waarde om ervoor te zorgen dat deze alleen cijfers bevat. + * + * @param mixed $oin De OIN-waarde uit de configuratie. + * + * @return string De gevalideerde OIN-waarde. + * + * @throws \InvalidArgumentException als de OIN ongeldig is. + */ + private function validateOin($oin): string + { + // Controleer of de OIN is ingesteld en een niet-lege string is + if (!isset($oin) || !is_string($oin) || trim($oin) === '') { + throw new \InvalidArgumentException('OIN-waarde ontbreekt of is ongeldig.'); + } + + // Controleer of de OIN alleen uit cijfers bestaat (voorloopnullen toegestaan) + if (!preg_match('/^\d+$/', $oin)) { + throw new \InvalidArgumentException('OIN-waarde moet alleen uit cijfers bestaan.'); + } + + return $oin; + } /** @@ -355,7 +380,7 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array isset($this->style) === true && $this->style->error("{$this->configuration['source']}, {$this->configuration['schema']} or {$this->configuration['mapping']} not found, ending syncXxllncCasesHandler"); return []; - }//end if + } isset($this->style) === true && $this->style->info("Fetching cases from {$source->getLocation()}"); $this->logger->info("Fetching cases from {$source->getLocation()}", ['plugin' => 'common-gateway/woo-bundle']); @@ -363,6 +388,15 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array $results = $this->fetchObjects($source); $this->entityManager->flush(); + // Valideer de OIN-waarde + try { + $oin = $this->validateOin($this->configuration['oin']); + } catch (\InvalidArgumentException $e) { + $this->logger->error('Validatie van OIN mislukt: ' . $e->getMessage(), ['plugin' => 'common-gateway/woo-bundle']); + isset($this->style) === true && $this->style->error('Validatie van OIN mislukt: ' . $e->getMessage()); + return []; + } + $idsSynced = []; $responseItems = []; $hydrationService = new HydrationService($this->syncService, $this->entityManager); @@ -377,7 +411,7 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array 'settings' => ['allowPDFOnly' => $configuration['allowPDFOnly']], 'autoPublish' => $this->configuration['autoPublish'] ?? true, 'organisatie' => [ - 'oin' => $this->configuration['oin'], + 'oin' => $oin, 'naam' => $this->configuration['organisatie'], ], ] @@ -431,8 +465,8 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array isset($this->style) === true && $this->style->error("Something went wrong synchronizing sourceId: {$result['id']} with error: {$exception->getMessage()}"); $this->logger->error("Something went wrong synchronizing sourceId: {$result['id']} with error: {$exception->getMessage()}", ['plugin' => 'common-gateway/woo-bundle']); continue; - }//end try - }//end foreach + } + } $this->entityManager->flush(); @@ -447,7 +481,6 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array return $this->data; - }//end syncXxllncCasesHandler() - + } -}//end class +} From 9899033d1ca86007108e34a968a27b0cbd7951ce Mon Sep 17 00:00:00 2001 From: GitHub Actions <> Date: Sat, 28 Sep 2024 19:16:05 +0000 Subject: [PATCH 2/2] Update src from PHP Codesniffer --- src/Service/SyncXxllncCasesService.php | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Service/SyncXxllncCasesService.php b/src/Service/SyncXxllncCasesService.php index b3930e0..93cde8d 100644 --- a/src/Service/SyncXxllncCasesService.php +++ b/src/Service/SyncXxllncCasesService.php @@ -25,8 +25,8 @@ /** * Service responsible for synchronizing xxllnc cases to woo objects. * - * @author - * @license + * @author + * @license * * @package CommonGateway\WOOBundle * @category Service @@ -137,7 +137,7 @@ public function __construct( $this->cacheService = $cacheService; $this->wooService = $wooService; - } + }//end __construct() /** @@ -155,7 +155,7 @@ public function setStyle(SymfonyStyle $style): self return $this; - } + }//end setStyle() /** @@ -208,7 +208,7 @@ private function retrieveFile(array $result, array $documentMeta, array $config) return $this->mappingService->mapping($config['mapping'], array_merge($documentMeta, ['url' => $url, 'documentText' => $documentText])); - } + }//end retrieveFile() /** @@ -251,7 +251,7 @@ private function getBijlagen(array $result, array $config, array &$fileURLS): ar return $bijlagen; - } + }//end getBijlagen() /** @@ -276,7 +276,7 @@ private function handleCustomLogic(array $objectArray, array $result, Endpoint $ return $this->mappingService->mapping($customFieldsMapping, array_merge($objectArray, $fileURLS, ["bijlagen" => $bijlagen, "portalUrl" => $portalURL, "id" => $result['id']])); - } + }//end handleCustomLogic() /** @@ -310,7 +310,7 @@ private function fetchObjects(Source $source, ?int $page=1, array $results=[]): return $results; - } + }//end fetchObjects() /** @@ -335,7 +335,8 @@ private function validateOin($oin): string } return $oin; - } + + }//end validateOin() /** @@ -392,8 +393,8 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array try { $oin = $this->validateOin($this->configuration['oin']); } catch (\InvalidArgumentException $e) { - $this->logger->error('Validatie van OIN mislukt: ' . $e->getMessage(), ['plugin' => 'common-gateway/woo-bundle']); - isset($this->style) === true && $this->style->error('Validatie van OIN mislukt: ' . $e->getMessage()); + $this->logger->error('Validatie van OIN mislukt: '.$e->getMessage(), ['plugin' => 'common-gateway/woo-bundle']); + isset($this->style) === true && $this->style->error('Validatie van OIN mislukt: '.$e->getMessage()); return []; } @@ -465,8 +466,8 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array isset($this->style) === true && $this->style->error("Something went wrong synchronizing sourceId: {$result['id']} with error: {$exception->getMessage()}"); $this->logger->error("Something went wrong synchronizing sourceId: {$result['id']} with error: {$exception->getMessage()}", ['plugin' => 'common-gateway/woo-bundle']); continue; - } - } + }//end try + }//end foreach $this->entityManager->flush(); @@ -481,6 +482,7 @@ public function syncXxllncCasesHandler(array $data, array $configuration): array return $this->data; - } + }//end syncXxllncCasesHandler() + -} +}//end class