changeset 260:0de24f5e7c01

Added boolean parameter to validate method to test if update or create was triggered.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 16 Jul 2013 08:24:34 +0200
parents 9da1ee33b1fa
children 07c4186cbfab
files src/main/java/de/intevation/lada/data/LMessungRepository.java src/main/java/de/intevation/lada/data/LMesswertRepository.java src/main/java/de/intevation/lada/data/LOrtRepository.java src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/validation/LMessungValidator.java src/main/java/de/intevation/lada/validation/LMesswertValidator.java src/main/java/de/intevation/lada/validation/LOrtValidator.java src/main/java/de/intevation/lada/validation/LProbeValidator.java src/main/java/de/intevation/lada/validation/Validator.java
diffstat 9 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LMessungRepository.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LMessungRepository.java	Tue Jul 16 08:24:34 2013 +0200
@@ -108,7 +108,7 @@
         LMessung messung = (LMessung)object;
         Response response = new Response(true, 200, messung);
         try {
-            Map<String, Integer> warnings = validator.validate(messung);
+            Map<String, Integer> warnings = validator.validate(messung, false);
             manager.create(messung);
             response.setWarnings(warnings);
             return response;
@@ -152,7 +152,7 @@
         Response response = new Response(true, 200, messung);
         // Try to save the new LProbe.
         try {
-            Map<String, Integer> warnings = validator.validate(messung);
+            Map<String, Integer> warnings = validator.validate(messung, true);
             manager.update(messung);
             response.setWarnings(warnings);
             return response;
--- a/src/main/java/de/intevation/lada/data/LMesswertRepository.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LMesswertRepository.java	Tue Jul 16 08:24:34 2013 +0200
@@ -107,7 +107,7 @@
         LMesswert messwert = (LMesswert)object;
         Response response = new Response(true, 200, messwert);
         try {
-            Map<String, Integer> warnings = validator.validate(messwert);
+            Map<String, Integer> warnings = validator.validate(messwert, false);
             manager.create(messwert);
             response.setWarnings(warnings);
             return response;
--- a/src/main/java/de/intevation/lada/data/LOrtRepository.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LOrtRepository.java	Tue Jul 16 08:24:34 2013 +0200
@@ -109,7 +109,7 @@
         Response response = new Response(true, 200, ort);
         // Try to save the new LOrt.
         try {
-            Map<String, Integer> warnings = validator.validate(ort);
+            Map<String, Integer> warnings = validator.validate(ort, false);
             manager.create(ort);
             response.setWarnings(warnings);
             return response;
@@ -153,7 +153,7 @@
         Response response = new Response(true, 200, ort);
         // Try to update a LOrt object.
         try {
-            Map<String, Integer> warnings = validator.validate(ort);
+            Map<String, Integer> warnings = validator.validate(ort, true);
             manager.update(ort);
             response.setWarnings(warnings);
             return response;
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Tue Jul 16 08:24:34 2013 +0200
@@ -104,7 +104,7 @@
         Response response = new Response(true, 200, probe);
         // Try to save the new LProbe.
         try {
-            Map<String, Integer> warnings = validator.validate(probe);
+            Map<String, Integer> warnings = validator.validate(probe, false);
             manager.create(probe);
             response.setWarnings(warnings);
             return response;
@@ -147,7 +147,7 @@
         LProbe probe = (LProbe)object;
         Response response = new Response(true, 200, probe);
         try {
-            Map<String, Integer> warnings = validator.validate(probe);
+            Map<String, Integer> warnings = validator.validate(probe, true);
             manager.update(probe);
             response.setWarnings(warnings);
             return response;
--- a/src/main/java/de/intevation/lada/validation/LMessungValidator.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/LMessungValidator.java	Tue Jul 16 08:24:34 2013 +0200
@@ -34,7 +34,7 @@
     private Repository messungRepository;
 
     @Override
-    public Map<String, Integer> validate(Object object)
+    public Map<String, Integer> validate(Object object, boolean update)
     throws ValidationException {
         Map<String, Integer> warnings = new HashMap<String, Integer>();
         if (!(object instanceof LMessung)) {
@@ -44,12 +44,15 @@
         }
         LMessung messung = (LMessung)object;
 
-        validateNebenprobenNr(messung, warnings);
+        validateHasNebenprobenNr(messung, warnings);
         validateDatum(messung, warnings);
+        if (!update) {
+            validateUniqueNebenprobenNr(messung, warnings);
+        }
         return warnings;
     }
 
-    private void validateNebenprobenNr(
+    private void validateHasNebenprobenNr(
         LMessung messung,
         Map<String, Integer> warnings)
     throws ValidationException {
@@ -57,6 +60,12 @@
             messung.getNebenprobenNr().equals("")) {
             warnings.put("nebenprobenNr", 631);
         }
+    }
+
+    private void validateUniqueNebenprobenNr(
+        LMessung messung,
+        Map<String, Integer> warnings)
+    throws ValidationException {
         QueryBuilder<LMessung> builder =
             new QueryBuilder<LMessung>(
                 messungRepository.getEntityManager(),
--- a/src/main/java/de/intevation/lada/validation/LMesswertValidator.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/LMesswertValidator.java	Tue Jul 16 08:24:34 2013 +0200
@@ -15,7 +15,7 @@
 {
 
     @Override
-    public Map<String, Integer> validate(Object object)
+    public Map<String, Integer> validate(Object object, boolean update)
     throws ValidationException {
         Map<String, Integer> warnings = new HashMap<String, Integer>();
         if (!(object instanceof LMesswert)) {
--- a/src/main/java/de/intevation/lada/validation/LOrtValidator.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/LOrtValidator.java	Tue Jul 16 08:24:34 2013 +0200
@@ -15,7 +15,7 @@
 {
 
     @Override
-    public Map<String, Integer> validate(Object object)
+    public Map<String, Integer> validate(Object object, boolean update)
     throws ValidationException {
         Map<String, Integer> warnings = new HashMap<String, Integer>();
         if (!(object instanceof LOrt)) {
--- a/src/main/java/de/intevation/lada/validation/LProbeValidator.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/LProbeValidator.java	Tue Jul 16 08:24:34 2013 +0200
@@ -40,7 +40,7 @@
      * @param probe The LProbe object.
      */
     @Override
-    public Map<String, Integer> validate(Object probe)
+    public Map<String, Integer> validate(Object probe, boolean update)
     throws ValidationException {
         Map<String, Integer>warnings = new HashMap<String, Integer>();
         if (!(probe instanceof LProbe)) {
--- a/src/main/java/de/intevation/lada/validation/Validator.java	Tue Jul 16 08:05:06 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/Validator.java	Tue Jul 16 08:24:34 2013 +0200
@@ -9,5 +9,6 @@
  */
 public interface Validator
 {
-    public Map<String, Integer> validate(Object object) throws ValidationException;
+    public Map<String, Integer> validate(Object object, boolean update)
+    throws ValidationException;
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)