Skip to content

Commit b454c34

Browse files
authored
Added cads:disabled_reason and JSON schema definition (#71)
* Added cads:disabled_reason and JSON schema definition * Made mypy happier
1 parent fabebbb commit b454c34

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

cads_catalogue_api_service/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,11 @@ def collection_serializer(
425425
# FIXME: this is not a 100% correct implementation of the STAC scientific extension.
426426
# One of the sci:xxx should be there, but CAMS dataset are not doing this
427427
**({"sci:doi": db_model.doi} if db_model.doi else {}),
428+
# *****************************************
428429
# *** CADS specific extension properties ***
430+
# *****************************************
429431
**({"cads:message": active_message} if active_message else {}),
432+
"cads:disabled_reason": db_model.disabled_reason,
430433
}
431434

432435
if schema_org:
@@ -449,9 +452,9 @@ def collection_serializer(
449452
keywords=[keyword.keyword_name for keyword in db_model.keywords],
450453
# https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#license
451454
# note that this small check, evenif correct, is triggering a lot of subrequests
452-
license="various"
453-
if not preview and len(db_model.licences) > 1
454-
else "proprietary",
455+
license=(
456+
"various" if not preview and len(db_model.licences) > 1 else "proprietary"
457+
),
455458
extent=get_extent(db_model),
456459
links=collection_links,
457460
**additional_properties,

cads_catalogue_api_service/exceptions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def add_exception_handlers(
6464
app.add_exception_handler(exc, exception_handler_factory(code))
6565

6666
def request_validation_exception_handler(
67-
request: fastapi.Request, exc: fastapi.exceptions.RequestValidationError
67+
request: fastapi.Request, exc: Exception
6868
) -> fastapi.responses.JSONResponse:
6969
return generate_exception_response(
7070
title="submitted data is not valid",
@@ -94,7 +94,8 @@ def __init__(self, message: str = "This STAC feature is not implemented yet."):
9494

9595
def generate_exception_response(
9696
title, detail=None, status_code=starlette.status.HTTP_500_INTERNAL_SERVER_ERROR
97-
):
97+
) -> fastapi.responses.JSONResponse:
98+
"""Build standard JSON error response."""
9899
return fastapi.responses.JSONResponse(
99100
status_code=status_code,
100101
content={

cads_catalogue_api_service/vocabularies.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def query_licences(
7272
.order_by(cads_catalogue.database.Licence.title)
7373
.all()
7474
)
75-
return results
75+
return results # type: ignore
7676

7777

7878
def query_licence(
@@ -101,12 +101,12 @@ def query_licence(
101101
.order_by(cads_catalogue.database.Licence.title)
102102
.one()
103103
)
104-
except sa.exc.NoResultFound:
104+
except sa.exc.NoResultFound as exc:
105105
raise fastapi.HTTPException(
106106
status_code=fastapi.status.HTTP_404_NOT_FOUND,
107107
detail=f"licence {licence_uid} not found",
108-
)
109-
return results
108+
) from exc
109+
return results # type: ignore
110110

111111

112112
def query_keywords(

schemas/dataset_preview.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
"license": {
2020
"enum": ["various", "proprietary"]
2121
},
22+
"cads:disabled_reason": {
23+
"type": ["string", "null"],
24+
"title": "Reason why download is disabled",
25+
"description": "The reason why the download form on this this dataset will not be enabled to standard users"
26+
},
2227
"cads:message": {
2328
"type": "object",
2429
"title": "Latest message related to this dataset",

tests/testing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def get_record(id: str) -> cads_catalogue.database.Resource:
7272
)
7373
],
7474
qa_flag=True,
75+
disabled_reason="Disabled because of a reason",
7576
)
7677

7778

@@ -174,6 +175,7 @@ def generate_expected(
174175
"published": "2020-01-01T00:00:00Z",
175176
"updated": "2020-02-05T00:00:00Z",
176177
"sci:doi": "11.2222/cads.12345",
178+
"cads:disabled_reason": "Disabled because of a reason",
177179
}
178180
if not preview:
179181
expected = {

0 commit comments

Comments
 (0)