Skip to content

Commit 87c7486

Browse files
committed
CMR-7719: Added handling of collection/granule without spatial info in STAC format
1 parent 98db88d commit 87c7486

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

search-app/src/cmr/search/results_handlers/stac_results_handler.clj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[cmr.common-app.services.search.elastic-results-to-query-results :as er-to-qr]
88
[cmr.common-app.services.search.elastic-search-index :as elastic-search-index]
99
[cmr.common-app.services.search.results-model :as r]
10+
[cmr.common.services.errors :as svc-errors]
1011
[cmr.common.util :as util]
1112
[cmr.search.models.query :as q]
1213
[cmr.search.results-handlers.orbit-swath-results-helper :as orbit-swath-helper]
@@ -206,6 +207,11 @@
206207
(defmethod stac-reference->json :collection
207208
[context concept-type reference]
208209
(let [{:keys [id dataset-id summary start-date end-date shapes]} reference
210+
bbox (ssrh/shapes->stac-bbox shapes)
211+
_ (when-not bbox
212+
(svc-errors/throw-service-error
213+
:bad-request
214+
(format "Collection [%s] without spatial info is not supported in STAC" id)))
209215
metadata-link (url/concept-xml-url context id)
210216
result {:id id
211217
:stac_version STAC_VERSION
@@ -233,7 +239,7 @@
233239
;; Even though there will only be one value for bbox and interval,
234240
;; we still put them into array of arrays based on STAC specification:
235241
;; https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#spatial-extent-object
236-
:extent {:spatial {:bbox [(ssrh/shapes->stac-bbox shapes)]}
242+
:extent {:spatial {:bbox [bbox]}
237243
:temporal {:interval [[start-date end-date]]}}}]
238244
;; remove entries with nil value
239245
(util/remove-nil-keys result)))
@@ -246,12 +252,17 @@
246252
;; cloud-cover requires the eo extension
247253
["https://stac-extensions.github.io/eo/v1.0.0/schema.json"]
248254
[])
255+
geometry (ssrh/shapes->stac-geometry shapes)
256+
_ (when-not geometry
257+
(svc-errors/throw-service-error
258+
:bad-request
259+
(format "Granule [%s] without spatial info is not supported in STAC" id)))
249260
result {:type "Feature"
250261
:id id
251262
:stac_version STAC_VERSION
252263
:stac_extensions stac-extension
253264
:collection collection-concept-id
254-
:geometry (ssrh/shapes->stac-geometry shapes)
265+
:geometry geometry
255266
:bbox (ssrh/shapes->stac-bbox shapes)
256267
:links [{:rel "self"
257268
:href (url/concept-stac-url context id)}

search-app/src/cmr/search/results_handlers/stac_spatial_results_handler.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
(defn shapes->stac-bbox
136136
"Returns the STAC bbox representation of the given shapes"
137137
[shapes]
138-
(when shapes
138+
(when (seq shapes)
139139
(let [mbrs (map shape->mbr shapes)
140140
mbr (if (> (count shapes) 1)
141141
(reduce m/union mbrs)

system-int-test/test/cmr/system_int_test/search/granule_search_format_test.clj

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,3 +971,67 @@
971971
"retrieval by suffix"
972972
{:url-extension "stac"}
973973
"The URL extension [stac] is not supported."))))
974+
975+
(deftest search-no-spatial-concept-stac
976+
(let [coll1 (d/ingest "PROV1" (dc/collection {:entry-title "Dataset1"
977+
:beginning-date-time "1970-01-01T12:00:00Z"}))
978+
coll-concept-id (:concept-id coll1)
979+
gran-spatial (dg/spatial (m/mbr 10 30 20 0))
980+
gran1 (d/ingest "PROV1" (dg/granule coll1 {:granule-ur "Granule1"
981+
:beginning-date-time "2010-01-01T12:00:00.000Z"
982+
:ending-date-time "2010-01-11T12:00:00.000Z"
983+
:cloud-cover 10.0}))
984+
gran-concept-id (:concept-id gran1)
985+
expected-gran-err-msg (format "Granule [%s] without spatial info is not supported in STAC"
986+
gran-concept-id)]
987+
988+
(index/wait-until-indexed)
989+
990+
(testing "granule search in STAC returns error when there is granule without spatial info"
991+
(let [response (search/find-concepts-stac
992+
:granule
993+
{:collection-concept-id coll-concept-id})
994+
ext-response (search/find-concepts-stac
995+
:granule
996+
{:collection-concept-id coll-concept-id}
997+
{:url-extension "stac"})]
998+
(is (= 400
999+
(:status response)
1000+
(:status ext-response)))
1001+
(is (= [expected-gran-err-msg]
1002+
(:errors response)
1003+
(:errors ext-response)))))
1004+
1005+
(testing "granule retrieval in STAC returns error when granule has no spatial info"
1006+
(util/are3 [options]
1007+
(let [{:keys [status errors]} (search/get-search-failure-data
1008+
(search/retrieve-concept
1009+
gran-concept-id
1010+
nil
1011+
(merge options {:throw-exceptions true})))]
1012+
(is (= 400 status))
1013+
(is (= [expected-gran-err-msg] errors)))
1014+
1015+
"retrieval by accept header"
1016+
{:accept "application/json; profile=stac-catalogue"}
1017+
1018+
"retrieval by suffix"
1019+
{:url-extension "stac"}))
1020+
1021+
(testing "collection retrieval in STAC returns error when collection has no spatial info"
1022+
(util/are3 [options]
1023+
(let [expected-err-msg (format "Collection [%s] without spatial info is not supported in STAC"
1024+
coll-concept-id)
1025+
{:keys [status errors]} (search/get-search-failure-data
1026+
(search/retrieve-concept
1027+
coll-concept-id
1028+
nil
1029+
(merge options {:throw-exceptions true})))]
1030+
(is (= 400 status))
1031+
(is (= [expected-err-msg] errors)))
1032+
1033+
"retrieval by accept header"
1034+
{:accept "application/json; profile=stac-catalogue"}
1035+
1036+
"retrieval by suffix"
1037+
{:url-extension "stac"}))))

0 commit comments

Comments
 (0)