From 9fd944727272307801f44b3965e2ead330269519 Mon Sep 17 00:00:00 2001 From: Robert Zondervan Date: Tue, 13 Aug 2024 11:53:15 +0200 Subject: [PATCH] Fixes from local tests --- lib/Controller/PublicationsController.php | 7 ++++++- lib/Service/ValidationService.php | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/Controller/PublicationsController.php b/lib/Controller/PublicationsController.php index d4983142..7c86e908 100644 --- a/lib/Controller/PublicationsController.php +++ b/lib/Controller/PublicationsController.php @@ -14,6 +14,7 @@ use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\JSONResponse; +use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\IAppConfig; use OCP\IRequest; use Symfony\Component\Uid\Uuid; @@ -215,7 +216,11 @@ public function create(ObjectService $objectService, ElasticSearchService $elast } } - $data = $validationService->validatePublication($data); + try { + $data = $validationService->validatePublication($data); + } catch (OCSBadRequestException $exception) { + return new JSONResponse(data: ['message' => $exception->getMessage()], statusCode: 400); + } if($this->config->hasKey($this->appName, 'mongoStorage') === false || $this->config->getValueString($this->appName, 'mongoStorage') !== '1' diff --git a/lib/Service/ValidationService.php b/lib/Service/ValidationService.php index 19269e30..8f68ff69 100644 --- a/lib/Service/ValidationService.php +++ b/lib/Service/ValidationService.php @@ -56,8 +56,8 @@ public function getMongodbConfig(): array */ public function getCatalog (string $id): array { - if ($this->config->hasKey(app: $this->appName, key: 'mongoStorage') === false - || $this->config->getValueString(app: $this->appName, key: 'mongoStorage') !== '1' + if ($this->config->hasKey(app: $this->appName, key: 'mongoStorage') !== false + || $this->config->getValueString(app: $this->appName, key: 'mongoStorage') === '1' ) { $filter = ['id' => $id, '_schema' => 'catalog']; @@ -77,7 +77,7 @@ public function getCatalog (string $id): array */ public function validatePublication(array $publication): array { - $catalogId = $publication['catalog']; + $catalogId = $publication['catalogi']; $metadata = $publication['metadata']; $catalog = $this->getCatalog($catalogId);