Skip to content

Commit e8b1b3b

Browse files
authored
Merge pull request #484 from jjrom/develop
Add user endpoints to get resources
2 parents 7f877ab + 6ad103b commit e8b1b3b

File tree

10 files changed

+182
-39
lines changed

10 files changed

+182
-39
lines changed

app/resto/core/RestoCollection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
* @OA\Property(
6767
* property="license",
6868
* type="string",
69-
* description="License for this collection as a SPDX License identifier. Alternatively, use proprietary if the license is not on the SPDX license list or various if multiple licenses apply. In these two cases links to the license texts SHOULD be added, see the license link relation type."
69+
* description="License for this collection as a SPDX License identifier. Alternatively, use other if the license is not on the SPDX license list. In these case link to the license texts SHOULD be added, see the license link relation type."
7070
* ),
7171
* @OA\Property(
7272
* property="links",
@@ -110,7 +110,7 @@
110110
* "version": "1.0",
111111
* "model": "OpticalModel",
112112
* "visibility": {"default"},
113-
* "license": "proprietary",
113+
* "license": "other",
114114
* "providers": {
115115
* {
116116
* "name": "European Union/ESA/Copernicus",
@@ -129,7 +129,7 @@
129129
* }
130130
* },
131131
* "summaries": {
132-
* "eo:bands": {
132+
* "bands": {
133133
* {
134134
* "name": "B1",
135135
* "common_name": "coastal",
@@ -250,8 +250,8 @@
250250
* @OA\Property(
251251
* property="license",
252252
* type="string",
253-
* enum={"proprietary", "various", "<license id>"},
254-
* description="License for this collection as a SPDX License identifier or expression. Alternatively, use proprietary if the license is not on the SPDX license list or various if multiple licenses apply. In these two cases links to the license texts SHOULD be added, see the license link relation type."
253+
* enum={"other", "<license id>"},
254+
* description="License for this collection as a SPDX License identifier or expression. Alternatively, use other if the license is not on the SPDX license list. In this case, links to the license texts SHOULD be added, see the license link relation type."
255255
* ),
256256
* @OA\Property(
257257
* property="extent",
@@ -342,7 +342,7 @@
342342
* "sentinel",
343343
* "sentinel2"
344344
* },
345-
* "license": "proprietary",
345+
* "license": "other",
346346
* "extent": {
347347
* "spatial": {
348348
* "bbox": {
@@ -419,7 +419,7 @@
419419
* "productType": {
420420
* "REFLECTANCE"
421421
* },
422-
* "eo:bands": {
422+
* "bands": {
423423
* {
424424
* "name": "B1",
425425
* "common_name": "coastal",

app/resto/core/RestoCollections.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ public function toArray()
288288
'rel' => 'child',
289289
'type' => RestoUtil::$contentTypes['json'],
290290
'title' => $collection['title'],
291-
'description' => $collection['description'],
292291
'href' => $this->context->core['baseUrl'] . RestoUtil::replaceInTemplate(RestoRouter::ROUTE_TO_COLLECTION, array('collectionId' => $key)),
293292
'roles' => array('collection')
294293
);
294+
295+
if ( isset($collection['description']) ) {
296+
$link['description'] = $collection['description'];
297+
}
298+
295299
if ( $matched > 0 ) {
296300
$link['matched'] = $matched;
297301
}

app/resto/core/RestoRouter.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,24 @@ class RestoRouter
6464
array('POST', RestoRouter::ROUTE_TO_USERS, false, 'UsersAPI::createUser'), // Create user
6565
array('GET', RestoRouter::ROUTE_TO_USER, true, 'UsersAPI::getUserProfile'), // Show user profile
6666
array('PUT', RestoRouter::ROUTE_TO_USER, true, 'UsersAPI::updateUserProfile'), // Update profile
67+
array('GET', RestoRouter::ROUTE_TO_USER . '/catalogs', true, 'UsersAPI::getUserCatalogs'), // Show user catalogs
68+
array('GET', RestoRouter::ROUTE_TO_USER . '/collections', true, 'UsersAPI::getUserCollections'), // Show user collections
69+
array('GET', RestoRouter::ROUTE_TO_USER . '/features', true, 'UsersAPI::getUserFeatures'), // Show user features
6770

6871
// API for groups
6972
array('GET' , RestoRouter::ROUTE_TO_GROUPS, true, 'GroupAPI::getGroups'), // List users profiles
70-
array('GET' , RestoRouter::ROUTE_TO_GROUPS . '/{name}', true, 'GroupAPI::getGroup'), // Get group
73+
array('GET' , RestoRouter::ROUTE_TO_GROUPS . '/{name}', true, 'GroupAPI::getGroup'), // Get group
7174
array('POST' , RestoRouter::ROUTE_TO_GROUPS, true, 'GroupAPI::createGroup'), // Create group
72-
array('DELETE', RestoRouter::ROUTE_TO_GROUPS . '/{name}', true, 'GroupAPI::deleteGroup'), // Delete group
75+
array('DELETE', RestoRouter::ROUTE_TO_GROUPS . '/{name}', true, 'GroupAPI::deleteGroup'), // Delete group
7376
array('GET' , RestoRouter::ROUTE_TO_USER . '/groups', true, 'GroupAPI::getUserGroups'), // Show user groups
74-
array('POST' , RestoRouter::ROUTE_TO_GROUPS . '/{name}/users', true, 'GroupAPI::addUser'), // Add user to group
75-
array('DELETE', RestoRouter::ROUTE_TO_GROUPS . '/{name}/users/{username}', true, 'GroupAPI::deleteUser'), // Delete user from group
77+
array('POST' , RestoRouter::ROUTE_TO_GROUPS . '/{name}/users', true, 'GroupAPI::addUser'), // Add user to group
78+
array('DELETE', RestoRouter::ROUTE_TO_GROUPS . '/{name}/users/{username}', true, 'GroupAPI::deleteUser'), // Delete user from group
7679

7780
// API for rights
7881
array('GET', RestoRouter::ROUTE_TO_USER . '/rights', true, 'RightsAPI::getUserRights'), // Show user rights
79-
array('GET', RestoRouter::ROUTE_TO_GROUPS . '/{name}/rights', true, 'RightsAPI::getGroupRights'), // Show group rights
82+
array('GET', RestoRouter::ROUTE_TO_GROUPS . '/{name}/rights', true, 'RightsAPI::getGroupRights'), // Show group rights
8083
array('POST' , RestoRouter::ROUTE_TO_USER . '/rights', true, 'RightsAPI::setUserRights'), // Set user rights
81-
array('POST' , RestoRouter::ROUTE_TO_GROUPS . '/{name}/rights', true, 'RightsAPI::setGroupRights'), // Set group rights
84+
array('POST' , RestoRouter::ROUTE_TO_GROUPS . '/{name}/rights', true, 'RightsAPI::setGroupRights'), // Set group rights
8285

8386
// API for collections
8487
array('GET', RestoRouter::ROUTE_TO_COLLECTIONS, false, 'CollectionsAPI::getCollections'), // List all collections
@@ -109,17 +112,17 @@ class RestoRouter
109112
array('POST', RestoRouter::ROUTE_TO_RESET_PASSWORD, false, 'ServicesAPI::resetPassword'), // Reset password
110113

111114
// STAC
112-
array('GET', RestoRouter::ROUTE_TO_ASSETS . '/{urlInBase64}', false, 'STACAPI::getAsset'), // Get an asset using HTTP 301 permanent redirect
113-
array('GET', RestoRouter::ROUTE_TO_CATALOGS, false, 'STACAPI::getCatalogs'),
114-
array('GET', RestoRouter::ROUTE_TO_CATALOGS . '/*', false, 'STACAPI::getCatalogs'), // Get catalogs
115-
array('GET', RestoRouter::ROUTE_TO_STAC_CHILDREN, false, 'STACAPI::getChildren'), // STAC API - Children
116-
array('GET', RestoRouter::ROUTE_TO_STAC_QUERYABLES, false, 'STACAPI::getQueryables'), // STAC/OAFeature API - Queryables
117-
array('GET', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STACAPI::search'), // STAC API - core search (GET)
118-
array('POST', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STACAPI::search'), // STAC API - core search (POST)
119-
array('POST', RestoRouter::ROUTE_TO_CATALOGS , true , 'STACAPI::addCatalog'), // STAC - Add a catalog
120-
array('POST', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::addCatalog'), // STAC - Add a catalog at a given level
121-
array('PUT' , RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::updateCatalog'), // STAC - Update a catalog
122-
array('DELETE', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::removeCatalog') // STAC - Remove a catalog
115+
array('GET', RestoRouter::ROUTE_TO_ASSETS . '/{urlInBase64}', false, 'STACAPI::getAsset'), // Get an asset using HTTP 301 permanent redirect
116+
array('GET', RestoRouter::ROUTE_TO_CATALOGS, false, 'STACAPI::getCatalogs'), // Get catalogs
117+
array('GET', RestoRouter::ROUTE_TO_CATALOGS . '/*', false, 'STACAPI::getCatalogs'), // Get catalogs
118+
array('GET', RestoRouter::ROUTE_TO_STAC_CHILDREN, false, 'STACAPI::getChildren'), // STAC API - Children
119+
array('GET', RestoRouter::ROUTE_TO_STAC_QUERYABLES, false, 'STACAPI::getQueryables'), // STAC/OAFeature API - Queryables
120+
array('GET', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STACAPI::search'), // STAC API - core search (GET)
121+
array('POST', RestoRouter::ROUTE_TO_STAC_SEARCH, false, 'STACAPI::search'), // STAC API - core search (POST)
122+
array('POST', RestoRouter::ROUTE_TO_CATALOGS , true , 'STACAPI::addCatalog'), // STAC - Add a catalog
123+
array('POST', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::addCatalog'), // STAC - Add a catalog at a given level
124+
array('PUT' , RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::updateCatalog'), // STAC - Update a catalog
125+
array('DELETE', RestoRouter::ROUTE_TO_CATALOGS . '/*', true , 'STACAPI::removeCatalog') // STAC - Remove a catalog
123126
);
124127

125128
/*

app/resto/core/api/CollectionsAPI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __construct($context, $user)
100100
* "level1C",
101101
* "USGS"
102102
* },
103-
* "license": "proprietary",
103+
* "license": "other",
104104
* "extent": {
105105
* "spatial": {
106106
* "bbox": {

app/resto/core/api/STACAPI.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class STACAPI
183183
* "href": "https://landsat-pds.s3.amazonaws.com/c1/L8/171/002/LC08_L1TP_171002_20200616_20200616_01_RT/LC08_L1TP_171002_20200616_20200616_01_RT_B1.TIF",
184184
* "type": "image/tiff; application=geotiff; profile=cloud-optimized",
185185
* "roles":{"data"},
186-
* "eo:bands": {
186+
* "bands": {
187187
* 0
188188
* }
189189
* }
@@ -193,7 +193,7 @@ class STACAPI
193193
/*
194194
* STAC version
195195
*/
196-
const STAC_VERSION = '1.0.0';
196+
const STAC_VERSION = '1.1.0';
197197

198198
/*
199199
* STAC namespaces
@@ -211,12 +211,12 @@ class STACAPI
211211
'https://api.stacspec.org/v1.0.0/item-search#sort',
212212
'https://api.stacspec.org/v1.0.0-rc.3/item-search#filter',
213213

214-
'http://www.opengis.net/spec/ogcapi_common-2/1.0/conf/collections',
215-
216214
'https://api.stacspec.org/v1.0.0/ogcapi-features#fields',
217215
'https://api.stacspec.org/v1.0.0/ogcapi-features#sort',
218216
'https://api.stacspec.org/v1.0.0/ogcapi-features#filter',
219217

218+
'http://www.opengis.net/spec/ogcapi_common-2/1.0/conf/collections',
219+
220220
'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core',
221221
'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson',
222222
'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30',

app/resto/core/api/UsersAPI.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,137 @@ public function updateUserProfile($params, $body)
561561
return RestoLogUtil::success('Update profile for user ' . $this->user->profile['username']);
562562
}
563563

564+
/**
565+
* Get user catalogs
566+
*
567+
* @OA\Get(
568+
* path="/users/{username}/catalogs",
569+
* summary="Get user's catalogs",
570+
* tags={"User"},
571+
* @OA\Parameter(
572+
* name="username",
573+
* in="path",
574+
* required=true,
575+
* description="User name",
576+
* @OA\Schema(
577+
* type="string"
578+
* )
579+
* ),
580+
* @OA\Response(
581+
* response="200",
582+
* description="User catalogs",
583+
* @OA\JsonContent()
584+
* ),
585+
* @OA\Response(
586+
* response="401",
587+
* description="Unauthorized",
588+
* @OA\JsonContent(ref="#/components/schemas/UnauthorizedError")
589+
* ),
590+
* @OA\Response(
591+
* response="404",
592+
* description="Resource not found",
593+
* @OA\JsonContent(ref="#/components/schemas/NotFoundError")
594+
* ),
595+
* security={
596+
* {"basicAuth":{}, "bearerAuth":{}, "queryAuth":{}}
597+
* }
598+
* )
599+
*/
600+
public function getUserCatalogs($params)
601+
{
602+
$owner = new RestoUser(array('username' => $params['username']), $this->context);
603+
return (new CatalogsFunctions($this->context->dbDriver))->getCatalogs(array(
604+
'where' => 'owner=' . $owner->profile['id']
605+
), $this->user, true);
606+
}
607+
608+
/**
609+
* Get user collections
610+
*
611+
* @OA\Get(
612+
* path="/users/{username}/collections",
613+
* summary="Get user's collections",
614+
* tags={"User"},
615+
* @OA\Parameter(
616+
* name="username",
617+
* in="path",
618+
* required=true,
619+
* description="User name",
620+
* @OA\Schema(
621+
* type="string"
622+
* )
623+
* ),
624+
* @OA\Response(
625+
* response="200",
626+
* description="User collections",
627+
* @OA\JsonContent()
628+
* ),
629+
* @OA\Response(
630+
* response="401",
631+
* description="Unauthorized",
632+
* @OA\JsonContent(ref="#/components/schemas/UnauthorizedError")
633+
* ),
634+
* @OA\Response(
635+
* response="404",
636+
* description="Resource not found",
637+
* @OA\JsonContent(ref="#/components/schemas/NotFoundError")
638+
* ),
639+
* security={
640+
* {"basicAuth":{}, "bearerAuth":{}, "queryAuth":{}}
641+
* }
642+
* )
643+
*/
644+
public function getUserCollections($params)
645+
{
646+
$owner = new RestoUser(array('username' => $params['username']), $this->context);
647+
return (new CollectionsFunctions($this->context->dbDriver))->getCollections($this->user, array(
648+
'owner' => $owner->profile['id']
649+
));
650+
}
651+
652+
/**
653+
* Get user features
654+
*
655+
* @OA\Get(
656+
* path="/users/{username}/features",
657+
* summary="Get user's features",
658+
* tags={"User"},
659+
* @OA\Parameter(
660+
* name="username",
661+
* in="path",
662+
* required=true,
663+
* description="User name",
664+
* @OA\Schema(
665+
* type="string"
666+
* )
667+
* ),
668+
* @OA\Response(
669+
* response="200",
670+
* description="User features",
671+
* @OA\JsonContent()
672+
* ),
673+
* @OA\Response(
674+
* response="401",
675+
* description="Unauthorized",
676+
* @OA\JsonContent(ref="#/components/schemas/UnauthorizedError")
677+
* ),
678+
* @OA\Response(
679+
* response="404",
680+
* description="Resource not found",
681+
* @OA\JsonContent(ref="#/components/schemas/NotFoundError")
682+
* ),
683+
* security={
684+
* {"basicAuth":{}, "bearerAuth":{}, "queryAuth":{}}
685+
* }
686+
* )
687+
*/
688+
public function getUserFeatures($params)
689+
{
690+
return (new RestoCollections($this->context, $this->user))->search(null, array(
691+
'owner' => $params['username']
692+
));
693+
}
694+
564695
/**
565696
* Store user profile
566697
*

app/resto/core/dbfunctions/CollectionsFunctions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public function getCollections($user, $params = array())
104104
if (isset($params['ck'])) {
105105
$where[] = 'keywords @> ARRAY[\'' . $this->dbDriver->escape_string( $params['ck']) . '\']';
106106
}
107+
108+
// Filter on owner
109+
if (isset($params['owner'])) {
110+
$where[] = 'owner=' . $this->dbDriver->escape_string( $params['owner']);
111+
}
107112

108113
// Query with aliases
109114
$query = join(' ', array(

docs/api/resto-api.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@
450450
"level1C",
451451
"USGS"
452452
],
453-
"license": "proprietary",
453+
"license": "other",
454454
"extent": {
455455
"spatial": {
456456
"bbox": [
@@ -4289,7 +4289,7 @@
42894289
"visibility": [
42904290
"default"
42914291
],
4292-
"license": "proprietary",
4292+
"license": "other",
42934293
"providers": [
42944294
{
42954295
"name": "European Union/ESA/Copernicus",
@@ -4308,7 +4308,7 @@
43084308
}
43094309
],
43104310
"summaries": {
4311-
"eo:bands": [
4311+
"bands": [
43124312
{
43134313
"name": "B1",
43144314
"common_name": "coastal",
@@ -4493,7 +4493,7 @@
44934493
"sentinel",
44944494
"sentinel2"
44954495
],
4496-
"license": "proprietary",
4496+
"license": "other",
44974497
"extent": {
44984498
"spatial": {
44994499
"bbox": [
@@ -4570,7 +4570,7 @@
45704570
"productType": [
45714571
"REFLECTANCE"
45724572
],
4573-
"eo:bands": [
4573+
"bands": [
45744574
{
45754575
"name": "B1",
45764576
"common_name": "coastal",
@@ -5717,7 +5717,7 @@
57175717
"roles": [
57185718
"data"
57195719
],
5720-
"eo:bands": [
5720+
"bands": [
57215721
0
57225722
]
57235723
}

examples/collections/L8.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939
],
4040
"summaries": {
41-
"eo:bands": [
41+
"bands": [
4242
{
4343
"name": "B1",
4444
"common_name": "coastal",

0 commit comments

Comments
 (0)