Skip to content

Commit 61437fc

Browse files
authored
RSPY550: Remove default geometry from cadip/auxip (#878)
* Removed default geometry from CADIP/AUXIP * Handling of geom in catalog side * Fix GET response * Fix for tests * Small comment
1 parent d4878b8 commit 61437fc

File tree

4 files changed

+23
-74
lines changed

4 files changed

+23
-74
lines changed

services/catalog/rs_server_catalog/user_catalog.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@
9090

9191
PRESIGNED_URL_EXPIRATION_TIME = int(os.environ.get("RSPY_PRESIGNED_URL_EXPIRATION_TIME", "1800")) # 30 minutes
9292
CATALOG_BUCKET = os.environ.get("RSPY_CATALOG_BUCKET", "rs-cluster-catalog")
93-
93+
DEFAULT_GEOM = {
94+
"type": "Polygon",
95+
"coordinates": [[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]],
96+
}
97+
DEFAULT_BBOX = (-180.0, -90.0, 180.0, 90.0)
9498
# pylint: disable=too-many-lines
9599
logger = Logging.default(__name__)
96100

@@ -697,6 +701,7 @@ async def manage_put_post_request( # pylint: disable=too-many-statements,too-ma
697701
content = await request.json()
698702
if not self.request_ids["owner_id"]:
699703
self.request_ids["owner_id"] = get_user(None, self.request_ids["user_login"])
704+
# If item is not geolocated, add a default one to comply pgstac format.
700705
if ( # If we are in cluster mode and the user_login is not authorized
701706
# to put/post returns a HTTP_401_UNAUTHORIZED status.
702707
common_settings.CLUSTER_MODE
@@ -768,6 +773,11 @@ async def manage_put_post_request( # pylint: disable=too-many-statements,too-ma
768773
original_published=published,
769774
original_expires=expires,
770775
)
776+
# If item doesn't contain a geometry/bbox, just fill with a default one.
777+
if not content.get("geometry", None):
778+
content["geometry"] = DEFAULT_GEOM
779+
if not content.get("bbox", None):
780+
content["bbox"] = DEFAULT_BBOX
771781
if hasattr(content, "status_code"):
772782
return content
773783

@@ -885,6 +895,11 @@ async def manage_get_response( # pylint: disable=too-many-locals, too-many-bran
885895
auth_roles = []
886896
user_login = ""
887897

898+
if content.get("geometry") == DEFAULT_GEOM:
899+
content["geometry"] = None
900+
if content.get("bbox") == DEFAULT_BBOX:
901+
content["bbox"] = None
902+
888903
if common_settings.CLUSTER_MODE: # Get the list of access and the user_login calling the endpoint.
889904
auth_roles = request.state.auth_roles
890905
user_login = request.state.user_login
@@ -1044,7 +1059,7 @@ async def manage_put_post_response(self, request: Request, response: StreamingRe
10441059
user = self.request_ids["owner_id"]
10451060
body = [chunk async for chunk in response.body_iterator]
10461061
response_content = json.loads(b"".join(body).decode()) # type: ignore
1047-
1062+
# Don't display geometry and bbox for default case since it was added just for compliance.
10481063
if request.scope["path"] == "/collections":
10491064
response_content = remove_user_from_collection(response_content, user)
10501065
response_content = self.adapt_object_links(response_content, user)
@@ -1054,6 +1069,10 @@ async def manage_put_post_response(self, request: Request, response: StreamingRe
10541069
):
10551070
response_content = remove_user_from_feature(response_content, user)
10561071
response_content = self.adapt_object_links(response_content, user)
1072+
if response_content.get("geometry") == DEFAULT_GEOM:
1073+
response_content["geometry"] = None
1074+
if response_content.get("bbox") == DEFAULT_BBOX:
1075+
response_content["bbox"] = None
10571076
delete_s3_files(self.s3_files_to_be_deleted)
10581077
self.s3_files_to_be_deleted.clear()
10591078
except RuntimeError as exc:

services/common/rs_server_common/stac_api_common.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,6 @@ def create_stac_collection(
867867
feature_tmp = odata_to_stac(copy.deepcopy(feature_template), product_data, stac_mapper)
868868
try:
869869
item = Item(**feature_tmp)
870-
# Add a default bbox and geometry, since L0 chunks items are not geo-located.
871-
item.bbox = (-180.0, -90.0, 180.0, 90.0)
872-
item.geometry = {
873-
"type": "Polygon",
874-
"coordinates": [[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]],
875-
}
876870
item.stac_extensions = [str(se) for se in item.stac_extensions] # type: ignore
877871
items.append(item)
878872
except ValidationError as e:

tests/resources/endpoints/adgs_feature.json

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
11
{
2-
"bbox": [
3-
-180.0,
4-
-90.0,
5-
180.0,
6-
90.0
7-
],
82
"type": "Feature",
9-
"geometry": {
10-
"type": "Polygon",
11-
"coordinates": [
12-
[
13-
[
14-
-180,
15-
-90
16-
],
17-
[
18-
180,
19-
-90
20-
],
21-
[
22-
180,
23-
90
24-
],
25-
[
26-
-180,
27-
90
28-
],
29-
[
30-
-180,
31-
-90
32-
]
33-
]
34-
]
35-
},
3+
"geometry": null,
364
"properties": {
375
"datetime": "2021-02-21T10:21:05.821Z",
386
"created": "2021-02-14T10:21:05.821Z",

tests/resources/endpoints/cadip_feature.json

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,6 @@
11
{
2-
"bbox": [
3-
-180.0,
4-
-90.0,
5-
180.0,
6-
90.0
7-
],
82
"type": "Feature",
9-
"geometry": {
10-
"type": "Polygon",
11-
"coordinates": [
12-
[
13-
[
14-
-180,
15-
-90
16-
],
17-
[
18-
180,
19-
-90
20-
],
21-
[
22-
180,
23-
90
24-
],
25-
[
26-
-180,
27-
90
28-
],
29-
[
30-
-180,
31-
-90
32-
]
33-
]
34-
]
35-
},
3+
"geometry": null,
364
"properties": {
375
"datetime": "2020-01-05T18:52:26.165Z",
386
"start_datetime": "2020-01-05T07:22:04.051Z",

0 commit comments

Comments
 (0)