# HG changeset patch # User Raimund Renkert # Date 1373955874 -7200 # Node ID 0de24f5e7c0179961db8d795624aa57b9dd7c42d # Parent 9da1ee33b1fad6d95646902cdac65115c8556955 Added boolean parameter to validate method to test if update or create was triggered. diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/data/LMessungRepository.java --- 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 warnings = validator.validate(messung); + Map 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 warnings = validator.validate(messung); + Map warnings = validator.validate(messung, true); manager.update(messung); response.setWarnings(warnings); return response; diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/data/LMesswertRepository.java --- 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 warnings = validator.validate(messwert); + Map warnings = validator.validate(messwert, false); manager.create(messwert); response.setWarnings(warnings); return response; diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/data/LOrtRepository.java --- 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 warnings = validator.validate(ort); + Map 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 warnings = validator.validate(ort); + Map warnings = validator.validate(ort, true); manager.update(ort); response.setWarnings(warnings); return response; diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/data/LProbeRepository.java --- 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 warnings = validator.validate(probe); + Map 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 warnings = validator.validate(probe); + Map warnings = validator.validate(probe, true); manager.update(probe); response.setWarnings(warnings); return response; diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/validation/LMessungValidator.java --- 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 validate(Object object) + public Map validate(Object object, boolean update) throws ValidationException { Map warnings = new HashMap(); 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 warnings) throws ValidationException { @@ -57,6 +60,12 @@ messung.getNebenprobenNr().equals("")) { warnings.put("nebenprobenNr", 631); } + } + + private void validateUniqueNebenprobenNr( + LMessung messung, + Map warnings) + throws ValidationException { QueryBuilder builder = new QueryBuilder( messungRepository.getEntityManager(), diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/validation/LMesswertValidator.java --- 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 validate(Object object) + public Map validate(Object object, boolean update) throws ValidationException { Map warnings = new HashMap(); if (!(object instanceof LMesswert)) { diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/validation/LOrtValidator.java --- 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 validate(Object object) + public Map validate(Object object, boolean update) throws ValidationException { Map warnings = new HashMap(); if (!(object instanceof LOrt)) { diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/validation/LProbeValidator.java --- 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 validate(Object probe) + public Map validate(Object probe, boolean update) throws ValidationException { Mapwarnings = new HashMap(); if (!(probe instanceof LProbe)) { diff -r 9da1ee33b1fa -r 0de24f5e7c01 src/main/java/de/intevation/lada/validation/Validator.java --- 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 validate(Object object) throws ValidationException; + public Map validate(Object object, boolean update) + throws ValidationException; }