Skip to content

Commit 0a4d089

Browse files
authored
CMR-7220: cloud_hosted search (#1234)
CMR-7220 - adding a cloud_hosted search parameter, updating api doc
1 parent 4e458aa commit 0a4d089

File tree

9 files changed

+106
-1
lines changed

9 files changed

+106
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ browse-scaler/src/node_modules
1414
.clj-kondo/
1515
.lsp
1616
.cider-repl-history
17+
**/ignore.*
1718

1819
###############################
1920
### Test Files

indexer-app/src/cmr/indexer/data/concepts/collection.clj

+7
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@
173173
distinct
174174
(remove nil?)))
175175

176+
(defn- cloud-hosted?
177+
"Test if the collection meets the criteria for being cloud hosted"
178+
[collection tags]
179+
(or (not (empty? (:DirectDistributionInformation collection)))
180+
(tag/has-cloud-s3-tag? tags)))
181+
176182
(defn- get-elastic-doc-for-full-collection
177183
"Get all the fields for a normal collection index operation."
178184
[context concept collection]
@@ -388,6 +394,7 @@
388394
:metadata-format (name (mt/format-key format))
389395
:related-urls (map json/generate-string opendata-related-urls)
390396
:has-opendap-url (not (empty? (filter opendap-util/opendap-url? related-urls)))
397+
:cloud-hosted (cloud-hosted? collection tags)
391398
:publication-references opendata-references
392399
:collection-citations (map json/generate-string opendata-citations)
393400
:update-time update-time

indexer-app/src/cmr/indexer/data/concepts/tag.clj

+10
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@
2727
:originator-id-lowercase (util/safe-lowercase originator-id)
2828
:tag-value-lowercase (when (string? data)
2929
(str/lower-case data))}))
30+
31+
(def earthdata-cloud-s3-tag
32+
"The Earthdata cloud tag for s3 resources"
33+
"gov.nasa.earthdata.cloud.s3")
34+
35+
(defn has-cloud-s3-tag?
36+
"Looks through a list of tags and returns true if one of them is the
37+
gov.nasa.earthdata.cloud.s3 tag"
38+
[tags]
39+
(some? (some #(= (:tag-key-lowercase %) earthdata-cloud-s3-tag) tags)))

indexer-app/src/cmr/indexer/data/index_set.clj

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@
375375
:has-spatial-subsetting m/bool-field-mapping
376376
:has-temporal-subsetting m/bool-field-mapping
377377
:has-opendap-url m/bool-field-mapping
378+
:cloud-hosted m/bool-field-mapping
378379

379380
:platform-sn m/string-field-mapping
380381
:platform-sn-lowercase m/string-field-mapping
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(ns cmr.indexer.test.data.concepts.tag
2+
"Code coverage tests for the functions of testing cmr.indexer.data.concepts.tag
3+
namespace."
4+
(:require
5+
[clojure.string :as str]
6+
[clojure.test :refer :all]
7+
[cmr.common.util :as util]
8+
[cmr.indexer.data.concepts.tag :as tag]))
9+
10+
(defn- create-tag
11+
"Create a tag map"
12+
[tag-key originator data]
13+
{:tag-key-lowercase (str/lower-case tag-key)
14+
:originator-id-lowercase (util/safe-lowercase originator)
15+
:tag-value-lowercase (when (string? data) (str/lower-case data))})
16+
17+
(deftest does-has-cloud-s3-tag-work
18+
"The function has-cloud-s3-tag should only return true if there is a
19+
gov.nasa.earthdata.cloud.s3 tag in the list"
20+
(let [bad1 (create-tag "This-Is-Not-The-Tag-Your-Looking-For" "My-Id" "Value")
21+
bad2 (create-tag "This-Is-Also-Not-The-Tag-Your-Looking-For" "My-Id" "Value")
22+
good (create-tag tag/earthdata-cloud-s3-tag "My-Id" "Value")
23+
will-not-be-found [bad1]
24+
these-will-not-be-found [bad1 bad2]
25+
will-be-found [good]
26+
one-will-be-found [bad1 bad2 good]]
27+
(is (false? (tag/has-cloud-s3-tag? will-not-be-found)))
28+
(is (false? (tag/has-cloud-s3-tag? these-will-not-be-found)))
29+
(is (true? (tag/has-cloud-s3-tag? will-be-found)))
30+
(is (true? (tag/has-cloud-s3-tag? one-will-be-found)))))

search-app/docs/api.md

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Join the [CMR Client Developer Forum](https://wiki.earthdata.nasa.gov/display/CM
8585
* [With/without granules Or Cwic](#c-has-granules-or-cwic)
8686
* [With/without granules Or OpenSearch](#c-has-granules-or-opensearch)
8787
* [OPeNDAP service URL](#c-has-opendap-url)
88+
* [Cloud Hosted](#c-cloud-hosted)
8889
* [Sorting Collection Results](#sorting-collection-results)
8990
* [Retrieving all Revisions of a Collection](#retrieving-all-revisions-of-a-collection)
9091
* [Granule Search By Parameters](#granule-search-by-parameters)
@@ -1887,6 +1888,10 @@ The `has_granules_or_opensearch` parameter can be set to "true" or "false". When
18871888

18881889
curl "%CMR-ENDPOINT%/collections?has_opendap_url=true"
18891890

1891+
#### <a name="c-cloud-hosted"></a> Find collections that have a `DirectDistributionInformation` element or have been tagged with `gov.nasa.earthdata.cloud.s3`.
1892+
1893+
curl "%CMR-ENDPOINT%/collections?cloud_hosted=true"
1894+
18901895
#### <a name="sorting-collection-results"></a> Sorting Collection Results
18911896

18921897
Collection results are sorted by ascending entry title by default when a search does not result in a score.

search-app/src/cmr/search/services/parameters/conversion.clj

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
:has-granules-created-at :multi-date-range
4848
:has-granules-revised-at :multi-date-range
4949
:has-opendap-url :boolean
50+
:cloud-hosted :boolean
5051
:instrument :string
5152
:instrument-h :humanizer
5253
:keyword :keyword

search-app/src/cmr/search/services/parameters/parameter_validation.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@
630630
(let [bool-params (select-keys params [:downloadable :browsable :include-granule-counts
631631
:include-has-granules :has-granules :hierarchical-facets
632632
:include-highlights :all-revisions :has-opendap-url
633-
:simplify-shapefile])]
633+
:simplify-shapefile :cloud-hosted])]
634634
(mapcat
635635
(fn [[param value]]
636636
(when-not (contains? #{"true" "false" "unset"} (when value (s/lower-case value)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(ns cmr.system-int-test.search.collection-cloud-hosted-search-test
2+
"Integration tests for searching for records that are cloud hosted"
3+
(:require
4+
[clojure.test :refer :all]
5+
[cmr.common.util :as util]
6+
[cmr.mock-echo.client.echo-util :as echo]
7+
[cmr.indexer.data.concepts.tag :as itag]
8+
[cmr.system-int-test.data2.core :as data2]
9+
[cmr.system-int-test.data2.umm-spec-collection :as data-umm-c]
10+
[cmr.system-int-test.system :as system]
11+
[cmr.system-int-test.utils.index-util :as index]
12+
[cmr.system-int-test.utils.ingest-util :as ingest]
13+
[cmr.system-int-test.utils.search-util :as search]
14+
[cmr.system-int-test.utils.tag-util :as tags]))
15+
16+
(use-fixtures :each (join-fixtures
17+
[(ingest/reset-fixture {"provguid1" "PROV1"})
18+
tags/grant-all-tag-fixture]))
19+
20+
(defn- create-direct-dist-info
21+
"Create a Direct Distribution"
22+
[]
23+
{:DirectDistributionInformation {:Region "us-east-1"
24+
:S3CredentialsAPIEndpoint "https://example.org"
25+
:S3CredentialsAPIDocumentationURL "https://example.org"}})
26+
27+
(deftest search-collections-that-are-cloud-hosted
28+
(let [coll1 (data2/ingest-umm-spec-collection "PROV1" (data-umm-c/collection 1 {}))
29+
coll2 (data2/ingest-umm-spec-collection "PROV1" (data-umm-c/collection 2 {}))
30+
coll3 (data2/ingest-umm-spec-collection "PROV1" (data-umm-c/collection 3 (create-direct-dist-info)))]
31+
(index/wait-until-indexed)
32+
33+
(testing "Search by the cloud_hosted flag only"
34+
(util/are3
35+
[expected items]
36+
(data2/refs-match? items (search/find-refs :collection {:cloud-hosted expected}))
37+
"Found using metadata" true [coll3]
38+
"Not found" false [coll1 coll2]))
39+
40+
(testing "Search for collections tagged as cloud hosted"
41+
(let [user1-token (echo/login (system/context) "user1")
42+
tag1 (tags/make-tag {:tag-key itag/earthdata-cloud-s3-tag})
43+
tag_record (tags/save-tag user1-token tag1 [coll1])]
44+
(index/wait-until-indexed)
45+
46+
(util/are3
47+
[expected items]
48+
(is (data2/refs-match? items (search/find-refs :collection {:cloud-hosted expected})))
49+
"Found using metadata or tags" true [coll1 coll3]
50+
"Not found" false [coll2])))))

0 commit comments

Comments
 (0)