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."
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))
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
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 )))
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" )
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
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))))
0 commit comments