Skip to content

Commit 9b908a3

Browse files
committed
CMR-10502: cleanup
1 parent 214edb0 commit 9b908a3

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
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: 19 additions & 19 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."
@@ -43,16 +43,15 @@
4343
get-field-values (fn [c fs]
4444
(let [metadata (json/parse-string (:metadata c) true)]
4545
(mapv #(let [field-path (rest (string/split % #"\."))
46-
keyword-path (keyword (first field-path))]
47-
(get-in metadata[keyword-path]))
46+
keyword-path (mapv keyword field-path)]
47+
(get-in metadata keyword-path))
4848
fs)))
4949

5050
;; Extract values for the specified fields from the current concept
5151
field-values (get-field-values concept fields)
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,10 @@
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.
76+
validation-value is here for possible future implementations but is not needed in the
77+
uniqueness validation.
7678
Returns a sequence of error messages if validation fails, empty sequence otherwise."
7779
[context concept validation-type fields validation-value]
7880
(case validation-type
@@ -98,14 +100,10 @@
98100
"Loads a single schema validation function for a concept type and version"
99101
[concept-type version]
100102
(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))
103+
(let [schema-json (generics/read-schema-config concept-type version)
104+
schema (json/parse-string schema-json true)]
105+
(fn [context concept]
106+
(validate-with-schema context concept schema)))
109107
(catch Exception e
110108
(error "Error loading schema for" concept-type "version" version ":" (.getMessage e))
111109
nil)))
@@ -123,12 +121,12 @@
123121
[]
124122
(info "Loading schema validation functions for all generic concept types")
125123
(let [generic-types (concepts/get-generic-concept-types-array)
126-
validators (reduce (fn [validators concept-type]
124+
validators (reduce (fn [vs concept-type]
127125
(let [current-version (generics/current-generic-version concept-type)
128126
validator (load-schema-validation concept-type current-version)]
129127
(if validator
130-
(assoc validators [concept-type current-version] validator)
131-
validators)))
128+
(assoc vs [concept-type current-version] validator)
129+
vs)))
132130
{}
133131
generic-types)]
134132
(info "Loaded" (count validators) "schema validators")
@@ -148,8 +146,10 @@
148146
Throws a :bad-request service error if validation fails."
149147
[context concept]
150148
(let [concept-type (:concept-type concept)
151-
metadata-spec (extract-concept-metadata-spec concept)
152-
version (or (:version metadata-spec)
149+
version (or (:version (extract-concept-metadata-spec concept))
150+
;; If version is not specified in metadata, use the current version
151+
;; of the concept type, though it is likey that the concept failed
152+
;; schema validation and we never reach this point.
153153
(generics/current-generic-version concept-type))
154154

155155
;; Get validation functions
@@ -163,4 +163,4 @@
163163

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

schemas/resources/schemas/config/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Index schema change Log
1+
# Config schema change Log
22

33
## [1.0.0]
44
- 2022-??-??

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)