Skip to content

Commit f76db34

Browse files
CMR-11421: Add Header to skip sending to KMS metadata fixer service if passed
1 parent fbf36b6 commit f76db34

3 files changed

Lines changed: 148 additions & 2 deletions

File tree

ingest-app/src/cmr/ingest/api/collections.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
(def VALIDATE_KEYWORDS_HEADER "cmr-validate-keywords")
1414
(def ENABLE_UMM_C_VALIDATION_HEADER "cmr-validate-umm-c")
1515
(def TESTING_EXISTING_ERRORS_HEADER "cmr-test-existing-errors")
16+
(def SEND_KMS_METADATA_FIXER_HEADER "cmr-send-kms-metadata-fixer")
1617
(def COLLECTION_WARNING_CONTEXT "After translating item to UMM-C the metadata had the following issue(s): ")
1718
(def COLLECTION_EXISTING_ERROR_CONTEXT "After translating item to UMM-C the metadata had the following existing error(s): ")
1819

@@ -28,7 +29,8 @@
2829
(= "true" (get headers VALIDATE_KEYWORDS_HEADER)))]
2930
{:validate-keywords? validate-keywords-value
3031
:validate-umm? (= "true" (get headers ENABLE_UMM_C_VALIDATION_HEADER))
31-
:test-existing-errors? (= "true" (get headers TESTING_EXISTING_ERRORS_HEADER))}))
32+
:test-existing-errors? (= "true" (get headers TESTING_EXISTING_ERRORS_HEADER))
33+
:send-metadata-fixer? (not= "false" (get headers SEND_KMS_METADATA_FIXER_HEADER))}))
3234

3335
(defn validate-collection
3436
[provider-id native-id request]

ingest-app/src/cmr/ingest/services/ingest_service/collection.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@
123123
(common-context/context->user-id context)
124124
"unknown user"))))
125125
;; When a keyword error is detected but, ingest is alllowed send to kms fixer to resolve keyword
126-
(when (should-notify-kms? has-keyword-error? existing-errors warnings)
126+
(when (and (should-notify-kms? has-keyword-error? existing-errors warnings)
127+
(:send-metadata-fixer? validation-options))
127128
(transmit-kms/notify-kms context concept-id))
128129
{:entry-title entry-title
129130
:concept-id concept-id
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
(ns cmr.ingest.api.collections-test
2+
"Unit tests for cmr.ingest.api.collections, starting with
3+
get-validation-options. More tests for other functions in this
4+
namespace can be added here over time."
5+
(:require [clojure.test :refer [deftest testing is]]
6+
[cmr.ingest.api.collections :as v :refer [get-validation-options
7+
VALIDATE_KEYWORDS_HEADER
8+
ENABLE_UMM_C_VALIDATION_HEADER
9+
TESTING_EXISTING_ERRORS_HEADER
10+
SEND_KMS_METADATA_FIXER_HEADER]]))
11+
12+
;; ---------------------------------------------------------------------
13+
;; :validate-keywords? — default-true-enabled? = true
14+
;; (only an explicit "false" header value turns validation off)
15+
;; ---------------------------------------------------------------------
16+
(deftest validate-keywords-default-true-enabled-true
17+
(with-redefs [v/validate-keywords-default-true-enabled? true]
18+
(testing "header explicitly \"false\" -> false"
19+
(is (= false (:validate-keywords?
20+
(get-validation-options {VALIDATE_KEYWORDS_HEADER "false"})))))
21+
22+
(testing "header explicitly \"true\" -> true"
23+
(is (= true (:validate-keywords?
24+
(get-validation-options {VALIDATE_KEYWORDS_HEADER "true"})))))
25+
26+
(testing "header missing -> true (defaults on)"
27+
(is (= true (:validate-keywords?
28+
(get-validation-options {})))))
29+
30+
(testing "header present but garbage value -> true (defaults on)"
31+
(is (= true (:validate-keywords?
32+
(get-validation-options {VALIDATE_KEYWORDS_HEADER "nope"})))))))
33+
34+
;; ---------------------------------------------------------------------
35+
;; :validate-keywords? — default-true-enabled? = false
36+
;; (must explicitly opt in with "true")
37+
;; ---------------------------------------------------------------------
38+
(deftest validate-keywords-default-true-enabled-false
39+
(with-redefs [v/validate-keywords-default-true-enabled? false]
40+
(testing "header explicitly \"true\" -> true"
41+
(is (= true (:validate-keywords?
42+
(get-validation-options {VALIDATE_KEYWORDS_HEADER "true"})))))
43+
44+
(testing "header explicitly \"false\" -> false"
45+
(is (= false (:validate-keywords?
46+
(get-validation-options {VALIDATE_KEYWORDS_HEADER "false"})))))
47+
48+
(testing "header missing -> false (defaults off)"
49+
(is (= false (:validate-keywords?
50+
(get-validation-options {})))))
51+
52+
(testing "header present but garbage value -> false (defaults off)"
53+
(is (= false (:validate-keywords?
54+
(get-validation-options {VALIDATE_KEYWORDS_HEADER "nope"})))))))
55+
56+
;; ---------------------------------------------------------------------
57+
;; :validate-umm? — defaults to false, only "true" turns it on
58+
;; ---------------------------------------------------------------------
59+
(deftest validate-umm-test
60+
(testing "header \"true\" -> true"
61+
(is (= true (:validate-umm?
62+
(get-validation-options {ENABLE_UMM_C_VALIDATION_HEADER "true"})))))
63+
64+
(testing "header missing -> false"
65+
(is (= false (:validate-umm? (get-validation-options {})))))
66+
67+
(testing "header \"false\" -> false"
68+
(is (= false (:validate-umm?
69+
(get-validation-options {ENABLE_UMM_C_VALIDATION_HEADER "false"})))))
70+
71+
(testing "header garbage value -> false"
72+
(is (= false (:validate-umm?
73+
(get-validation-options {ENABLE_UMM_C_VALIDATION_HEADER "yes"}))))))
74+
75+
;; ---------------------------------------------------------------------
76+
;; :test-existing-errors? — defaults to false, only "true" turns it on
77+
;; ---------------------------------------------------------------------
78+
(deftest test-existing-errors-test
79+
(testing "header \"true\" -> true"
80+
(is (= true (:test-existing-errors?
81+
(get-validation-options {TESTING_EXISTING_ERRORS_HEADER "true"})))))
82+
83+
(testing "header missing -> false"
84+
(is (= false (:test-existing-errors? (get-validation-options {})))))
85+
86+
(testing "header \"false\" -> false"
87+
(is (= false (:test-existing-errors?
88+
(get-validation-options {TESTING_EXISTING_ERRORS_HEADER "false"})))))
89+
90+
(testing "header garbage value -> false"
91+
(is (= false (:test-existing-errors?
92+
(get-validation-options {TESTING_EXISTING_ERRORS_HEADER "yes"}))))))
93+
94+
;; ---------------------------------------------------------------------
95+
;; :send-metadata-fixer? — defaults to true, only explicit "false" turns it off
96+
;; ---------------------------------------------------------------------
97+
(deftest send-metadata-fixer-test
98+
(testing "header missing -> true (defaults on)"
99+
(is (= true (:send-metadata-fixer? (get-validation-options {})))))
100+
101+
(testing "header \"true\" -> true"
102+
(is (= true (:send-metadata-fixer?
103+
(get-validation-options {SEND_KMS_METADATA_FIXER_HEADER "true"})))))
104+
105+
(testing "header \"false\" -> false"
106+
(is (= false (:send-metadata-fixer?
107+
(get-validation-options {SEND_KMS_METADATA_FIXER_HEADER "false"})))))
108+
109+
(testing "header garbage value -> true (anything other than \"false\" is on)"
110+
(is (= true (:send-metadata-fixer?
111+
(get-validation-options {SEND_KMS_METADATA_FIXER_HEADER "nope"}))))))
112+
113+
;; ---------------------------------------------------------------------
114+
;; Combination / full-map tests
115+
;; ---------------------------------------------------------------------
116+
(deftest get-validation-options-combined-test
117+
(testing "empty headers map, default-true-enabled? true -> keywords on, rest off/on defaults"
118+
(with-redefs [v/validate-keywords-default-true-enabled? true]
119+
(is (= {:validate-keywords? true
120+
:validate-umm? false
121+
:test-existing-errors? false
122+
:send-metadata-fixer? true}
123+
(get-validation-options {})))))
124+
125+
(testing "empty headers map, default-true-enabled? false -> keywords off, rest off/on defaults"
126+
(with-redefs [v/validate-keywords-default-true-enabled? false]
127+
(is (= {:validate-keywords? false
128+
:validate-umm? false
129+
:test-existing-errors? false
130+
:send-metadata-fixer? true}
131+
(get-validation-options {})))))
132+
133+
(testing "all headers explicitly set"
134+
(with-redefs [v/validate-keywords-default-true-enabled? true]
135+
(is (= {:validate-keywords? false
136+
:validate-umm? true
137+
:test-existing-errors? true
138+
:send-metadata-fixer? false}
139+
(get-validation-options
140+
{VALIDATE_KEYWORDS_HEADER "false"
141+
ENABLE_UMM_C_VALIDATION_HEADER "true"
142+
TESTING_EXISTING_ERRORS_HEADER "true"
143+
SEND_KMS_METADATA_FIXER_HEADER "false"}))))))

0 commit comments

Comments
 (0)