From d5910f07abafa42d86c765f0ccbcc95e1ae7d7ee Mon Sep 17 00:00:00 2001 From: jjrom Date: Wed, 12 Jun 2024 09:40:42 +0200 Subject: [PATCH 1/4] Convert STAC addon to STACAPI class --- app/resto/core/RestoCollection.php | 2 +- app/resto/core/RestoCollections.php | 2 +- app/resto/core/RestoConstants.php | 2 +- app/resto/core/RestoContext.php | 5 ++-- app/resto/core/RestoRouter.php | 22 +++++++------- .../core/{addons/STAC.php => api/STACAPI.php} | 21 +++++++------ app/resto/core/api/ServicesAPI.php | 4 +-- app/resto/core/utils/RestoFeatureUtil.php | 2 +- build/resto/config.php.template | 7 +---- config.env | 8 ++--- docs/api/resto-api.html | 30 +++++++++---------- docs/api/resto-api.json | 10 +++---- 12 files changed, 54 insertions(+), 61 deletions(-) rename app/resto/core/{addons/STAC.php => api/STACAPI.php} (98%) diff --git a/app/resto/core/RestoCollection.php b/app/resto/core/RestoCollection.php index d14165d1..d25aa0b4 100755 --- a/app/resto/core/RestoCollection.php +++ b/app/resto/core/RestoCollection.php @@ -993,7 +993,7 @@ public function toArray() $osDescription = $this->osDescription[$this->context->lang] ?? $this->osDescription['en']; $collectionArray = array( - 'stac_version' => STAC::STAC_VERSION, + 'stac_version' => STACAPI::STAC_VERSION, 'stac_extensions' => $this->model->stacExtensions, 'id' => $this->id, 'type' => 'Collection', diff --git a/app/resto/core/RestoCollections.php b/app/resto/core/RestoCollections.php index 00d96ed4..3fb192e0 100755 --- a/app/resto/core/RestoCollections.php +++ b/app/resto/core/RestoCollections.php @@ -233,7 +233,7 @@ public function load($params = array()) public function toArray() { $collections = array( - 'stac_version' => STAC::STAC_VERSION, + 'stac_version' => STACAPI::STAC_VERSION, 'id' => $this->context->osDescription['ShortName'], 'type' => 'Catalog', 'title' => $this->context->osDescription['LongName'] ?? $this->context->osDescription['ShortName'], diff --git a/app/resto/core/RestoConstants.php b/app/resto/core/RestoConstants.php index 972efc07..988cd4f6 100644 --- a/app/resto/core/RestoConstants.php +++ b/app/resto/core/RestoConstants.php @@ -20,7 +20,7 @@ class RestoConstants // [IMPORTANT] Starting resto 7.x, default routes are defined in RestoRouter class // resto version - const VERSION = '9.0.0-RC1'; + const VERSION = '9.0.0-RC2'; /* ============================================================ * NEVER EVER TOUCH THESE VALUES diff --git a/app/resto/core/RestoContext.php b/app/resto/core/RestoContext.php index 27c0a739..84d766da 100755 --- a/app/resto/core/RestoContext.php +++ b/app/resto/core/RestoContext.php @@ -50,9 +50,8 @@ class RestoContext // True to store all user queries to database 'storeQuery' => false, - // True to display "catalogs" and "facets" childs directly within the STAC root endpoint - // instead of having them under respectively "catalogs" and "facets" parents - 'mergeRootCatalogLinks' => false, + // Display catalog that have at least 'catalogMinMatch' object + 'catalogMinMatch' => 0, // Use cache 'useCache' => false, diff --git a/app/resto/core/RestoRouter.php b/app/resto/core/RestoRouter.php index 1d273c27..4447a36b 100755 --- a/app/resto/core/RestoRouter.php +++ b/app/resto/core/RestoRouter.php @@ -87,7 +87,7 @@ class RestoRouter array('GET', RestoRouter::ROUTE_TO_COLLECTION, false, 'CollectionsAPI::getCollection'), // Get :collectionId description array('PUT', RestoRouter::ROUTE_TO_COLLECTION, true, 'CollectionsAPI::updateCollection'), // Update :collectionId array('DELETE', RestoRouter::ROUTE_TO_COLLECTION, true, 'CollectionsAPI::deleteCollection'), // Delete :collectionId - array('GET', RestoRouter::ROUTE_TO_COLLECTION . '/queryables', false, 'STAC::getQueryables'), // OAFeature API - Queryables + array('GET', RestoRouter::ROUTE_TO_COLLECTION . '/queryables', false, 'STACAPI::getQueryables'), // OAFeature API - Queryables // API for features array('GET', RestoRouter::ROUTE_TO_FEATURES, false, 'FeaturesAPI::getFeaturesInCollection'), // Search features in :collectionId @@ -112,16 +112,16 @@ class RestoRouter array('POST', RestoRouter::ROUTE_TO_RESET_PASSWORD, false, 'ServicesAPI::resetPassword'), // Reset password // STAC - array('GET', RestoRouter::ROUTE_TO_ASSETS . '/{urlInBase64}', false, 'STAC::getAsset'), // Get an asset using HTTP 301 permanent redirect - array('GET', RestoRouter::ROUTE_TO_CATALOGS, false, 'STAC::getCatalogs'), - array('GET', RestoRouter::ROUTE_TO_CATALOGS . '/*', false, 'STAC::getCatalogs'), // Get catalogs - array('GET', RestoRouter::ROUTE_TO_STAC_CHILDREN, false, 'STAC::getChildren'), // STAC API - Children - array('GET', RestoRouter::ROUTE_TO_STAC_QUERYABLES, false, 'STAC::getQueryables'), // STAC/OAFeature API - Queryables - array('GET', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STAC::search'), // STAC API - core search (GET) - array('POST', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STAC::search'), // STAC API - core search (POST) - array('POST', RestoRouter::ROUTE_TO_CATALOGS , true , 'STAC::addCatalog'), // STAC - Add a catalog - array('PUT' , RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STAC::updateCatalog'), // STAC - Update a catalog - array('DELETE', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STAC::removeCatalog') // STAC - Remove a catalog + array('GET', RestoRouter::ROUTE_TO_ASSETS . '/{urlInBase64}', false, 'STACAPI::getAsset'), // Get an asset using HTTP 301 permanent redirect + array('GET', RestoRouter::ROUTE_TO_CATALOGS, false, 'STACAPI::getCatalogs'), + array('GET', RestoRouter::ROUTE_TO_CATALOGS . '/*', false, 'STACAPI::getCatalogs'), // Get catalogs + array('GET', RestoRouter::ROUTE_TO_STAC_CHILDREN, false, 'STACAPI::getChildren'), // STAC API - Children + array('GET', RestoRouter::ROUTE_TO_STAC_QUERYABLES, false, 'STACAPI::getQueryables'), // STAC/OAFeature API - Queryables + array('GET', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STACAPI::search'), // STAC API - core search (GET) + array('POST', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STACAPI::search'), // STAC API - core search (POST) + array('POST', RestoRouter::ROUTE_TO_CATALOGS , true , 'STACAPI::addCatalog'), // STAC - Add a catalog + array('PUT' , RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::updateCatalog'), // STAC - Update a catalog + array('DELETE', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::removeCatalog') // STAC - Remove a catalog ); /* diff --git a/app/resto/core/addons/STAC.php b/app/resto/core/api/STACAPI.php similarity index 98% rename from app/resto/core/addons/STAC.php rename to app/resto/core/api/STACAPI.php index d6596c24..a719bb79 100644 --- a/app/resto/core/addons/STAC.php +++ b/app/resto/core/api/STACAPI.php @@ -109,7 +109,7 @@ * ) * ) */ -class STAC extends RestoAddOn +class STACAPI { /** * Links @@ -234,6 +234,9 @@ class STAC extends RestoAddOn */ private $catalogsFunctions; + private $context; + private $user; + /** * Constructor * @@ -242,8 +245,8 @@ class STAC extends RestoAddOn */ public function __construct($context, $user) { - parent::__construct($context, $user); - $this->options['minMatch'] = isset($this->options['minMatch']) && is_int($this->options['minMatch']) ? $this->options['minMatch'] : 0; + $this->context = $context; + $this->user = $user; $this->catalogsFunctions = new CatalogsFunctions($this->context->dbDriver); } @@ -273,14 +276,14 @@ public function getCatalogs($params) // This is /catalogs if ( !isset($params['segments']) ) { return array( - 'stac_version' => STAC::STAC_VERSION, + 'stac_version' => STACAPI::STAC_VERSION, 'id' => 'catalogs', 'type' => 'Catalog', 'title' => 'Catalogs', 'description' => 'List of available catalogs', 'links' => array_merge( $this->getBaseLinks(), - $this->getRootCatalogLinks($this->options['minMatch']) + $this->getRootCatalogLinks($this->context->core['catalogMinMatch']) ) ); } @@ -356,7 +359,7 @@ public function addCatalog($params, $body) * Check mandatory properties */ /*if ( isset($body['stac_version']) ) { - return RestoLogUtil::httpError(400, 'Missing mandatory catalog stac_version - should be set to ' . STAC::STAC_VERSION ); + return RestoLogUtil::httpError(400, 'Missing mandatory catalog stac_version - should be set to ' . STACAPI::STAC_VERSION ); }*/ if ( !isset($body['id']) ) { return RestoLogUtil::httpError(400, 'Missing mandatory catalog id'); @@ -671,7 +674,7 @@ public function getChildren($params) // Initialize router to process each children individually $router = new RestoRouter($this->context, $this->user); - $links = $this->getRootCatalogLinks($this->options['minMatch']); + $links = $this->getRootCatalogLinks($this->context->core['catalogMinMatch']); for ($i = 0, $ii = count($links); $i < $ii; $i++) { if ($links[$i]['rel'] == 'child') { try { @@ -1327,7 +1330,7 @@ private function processPath($segments, $params = array()) // The path is the catalog identifier $parentAndChilds = $this->getParentAndChilds(join('/', $segments)); return array( - 'stac_version' => STAC::STAC_VERSION, + 'stac_version' => STACAPI::STAC_VERSION, 'id' => $segments[count($segments) -1 ], 'title' => $parentAndChilds['parent']['title'] ?? '', 'description' => $parentAndChilds['parent']['description'] ?? '', @@ -1563,7 +1566,7 @@ private function getRootCatalogLinks() for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) { // Returns only catalogs with count >= minMath - if ($catalogs[$i]['counters']['total'] >= $this->options['minMatch']) { + if ($catalogs[$i]['counters']['total'] >= $this->context->core['catalogMinMatch']) { $link = array( 'rel' => 'child', 'title' => $catalogs[$i]['title'], diff --git a/app/resto/core/api/ServicesAPI.php b/app/resto/core/api/ServicesAPI.php index 42093d88..b8cada94 100755 --- a/app/resto/core/api/ServicesAPI.php +++ b/app/resto/core/api/ServicesAPI.php @@ -182,7 +182,7 @@ public function hello() { return array( - 'stac_version' => STAC::STAC_VERSION, + 'stac_version' => STACAPI::STAC_VERSION, 'id' => 'root', 'type' => 'Catalog', 'title' => $this->title, @@ -511,6 +511,6 @@ public function resetPassword($params, $body) */ private function conformsTo() { - return STAC::CONFORMANCE_CLASSES; + return STACAPI::CONFORMANCE_CLASSES; } } diff --git a/app/resto/core/utils/RestoFeatureUtil.php b/app/resto/core/utils/RestoFeatureUtil.php index afe7a807..603c5034 100755 --- a/app/resto/core/utils/RestoFeatureUtil.php +++ b/app/resto/core/utils/RestoFeatureUtil.php @@ -142,7 +142,7 @@ private function formatRawFeatureArray($rawFeatureArray, $collection) ) ), 'assets' => array(), - 'stac_version' => STAC::STAC_VERSION, + 'stac_version' => STACAPI::STAC_VERSION, 'stac_extensions' => $collection->model->stacExtensions ); diff --git a/build/resto/config.php.template b/build/resto/config.php.template index 7e77676c..8349cbd4 100755 --- a/build/resto/config.php.template +++ b/build/resto/config.php.template @@ -11,7 +11,7 @@ return array( 'endpoint' => '${STORAGE_PUBLIC_ENDPOINT:-/static}' ), 'storeQuery' => ${STORE_QUERY:-false}, - 'mergeRootCatalogLinks' => ${MERGE_ROOT_CATALOG_LINKS:-false}, + 'catalogMinMatch' => ${CATALOG_MINMATCH:-0}, 'timezone' => '${TIMEZONE:-Europe/Paris}', 'tokenDuration' => ${JWT_DURATION:-8640000}, 'userAutoValidation' => ${USER_AUTOVALIDATION:-true}, @@ -88,11 +88,6 @@ return array( ) ), 'addons' => array( - 'STAC' => array( - 'options' => array( - 'minMatch' => ${ADDON_STAC_MINMATCH:-0} - ) - ), 'Cataloger' => array( 'options' => array( 'iTag' => array( diff --git a/config.env b/config.env index d692b44a..2df8056d 100644 --- a/config.env +++ b/config.env @@ -96,9 +96,8 @@ JWT_PASSPHRASE="Super secret passphrase" ### True to store all user queries to database #STORE_QUERY=false -### True to display "catalogs" and "facets" childs directly within the STAC root endpoint -### instead of having them under respectively "catalogs" and "facets" parents -#MERGE_ROOT_CATALOG_LINKS=false +### STAC - only display child/items links with at least minMatch child/items +#CATALOG_MINMATCH=0 ### Automatic user validation on activation #USER_AUTOVALIDATION=true @@ -173,9 +172,6 @@ ADDON_TAG_ITAG_ENDPOINT=http://itag #ADDON_TAG_ITAG_TAGGERS=political,physical #ADDON_TAG_ADD_SEARCH_FILTERS=false -### STAC - only display child/items links with at least minMatch child/items -#ADDON_STAC_MINMATCH=0 - ### ===================================================================== ### Server configuration (nginx/php-fpm) ### ===================================================================== diff --git a/docs/api/resto-api.html b/docs/api/resto-api.html index aacc0526..3a896157 100644 --- a/docs/api/resto-api.html +++ b/docs/api/resto-api.html @@ -1560,7 +1560,7 @@