From 6d2f5c69474d167bdcbe3f0f3d80c482a0b361ee Mon Sep 17 00:00:00 2001 From: David Schneider Date: Wed, 15 Nov 2017 14:41:28 +0100 Subject: [PATCH 1/2] Added a test and a fix to properly validate missing min/max cp values on level tags in cp based trees --- src/mincer/xml/tree_validation.clj | 49 +++++++++++++++++++++++++-- test/mincer/xml/tree_cp_test_data.clj | 3 ++ test/mincer/xml/tree_test_cp.clj | 6 ++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/mincer/xml/tree_validation.clj b/src/mincer/xml/tree_validation.clj index 210f764..2e864c7 100644 --- a/src/mincer/xml/tree_validation.clj +++ b/src/mincer/xml/tree_validation.clj @@ -7,6 +7,7 @@ [clojure.tools.logging :as log])) (defmulti validate :tag) +(defmulti validate-cp :tag) (def ^:dynamic errors) @@ -40,7 +41,10 @@ (defmethod validate :b [b] (log/trace (:tag b)) - (flatten (map validate (:content b)))) + ; if b tag has cp field + + (let [validation-fn (if (contains? (:attrs b) :cp) validate-cp validate)] + (flatten (map validation-fn (:content b))))) (defmethod validate :l [l] (log/trace (:tag l)) @@ -78,6 +82,47 @@ (log/trace "Ignoring" tag) []) +(defmethod validate-cp :l [l] + (log/trace (:tag l)) + (log/trace l) + ; validate that l has min-cp and max-cp attrs + (if (not (subset? #{:min-cp :max-cp} (-> l :attrs keys set))) + (do + (set! errors true) + (log/error "l (level) tag for a cp based course does not contain min-cp and max-cp attributes" (-> l :attrs :name)))) + ; validate mixed l and m tags in levels + ; checking if content containts l and m tags + (if (subset? #{:l :m} (set (map :tag (:content l)))) + (do + (set! errors true) + (log/error "level containts l and m tags as children in level " (-> l :attrs :name)))) + (flatten (map validate-cp (:content l)))) + +(defmethod validate-cp :minors [minors] + (log/trace (:tag minors)) + ; only minor tags + (if (not (= #{:minor} (set (map :tag (:content minors))))) + (log/error "Tag 'minors' can only contain minor-Tags.")) + (flatten (map validate-cp (:content minors)))) + +(defmethod validate-cp :minor [minor] + (log/trace (:tag minor)) + (let [stg (-> minor :attrs :stg) + po (-> minor :attrs :pversion)] + (do (when (nil? stg) (log_error "Missing 'stg' in minor tag.")) + (when (nil? po) (log_error "Missing 'pversion' in minor tag.")) + (try (Integer/parseInt po) (catch NumberFormatException e (log_error "Attribute 'pversion' has to be an integer.")))))) + +(defmethod validate-cp :m [m] + (log/trace (:tag m)) + (let [pordnr (-> m :attrs :pordnr)] + (when (nil? pordnr) (log/error "pordnr missing " (-> m :attrs :name))) + pordnr)) + +(defmethod validate-cp :default [tag] + (log/trace "Ignoring" tag) + []) + (defn validate-modules [xml] (let [modules (group-by (fn [node] (-> node :attrs :pordnr)) (filter (fn [node] (= :m (:tag node))) @@ -93,4 +138,4 @@ (validate xml) (validate-modules xml) (if errors - (throw (IllegalArgumentException. "Module tree contains validation errors."))))) \ No newline at end of file + (throw (IllegalArgumentException. "Module tree contains validation errors."))))) diff --git a/test/mincer/xml/tree_cp_test_data.clj b/test/mincer/xml/tree_cp_test_data.clj index 14fcb84..6aca3c0 100644 --- a/test/mincer/xml/tree_cp_test_data.clj +++ b/test/mincer/xml/tree_cp_test_data.clj @@ -14,6 +14,9 @@ :content [m-cp-tag] :tag :l}] :tag :l}) +(def l-cp-tag-missing-data {:attrs {:name "Wahlpflichtmodule"} + :content [] + :tag :l}) (def b-cp-tag {:attrs {:abschl "bk" :kzfa "H" diff --git a/test/mincer/xml/tree_test_cp.clj b/test/mincer/xml/tree_test_cp.clj index 3c8741d..3827718 100644 --- a/test/mincer/xml/tree_test_cp.clj +++ b/test/mincer/xml/tree_test_cp.clj @@ -1,6 +1,7 @@ (ns mincer.xml.tree-test-cp (:require [clojure.test :refer :all] [mincer.xml.tree-cp-test-data :refer :all] + [mincer.xml.tree-validation :refer :all] [mincer.xml.tree :refer :all])) (def result-cp-module {:type :module @@ -84,3 +85,8 @@ children (:children course)] (is (= 1 (count children))) (is (not-any? nil? children)))) + +(deftest test-validate-cp-based-level-with-missing-cp-data + (binding [errors false] + (validate-cp l-cp-tag-missing-data) + (is errors))) From 8272ea783260c12b5417a8bf0f66e1dd6d8ce450 Mon Sep 17 00:00:00 2001 From: David Schneider Date: Wed, 15 Nov 2017 14:46:23 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Bump=20version:=203.2.0=20=E2=86=92=203.2.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- .travis.yml | 2 +- README.md | 2 +- config.xml | 10 +++++----- project.clj | 2 +- src/mincer/db.clj | 2 +- src/mincer/ui.clj | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index db8f815..f33a29a 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.2.0 +current_version = 3.2.1 parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?P\w+))? tag = False commit = True diff --git a/.travis.yml b/.travis.yml index c4031e0..4d0cd60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ script: - lein launch4j after_success: -- travis-custom-deploy sftp target/mincer-3.2.0-standalone.jar target/mincer-3.2.0.exe +- travis-custom-deploy sftp target/mincer-3.2.1-standalone.jar target/mincer-3.2.1.exe env: global: - DISPLAY=:99.0 diff --git a/README.md b/README.md index eb30d1b..4a900f1 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Mincer supports two usage modes: batch/CLI and GUI modes. To start the graphical user-interface run the provided jar without arguments: ``` -$ java -jar mincer-3.2.0-standalone.jar +$ java -jar mincer-3.2.1-standalone.jar ``` ### CLI diff --git a/config.xml b/config.xml index fbda7e4..cea9251 100644 --- a/config.xml +++ b/config.xml @@ -2,8 +2,8 @@ false gui - target/mincer-3.2.0-standalone.jar - target/mincer-3.2.0.exe + target/mincer-3.2.1-standalone.jar + target/mincer-3.2.1.exe normal http://java.com/download @@ -23,15 +23,15 @@ 0.0.0.1 - 3.2.0-dev + 3.2.1-dev mincer ISC 0.0.0.1 - 3.2.0-dev + 3.2.1-dev mincer mincer - mincer-3.2.0.exe + mincer-3.2.1.exe Startup Error diff --git a/project.clj b/project.clj index 5e2054f..ef12c36 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject mincer "3.2.0" +(defproject mincer "3.2.1" :description "Tool to create a SQLite database from PlüS module tree and data XML files." :url "https://github.com/plues/mincer" :license {:name "Eclipse Public License" diff --git a/src/mincer/db.clj b/src/mincer/db.clj index f1526cf..a65343b 100644 --- a/src/mincer/db.clj +++ b/src/mincer/db.clj @@ -5,7 +5,7 @@ [clojure.java.jdbc :refer [with-db-transaction]] [clojure.tools.logging :as log])) -(def mincer-version "3.2.0") ; updated with bumpversion +(def mincer-version "3.2.1") ; updated with bumpversion (defn now [] (new java.util.Date)) diff --git a/src/mincer/ui.clj b/src/mincer/ui.clj index 1cd8026..f48521e 100644 --- a/src/mincer/ui.clj +++ b/src/mincer/ui.clj @@ -161,7 +161,7 @@ (let [lbl-mincer (label ::mincer) lbl-icon (label :icon logo) lbl-file-select (label ::file-select) - lbl-version (label "3.2.0") ; managed by bumpversion + lbl-version (label "3.2.1") ; managed by bumpversion lbl-save (label ::save)] (doall (map #(config! % :border 10) [lbl-mincer lbl-file-select lbl-version lbl-icon])) (config! lbl-save :halign :center)