changeset 574:b0d674240c29

Merged branch openid back to default.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 19 Mar 2015 14:28:44 +0100
parents 08084d754073 (diff) 0e46adb8fcc5 (current diff)
children 4f83f2fc188a
files src/main/java/de/intevation/lada/rest/ProbeService.java
diffstat 23 files changed, 473 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Fri Mar 13 17:05:27 2015 +0100
+++ b/.hgtags	Thu Mar 19 14:28:44 2015 +0100
@@ -12,3 +12,4 @@
 0bc65c128530cf25f0a751ee416f1b8ff6ab6d8f 1.0
 0bc65c128530cf25f0a751ee416f1b8ff6ab6d8f 1.0
 146b2dfd7ddfad7cf37629d65e738f3246bf0600 1.0
+3d38d1fe9e884113cfbbc453931858e24ff54026 2.0-alpha1
--- a/src/main/java/de/intevation/lada/model/KommentarM.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/model/KommentarM.java	Thu Mar 19 14:28:44 2015 +0100
@@ -27,7 +27,7 @@
     private static final long serialVersionUID = 1L;
 
     @Column(name="messungs_id")
-    private Integer messungId;
+    private Integer messungsId;
 
     private Timestamp datum;
 
@@ -75,11 +75,11 @@
         this.text = text;
     }
 
-    public Integer getMessungId() {
-        return this.messungId;
+    public Integer getMessungsId() {
+        return this.messungsId;
     }
 
-    public void setMessungId(Integer messungId) {
-        this.messungId = messungId;
+    public void setMessungsId(Integer messungsId) {
+        this.messungsId = messungsId;
     }
 }
--- a/src/main/java/de/intevation/lada/model/land/LProbe.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/model/land/LProbe.java	Thu Mar 19 14:28:44 2015 +0100
@@ -131,8 +131,21 @@
     }
 
     public String getProbeIdAlt() {
-        return this.probeTranslation.getProbeIdAlt();
+        if (this.probeTranslation != null) {
+            return this.probeTranslation.getProbeIdAlt();
+        }
+        else {
+            return "";
+        }
     }
 
     public void setProbeIdAlt(String probeIdAlt) {}
+
+    public boolean getIsOwner() {
+        return true; //TODO set a valid value in authorization process.
+    }
+
+    public boolean getReadonly() {
+        return false; //TODO set a valid value in authorization process.
+    }
 }
--- a/src/main/java/de/intevation/lada/rest/KommentarMService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/KommentarMService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -77,15 +77,15 @@
             return new Response(false, 699, null);
         }
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty() || !params.containsKey("messungId")) {
+        if (params.isEmpty() || !params.containsKey("messungsId")) {
             return defaultRepo.getAll(LKommentarM.class, "land");
         }
-        String messungId = params.getFirst("messungId");
+        String messungId = params.getFirst("messungsId");
         QueryBuilder<LKommentarM> builder =
             new QueryBuilder<LKommentarM>(
                 defaultRepo.entityManager("land"),
                 LKommentarM.class);
-        builder.and("messungId", messungId);
+        builder.and("messungsId", messungId);
         return defaultRepo.filter(builder.getQuery(), "land");
     }
 
@@ -131,7 +131,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(
         @Context HttpHeaders headers,
--- a/src/main/java/de/intevation/lada/rest/KommentarPService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/KommentarPService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -131,7 +131,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(@Context HttpHeaders headers, LKommentarP kommentar) {
         if (!authentication.isAuthenticated(headers)) {
--- a/src/main/java/de/intevation/lada/rest/MessungService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/MessungService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -140,7 +140,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(@Context HttpHeaders headers, LMessung messung) {
         if (!authentication.isAuthenticated(headers)) {
--- a/src/main/java/de/intevation/lada/rest/MesswertService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/MesswertService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -77,11 +77,11 @@
             return new Response(false, 699, null);
         }
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty() || !params.containsKey("messungId")) {
+        if (params.isEmpty() || !params.containsKey("messungsId")) {
             logger.debug("get all");
             return defaultRepo.getAll(LMesswert.class, "land");
         }
-        String messungId = params.getFirst("messungId");
+        String messungId = params.getFirst("messungsId");
         QueryBuilder<LMesswert> builder =
             new QueryBuilder<LMesswert>(
                 defaultRepo.entityManager("land"),
@@ -129,7 +129,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(@Context HttpHeaders headers, LMesswert messwert) {
         if (!authentication.isAuthenticated(headers)) {
--- a/src/main/java/de/intevation/lada/rest/OrtService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/OrtService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -129,7 +129,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(@Context HttpHeaders headers, LOrt ort) {
         if (!authentication.isAuthenticated(headers)) {
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/ProbeService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -7,14 +7,18 @@
  */
 package de.intevation.lada.rest;
 
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
+import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonException;
 import javax.json.JsonObject;
+import javax.json.JsonReader;
 import javax.persistence.Query;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -110,12 +114,21 @@
         List<String> results = new ArrayList<String>();
         try {
             sql = jsonQuery.getString("sql");
+            if (params.containsKey("sort")) {
+                String sort = params.getFirst("sort");
+                JsonReader reader = Json.createReader(new StringReader(sort));
+                JsonObject sortProperties = reader.readObject();
+                sql += " ORDER BY ";
+                sql += sortProperties.getJsonString("property") + " ";
+                sql += sortProperties.getJsonString("direction");
+            }
             JsonArray jsonFilters = jsonQuery.getJsonArray("filters");
             JsonArray jsonResults = jsonQuery.getJsonArray("result");
             for (int i = 0; i < jsonFilters.size(); i++) {
                 filters.add(
                     jsonFilters.getJsonObject(i).getString("dataIndex"));
             }
+            results.add("id");
             for (int i = 0; i < jsonResults.size(); i++) {
                 results.add(
                     jsonResults.getJsonObject(i).getString("dataIndex"));
@@ -129,7 +142,15 @@
             filters,
             params,
             defaultRepo.entityManager("land"));
-        return new Response(true, 200, QueryTools.prepareResult(query.getResultList(), results));
+        List<Map<String, Object>> result =
+            QueryTools.prepareResult(query.getResultList(), results);
+        if (params.containsKey("start") && params.containsKey("limit")) {
+            int start = Integer.valueOf(params.getFirst("start"));
+            int limit = Integer.valueOf(params.getFirst("limit"));
+            List<Map<String, Object>> subList = result.subList(start, limit + start);
+            return new Response(true, 200, subList, result.size());
+        }
+        return new Response(true, 200, result, result.size());
     }
 
     /**
@@ -198,7 +219,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(@Context HttpHeaders headers, LProbe probe) {
         if (!authentication.isAuthenticated(headers)) {
@@ -207,7 +228,7 @@
         }
         Violation violation = validator.validate(probe);
         if (violation.hasErrors()) {
-            Response response = new Response(false, 604, probe);
+            Response response = new Response(false, 604, null);
             response.setErrors(violation.getErrors());
             response.setWarnings(violation.getWarnings());
             return response;
--- a/src/main/java/de/intevation/lada/rest/StatusService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/StatusService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -77,10 +77,10 @@
             return new Response(false, 699, null);
         }
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty() || !params.containsKey("messungId")) {
+        if (params.isEmpty() || !params.containsKey("messungsId")) {
             return defaultRepo.getAll(LStatus.class, "land");
         }
-        String messungId = params.getFirst("messungId");
+        String messungId = params.getFirst("messungsId");
         QueryBuilder<LStatus> builder =
             new QueryBuilder<LStatus>(
                 defaultRepo.entityManager("land"),
@@ -128,7 +128,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(@Context HttpHeaders headers, LStatus status) {
         if (!authentication.isAuthenticated(headers)) {
--- a/src/main/java/de/intevation/lada/rest/ZusatzwertService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/ZusatzwertService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -128,7 +128,7 @@
      * @return Response object containing the updated probe object.
      */
     @PUT
-    @Path("/")
+    @Path("/{id}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response update(
         @Context HttpHeaders headers,
--- a/src/main/java/de/intevation/lada/rest/stamm/LocationService.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/LocationService.java	Thu Mar 19 14:28:44 2015 +0100
@@ -19,6 +19,7 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.log4j.Logger;
@@ -31,6 +32,7 @@
 import de.intevation.lada.util.auth.AuthenticationType;
 import de.intevation.lada.util.auth.Authorization;
 import de.intevation.lada.util.auth.AuthorizationType;
+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;
@@ -74,7 +76,17 @@
             logger.debug("User is not authenticated!");
             return new Response(false, 699, null);
         }
-        return defaultRepo.getAll(SOrt.class, "stamm");
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        if (params.isEmpty() || !params.containsKey("ortId")) {
+            return defaultRepo.getAll(SOrt.class, "stamm");
+        }
+        String probeId = params.getFirst("ortId");
+        QueryBuilder<SOrt> builder =
+            new QueryBuilder<SOrt>(
+                defaultRepo.entityManager("land"),
+                SOrt.class);
+        builder.and("probeId", probeId);
+        return defaultRepo.filter(builder.getQuery(), "stamm");
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/MessungValidator.java	Thu Mar 19 14:28:44 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.LMessung;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+@ValidationConfig(type="Messung")
+@ApplicationScoped
+public class MessungValidator implements Validator {
+
+    @Inject
+    @ValidationRule("Messung")
+    private Instance<Rule> rules;
+
+    @Override
+    public Violation validate(Object object) {
+        Violation violations = new Violation();
+        if (!(object instanceof LMessung)) {
+            violations.addError("messung", 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;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasMesswert.java	Thu Mar 19 14:28:44 2015 +0100
@@ -0,0 +1,42 @@
+package de.intevation.lada.validation.rules.messung;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.land.LMesswert;
+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;
+
+@ValidationRule("Messung")
+public class HasMesswert implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repo;
+
+    @Override
+    public Violation execute(Object object) {
+        LMessung messung = (LMessung)object;
+        QueryBuilder<LMesswert> builder =
+            new QueryBuilder<LMesswert>(
+                repo.entityManager("land"), LMesswert.class);
+        builder.and("messungsId", messung.getId());
+        Response response = repo.filter(builder.getQuery(), "land");
+        @SuppressWarnings("unchecked")
+        List<LMesswert> messwerte = (List<LMesswert>)response.getData();
+        if (messwerte == null || messwerte.isEmpty()) {
+            Violation violation = new Violation();
+            violation.addWarning("messwert", 631);
+            return violation;
+        }
+        return null;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasNebenprobenNr.java	Thu Mar 19 14:28:44 2015 +0100
@@ -0,0 +1,23 @@
+package de.intevation.lada.validation.rules.messung;
+
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+@ValidationRule("Messung")
+public class HasNebenprobenNr implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LMessung messung = (LMessung)object;
+        if (messung.getNebenprobenNr() == null ||
+            messung.getNebenprobenNr().equals("")) {
+            Violation violation = new Violation();
+            violation.addWarning("nebenprobenNr", 631);
+            return violation;
+        }
+        return null;
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/UniqueNebenprobenNr.java	Thu Mar 19 14:28:44 2015 +0100
@@ -0,0 +1,47 @@
+package de.intevation.lada.validation.rules.messung;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LMessung;
+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;
+
+@ValidationRule("Messung")
+public class UniqueNebenprobenNr implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repo;
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Violation execute(Object object) {
+        LMessung messung= (LMessung)object;
+        QueryBuilder<LMessung> builder = new QueryBuilder<LMessung>(
+            repo.entityManager("land"),
+            LMessung.class);
+        builder.and("nebenprobenNr", messung.getNebenprobenNr());
+        builder.and("probeId", messung.getProbeId());
+        Response response = repo.filter(builder.getQuery(), "land");
+        if (!((List<LMessung>)response.getData()).isEmpty()) {
+            LMessung found = ((List<LMessung>)response.getData()).get(0);
+            // The messung found in the db equals the new messung. (Update)
+            if (messung.getId() != null && messung.getId() == found.getId()) {
+                return null;
+            }
+            Violation violation = new Violation();
+            violation.addError("nebenprobenNr", 611);
+            return violation;
+        }
+        return null;
+    }
+
+}
--- a/src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java	Thu Mar 19 14:28:44 2015 +0100
@@ -16,7 +16,7 @@
         Timestamp begin = probe.getProbeentnahmeBeginn();
         if (begin == null) {
             Violation violation = new Violation();
-            violation.addWarning("probeentnahmeBegin", 631);
+            violation.addWarning("probeentnahmeBeginn", 631);
             return violation;
         }
         return null;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasTestdatensatz.java	Thu Mar 19 14:28:44 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;
+
+@ValidationRule("Probe")
+public class HasTestdatensatz implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        if (probe.getTest() == null ||
+            probe.getTest().equals("")) {
+            Violation violation = new Violation();
+            violation.addError("test", 631);
+            return violation;
+        }
+        return null;
+    }
+}
--- a/src/main/java/de/intevation/lada/validation/rules/probe/HasUmwelt.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasUmwelt.java	Thu Mar 19 14:28:44 2015 +0100
@@ -14,7 +14,7 @@
         if (probe.getUmwId() == null ||
             probe.getUmwId().equals("")) {
             Violation violation = new Violation();
-            violation.addWarning("uwb", 631);
+            violation.addWarning("umwId", 631);
             return violation;
         }
         return null;
--- a/src/main/java/de/intevation/lada/validation/rules/probe/TimeProbeentnahmeBegin.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/TimeProbeentnahmeBegin.java	Thu Mar 19 14:28:44 2015 +0100
@@ -21,12 +21,12 @@
         }
         if (begin == null && end != null) {
             Violation violation = new Violation();
-            violation.addWarning("probeentnahmeBegin", 662);
+            violation.addWarning("probeentnahmeBeginn", 662);
             return violation;
         }
         if (begin.after(new Date())) {
             Violation violation = new Violation();
-            violation.addWarning("probeentnahmeBegin", 661);
+            violation.addWarning("probeentnahmeBeginn", 661);
             return violation;
         }
         if (end == null) {
@@ -34,7 +34,7 @@
         }
         if (begin.after(end)) {
             Violation violation = new Violation();
-            violation.addWarning("probeentnahmeBegin", 662);
+            violation.addWarning("probeentnahmeBeginn", 662);
             return violation;
         }
         return null;
--- a/src/main/resources/queryconf.json	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/main/resources/queryconf.json	Thu Mar 19 14:28:44 2015 +0100
@@ -2,7 +2,7 @@
 {   "id": "1",
     "name": "Kein Filter",
     "description": "Abfrage der Proben ohne Filter",
-    "sql": "select pt.probe_id_alt, mst_id, umw_id from probe join probe_translation pt on probe.id = pt.probe_id",
+    "sql": "select p.id, pt.probe_id_alt, p.mst_id, p.umw_id from probe p join probe_translation pt on p.id = pt.probe_id",
     "result": [
         {"dataIndex": "probeId", "header": "ProbeId", "width": 100},
         {"dataIndex": "mstId", "header": "MST", "width": 100},
@@ -14,7 +14,7 @@
 {   "id": "2",
     "name": "MST und UMW",
     "description": "Abfrage der Proben gefiltert nach Messtellen ID und ID des Umweltbereichs",
-    "sql": "select pt.probe_id_alt, p.mst_id, p.umw_id from probe p join probe_translation pt on p.id = pt.probe_id where (p.mst_id = :mst_id OR '' = :mst_id) and (p.umw_id = :umw_id OR '' = :umw_id)",
+    "sql": "select p.id as id, pt.probe_id_alt as probeId, p.mst_id as mstId, p.umw_id as umwId from probe p join probe_translation pt on p.id = pt.probe_id where (p.mst_id = :mst_id OR '' = :mst_id) and (p.umw_id = :umw_id OR '' = :umw_id)",
     "result": [
         {"dataIndex": "probeId", "header": "ProbeId", "width": 100},
         {"dataIndex": "mstId", "header": "MST", "width": 100},
--- a/src/test/java/de/intevation/lada/LadaValidatorTest.java	Fri Mar 13 17:05:27 2015 +0100
+++ b/src/test/java/de/intevation/lada/LadaValidatorTest.java	Thu Mar 19 14:28:44 2015 +0100
@@ -10,6 +10,7 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import de.intevation.lada.test.validator.Messung;
 import de.intevation.lada.test.validator.Probe;
 import de.intevation.lada.validation.Validator;
 import de.intevation.lada.validation.annotation.ValidationConfig;
@@ -24,8 +25,14 @@
     private Validator probeValidator;
     private Probe probeTest;
 
+    @Inject
+    @ValidationConfig(type="Messung")
+    private Validator messungValidator;
+    private Messung messungTest;
+
     public LadaValidatorTest() {
         probeTest = new Probe();
+        messungTest = new Messung();
         testProtocol = new ArrayList<Protocol>();
     }
 
@@ -135,4 +142,58 @@
         probeTest.setValidator(probeValidator);
         probeTest.hasEmptyUmwelt(testProtocol);
     }
+
+    @Test
+    public final void messungHasNebenprobenNr() {
+        messungTest.setValidator(messungValidator);
+        messungTest.hasNebenprobenNr(testProtocol);
+    }
+
+    @Test
+    public final void messungHasNoNebenprobenNr() {
+        messungTest.setValidator(messungValidator);
+        messungTest.hasNoNebenprobenNr(testProtocol);
+    }
+
+    @Test
+    public final void messungHasEmptyNebenprobenNr() {
+        messungTest.setValidator(messungValidator);
+        messungTest.hasEmptyNebenprobenNr(testProtocol);
+    }
+
+    @Test
+    public final void messungUniqueNebenprobenNrNew() {
+        messungTest.setValidator(messungValidator);
+        messungTest.uniqueNebenprobenNrNew(testProtocol);
+    }
+
+    @Test
+    public final void messungUniqueNebenprobenNrUpdate() {
+        messungTest.setValidator(messungValidator);
+        messungTest.uniqueNebenprobenNrUpdate(testProtocol);
+    }
+
+    @Test
+    public final void messungExistingNebenprobenNrNew() {
+        messungTest.setValidator(messungValidator);
+        messungTest.existingNebenprobenNrNew(testProtocol);
+    }
+
+    @Test
+    public final void messungExistingNebenprobenNrUpdate() {
+        messungTest.setValidator(messungValidator);
+        messungTest.existingHauptprobenNrUpdate(testProtocol);
+    }
+
+    @Test
+    public final void messungHasMesswert() {
+        messungTest.setValidator(messungValidator);
+        messungTest.hasMesswert(testProtocol);
+    }
+
+    @Test
+    public final void messungHasNoMesswert() {
+        messungTest.setValidator(messungValidator);
+        messungTest.hasNoMesswert(testProtocol);
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/test/validator/Messung.java	Thu Mar 19 14:28:44 2015 +0100
@@ -0,0 +1,160 @@
+package de.intevation.lada.test.validator;
+
+import java.util.List;
+
+import org.junit.Assert;
+
+import de.intevation.lada.Protocol;
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.validation.Validator;
+import de.intevation.lada.validation.Violation;
+
+public class Messung {
+
+    private Validator validator;
+
+    public void setValidator(Validator validator) {
+        this.validator = validator;
+    }
+
+    public final void hasNebenprobenNr(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("has nebenprobenNr");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setNebenprobenNr("10R1");
+        Violation violation = validator.validate(messung);
+        if (violation.hasWarnings()) {
+            Assert.assertFalse(violation.getWarnings().containsKey("nebenprobenNr"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void hasNoNebenprobenNr(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("has no nebenprobenNr");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        Violation violation = validator.validate(messung);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("nebenprobenNr"));
+        Assert.assertTrue(violation.getWarnings().get("nebenprobenNr").contains(631));
+        prot.setPassed(true);
+    }
+
+    public final void hasEmptyNebenprobenNr(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("has empty nebenprobenNr");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setNebenprobenNr("");
+        Violation violation = validator.validate(messung);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("nebenprobenNr"));
+        Assert.assertTrue(violation.getWarnings().get("nebenprobenNr").contains(631));
+        prot.setPassed(true);
+    }
+
+    public final void existingNebenprobenNrNew(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("existing nebenprobenNr (new)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setNebenprobenNr("00G1");
+        messung.setProbeId(4);
+        Violation violation = validator.validate(messung);
+        Assert.assertTrue(violation.hasErrors());
+        Assert.assertTrue(violation.getErrors().containsKey("nebenprobenNr"));
+        Assert.assertTrue(violation.getErrors().get("nebenprobenNr").contains(611));
+        prot.setPassed(true);
+    }
+
+    public final void uniqueNebenprobenNrNew(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("unique nebenprobenNr (new)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setNebenprobenNr("00G2");
+        messung.setProbeId(4);
+        Violation violation = validator.validate(messung);
+        if (violation.hasErrors()) {
+            Assert.assertFalse(violation.getErrors().containsKey("nebenprobenNr"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void uniqueNebenprobenNrUpdate(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("unique nebenprobenNr (update)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setId(45);
+        messung.setProbeId(4);
+        messung.setNebenprobenNr("00G2");
+        Violation violation = validator.validate(messung);
+        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("MessungValidator");
+        prot.setType("existing nebenprobenNr (update)");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setId(776);
+        messung.setProbeId(1);
+        messung.setNebenprobenNr("0003");
+        Violation violation = validator.validate(messung);
+        Assert.assertTrue(violation.hasErrors());
+        Assert.assertTrue(violation.getErrors().containsKey("nebenprobenNr"));
+        Assert.assertTrue(violation.getErrors().get("nebenprobenNr").contains(611));
+        prot.setPassed(true);
+    }
+
+    public final void hasMesswert(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("has messwert");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setId(1);
+        Violation violation = validator.validate(messung);
+        if (violation.hasWarnings()) {
+            Assert.assertFalse(violation.getWarnings().containsKey("messwert"));
+        }
+        prot.setPassed(true);
+    }
+
+    public final void hasNoMesswert(List<Protocol> protocol) {
+        Protocol prot = new Protocol();
+        prot.setName("MessungValidator");
+        prot.setType("has no messwert");
+        prot.setPassed(false);
+        protocol.add(prot);
+        LMessung messung = new LMessung();
+        messung.setId(990);
+        Violation violation = validator.validate(messung);
+        Assert.assertTrue(violation.hasWarnings());
+        Assert.assertTrue(violation.getWarnings().containsKey("messwert"));
+        Assert.assertTrue(violation.getWarnings().get("messwert").contains(631));
+        prot.setPassed(true);
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)