From ca907082d8fd4d418d3c616d3dde99d597681687 Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Sun, 20 Oct 2024 10:56:06 +0200 Subject: [PATCH 1/2] small route fixes --- appinfo/routes.php | 4 ++-- lib/Service/DirectoryService.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 862602a1..a03872fb 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -16,9 +16,9 @@ ['name' => 'directory#index', 'url' => '/api/directory', 'verb' => 'GET'], ['name' => 'directory#show', 'url' => '/api/directory/{id}', 'verb' => 'GET', 'requirements' => ['path' => '.+']], ['name' => 'directory#update', 'url' => '/api/directory', 'verb' => 'POST'], - ['name' => 'directory#syncPublicationType', 'url' => '/api/directory/copy_pubpication_type', 'verb' => 'POST'], // Should be in directory becouse its public + ['name' => 'directory#publicationType', 'url' => '/api/directory/publication_types/{id}', 'verb' => 'GET'], // Should be in directory becouse its public // Publication - ['name' => 'synchronise#synchronise', 'url' => '/api/publication_types/synchronise/{id}', 'verb' => 'POST'], + ['name' => 'synchronise#synchronise', 'url' => '/api/publication_types/synchronise', 'verb' => 'POST'], // Dashboard ['name' => 'dashboard#index', 'url' => '/index', 'verb' => 'GET'], ['name' => 'dashboard#page', 'url' => '/', 'verb' => 'GET'], diff --git a/lib/Service/DirectoryService.php b/lib/Service/DirectoryService.php index 89f4e45b..46b2265d 100644 --- a/lib/Service/DirectoryService.php +++ b/lib/Service/DirectoryService.php @@ -406,6 +406,9 @@ public function syncPublicationType(string $url): array if (json_last_error() !== JSON_ERROR_NONE) { throw new \InvalidArgumentException('Invalid JSON data received from the URL'); } + + // Set the source to the URL + $publicationType['source'] = $url; // Check if a publication type with the same name already exists $existingPublicationType = $this->objectService->getObjects( From 364e3ddf93565ca974bf633b5ec58c984620812c Mon Sep 17 00:00:00 2001 From: Ruben van der Linde Date: Sun, 20 Oct 2024 11:58:21 +0200 Subject: [PATCH 2/2] Added ownership and listed on the directory --- lib/Service/DirectoryService.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Service/DirectoryService.php b/lib/Service/DirectoryService.php index 46b2265d..228de0cf 100644 --- a/lib/Service/DirectoryService.php +++ b/lib/Service/DirectoryService.php @@ -124,6 +124,18 @@ private function getDirectoryFromListing(Listing|array $listing): array // $listing['uuid'], //@todo this breaks stuff when trying to find and update a listing $listing['hash']); + // Process publication types + if (isset($listing['publicationTypes']) && is_array($listing['publicationTypes'])) { + foreach ($listing['publicationTypes'] as &$publicationType) { + // Convert publicationType to array if it's an object + if ($publicationType instanceof \JsonSerializable) { + $publicationType = $publicationType->jsonSerialize(); + } + + + } + } + // TODO: This should be mapped to the stoplight documentation return $listing; } @@ -158,6 +170,21 @@ private function getDirectoryFromCatalog(Catalog|array $catalog): array $catalog['search'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("opencatalogi.search.index")); $catalog['directory'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("opencatalogi.directory.index")); + // Process publication types + if (isset($catalog['publicationTypes']) && is_array($catalog['publicationTypes'])) { + foreach ($catalog['publicationTypes'] as &$publicationType) { + // Convert publicationType to array if it's an object + if ($publicationType instanceof \JsonSerializable) { + $publicationType = $publicationType->jsonSerialize(); + } + $publicationType['listed'] = true; + $publicationType['owner'] = true; + if (!isset($publicationType['source']) || empty($publicationType['source'])) { + $publicationType['source'] = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute("opencatalogi.directory.publicationType", ['id' => $publicationType['id']])); + } + } + } + // TODO: This should be mapped to the stoplight documentation return $catalog; } @@ -200,7 +227,7 @@ public function getDirectories(): array // TODO: Define when a listed item should not be shown (e.g. when secret or trusted is true), this is a product decision // Get all the catalogi - $catalogi = $this->objectService->getObjects(objectType: 'catalog', extend: ['publicationTypes','organization']); + $catalogi = $this->objectService->getObjects(objectType: 'catalog', extend: ['publicationTypes', 'organization']); $catalogi = array_map([$this, 'getDirectoryFromCatalog'], $catalogi); // Filter out the catalogi that are not listed