[Lada-commits] [PATCH 1 of 2] Replace code duplicating validation rule with validation

Wald Commits scm-commit at wald.intevation.org
Thu Oct 27 19:33:26 CEST 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1477588828 -7200
# Node ID ccd077c29f721638f10adf5f39102f280e29e1ae
# Parent  628e0da7435a8f8d0be30027d0d7f163060452d9
Replace code duplicating validation rule with validation.

diff -r 628e0da7435a -r ccd077c29f72 src/main/java/de/intevation/lada/rest/StatusService.java
--- a/src/main/java/de/intevation/lada/rest/StatusService.java	Thu Oct 27 15:59:05 2016 +0200
+++ b/src/main/java/de/intevation/lada/rest/StatusService.java	Thu Oct 27 19:20:28 2016 +0200
@@ -247,26 +247,20 @@
             status.setStatusKombi(1);
         }
         else {
+            Violation violation = validator.validate(status);
+            if (violation.hasErrors()) {
+                Response response = new Response(false, 604, status);
+                response.setErrors(violation.getErrors());
+                response.setWarnings(violation.getWarnings());
+                return response;
+            }
+
             StatusProtokoll oldStatus = defaultRepo.getByIdPlain(
                 StatusProtokoll.class, messung.getStatus(), "land");
 
             StatusKombi oldKombi = defaultRepo.getByIdPlain(StatusKombi.class, oldStatus.getStatusKombi(), "stamm");
             StatusKombi newKombi = defaultRepo.getByIdPlain(StatusKombi.class, status.getStatusKombi(), "stamm");
 
-            // Check if changing to the requested status_kombi is allowed.
-            QueryBuilder<StatusReihenfolge> builder = new QueryBuilder<StatusReihenfolge>(defaultRepo.entityManager("stamm"), StatusReihenfolge.class);
-            builder.and("vonId", oldStatus.getStatusKombi());
-            List<StatusReihenfolge> reachable = defaultRepo.filterPlain(builder.getQuery(), "stamm");
-            boolean allowed = false;
-            for (int i = 0; i < reachable.size(); i++) {
-                if (reachable.get(i).getZuId() == status.getStatusKombi()) {
-                    allowed = true;
-                }
-            }
-            if (!allowed) {
-                return new Response(false, 604, null);
-            }
-
             // Check if the user is allowed to change to the requested
             // status_kombi
             // 1. The old 'status_wert' is 'rückfrage'


More information about the Lada-commits mailing list