diff --git a/src/Service/SyncXxllncCasesService.php b/src/Service/SyncXxllncCasesService.php index f3a77b1..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 Conduction BV , Barry Brands , Wilco Louwerse . - * @license EUPL + * @author + * @license * * @package CommonGateway\WOOBundle * @category Service @@ -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,8 +246,8 @@ 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; @@ -313,6 +313,32 @@ private function fetchObjects(Source $source, ?int $page=1, array $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; + + }//end validateOin() + + /** * Handles the synchronization of xxllnc cases. * @@ -355,7 +381,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 +389,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 +412,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'], ], ]