Mercurial > lada > lada-server
changeset 774:2719c9602f2c
Search the next StatusStufe and create a new copy of a Status in on PUT.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 12 Nov 2015 12:17:29 +0100 |
parents | c151b09af33b |
children | 95fa207dbd54 |
files | src/main/java/de/intevation/lada/rest/StatusService.java |
diffstat | 1 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/StatusService.java Thu Nov 12 12:15:18 2015 +0100 +++ b/src/main/java/de/intevation/lada/rest/StatusService.java Thu Nov 12 12:17:29 2015 +0100 @@ -32,6 +32,7 @@ import de.intevation.lada.util.annotation.RepositoryConfig; import de.intevation.lada.util.auth.Authorization; import de.intevation.lada.util.auth.AuthorizationType; +import de.intevation.lada.util.auth.UserInfo; import de.intevation.lada.util.data.QueryBuilder; import de.intevation.lada.util.data.Repository; import de.intevation.lada.util.data.RepositoryType; @@ -192,11 +193,37 @@ ) { return new Response(false, 699, null); } + UserInfo userInfo = authorization.getInfo(request); + LMessung messung = defaultRepo.getByIdPlain( + LMessung.class, status.getMessungsId(), "land"); + LStatusProtokoll currentStatus = defaultRepo.getByIdPlain( + LStatusProtokoll.class, messung.getStatus(), "land"); + boolean next = false; + boolean change = false; + for (int i = 0; i < userInfo.getFunktionen().size(); i++) { + if (userInfo.getFunktionen().get(i) > currentStatus.getStatusStufe()) { + next = true; + change = false; + break; + } + else if (userInfo.getFunktionen().get(i) == currentStatus.getStatusStufe()) { + change = true; + } + } + if ((change || next) && status.getStatusWert() == 4) { + status.setStatusStufe(1); + } + else if (change) { + status.setStatusStufe(currentStatus.getStatusStufe()); + } + else if (next) { + status.setStatusStufe(currentStatus.getStatusStufe() + 1); + } + else { + return new Response(false, 699, null); + } Response response = defaultRepo.create(status, "land"); LStatusProtokoll created = (LStatusProtokoll)response.getData(); - Response messungResponse = defaultRepo.getById( - LMessung.class, status.getMessungsId(), "land"); - LMessung messung = (LMessung)messungResponse.getData(); messung.setStatus(created.getId()); defaultRepo.update(messung, "land"); /* Persist the new object*/ @@ -247,13 +274,24 @@ if (lock.isLocked(status)) { return new Response(false, 697, null); } - Response response = defaultRepo.update(status, "land"); - Response updated = defaultRepo.getById( - LStatusProtokoll.class, - ((LStatusProtokoll)response.getData()).getId(), "land"); + if (status.getStatusWert() == 0) { + return new Response(false, 699, null); + } + + UserInfo userInfo = authorization.getInfo(request); + if (!userInfo.getMessstellen().contains(status.getErzeuger())) { + return new Response(false, 699, null); + } + LMessung messung = defaultRepo.getByIdPlain( + LMessung.class, status.getMessungsId(), "land"); + Response response = defaultRepo.create(status, "land"); + LStatusProtokoll created = (LStatusProtokoll)response.getData(); + messung.setStatus(created.getId()); + defaultRepo.update(messung, "land"); + return authorization.filter( request, - updated, + response, LStatusProtokoll.class); }