Skip to content

Commit

Permalink
Merge pull request #420 from jjrom/I419-rewrite-facet
Browse files Browse the repository at this point in the history
Rewrite facets/catalogs/keywords
  • Loading branch information
jjrom authored Jun 11, 2024
2 parents 1b8ad1a + 286507f commit c7404e6
Show file tree
Hide file tree
Showing 30 changed files with 2,380 additions and 2,074 deletions.
5 changes: 4 additions & 1 deletion app/resto/core/RestoAddOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class RestoAddOn
protected $options;

/*
* If set, options array is initialize from "$optionsFrom" add-on
* By default addon options is set from the addon name.
* If optionsFrom is set, then options array is set from the addon named "$optionsFrom" instead
*
* For an example, see https://github.com/jjrom/resto-addon-snapplanet)
*/
protected $optionsFrom = null;

Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ public function addFeatures($body, $params)
public function getSummaries()
{
if ( !isset($this->summaries) ) {
$summaries = (new FacetsFunctions($this->context->dbDriver))->getSummaries(null, $this->id);
$summaries = (new CatalogsFunctions($this->context->dbDriver))->getSummaries(null, $this->id);
if ( isset($summaries[$this->id]) ) {
$this->setSummaries($summaries[$this->id]);
}
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 @@ -327,7 +327,7 @@ public function getOSDD($model)
public function getSummaries()
{
if ( !isset($this->summaries) ) {
$this->summaries = (new FacetsFunctions($this->context->dbDriver))->getSummaries(null, null);
$this->summaries = (new CatalogsFunctions($this->context->dbDriver))->getSummaries(null, null);
}
return $this->summaries;
}
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 = '8.0.10';
const VERSION = '9.0.0-RC1';

/* ============================================================
* NEVER EVER TOUCH THESE VALUES
Expand Down
3 changes: 0 additions & 3 deletions app/resto/core/RestoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class RestoContext
// Shared links validity duration (in seconds)
'sharedLinkDuration' => 86400,

// True to store count statistics for each POST,PUT,DELETE on features
'storeFacets' => true,

// True to store all user queries to database
'storeQuery' => false,

Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoDatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function pQuery($query, $params, $errorCode = 500, $errorMessage = null)
* Convert database query result into array
*
* @param PgSql\Result $results
* @return array
* @return Array
*/
public function fetch($results)
{
Expand Down
42 changes: 17 additions & 25 deletions app/resto/core/RestoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,6 @@ abstract class RestoModel
*/
public $tables = array();

/*
* Parameters to apply to database storage for products related to this model
*
* - tablePrefix : all features belonging to a collection referencing this model will be stored in a dedicated table [tablePrefix]__feature instead of feature"
* - storeFacets = if true, facets are stored for model related products
*/
public $dbParams = array(
'tablePrefix' => '',
'storeFacets' => true
);

/*
* Tag add-on configuration:
* [IMPORTANT] strategy values:
Expand Down Expand Up @@ -443,12 +432,10 @@ public function storeFeatures($collection, $body, $params)
// Feature case
if ($data['type'] === 'Feature') {
$insert = $this->storeFeature($collection, $data, $params);

if ($insert['result'] !== false) {
if ( isset($insert['result']) ) {
$featuresInserted[] = array(
'featureId' => $insert['result']['id'],
'productIdentifier' => $insert['result']['productIdentifier'],
'facetsStored' => $insert['result']['facetsStored']
'productIdentifier' => $insert['result']['productIdentifier']
);

$dates[] = isset($insert['featureArray']['properties']) && isset($insert['featureArray']['properties']['startDate']) ? $insert['featureArray']['properties']['startDate'] : null;
Expand All @@ -464,8 +451,7 @@ public function storeFeatures($collection, $body, $params)
if ($insert['result'] !== false) {
$featuresInserted[] = array(
'featureId' => $insert['result']['id'],
'productIdentifier' => $insert['result']['productIdentifier'],
'facetsStored' => $insert['result']['facetsStored']
'productIdentifier' => $insert['result']['productIdentifier']
);

$dates[] = isset($insert['featureArray']['properties']) && isset($insert['featureArray']['properties']['startDate']) ? $insert['featureArray']['properties']['startDate'] : null;
Expand Down Expand Up @@ -836,7 +822,7 @@ private function storeFeature($collection, $data, $params)
*
* (do this before getKeywords to avoid iTag process)
*/
if (isset($productIdentifier) && (new FeaturesFunctions($collection->context->dbDriver))->featureExists($featureId, $collection->context->dbDriver->targetSchema . '.' . $collection->model->dbParams['tablePrefix'] . 'feature')) {
if (isset($productIdentifier) && (new FeaturesFunctions($collection->context->dbDriver))->featureExists($featureId, $collection->context->dbDriver->targetSchema . '.feature')) {
RestoLogUtil::httpError(409, 'Feature ' . $featureId . ' (with productIdentifier=' . $productIdentifier . ') already in database');
}

Expand Down Expand Up @@ -917,16 +903,22 @@ private function prepareFeatureArray($collection, $data, $params = array())
RestoLogUtil::httpError(400, $topologyAnalysis['error']);
}

// Compute catalogs associated with this feature
// Eventually remove input _catalogs from properties
$catalogs = (new Cataloger($collection->context, $collection->user))->getCatalogs($properties, $data['geometry'] ?? null, $collection, $this->getITagParams($collection));
if (isset($properties['resto:catalogs'])) {
unset($properties['resto:catalogs']);
}

/*
* Return prepared data
*/
return array(
'topologyAnalysis' => $topologyAnalysis,
'properties' => array_merge($properties, array(
'keywords' => (new Tag($collection->context, $collection->user))->getKeywords($properties, $data['geometry'] ?? null, $collection->model, $this->getITagParams($collection))
)),
'properties' => $properties,
'assets' => $data['assets'] ?? null,
'links' => $data['links'] ?? null
'links' => $data['links'] ?? null,
'catalogs' => $catalogs
);
}

Expand All @@ -948,9 +940,9 @@ private function getITagParams($collection)
/*
* Default is to convert array of string to associative array
*/
if ($collection->context->addons['Tag']['options']['iTag']['taggers']) {
for ($i = 0, $ii = count($collection->context->addons['Tag']['options']['iTag']['taggers']); $i < $ii; $i++) {
$taggers[$collection->context->addons['Tag']['options']['iTag']['taggers'][$i]] = array();
if ($collection->context->addons['Cataloger']['options']['iTag']['taggers']) {
for ($i = 0, $ii = count($collection->context->addons['Cataloger']['options']['iTag']['taggers']); $i < $ii; $i++) {
$taggers[$collection->context->addons['Cataloger']['options']['iTag']['taggers'][$i]] = array();
}
}

Expand Down
9 changes: 4 additions & 5 deletions app/resto/core/RestoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,15 @@ class RestoRouter

// 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)

// STAC Catalog
array('POST', RestoRouter::ROUTE_TO_CATALOGS , true , 'STACCatalog::addCatalog'), // STAC - Add a catalog
array('PUT' , RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACCatalog::updateCatalog'), // STAC - Update a catalog
array('DELETE', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACCatalog::removeCatalog') // STAC - Remove a catalog
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
);

/*
Expand Down
Loading

0 comments on commit c7404e6

Please sign in to comment.