Mercurial > lada > lada-server
changeset 1114:ccd077c29f72
Replace code duplicating validation rule with validation.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 27 Oct 2016 19:20:28 +0200 |
parents | 628e0da7435a |
children | 2f42a7607bbd |
files | src/main/java/de/intevation/lada/rest/StatusService.java |
diffstat | 1 files changed, 8 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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'