diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 0d28fe6d3..0638dfc8a 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -284,7 +284,7 @@ [component] (if (and (contains? component :objects) (nil? (:objects component))) (if (:deleted component) - (assoc component :objects []) + (assoc component :objects {}) (dissoc component :objects)) component))] (-> file-data diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index da366a0ef..016e18769 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -408,11 +408,11 @@ [_ {:keys [shape] :as error} file-data _] (let [repair-component (fn [component] - ; Remove the objects key, or set it to [] if the component is deleted + ; Remove the objects key, or set it to {} if the component is deleted (if (:deleted component) (do - (log/debug :hint " -> Set :objects []") - (assoc component :objects [])) + (log/debug :hint " -> Set :objects {}") + (assoc component :objects {})) (do (log/debug :hint " -> Remove :objects") (dissoc component :objects))))] diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 30e14acf5..eff81bd03 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -46,7 +46,8 @@ :nested-copy-not-allowed :not-head-main-not-allowed :not-head-copy-not-allowed - :not-component-not-allowed}) + :not-component-not-allowed + :component-nil-objects-not-allowed}) (def validation-error [:map {:title "ValidationError"} @@ -328,8 +329,7 @@ (defn validate-shape! "Validate referential integrity and semantic coherence of - a shape and all its children. Raises an exception on first - error found. + a shape and all its children. Report all errors found. The context is the situation of the parent in respect to components: - :not-component @@ -406,22 +406,27 @@ (validate-shape-not-component! shape file page libraries))))))) (defn validate-shape - "Validate referential integrity and semantic coherence of - a shape and all its children. Returns a list of errors." + "Validate a shape and all its children. Returns a list of errors." [shape-id file page libraries] (binding [*errors* (volatile! [])] (validate-shape! shape-id file page libraries) (deref *errors*))) (defn validate-component! - " Validate semantic coherence of a component. Raises an exception - on first error found." + "Validate semantic coherence of a component. Report all errors found." [component file] (when (and (contains? component :objects) (nil? (:objects component))) (report-error! :component-nil-objects-not-allowed "Objects list cannot be nil" component file nil))) +(defn validate-component + "Validate a component. Returns a list of errors." + [component file] + (binding [*errors* (volatile! [])] + (validate-component! component file) + (deref *errors*))) + (def valid-fdata? "Structural validation of file data using defined schema" (sm/lazy-validator ::ctf/data)) @@ -451,14 +456,13 @@ ;; If `libraries` is provided, this means the full file ;; validation is activated so we proceed to execute the ;; validation - (when (some? libraries) - (when (:components data) - (doseq [component (vals (:components data))] - (validate-component! component file))) - (doseq [page (filter :id (ctpl/pages-seq data))] - (validate-shape! uuid/zero file page libraries))) + (when (some? libraries) + (doseq [page (filter :id (ctpl/pages-seq data))] + (validate-shape! uuid/zero file page libraries)) + (doseq [component (vals (:components data))] + (validate-component! component file))) - file)) + file)) (defn validate-file "Validate referencial integrity and semantic coherence of