Skip to content
Open
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
51 changes: 43 additions & 8 deletions src/Service/SyncXxllncCasesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
/**
* Service responsible for synchronizing xxllnc cases to woo objects.
*
* @author Conduction BV <info@conduction.nl>, Barry Brands <barry@conduction.nl>, Wilco Louwerse <wilco@conduction.nl>.
* @license EUPL <https://github.com/ConductionNL/contactcatalogus/blob/master/LICENSE.md>
* @author
* @license
*
* @package CommonGateway\WOOBundle
* @category Service
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -355,14 +381,23 @@ 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']);

$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);
Expand All @@ -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'],
],
]
Expand Down