Skip to content

Commit

Permalink
Merge pull request #421 from jjrom/I419-rewrite-facet
Browse files Browse the repository at this point in the history
I419 rewrite facet
  • Loading branch information
jjrom authored Jun 21, 2024
2 parents c7404e6 + 2ac6846 commit b38d0e1
Show file tree
Hide file tree
Showing 22 changed files with 4,991 additions and 5,788 deletions.
77 changes: 2 additions & 75 deletions app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,80 +692,7 @@ class RestoCollection
public $osDescription = null;

/**
* Statistics
*
* @OA\Schema(
* schema="Statistics",
* description="Collection facets statistics",
* required={"count", "facets"},
* @OA\Property(
* property="count",
* type="integer",
* description="Total number of features in the collection"
* ),
* @OA\Property(
* property="facets",
* description="Statistics per facets",
* @OA\JsonContent(
* @OA\Property(
* property="continent",
* type="array",
* description="Number of features in the collection per continent"
* ),
* @OA\Property(
* property="instrument",
* type="array",
* description="Number of features in the collection per instrument"
* ),
* @OA\Property(
* property="platform",
* type="array",
* description="Number of features in the collection per platform"
* ),
* @OA\Property(
* property="processingLevel",
* type="array",
* description="Number of features in the collection per processing level"
* ),
* @OA\Property(
* property="productType",
* type="array",
* description="Number of features in the collection per product Type"
* )
* )
* ),
* example={
* "count": 5322724,
* "facets": {
* "continent": {
* "Africa": 671538,
* "Antarctica": 106337,
* "Asia": 747847,
* "Europe": 1992756,
* "North America": 1012027,
* "Oceania": 218789,
* "Seven seas (open ocean)": 9481,
* "South America": 313983
* },
* "instrument": {
* "HRS": 2,
* "MSI": 5322722
* },
* "platform": {
* "S2A": 3346319,
* "S2B": 1976403,
* "SPOT6": 1
* },
* "processingLevel": {
* "LEVEL1C": 5322722
* },
* "productType": {
* "PX": 2,
* "REFLECTANCE": 5322722
* }
* }
* }
* )
* Summaries
*/
private $summaries = null;

Expand Down Expand Up @@ -993,7 +920,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',
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoConstants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/resto/core/RestoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ abstract class RestoModel
* ...
* )
* 2. 'auto'
* In this case will be computed from facets table
* In this case will be computed from catalog table
*/
public $searchFilters = array(

Expand Down
22 changes: 11 additions & 11 deletions app/resto/core/RestoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);

/*
Expand Down
6 changes: 3 additions & 3 deletions app/resto/core/addons/Cataloger.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private function catalogsFromProperties($properties, $collection)
*/
$model = isset($collection) ? $collection->model : new DefaultModel();
foreach (array_values($model->facetCategories) as $facetCategory) {
$catalogs = array_merge($catalogs, $this->catalogsFromFacets($properties, $facetCategory, $model));
$catalogs = array_merge($catalogs, $this->catalogsFromFacetCategory($properties, $facetCategory, $model));
}

/*
Expand All @@ -438,14 +438,14 @@ private function catalogsFromProperties($properties, $collection)
}

/**
* Process catalogs for facets
* Process catalogs from facet category
*
* @param array $properties
* @param array $facetCategory
* @param RestoModel $model
* @return array
*/
private function catalogsFromFacets($properties, $facetCategory, $model)
private function catalogsFromFacetCategory($properties, $facetCategory, $model)
{
$parentId = null;
$catalogs = array();
Expand Down
21 changes: 0 additions & 21 deletions app/resto/core/api/CollectionsAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ public function __construct($context, $user)
* )
* ),
* @OA\Property(
* property="summaries",
* type="object",
* @OA\JsonContent(
* @OA\Property(
* property="resto:stats",
* type="object",
* ref="#/components/schemas/Statistics"
* )
* )
* ),
* @OA\Property(
* property="collections",
* description="List of available collections",
* type="array",
Expand Down Expand Up @@ -113,16 +102,6 @@ public function __construct($context, $user)
* "trs": "http://www.opengis.net/def/uom/ISO-8601/0/Gregorian"
* }
* },
* "summaries": {
* "resto:stats": {
* "count": 11310,
* "facets": {
* "collection": {
* "L8": 11307
* }
* }
* }
* },
* "resto:info": {
* "osDescription": {
* "ShortName": "resto",
Expand Down
1 change: 0 additions & 1 deletion app/resto/core/api/FeaturesAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,6 @@ public function deleteFeature($params)
RestoLogUtil::httpError(403);
}

// Result contains boolean for facetsDeleted
$result = (new FeaturesFunctions($this->context->dbDriver))->removeFeature($feature);

return RestoLogUtil::success('Feature deleted', array(
Expand Down
21 changes: 12 additions & 9 deletions app/resto/core/addons/STAC.php → app/resto/core/api/STACAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
* )
* )
*/
class STAC extends RestoAddOn
class STACAPI
{
/**
* Links
Expand Down Expand Up @@ -234,6 +234,9 @@ class STAC extends RestoAddOn
*/
private $catalogsFunctions;

private $context;
private $user;

/**
* Constructor
*
Expand All @@ -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);
}

Expand Down Expand Up @@ -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'])
)
);
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'] ?? '',
Expand Down Expand Up @@ -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'],
Expand Down
6 changes: 3 additions & 3 deletions app/resto/core/api/ServicesAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -241,7 +241,7 @@ public function hello()
'roles' => array('collections')
),
array(
'rel' => 'catalogs',
'rel' => 'child',
'type' => RestoUtil::$contentTypes['json'],
'title' => 'Catalogs',
'href' => $this->context->core['baseUrl'] . RestoRouter::ROUTE_TO_CATALOGS
Expand Down Expand Up @@ -511,6 +511,6 @@ public function resetPassword($params, $body)
*/
private function conformsTo()
{
return STAC::CONFORMANCE_CLASSES;
return STACAPI::CONFORMANCE_CLASSES;
}
}
2 changes: 1 addition & 1 deletion app/resto/core/dbfunctions/CollectionsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getCollectionDescription($id)
}

/**
* Get description of all collections including facets
* Get description of all collections
*
* @param array $params
* @return array
Expand Down
Loading

0 comments on commit b38d0e1

Please sign in to comment.