Skip to content

Commit

Permalink
[MAJOR] Remove osdescription - needs database update
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrom committed Nov 29, 2024
1 parent 45a152f commit e61212e
Show file tree
Hide file tree
Showing 38 changed files with 343 additions and 1,207 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

resto is a metadata catalog and a search engine dedicated to geospatialized data. Originally, it’s main purpose it to handle Earth Observation satellite imagery but it can be used to store any kind of metadata localized in time and space.

resto search API conforms to the [SpatioTemporal Asset Catalog (STAC) specification v1.0.0](https://github.com/radiantearth/stac-spec) and to the [CEOS OpenSearch Best Practice Document](http://ceos.org/ourwork/workinggroups/wgiss/access/opensearch/).
resto search API conforms to the [SpatioTemporal Asset Catalog (STAC) specification v1.0.0](https://github.com/radiantearth/stac-spec)

It is mentioned in ESA's "Exploitation Platform Common Core Components" as the closest implementation of a catalogue component according to the requirements specified in ESA's ["Exploitation Platform Open Architecture"](https://tep.eo.esa.int/news/-/blogs/exploitation-platforms-open-architecture-released)

Expand Down
19 changes: 8 additions & 11 deletions app/resto/core/Resto.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@
*
* @OA\OpenApi(
* @OA\Info(
* title=API_INFO_TITLE,
* description=API_INFO_DESCRIPTION,
* version=RESTO_VERSION,
* @OA\Contact(
* email=API_INFO_CONTACT_EMAIL
* )
* title=STAC_ROOT_TITLE,
* description=STAC_ROOT_DESCRIPTION,
* version=RESTO_VERSION
* ),
* @OA\Server(
* description=API_HOST_DESCRIPTION,
* description=STAC_ROOT_DESCRIPTION,
* url=PUBLIC_ENDPOINT
* )
* )
Expand Down Expand Up @@ -190,7 +187,7 @@ private function getResponse()
return $this->setCORSHeaders();

default:
return RestoLogUtil::httpError(404);
RestoLogUtil::httpError(404);
}

$response = $this->router->process($method, $this->context->path, $this->context->query);
Expand Down Expand Up @@ -261,7 +258,7 @@ private function format($object)
* Case 0 - Object is null
*/
if (!isset($object)) {
return RestoLogUtil::httpError(400, 'Empty object');
RestoLogUtil::httpError(400, 'Empty object');
}

$pretty = isset($this->context->query['_pretty']) ? filter_var($this->context->query['_pretty'], FILTER_VALIDATE_BOOLEAN) : false;
Expand All @@ -283,15 +280,15 @@ private function format($object)
if (method_exists(get_class($object), $methodName)) {
return $outputFormat === 'json' ? $object->$methodName($pretty) : $object->$methodName();
}
return RestoLogUtil::httpError(404);
RestoLogUtil::httpError(404);
}

return $object;

/*
* Unknown stuff
*/
return RestoLogUtil::httpError(400, 'Invalid object');
RestoLogUtil::httpError(400, 'Invalid object');
}

/**
Expand Down
180 changes: 31 additions & 149 deletions app/resto/core/RestoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,6 @@
* )
* ),
* @OA\Property(
* property="osDescription",
* type="object",
* required={"en"},
* @OA\Property(
* property="en",
* description="OpenSearch description in English",
* ref="#/components/schemas/OpenSearchDescription"
* ),
* @OA\Property(
* property="fr",
* description="OpenSearch description in French",
* ref="#/components/schemas/OpenSearchDescription"
* )
* ),
* @OA\Property(
* property="links",
* type="array",
* @OA\Items(ref="#/components/schemas/Link")
Expand Down Expand Up @@ -135,6 +120,9 @@
* ),
* example={
* "id": "S2",
* "type": "Collection",
* "title": "Level 1C Sentinel-2 images",
* "description": "The SENTINEL-2 mission is a land monitoring constellation of two satellites each equipped with a MSI (Multispectral Imager) instrument covering 13 spectral bands providing high resolution optical imagery (i.e., 10m, 20m, 60 m) every 10 days with one satellite and 5 days with two satellites",
* "version": "1.0",
* "model": "OpticalModel",
* "rights": {
Expand All @@ -143,28 +131,6 @@
* },
* "visibility": 1,
* "license": "proprietary",
* "osDescription": {
* "en": {
* "ShortName": "Sentinel-2",
* "LongName": "Level 1C Sentinel-2 images",
* "Description": "The SENTINEL-2 mission is a land monitoring constellation of two satellites each equipped with a MSI (Multispectral Imager) instrument covering 13 spectral bands providing high resolution optical imagery (i.e., 10m, 20m, 60 m) every 10 days with one satellite and 5 days with two satellites",
* "Tags": "copernicus esa eu msi radiance sentinel sentinel2",
* "Developer": "Jérôme Gasperi",
* "Contact": "jrom@snapplanet.io",
* "Query": "Toulouse",
* "Attribution": "European Union/ESA/Copernicus"
* },
* "fr": {
* "ShortName": "Sentinel-2",
* "LongName": "Images Sentinel-2 Niveau 1C",
* "Description": "La mission SENTINEL-2 est constituée de deux satellites d'imagerie optique équipés d’un imageur multispectral (MSI) en 13 bandes spectrales avec des résolutions de 10, 20 et 60 mètres et d'une fauchée unique de 290 km de large. La capacité d'observation des deux satellites permet de surveiller l'intégralité des terres émergées du globe tous les 5 jours",
* "Tags": "copernicus esa eu msi radiance sentinel sentinel2",
* "Developer": "Jérôme Gasperi",
* "Contact": "jrom@snapplanet.io",
* "Query": "Toulouse",
* "Attribution": "European Union/ESA/Copernicus"
* }
* },
* "providers": {
* {
* "name": "European Union/ESA/Copernicus",
Expand Down Expand Up @@ -263,7 +229,7 @@
*
* @OA\Schema(
* schema="OutputCollection",
* required={"id", "type", "title", "description", "license", "extent", "links"},
* required={"id", "type", "description", "license", "extent", "links"},
* @OA\Property(
* property="id",
* type="string",
Expand Down Expand Up @@ -336,11 +302,6 @@
* )
* ),
* @OA\Property(
* property="osDescription",
* type="object",
* ref="#/components/schemas/OpenSearchDescription"
* ),
* @OA\Property(
* property="owner",
* type="string",
* description="Collection owner (i.e. resto user identifier as bigint)"
Expand Down Expand Up @@ -450,16 +411,6 @@
* "SatelliteModel",
* "OpticalModel"
* },
* "osDescription": {
* "ShortName": "Sentinel-2",
* "LongName": "Level 1C Sentinel-2 images",
* "Description": "The SENTINEL-2 mission is a land monitoring constellation of two satellites each equipped with a MSI (Multispectral Imager) instrument covering 13 spectral bands providing high resolution optical imagery (i.e., 10m, 20m, 60 m) every 10 days with one satellite and 5 days with two satellites",
* "Tags": "copernicus esa eu msi radiance sentinel sentinel2",
* "Developer": "J\u00e9r\u00f4me Gasperi",
* "Contact": "jrom@snapplanet.io",
* "Query": "Toulouse",
* "Attribution": "European Union/ESA/Copernicus"
* },
* "owner": "203883411255198721"
* },
* "providers": {
Expand Down Expand Up @@ -578,6 +529,16 @@ class RestoCollection
*/
public $id = null;

/*
* Collection title
*/
public $title = null;

/*
* Collection description
*/
public $description = null;

/*
* Data model for this collection
*/
Expand Down Expand Up @@ -605,7 +566,7 @@ class RestoCollection
public $aliases = array();
public $visibility = RestoConstants::GROUP_DEFAULT_ID;
public $version = '1.0.0';
public $license = 'proprietary';
public $license = 'other';
public $links = array();
public $providers = array();
public $rights = array();
Expand All @@ -629,68 +590,6 @@ class RestoCollection
*/
public $owner;

/**
*
* Array of OpenSearch Description parameters per lang
*
* @OA\Schema(
* schema="OpenSearchDescription",
* description="OpenSearch description of the search engine attached to the collection",
* required={"ShortName", "Description"},
* @OA\Property(
* property="ShortName",
* type="string",
* description="Contains a brief human-readable title that identifies the search engine"
* ),
* @OA\Property(
* property="LongName",
* type="string",
* description="Contains an extended human-readable title that identifies this search engine"
* ),
* @OA\Property(
* property="Description",
* type="string",
* description="Contains a human-readable text description of the collection search engine"
* ),
* @OA\Property(
* property="Tags",
* type="string",
* description="Contains a set of words that are used as keywords to identify and categorize this search content. Tags must be a single word and are delimited by the space character"
* ),
* @OA\Property(
* property="Developer",
* type="string",
* description="Contains the human-readable name or identifier of the creator or maintainer of the description document"
* ),
* @OA\Property(
* property="Contact",
* type="string",
* description="Contains an email address at which the maintainer of the description document can be reached"
* ),
* @OA\Property(
* property="Query",
* type="string",
* description="Defines a search query that can be performed by search clients. Please see the OpenSearch Query element specification for more information"
* ),
* @OA\Property(
* property="Attribution",
* type="string",
* description="Contains a list of all sources or entities that should be credited for the content contained in the search feed"
* ),
* example={
* "ShortName": "S2",
* "LongName": "Sentinel-2",
* "Description": "Sentinel-2 tiles",
* "Tags": "s2 sentinel2",
* "Developer": "Jérôme Gasperi",
* "Contact": "jrom@snapplanet.io",
* "Query": "Toulouse",
* "Attribution": "SnapPlanet - Copyright 2016, All Rights Reserved"
* }
* )
*/
public $osDescription = null;

/**
* Summaries
*/
Expand Down Expand Up @@ -751,7 +650,6 @@ class RestoCollection
'license',
'links',
'model',
'osDescription',
'providers',
'rights',
'stac_extension',
Expand Down Expand Up @@ -798,9 +696,9 @@ public function load($object = null, $modelName = null)

if ( !$this->isLoaded ) {
$this->isLoaded = true;
$collectionObject = (new CollectionsFunctions($this->context->dbDriver))->getCollectionDescription($this->id);
$collectionObject = (new CollectionsFunctions($this->context->dbDriver))->getCollection($this->id);
if (! isset($collectionObject)) {
return RestoLogUtil::httpError(404);
RestoLogUtil::httpError(404);
}

foreach ($collectionObject as $key => $value) {
Expand Down Expand Up @@ -829,13 +727,13 @@ public function store()
* Update collection - collection must be load first !
*
* @param array $object
* @return This object
* @return RestoCollection
*/
public function update($object)
{
// It means that collection is not loaded - so cannot be updated
if (! isset($this->model)) {
return RestoLogUtil::httpError(400, 'Model does not exist');
RestoLogUtil::httpError(400, 'Model does not exist');
}

$this->loadFromJSON($object);
Expand All @@ -847,7 +745,7 @@ public function update($object)
* Search features within collection
*
* @param array $query
* @return array (FeatureCollection)
* @return RestoFeatureCollection
*/
public function search($query)
{
Expand Down Expand Up @@ -918,16 +816,14 @@ public function setSummaries($summaries)
public function toArray()
{

$osDescription = $this->osDescription[$this->context->lang] ?? $this->osDescription['en'];

$collectionArray = array(
'stac_version' => STACAPI::STAC_VERSION,
'stac_extensions' => $this->model->stacExtensions,
'id' => $this->id,
'type' => 'Collection',
'title' => $osDescription['LongName'] ?? $osDescription['ShortName'],
'title' => $this->title,
'description' => $this->description,
'version' => $this->version ?? null,
'description' => $osDescription['Description'],
'aliases' => $this->aliases ?? array(),
'license' => $this->license,
'extent' => $this->extent,
Expand Down Expand Up @@ -960,7 +856,6 @@ public function toArray()
'resto:info' => array(
'model' => $this->model->getName(),
'lineage' => $this->model->getLineage(),
'osDescription' => $this->osDescription[$this->context->lang] ?? $this->osDescription['en'],
'owner' => $this->owner,
'visibility' => $this->visibility
)
Expand Down Expand Up @@ -1006,14 +901,6 @@ public function toJSON($pretty = false)
return json_encode($this->toArray(), $pretty ? JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES : JSON_UNESCAPED_SLASHES);
}

/**
* Output collection description as an XML OpenSearch document
*/
public function getOSDD()
{
return new OSDD($this->context, $this->model, $this->getSummaries(), $this);
}

/**
* On which planet this collection applied
* Based on ssys:target
Expand Down Expand Up @@ -1046,18 +933,6 @@ private function loadFromJSON($object, $modelName = null)
* Check mandatory properties are required
*/
$this->checkCreationMandatoryProperties($object, $modelName);

/*
* If OpenSearch Description object is not set, create a minimal one from $object['description']
*/
if (!isset($object['osDescription']) || !is_array($object['osDescription']) || !isset($object['osDescription']['en']) || !is_array($object['osDescription']['en'])) {
$object['osDescription'] = array(
'en' => array(
'ShortName' => $object['title'] ?? $object['id'],
'Description' => $object['description'] ?? ''
)
);
}

/*
* Default collection visibility is the value of RestoConstants::GROUP_DEFAULT_ID
Expand All @@ -1068,7 +943,7 @@ private function loadFromJSON($object, $modelName = null)
/*
* Set values
*/
foreach (array_values(array('aliases', 'version', 'license', 'links', 'osDescription', 'providers', 'rights', 'assets', 'keywords', 'extent')) as $key) {
foreach (array_values(array('title', 'description', 'aliases', 'version', 'license', 'links', 'providers', 'rights', 'assets', 'keywords', 'extent')) as $key) {
if (isset($object[$key])) {
$this->$key = $key === 'links' ? $this->cleanInputLinks($object['links']) : $object[$key];
}
Expand Down Expand Up @@ -1112,6 +987,13 @@ private function checkCreationMandatoryProperties($object, $modelName)
if ( !isset($object['type']) || $object['type'] !== 'Collection') {
RestoLogUtil::httpError(400, 'Property "type" is mandatory and must be set to *Collection*');
}

/*
* description is mandatory
*/
if ( !isset($object['description']) ) {
RestoLogUtil::httpError(400, 'Property "description" is mandatory');
}

/*
* Set DefaultModel if not set - preseance to input $modelName
Expand All @@ -1126,7 +1008,7 @@ private function checkCreationMandatoryProperties($object, $modelName)
if (!class_exists($object['model']) || !is_subclass_of($object['model'], 'RestoModel')) {
RestoLogUtil::httpError(400, 'Model "' . $object['model'] . '" is not a valid model name');
}

/*
* Set collection model
*/
Expand Down
Loading

0 comments on commit e61212e

Please sign in to comment.