Skip to content

Commit

Permalink
Merge branch 'hotfix/sync-publication-types'
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvdlinde committed Oct 20, 2024
2 parents b46e6a8 + 364e3dd commit e753a29
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
32 changes: 31 additions & 1 deletion lib/Service/DirectoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -406,6 +433,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(
Expand Down

0 comments on commit e753a29

Please sign in to comment.