[Lada-commits] [PATCH 1 of 3] Merge current default into openid

Wald Commits scm-commit at wald.intevation.org
Fri Mar 13 15:20:37 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1426253212 -3600
# Branch openid
# Node ID 2b7c7f3e51b716fb6ca2f38db62858cff9a607ba
# Parent  28fd6616e0f886886cea360affef86e7f2abb5e1
# Parent  7a0e3d49ae33755be8f1be56b48f7ffb71c112ab
Merge current default into openid

diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/model/stamm/Verwaltungseinheit.java
--- a/src/main/java/de/intevation/lada/model/stamm/Verwaltungseinheit.java	Fri Mar 13 09:58:41 2015 +0100
+++ b/src/main/java/de/intevation/lada/model/stamm/Verwaltungseinheit.java	Fri Mar 13 14:26:52 2015 +0100
@@ -12,8 +12,6 @@
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
 
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/rest/ProbeService.java
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java	Fri Mar 13 09:58:41 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/ProbeService.java	Fri Mar 13 14:26:52 2015 +0100
@@ -45,6 +45,9 @@
 import de.intevation.lada.util.data.Repository;
 import de.intevation.lada.util.data.RepositoryType;
 import de.intevation.lada.util.rest.Response;
+import de.intevation.lada.validation.Validator;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationConfig;
 
 
 /**
@@ -75,6 +78,10 @@
     @AuthorizationConfig(type=AuthorizationType.NONE)
     private Authorization authorization;
 
+    @Inject
+    @ValidationConfig(type="Probe")
+    private Validator validator;
+
     /**
      * Get all probe objects.
      *
@@ -141,7 +148,13 @@
             logger.debug("User is not authenticated!");
             return new Response(false, 699, null);
         }
-        return defaultRepo.getById(LProbe.class, Integer.valueOf(id), "land");
+        Response response =
+            defaultRepo.getById(LProbe.class, Integer.valueOf(id), "land");
+        Violation violation = validator.validate(response.getData());
+        if (violation.hasWarnings()) {
+            response.setWarnings(violation.getWarnings());
+        }
+        return response;
     }
 
     /**
@@ -156,17 +169,27 @@
         if (!authentication.isAuthenticated(headers)) {
             return new Response(false, 699, null);
         }
+        Violation violation = validator.validate(probe);
+        if (violation.hasErrors()) {
+            Response response = new Response(false, 604, probe);
+            response.setErrors(violation.getErrors());
+            response.setWarnings(violation.getWarnings());
+            return response;
+        }
         /* Persist the new probe object*/
-        Response response = defaultRepo.create(probe, "land");
-        LProbe ret = (LProbe)response.getData();
+        Response newProbe = defaultRepo.create(probe, "land");
+        LProbe ret = (LProbe)newProbe.getData();
         /* Create and persist a new probe translation object*/
         ProbeTranslation trans = new ProbeTranslation();
         trans.setProbeId(ret);
         defaultRepo.create(trans, "land");
         /* Get and return the new probe object*/
-        Response created =
+        Response response =
             defaultRepo.getById(LProbe.class, ret.getId(), "land");
-        return new Response(true, 200, created.getData());
+        if(violation.hasWarnings()) {
+            response.setWarnings(violation.getWarnings());
+        }
+        return response;
     }
 
     /**
@@ -182,10 +205,20 @@
             logger.debug("User is not authenticated!");
             return new Response(false, 699, null);
         }
+        Violation violation = validator.validate(probe);
+        if (violation.hasErrors()) {
+            Response response = new Response(false, 604, probe);
+            response.setErrors(violation.getErrors());
+            response.setWarnings(violation.getWarnings());
+            return response;
+        }
         Response response = defaultRepo.update(probe, "land");
         Response updated = defaultRepo.getById(
             LProbe.class,
             ((LProbe)response.getData()).getId(), "land");
+        if (violation.hasWarnings()) {
+            updated.setWarnings(violation.getWarnings());
+        }
         return updated;
     }
 
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/util/rest/Response.java
--- a/src/main/java/de/intevation/lada/util/rest/Response.java	Fri Mar 13 09:58:41 2015 +0100
+++ b/src/main/java/de/intevation/lada/util/rest/Response.java	Fri Mar 13 14:26:52 2015 +0100
@@ -11,6 +11,9 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
 
 /**
 * Response object storing information about success, warnings, errors and
@@ -25,8 +28,8 @@
     private Boolean success;
     private String message;
     private Object data;
-    private Map<String, String> errors;
-    private Map<String, String> warnings;
+    private MultivaluedMap<String, Integer> errors;
+    private MultivaluedMap<String, Integer> warnings;
     private Boolean readonly;
     private int totalCount;
 
@@ -41,8 +44,8 @@
         this.success = success;
         this.message = Integer.toString(code);
         this.data = data;
-        this.errors = new HashMap<String, String>();
-        this.warnings = new HashMap<String, String>();
+        this.errors = new MultivaluedHashMap<String, Integer>();
+        this.warnings = new MultivaluedHashMap<String, Integer>();
         this.readonly = Boolean.FALSE;
         this.totalCount = 0;
     }
@@ -58,8 +61,8 @@
         this.success = success;
         this.message = Integer.toString(code);
         this.data = data;
-        this.errors = new HashMap<String, String>();
-        this.warnings = new HashMap<String, String>();
+        this.errors = new MultivaluedHashMap<String, Integer>();
+        this.warnings = new MultivaluedHashMap<String, Integer>();
         this.readonly = Boolean.FALSE;
         this.totalCount = totalCount;
     }
@@ -88,20 +91,22 @@
         this.data = data;
     }
 
-    public Map<String, String> getErrors() {
+    public MultivaluedMap<String, Integer> getErrors() {
         return errors;
     }
 
-    public void setErrors(Map<String, Integer> errors) {
-        this.errors = this.convertCodes(errors);
+    public void setErrors(MultivaluedMap<String, Integer> errors) {
+        this.errors.putAll(errors);
+//        this.errors = this.convertCodes(errors);
     }
 
-    public Map<String, String> getWarnings() {
+    public MultivaluedMap<String, Integer> getWarnings() {
         return warnings;
     }
 
-    public void setWarnings(Map<String, Integer> warnings) {
-        this.warnings = this.convertCodes(warnings);
+    public void setWarnings(MultivaluedMap<String, Integer> warnings) {
+        this.warnings.putAll(warnings);
+        //this.warnings = this.convertCodes(warnings);
     }
 
     public Boolean getReadonly() {
@@ -126,6 +131,7 @@
         this.totalCount = totalCount;
     }
 
+    @SuppressWarnings("unused")
     private HashMap<String, String> convertCodes(Map<String, Integer> codes) {
         HashMap<String, String> converted = new HashMap<String, String>();
         if (codes == null || codes.isEmpty()) {
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/ProbeValidator.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/ProbeValidator.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,40 @@
+package de.intevation.lada.validation;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationConfig(type="Probe")
+ at ApplicationScoped
+public class ProbeValidator implements Validator {
+
+    @Inject
+    @ValidationRule("Probe")
+    private Instance<Rule> rules;
+
+    @Override
+    public Violation validate(Object object) {
+        Violation violations = new Violation();
+        if (!(object instanceof LProbe)) {
+            violations.addError("probe", 602);
+            return violations;
+        }
+        for(Rule rule: rules) {
+            Violation result = rule.execute(object);
+            if (result != null) {
+                if (result.hasWarnings()) {
+                    violations.addWarnings(result.getWarnings());
+                }
+                if (result.hasErrors()) {
+                    violations.addErrors(result.getErrors());
+                }
+            }
+        }
+        return violations;
+    }
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/Validator.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/Validator.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,18 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation;
+
+
+/**
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+public interface Validator {
+
+    public Violation validate(Object object);
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/Violation.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/Violation.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,63 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
+/**
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+public class Violation {
+
+    private MultivaluedMap<String, Integer> warnings;
+
+    private MultivaluedMap<String, Integer> errors;
+
+    public Violation() {
+        this.warnings = new MultivaluedHashMap<String, Integer>();
+        this.errors = new MultivaluedHashMap<String, Integer>();
+    }
+
+    public MultivaluedMap<String, Integer> getWarnings() {
+        return this.warnings;
+    }
+
+    public MultivaluedMap<String, Integer> getErrors() {
+        return this.errors;
+    }
+
+    public void addWarning(String key, Integer value) {
+        this.warnings.add(key, value);
+    }
+
+    public void addError(String key, Integer value) {
+        this.errors.add(key, value);
+    }
+
+    public void addWarnings(MultivaluedMap<String, Integer> warnings) {
+        for (String key: warnings.keySet()) {
+            this.warnings.addAll(key, warnings.get(key));
+        }
+    }
+
+    public void addErrors(MultivaluedMap<String, Integer> errors) {
+        for (String key: errors.keySet()) {
+            this.errors.addAll(key, errors.get(key));
+        }
+    }
+
+    public boolean hasWarnings() {
+        return this.warnings.size() > 0;
+    }
+
+    public boolean hasErrors() {
+        return this.errors.size() > 0;
+    }
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/annotation/ValidationConfig.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/annotation/ValidationConfig.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,31 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+
+/**
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({
+    ElementType.TYPE,
+    ElementType.FIELD,
+    ElementType.METHOD,
+    ElementType.PARAMETER})
+public @interface ValidationConfig {
+    String type() default "";
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/annotation/ValidationRule.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/annotation/ValidationRule.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,31 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+
+/**
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target({
+    ElementType.TYPE,
+    ElementType.FIELD,
+    ElementType.METHOD,
+    ElementType.PARAMETER})
+public @interface ValidationRule {
+    String value() default "";
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/Rule.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/Rule.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,19 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation.rules;
+
+import de.intevation.lada.validation.Violation;
+
+/**
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+public interface Rule {
+
+    public Violation execute(Object object);
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,50 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LOrt;
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.Response;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class HasEntnahmeOrt implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repo;
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        Integer id = probe.getId();
+        if (id == null) {
+            Violation violation = new Violation();
+            violation.addWarning("entnahmeOrt", 631);
+            return violation;
+        }
+        QueryBuilder<LOrt> builder =
+            new QueryBuilder<LOrt>(repo.entityManager("land"), LOrt.class);
+        builder.and("probeId", id);
+        Response response = repo.filter(builder.getQuery(), "land");
+        @SuppressWarnings("unchecked")
+        List<LOrt> orte = (List<LOrt>)response.getData();
+        for (LOrt ort: orte) {
+            if (ort.getOrtsTyp().equals("E")) {
+                return null;
+            }
+        }
+        Violation violation = new Violation();
+        violation.addWarning("entnahmeOrt", 631);
+        return violation;
+    }
+
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/probe/HasHauptprobenNr.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasHauptprobenNr.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,22 @@
+package de.intevation.lada.validation.rules.probe;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class HasHauptprobenNr implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        if (probe.getHauptprobenNr() == null ||
+            probe.getHauptprobenNr().equals("")) {
+            Violation violation = new Violation();
+            violation.addError("hauptprobenNr", 631);
+            return violation;
+        }
+        return null;
+    }
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,25 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.sql.Timestamp;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class HasProbenahmeBegin implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        Timestamp begin = probe.getProbeentnahmeBeginn();
+        if (begin == null) {
+            Violation violation = new Violation();
+            violation.addWarning("probeentnahmeBegin", 631);
+            return violation;
+        }
+        return null;
+    }
+
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/probe/HasUmwelt.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasUmwelt.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,22 @@
+package de.intevation.lada.validation.rules.probe;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class HasUmwelt implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        if (probe.getUmwId() == null ||
+            probe.getUmwId().equals("")) {
+            Violation violation = new Violation();
+            violation.addWarning("uwb", 631);
+            return violation;
+        }
+        return null;
+    }
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/probe/TimeProbeentnahmeBegin.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/TimeProbeentnahmeBegin.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,42 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.sql.Timestamp;
+import java.util.Date;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class TimeProbeentnahmeBegin implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        Timestamp begin = probe.getProbeentnahmeBeginn();
+        Timestamp end = probe.getProbeentnahmeEnde();
+        if (begin == null && end == null) {
+            return null;
+        }
+        if (begin == null && end != null) {
+            Violation violation = new Violation();
+            violation.addWarning("probeentnahmeBegin", 662);
+            return violation;
+        }
+        if (begin.after(new Date())) {
+            Violation violation = new Violation();
+            violation.addWarning("probeentnahmeBegin", 661);
+            return violation;
+        }
+        if (end == null) {
+            return null;
+        }
+        if (begin.after(end)) {
+            Violation violation = new Violation();
+            violation.addWarning("probeentnahmeBegin", 662);
+            return violation;
+        }
+        return null;
+    }
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,46 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.util.rest.Response;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class UniqueHauptprobenNr implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repo;
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        QueryBuilder<LProbe> builder = new QueryBuilder<LProbe>(
+            repo.entityManager("land"),
+            LProbe.class);
+        builder.and("hauptprobenNr", probe.getHauptprobenNr());
+        Response response = repo.filter(builder.getQuery(), "land");
+        if (!((List<LProbe>)response.getData()).isEmpty()) {
+            LProbe found = ((List<LProbe>)response.getData()).get(0);
+            // The probe found in the db equals the new probe. (Update)
+            if (probe.getId() != null && probe.getId() == found.getId()) {
+                return null;
+            }
+            Violation violation = new Violation();
+            violation.addError("hauptprobenNr", 611);
+            return violation;
+        }
+        return null;
+    }
+
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/test/java/de/intevation/lada/LadaStammTest.java
--- a/src/test/java/de/intevation/lada/LadaStammTest.java	Fri Mar 13 09:58:41 2015 +0100
+++ b/src/test/java/de/intevation/lada/LadaStammTest.java	Fri Mar 13 14:26:52 2015 +0100
@@ -29,7 +29,6 @@
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.MethodSorters;
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/test/java/de/intevation/lada/LadaValidatorTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/LadaValidatorTest.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,138 @@
+package de.intevation.lada;
+
+import java.util.ArrayList;
+
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.jboss.arquillian.junit.Arquillian;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import de.intevation.lada.test.validator.Probe;
+import de.intevation.lada.validation.Validator;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+
+ at RunWith(Arquillian.class)
+public class LadaValidatorTest extends BaseTest {
+
+    private static Logger logger = Logger.getLogger(LadaStammTest.class);
+
+    @Inject
+    @ValidationConfig(type="Probe")
+    private Validator probeValidator;
+    private Probe probeTest;
+
+    public LadaValidatorTest() {
+        probeTest = new Probe();
+        testProtocol = new ArrayList<Protocol>();
+    }
+
+    @BeforeClass
+    public static void beforeTests() {
+        logger.info("---------- Testing Lada Validator ----------");
+    }
+
+    @Test
+    public final void probeHasHauptprobenNr() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasHauptprobenNr(testProtocol);
+    }
+
+    @Test
+    public final void probeHasNoHauptprobenNr() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasNoHauptprobenNr(testProtocol);
+    }
+
+    @Test
+    public final void probeExistingHauptprobenNrNew() {
+        probeTest.setValidator(probeValidator);
+        probeTest.existingHauptprobenNrNew(testProtocol);
+    }
+
+    @Test
+    public final void probeUniqueHauptprobenNrNew() {
+        probeTest.setValidator(probeValidator);
+        probeTest.uniqueHauptprobenNrNew(testProtocol);
+    }
+
+    @Test
+    public final void probeExistingHauptprobenNrUpdate() {
+        probeTest.setValidator(probeValidator);
+        probeTest.existingHauptprobenNrUpdate(testProtocol);
+    }
+
+    @Test
+    public final void probeUniqueHauptprobenNrUpdate() {
+        probeTest.setValidator(probeValidator);
+        probeTest.uniqueHauptprobenNrUpdate(testProtocol);
+    }
+
+    @Test
+    public final void probeHasEntnahmeOrt() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasEntnahmeOrt(testProtocol);
+    }
+
+    @Test
+    public final void probeHasNoEntnahmeOrt() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasNoEntnahmeOrt(testProtocol);
+    }
+
+    @Test
+    public final void probeHasProbenahmeBegin() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasProbeentnahmeBegin(testProtocol);
+    }
+
+    @Test
+    public final void probeHasNoProbenahmeBegin() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasNoProbeentnahmeBegin(testProtocol);
+    }
+
+    @Test
+    public final void probeTimeNoEndProbenahmeBegin() {
+        probeTest.setValidator(probeValidator);
+        probeTest.timeNoEndProbeentnahmeBegin(testProtocol);
+    }
+
+    @Test
+    public final void probeTimeNoBeginProbenahmeBegin() {
+        probeTest.setValidator(probeValidator);
+        probeTest.timeNoBeginProbeentnahmeBegin(testProtocol);
+    }
+
+    @Test
+    public final void probeTimeBeginAfterEndProbenahmeBegin() {
+        probeTest.setValidator(probeValidator);
+        probeTest.timeBeginAfterEndProbeentnahmeBegin(testProtocol);
+    }
+
+    @Test
+    public final void probeTimeBeginFutureProbenahmeBegin() {
+        probeTest.setValidator(probeValidator);
+        probeTest.timeBeginFutureProbeentnahmeBegin(testProtocol);
+    }
+
+    @Test
+    public final void probeHasUmwelt() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasUmwelt(testProtocol);
+    }
+
+    @Test
+    public final void probeHasNoUmwelt() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasNoUmwelt(testProtocol);
+    }
+
+    @Test
+    public final void probeHasEmptyUmwelt() {
+        probeTest.setValidator(probeValidator);
+        probeTest.hasEmptyUmwelt(testProtocol);
+    }
+}
diff -r 28fd6616e0f8 -r 2b7c7f3e51b7 src/test/java/de/intevation/lada/test/validator/Probe.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/test/validator/Probe.java	Fri Mar 13 14:26:52 2015 +0100
@@ -0,0 +1,279 @@
+package de.intevation.lada.test.validator;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+import org.junit.Assert;
+
+import de.intevation.lada.Protocol;
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Validator;
+import de.intevation.lada.validation.Violation;
+
+public class Probe {
+
+    private Validator validator;
+
+    public void setValidator(Validator validator) {
+        this.validator = validator;
+    }
+
+    public final void hasHauptprobenNr(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has hauptprobenNr");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setHauptprobenNr("1234567890");
+        Violation violation = validator.validate(probe);
+        if (violation.hasErrors()) {
+            Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
+            prot.setPassed(true);
+            return;
+        }
+        prot.setPassed(true);
+    }
+
+    public final void hasNoHauptprobenNr(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has no hauptprobenNr");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasErrors());
+        Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr"));
+        Assert.assertTrue(violation.getErrors().get("hauptprobenNr").contains(631));
+        prot.setPassed(true);
+    }
+
+    public final void existingHauptprobenNrNew(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("existing hauptprobenNr (new)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setHauptprobenNr("120510002");
+        prot.addInfo("hauptprobenNr", "120510002");
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasErrors());
+        Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr"));
+        Assert.assertTrue(violation.getErrors().get("hauptprobenNr").contains(611));
+        prot.setPassed(true);
+    }
+
+    public final void uniqueHauptprobenNrNew(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("unique hauptprobenNr (new)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setHauptprobenNr("1234567890");
+        prot.addInfo("hauptprobenNr", "1234567890");
+        Violation violation = validator.validate(probe);
+        if (violation.hasErrors()) {
+            Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
+            return;
+        }
+        prot.setPassed(true);
+    }
+
+    public final void uniqueHauptprobenNrUpdate(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("unique hauptprobenNr (update)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setId(1);
+        probe.setHauptprobenNr("1234567890");
+        prot.addInfo("hauptprobenNr", "1234567890");
+        Violation violation = validator.validate(probe);
+        if (violation.hasErrors()) {
+            Assert.assertFalse(violation.getErrors().containsKey("hauptprobenNr"));
+            return;
+        }
+        prot.setPassed(true);
+    }
+
+    public final void existingHauptprobenNrUpdate(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("existing hauptprobenNr (update)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setId(1);
+        probe.setHauptprobenNr("120224003");
+        prot.addInfo("hauptprobenNr", "120224003");
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasErrors());
+        Assert.assertTrue(violation.getErrors().containsKey("hauptprobenNr"));
+        Assert.assertTrue(violation.getErrors().get("hauptprobenNr").contains(611));
+        prot.setPassed(true);
+    }
+
+    public final void hasEntnahmeOrt(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has entnahmeOrt");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setId(1);
+        Violation violation = validator.validate(probe);
+        if (violation.hasWarnings()) {
+            Assert.assertFalse(violation.getWarnings().containsKey("entnahmeOrt"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void hasNoEntnahmeOrt(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has no entnahmeOrt");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setId(710);
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("entnahmeOrt"));
+        Assert.assertTrue(violation.getWarnings().get("entnahmeOrt").contains(631));
+        prot.setPassed(true);
+    }
+
+    public final void hasProbeentnahmeBegin(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has probeentnahmeBegin");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setProbeentnahmeBeginn(new Timestamp(1376287046510l));
+        probe.setProbeentnahmeEnde(new Timestamp(1376287046511l));
+        Violation violation = validator.validate(probe);
+        if (violation.hasWarnings()) {
+            Assert.assertFalse(violation.getWarnings().containsKey("probeentnahmeBegin"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void hasNoProbeentnahmeBegin(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has no probeentnahmeBegin");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("probeentnahmeBegin"));
+        Assert.assertTrue(violation.getWarnings().get("probeentnahmeBegin").contains(631));
+        prot.setPassed(true);
+    }
+
+    public final void timeNoEndProbeentnahmeBegin(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("time no end probeentnahmeBegin");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setProbeentnahmeBeginn(new Timestamp(1376287046510l));
+        Violation violation = validator.validate(probe);
+        if (violation.hasWarnings()) {
+            Assert.assertFalse(violation.getWarnings().containsKey("probeentnahmeBegin"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void timeNoBeginProbeentnahmeBegin(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("time no begin probeentnahmeBegin");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setProbeentnahmeEnde(new Timestamp(1376287046510l));
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.getWarnings().get("probeentnahmeBegin").contains(631));
+        Assert.assertTrue(violation.getWarnings().get("probeentnahmeBegin").contains(662));
+        prot.setPassed(true);
+    }
+
+    public final void timeBeginAfterEndProbeentnahmeBegin(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("time begin after end probeentnahmeBegin");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setProbeentnahmeBeginn(new Timestamp(1376287046511l));
+        probe.setProbeentnahmeEnde(new Timestamp(1376287046510l));
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.getWarnings().get("probeentnahmeBegin").contains(662));
+        prot.setPassed(true);
+    }
+
+    public final void timeBeginFutureProbeentnahmeBegin(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("time begin in future probeentnahmeBegin");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setProbeentnahmeBeginn(new Timestamp(2376287046511l));
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.getWarnings().get("probeentnahmeBegin").contains(661));
+        prot.setPassed(true);
+    }
+
+    public final void hasUmwelt(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has Umwelt");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setUmwId("A4");
+        Violation violation = validator.validate(probe);
+        if (violation.hasWarnings()) {
+            Assert.assertFalse(violation.getWarnings().containsKey("uwb"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void hasNoUmwelt(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has no Umwelt");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("uwb"));
+        Assert.assertTrue(violation.getWarnings().get("uwb").contains(631));
+        prot.setPassed(true);
+    }
+
+    public final void hasEmptyUmwelt(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("ProbeValidator");
+        prot.setType("has empty Umwelt");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LProbe probe = new LProbe();
+        probe.setUmwId("");
+        Violation violation = validator.validate(probe);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("uwb"));
+        Assert.assertTrue(violation.getWarnings().get("uwb").contains(631));
+        prot.setPassed(true);
+    }
+}


More information about the Lada-commits mailing list