Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct bunch of issue with catalog creation #438

Merged
merged 14 commits into from
Sep 27, 2024
6 changes: 4 additions & 2 deletions app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,13 @@ public function addFeatures($body, $params)
public function getSummaries()
{
if ( !isset($this->summaries) ) {
$summaries = (new CatalogsFunctions($this->context->dbDriver))->getSummaries(null, $this->id);
$summaries = (new CatalogsFunctions($this->context->dbDriver))->getSummaries(null);
if ( isset($summaries[$this->id]) ) {
$this->setSummaries($summaries[$this->id]);
}
else $this->summaries = array();
else {
$this->summaries = array();
}
}
return $this->summaries;
}
Expand Down
13 changes: 10 additions & 3 deletions app/resto/core/RestoCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function toArray()
'stac_version' => STACAPI::STAC_VERSION,
'id' => $this->context->osDescription['ShortName'],
'type' => 'Catalog',
'title' => $this->context->osDescription['LongName'] ?? $this->context->osDescription['ShortName'],
'title' => 'Collections',
'description' => $this->context->osDescription['Description'],
'keywords' => explode(' ', $this->context->osDescription['Tags']),
'links' => array(
Expand Down Expand Up @@ -282,12 +282,19 @@ public function toArray()
$this->collections[$key]->setSummaries($this->summaries[$this->collections[$key]->id] ?? array());

$collection = $this->collections[$key]->toArray();

$matched = $collection['summaries']['collection']['count'] ?? 0;

if ($matched < $this->context->core['collectionMinMatch']) {
continue;
}

$collections['links'][] = array(
'rel' => 'child',
'type' => RestoUtil::$contentTypes['json'],
'title' => $collection['title'],
'description' => $collection['description'],
'matched' => $collection['summaries']['collection']['count'] ?? 0,
'matched' => $matched,
'href' => $this->context->core['baseUrl'] . RestoUtil::replaceInTemplate(RestoRouter::ROUTE_TO_COLLECTION, array('collectionId' => $key)),
'roles' => array('collection')
);
Expand Down Expand Up @@ -333,7 +340,7 @@ public function getOSDD($model)
public function getSummaries()
{
if ( !isset($this->summaries) ) {
$this->summaries = (new CatalogsFunctions($this->context->dbDriver))->getSummaries(null, null);
$this->summaries = (new CatalogsFunctions($this->context->dbDriver))->getSummaries(null);
}
return $this->summaries;
}
Expand Down
3 changes: 3 additions & 0 deletions app/resto/core/RestoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class RestoContext
// Display catalog that have at least 'catalogMinMatch' object
'catalogMinMatch' => 0,

// Display collection that have at least 'collectionMinMatch' object
'collectionMinMatch' => 0,

// Use cache
'useCache' => false,

Expand Down
2 changes: 1 addition & 1 deletion app/resto/core/RestoQueryAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function analyze($params, $model)
* Special gazetteer hashtags - if found, the first is converted to geouid
* A gazetteer hashtag format is type:name:geouid
*/
if (!isset($params['geo:name'])) {
if (!isset($params['geo:name']) && isset($this->gazetteer) ) {
for ($i = 0, $ii = $nbOfHashtags; $i < $ii; $i++) {
$splitted = explode(RestoConstants::TAG_SEPARATOR, $hashtags[$i]);
if (count($splitted) === 3 && is_numeric($splitted[2])) {
Expand Down
11 changes: 6 additions & 5 deletions app/resto/core/api/STACAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public function getChildren($params)
continue;
}
if (isset($response)) {
$childs[] = $response->toArray();
$childs[] = $response;
}
}
}
Expand Down Expand Up @@ -1565,8 +1565,12 @@ private function getRootCatalogLinks()

for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {

// Returns only catalogs with count >= minMath
// Returns only catalogs with count >= minMatch
if ($catalogs[$i]['counters']['total'] >= $this->context->core['catalogMinMatch']) {
if ($catalogs[$i]['id'] === 'collections') {
//$link['roles'] = array('collections');
continue;
}
$link = array(
'rel' => 'child',
'title' => $catalogs[$i]['title'],
Expand All @@ -1575,9 +1579,6 @@ private function getRootCatalogLinks()
'href' => $this->context->core['baseUrl'] . '/catalogs/' . rawurlencode($catalogs[$i]['id']),
'matched' => $catalogs[$i]['counters']['total']
);
if ($catalogs[$i]['id'] === 'collections') {
$link['roles'] = array('collections');
}
$links[] = $link;
}

Expand Down
101 changes: 49 additions & 52 deletions app/resto/core/dbfunctions/CatalogsFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function updateCatalog($catalog)
);
}

$results = $this->dbDriver->fetch($this->dbDriver->pQuery('UPDATE ' . $this->dbDriver->targetSchema . '.catalog SET ' . join(',', $set) . ' WHERE public.normalize(id)=public.normalize($1) RETURNING id', $values, 500, 'Cannot update facet ' . $catalog['id']));
$results = $this->dbDriver->fetch($this->dbDriver->pQuery('UPDATE ' . $this->dbDriver->targetSchema . '.catalog SET ' . join(',', $set) . ' WHERE public.normalize(id)=public.normalize($1) RETURNING id', $values, 500, 'Cannot update catalog ' . $catalog['id']));

return array(
'catalogsUpdated' => count($results)
Expand Down Expand Up @@ -489,80 +489,77 @@ public function removeCatalog($catalogId)
* )
*
* @param array $types
* @param string $collectionId
*
* @return array
*/
public function getSummaries($types, $collectionId)
public function getSummaries($types)
{

$summaries = array();

$pivots = array();

$catalogs = $this->getCatalogs(array(
'where' => !empty($types) ? 'rtype IN (\'' . join('\',\'', $types) . '\')' : 'rtype NOT IN (\'' . join('\',\'', CatalogsFunctions::TOPONYM_TYPES) . '\')'
));

$counter = 0;

// First create collection pivots
$pivots = array();
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {

// Discard level 1 catalog and empty one
if ( $catalogs[$i]['level'] === 1 || !isset($catalogs[$i]['counters']) || $catalogs[$i]['counters']['total'] === 0 ) {
continue;
}

// Collection is set => get only catalogs with collectionId counter > 0
// Otherwise get only catalogs with total counter > 0
if ( isset($collectionId) ) {
if ( !isset($catalogs[$i]['counters']['collections'][$collectionId]) || $catalogs[$i]['counters']['collections'][$collectionId] === 0 ) {
continue;
}
$counter = $catalogs[$i]['counters']['collections'][$collectionId];
// Process only collection
if ( $catalogs[$i]['rtype'] !== 'collection' ) {
continue;
}
else {
$collectionId = '*';
$counter = $catalogs[$i]['counters']['total'];
$exploded = explode('/', $catalogs[$i]['id']);
$_collectionId = array_pop($exploded);
if ( !isset($pivots[$_collectionId]) ) {
$pivots[$_collectionId] = array(
'collection' => array(
array(
'const' => $_collectionId,
'count' => $catalogs[$i]['counters']['collections'][$_collectionId]
)
)
);
}
}

if ( !isset($pivots[$collectionId]) ) {
$pivots[$collectionId] = array();
// Populate with summaries i.e. other rtype
for ($i = 0, $ii = count($catalogs); $i < $ii; $i++) {

if ( $catalogs[$i]['rtype'] === 'collection' ) {
continue;
}

$type = $catalogs[$i]['rtype'];

if (!isset($pivots[$collectionId][$type])) {
$pivots[$collectionId][$type] = array();
}

$create = true;

// Constant is the last part of the id url
$exploded = explode('/', $catalogs[$i]['id']);
$const = array_pop($exploded);
for ($j = count($pivots[$collectionId][$type]); $j--;) {
if (isset($pivots[$collectionId][$type][$j]['const'])) {
if ($pivots[$collectionId][$type][$j]['const'] === $const) {
$pivots[$collectionId][$type][$j]['count'] += $counter;
$create = false;
break;
if ( isset($catalogs[$i]['counters']['collections']) ) {
foreach (array_keys($catalogs[$i]['counters']['collections']) as $_collectionId) {

if ( !isset($pivots[$_collectionId][$type]) ) {
$pivots[$_collectionId][$type] = array();
}

// Constant is the last part of the id url
$exploded = explode('/', $catalogs[$i]['id']);
$const = array_pop($exploded);

$newPivot = array(
'const' => $const,
'count' => $catalogs[$i]['counters']['collections'][$_collectionId]
);

if ($catalogs[$i]['title'] !== $newPivot['const']) {
$newPivot['title'] = $catalogs[$i]['title'];
}

$pivots[$_collectionId][$type][] = $newPivot;

}
}

if ($create) {
$newPivot = array(
'const' => $const,
'count' => $counter
);

if ($catalogs[$i]['title'] !== $newPivot['const']) {
$newPivot['title'] = $catalogs[$i]['title'];
}
$pivots[$collectionId][$type][] = $newPivot;
}
}

foreach (array_keys($pivots) as $_collectionId) {
if ( !isset($summaries[$_collectionId]) ) {
$summaries[$_collectionId] = array();
Expand Down Expand Up @@ -689,7 +686,7 @@ private function getCleanLinks($catalog, $userid, $baseUrl) {
}

if ($childCatalog['level'] === 1 && $childCatalog['owner'] === $userid) {
$output['updateCatalogs'][] = $childCatalog;
array_push($output['updateCatalogs'], ...$this->getCatalogs(array('id' => $childCatalog['id']), true));
}
else {
$output['links'][] = $link;
Expand Down
1 change: 1 addition & 0 deletions app/resto/core/utils/RestoUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class RestoUtil
'geojson' => 'application/geo+json',
'geopackage' => 'application/geopackage+sqlite3',
'geotiff' => 'image/tiff; application=geotiff',
'gif' => 'image/gif',
'hdf' => 'application/x-hdf',
'hdf5' => 'application/x-hdf5',
'html' => 'text/html',
Expand Down
Loading
Loading