Skip to content

Commit c7086de

Browse files
committed
CMR-10502 cleanup
1 parent ffe9cac commit c7086de

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,7 @@
204204
(when concept
205205
(let [concept-type (:concept-type concept)]
206206
(when-not (common-concepts/is-draft-concept? concept-type)
207-
(try
208-
(generic-document-validation/validate-concept context concept)
209-
(catch Exception e
210-
(errors/throw-service-error
211-
:invalid-data
212-
(format "While validating the business rules for the record, the following error occurred: [%s]"
213-
(.getMessage e)))))))))
207+
(generic-document-validation/validate-concept context concept)))))
214208

215209
(defn ingest-document
216210
"Ingest the concept into the database and the indexer through the database."

ingest-app/src/cmr/ingest/validation/generic_document_validation.clj

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
(def SCHEMA_CACHE_TIME
1919
"The number of milliseconds schema validation functions will be cached."
20-
(* 60 60 1000)) ;; 1 hour
20+
(* 24 60 60 1000)) ;; 24 hours
2121

2222
(defn create-schema-validation-cache
2323
"Creates a cache for schema validation functions."
@@ -52,7 +52,6 @@
5252

5353
;; Check if any other document in the collection has the same combination of values
5454
duplicate-concepts (filter (fn [existing-concept]
55-
;; Debug print to show values being compared
5655
(and (not= (:native-id existing-concept) (:native-id concept))
5756
(not= (:deleted existing-concept) true)
5857
(= (set (get-field-values existing-concept fields))
@@ -72,7 +71,8 @@
7271
[])))
7372

7473
(defn- validate-by-type
75-
"Validates fields based on validation type.
74+
"Validates fields based on validation type. Any new validation added to the config.json
75+
should be added here and implemented in the corresponding function.
7676
Returns a sequence of error messages if validation fails, empty sequence otherwise."
7777
[context concept validation-type fields validation-value]
7878
(case validation-type
@@ -98,14 +98,10 @@
9898
"Loads a single schema validation function for a concept type and version"
9999
[concept-type version]
100100
(try
101-
(if (generics/approved-generic? concept-type version)
102-
(let [schema-json (generics/read-schema-config concept-type version)
103-
schema (json/parse-string schema-json true)]
104-
(fn [context concept]
105-
(validate-with-schema context concept schema)))
106-
(do
107-
(error "Schema version not approved for" concept-type "version" version)
108-
nil))
101+
(let [schema-json (generics/read-schema-config concept-type version)
102+
schema (json/parse-string schema-json true)]
103+
(fn [context concept]
104+
(validate-with-schema context concept schema)))
109105
(catch Exception e
110106
(error "Error loading schema for" concept-type "version" version ":" (.getMessage e))
111107
nil)))
@@ -123,12 +119,12 @@
123119
[]
124120
(info "Loading schema validation functions for all generic concept types")
125121
(let [generic-types (concepts/get-generic-concept-types-array)
126-
validators (reduce (fn [validators concept-type]
122+
validators (reduce (fn [vs concept-type]
127123
(let [current-version (generics/current-generic-version concept-type)
128124
validator (load-schema-validation concept-type current-version)]
129125
(if validator
130-
(assoc validators [concept-type current-version] validator)
131-
validators)))
126+
(assoc vs [concept-type current-version] validator)
127+
vs)))
132128
{}
133129
generic-types)]
134130
(info "Loaded" (count validators) "schema validators")
@@ -148,8 +144,10 @@
148144
Throws a :bad-request service error if validation fails."
149145
[context concept]
150146
(let [concept-type (:concept-type concept)
151-
metadata-spec (extract-concept-metadata-spec concept)
152-
version (or (:version metadata-spec)
147+
version (or (:version (extract-concept-metadata-spec concept))
148+
;; If version is not specified in metadata, use the current version
149+
;; of the concept type, though it is likey that the concept failed
150+
;; schema validation and we never reach this point.
153151
(generics/current-generic-version concept-type))
154152

155153
;; Get validation functions
@@ -163,4 +161,4 @@
163161

164162
;; Throw service errors if any validation errors are found
165163
(when (seq errors)
166-
(errors/throw-service-errors :bad-request errors))))
164+
(errors/throw-service-errors :invalid-data errors))))

schemas/resources/schemas/config/v0.0.1/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"additionalProperties": false,
3535
"properties": {
3636
"Fields": {
37-
"description": "The Field to validate, defined as a jq style path",
37+
"description": "The field to validate, defined as a jq style path",
3838
"type": "array",
3939
"items": {
4040
"type": "string",

system-int-test/test/cmr/system_int_test/search/acls/collection_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
(use-fixtures :each (join-fixtures
1919
[(ingest/reset-fixture {"provguid1" "PROV1" "provguid2" "PROV2"
2020
"provguid3" "PROV3" "provguid4" "PROV4"}
21-
{:grant-all-search? true})
21+
{:grant-all-search? false})
2222
(search/freeze-resume-time-fixture)]))
2323

2424
(comment

0 commit comments

Comments
 (0)