Mercurial > lada > lada-server
changeset 840:2fe625c91ab3
Merged branches.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 21 Jan 2016 09:01:57 +0100 |
parents | 9dd9a3de7a61 (current diff) 2203e5d76071 (diff) |
children | bd51cb7b8d20 |
files | .hgignore src/main/java/de/intevation/lada/rest/KommentarMService.java src/main/java/de/intevation/lada/rest/MessprogrammService.java src/main/java/de/intevation/lada/rest/MesswertService.java src/main/java/de/intevation/lada/rest/ProbeService.java src/main/java/de/intevation/lada/rest/StatusService.java src/main/java/de/intevation/lada/util/auth/BaseAuthorizer.java src/main/java/de/intevation/lada/util/auth/HeaderAuthorization.java src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java src/main/java/de/intevation/lada/util/auth/TestAuthorization.java src/test/java/de/intevation/lada/test/ServiceTest.java |
diffstat | 12 files changed, 229 insertions(+), 151 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Jan 08 12:20:31 2016 +0100 +++ b/.hgignore Thu Jan 21 09:01:57 2016 +0100 @@ -8,6 +8,8 @@ .factorypath .gitignore .project +*.swp +*.swo *~ # intellij support - ignore *.iml, .idea @@ -18,4 +20,3 @@ syntax: regexp ^target/ ^.settings -
--- a/src/main/java/de/intevation/lada/rest/KommentarMService.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/KommentarMService.java Thu Jan 21 09:01:57 2016 +0100 @@ -87,12 +87,14 @@ /** * Get all KommentarM objects. * <p> - * The requested objects can be filtered using a URL parameter named + * The requested objects have to be filtered using an URL parameter named * messungsId. * <p> * Example: http://example.com/mkommentar?messungsId=[ID] * - * @return Response object containing all (filtered) KommentarM objects. + * @return Response object containing filtered KommentarM objects. + * Status-Code 699 if parameter is missing or requested objects are + * not authorized. */ @GET @Path("/")
--- a/src/main/java/de/intevation/lada/rest/MessprogrammService.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MessprogrammService.java Thu Jan 21 09:01:57 2016 +0100 @@ -326,7 +326,9 @@ return new Response(false, 699, null); } messprogramm.setLetzteAenderung(new Timestamp(new Date().getTime())); - messprogramm = factory.findUmweltId(messprogramm); + if (messprogramm.getUmwId() == null || messprogramm.getUmwId().equals("")) { + messprogramm = factory.findUmweltId(messprogramm); + } Response response = defaultRepo.update(messprogramm, "land"); Response updated = defaultRepo.getById( Messprogramm.class,
--- a/src/main/java/de/intevation/lada/rest/MesswertService.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/MesswertService.java Thu Jan 21 09:01:57 2016 +0100 @@ -122,12 +122,14 @@ /** * Get all Messwert objects. * <p> - * The requested objects can be filtered using a URL parameter named - * probeId. + * The requested objects have to be filtered using an URL parameter named + * messungsId. * <p> * Example: http://example.com/messwert?messungsId=[ID] * - * @return Response object containing all Messwert objects. + * @return Response object containing filtered Messwert objects. + * Status-Code 699 if parameter is missing or requested objects are + * not authorized. */ @GET @Path("/")
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/ProbeService.java Thu Jan 21 09:01:57 2016 +0100 @@ -450,7 +450,9 @@ if (lock.isLocked(probe)) { return new Response(false, 697, null); } - probe = factory.findMediaDesk(probe); + if (probe.getMediaDesk() == null || probe.getMediaDesk() == "") { + probe = factory.findMediaDesk(probe); + } Violation violation = validator.validate(probe); if (violation.hasErrors()) { Response response = new Response(false, 604, null); @@ -458,7 +460,9 @@ response.setWarnings(violation.getWarnings()); return response; } - factory.findUmweltId(probe); + if (probe.getUmwId() == null || probe.getUmwId() == "") { + factory.findUmweltId(probe); + } probe.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(probe, "land"); Response updated = defaultRepo.getById(
--- a/src/main/java/de/intevation/lada/rest/StatusService.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/StatusService.java Thu Jan 21 09:01:57 2016 +0100 @@ -7,6 +7,8 @@ */ package de.intevation.lada.rest; +import java.sql.Timestamp; +import java.util.Date; import java.util.List; import javax.enterprise.context.RequestScoped; @@ -31,6 +33,7 @@ import de.intevation.lada.lock.LockType; import de.intevation.lada.lock.ObjectLocker; import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LProbe; import de.intevation.lada.model.land.LStatusProtokoll; import de.intevation.lada.util.annotation.AuthorizationConfig; import de.intevation.lada.util.annotation.RepositoryConfig; @@ -115,12 +118,14 @@ /** * Get all Status objects. * <p> - * The requested objects can be filtered using a URL parameter named + * The requested objects have to be filtered using an URL parameter named * messungsId. * <p> * Example: http://example.com/status?messungsId=[ID] * - * @return Response object containing all Status objects. + * @return Response object containing filtered Status objects. + * Status-Code 699 if parameter is missing or requested objects are + * not authorized. */ @GET @Path("/") @@ -240,27 +245,71 @@ else { LStatusProtokoll currentStatus = defaultRepo.getByIdPlain( LStatusProtokoll.class, messung.getStatus(), "land"); - for (int i = 0; i < userInfo.getFunktionen().size(); i++) { - if (userInfo.getFunktionen().get(i) > currentStatus.getStatusStufe()) { - next = true; - change = false; - break; + + if (currentStatus.getStatusWert() == 4) { + LProbe probe = defaultRepo.getByIdPlain( + LProbe.class, + messung.getProbeId(), + "land"); + if (userInfo.getFunktionenForMst(probe.getMstId()).contains(1) && + probe.getMstId().equals(status.getErzeuger()) + ) { + status.setStatusStufe(1); } - else if (userInfo.getFunktionen().get(i) == currentStatus.getStatusStufe()) { - change = true; + else { + return new Response(false, 699, null); } } - 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); + for (int i = 0; + i < userInfo.getFunktionenForMst(status.getErzeuger()).size(); + i++ + ) { + if (userInfo.getFunktionenForMst( + status.getErzeuger()).get(i) > + currentStatus.getStatusStufe() && + currentStatus.getStatusWert() != 0 + ) { + next = true; + } + else if (userInfo.getFunktionenForMst( + status.getErzeuger()).get(i) == + currentStatus.getStatusStufe() + ) { + change = true; + } + } + if (change && + status.getStatusWert() == 4 && + status.getStatusStufe() > 1 + ) { + status.setStatusStufe(currentStatus.getStatusStufe()); + messung.setFertig(false); + } + else if (change && status.getStatusWert() == 8) { + return authorization.filter( + request, + resetStatus(status, currentStatus, messung), + LStatusProtokoll.class); + } + else if (change && status.getStatusWert() != 0) { + status.setStatusStufe(currentStatus.getStatusStufe()); + if (status.getStatusStufe() == 1) { + messung.setFertig(true); + } + } + else if (next && + (status.getStatusWert() > 0 && + status.getStatusWert() <= 4 || + status.getStatusWert() == 7)) { + status.setStatusStufe(currentStatus.getStatusStufe() + 1); + if (status.getStatusWert() == 4) { + messung.setFertig(false); + } + } + else { + return new Response(false, 699, null); + } } } Violation violation = validator.validate(status); @@ -311,55 +360,7 @@ @Context HttpServletRequest request, LStatusProtokoll status ) { - if (lock.isLocked(status)) { - return new Response(false, 697, 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"); - LStatusProtokoll statusNew = new LStatusProtokoll(); - statusNew.setDatum(status.getDatum()); - statusNew.setErzeuger(status.getErzeuger()); - statusNew.setMessungsId(status.getMessungsId()); - statusNew.setStatusStufe(status.getStatusStufe()); - statusNew.setStatusWert(status.getStatusWert()); - statusNew.setText(status.getText()); - Violation violation = validator.validate(statusNew); - if (violation.hasErrors()) { - Response response = new Response(false, 604, statusNew); - response.setErrors(violation.getErrors()); - response.setWarnings(violation.getWarnings()); - return response; - } - - Response response = defaultRepo.create(statusNew, "land"); - LStatusProtokoll created = (LStatusProtokoll)response.getData(); - if (status.getStatusWert() == 0) { - QueryBuilder<LStatusProtokoll> lastFilter = - new QueryBuilder<LStatusProtokoll>( - defaultRepo.entityManager("land"), - LStatusProtokoll.class); - - lastFilter.and("messungsId", status.getMessungsId()); - lastFilter.orderBy("datum", false); - List<LStatusProtokoll> protos = - defaultRepo.filterPlain(lastFilter.getQuery(), "land"); - messung.setStatus(protos.get(protos.size() - 3).getId()); - } - else { - messung.setStatus(created.getId()); - } - - defaultRepo.update(messung, "land"); - - return authorization.filter( - request, - response, - LStatusProtokoll.class); + return new Response(false, 699, null); } /** @@ -397,4 +398,59 @@ /* Delete the object*/ return defaultRepo.delete(obj, "land"); } + + private Response resetStatus( + LStatusProtokoll status, + LStatusProtokoll currentStatus, + LMessung messung + ) { + // Create a new Status with value = 8. + LStatusProtokoll statusNew = new LStatusProtokoll(); + statusNew.setDatum(new Timestamp(new Date().getTime())); + statusNew.setErzeuger(status.getErzeuger()); + statusNew.setMessungsId(status.getMessungsId()); + statusNew.setStatusStufe(status.getStatusStufe()); + statusNew.setStatusWert(8); + statusNew.setText("Reset"); + + defaultRepo.create(statusNew, "land"); + + Response retValue; + if (currentStatus.getStatusStufe() == 1) { + LStatusProtokoll nV = new LStatusProtokoll(); + nV.setDatum(new Timestamp(new Date().getTime())); + nV.setErzeuger(status.getErzeuger()); + nV.setMessungsId(status.getMessungsId()); + nV.setStatusStufe(1); + nV.setStatusWert(0); + nV.setText(""); + retValue = defaultRepo.create(nV, "land"); + messung.setStatus(((LStatusProtokoll)retValue.getData()).getId()); + messung.setFertig(false); + } + else { + QueryBuilder<LStatusProtokoll> lastFilter = + new QueryBuilder<LStatusProtokoll>( + defaultRepo.entityManager("land"), + LStatusProtokoll.class); + lastFilter.and("messungsId", status.getMessungsId()); + lastFilter.and("statusStufe", status.getStatusStufe() - 1); + lastFilter.orderBy("datum", true); + List<LStatusProtokoll> proto = + defaultRepo.filterPlain(lastFilter.getQuery(), "land"); + LStatusProtokoll copy = new LStatusProtokoll(); + LStatusProtokoll orig = proto.get(proto.size() - 1); + copy.setDatum(new Timestamp(new Date().getTime())); + copy.setErzeuger(orig.getErzeuger()); + copy.setMessungsId(orig.getMessungsId()); + copy.setStatusStufe(orig.getStatusStufe()); + copy.setStatusWert(orig.getStatusWert()); + copy.setText(orig.getText()); + retValue = defaultRepo.create(copy, "land"); + LStatusProtokoll createdCopy = (LStatusProtokoll)retValue.getData(); + messung.setStatus(createdCopy.getId()); + } + defaultRepo.update(messung, "land"); + return retValue; + } }
--- a/src/main/java/de/intevation/lada/util/auth/BaseAuthorizer.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/BaseAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -56,7 +56,7 @@ List<LMessung> messungen = (List<LMessung>) response.getData(); for (int i = 0; i < messungen.size(); i++) { if (messungen.get(i).getStatus() == null) { - return false; + continue; } LStatusProtokoll status = repository.getByIdPlain( LStatusProtokoll.class, messungen.get(i).getStatus(), "land");
--- a/src/main/java/de/intevation/lada/util/auth/HeaderAuthorization.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/HeaderAuthorization.java Thu Jan 21 09:01:57 2016 +0100 @@ -92,9 +92,7 @@ HttpServletRequest request = (HttpServletRequest)source; String roleString = request.getAttribute("lada.user.roles").toString(); - String[] roles = roleString.split(","); UserInfo info = getGroupsFromDB(roleString); - info.setRoles(new ArrayList<String>(Arrays.asList(roles))); info.setName(request.getAttribute("lada.user.name").toString()); return info; } @@ -170,27 +168,8 @@ Response response = repository.filter(builder.getQuery(), "stamm"); @SuppressWarnings("unchecked") List<Auth> auth = (List<Auth>)response.getData(); - List<String> netzbetreiber = new ArrayList<String>(); - List<String> messstellen = new ArrayList<String>(); - List<Integer> funktionen = new ArrayList<Integer>(); - for (Auth a : auth) { - if (a.getNetzbetreiberId() != null) { - netzbetreiber.add(a.getNetzbetreiberId()); - } - if (a.getMstId() != null) { - messstellen.add(a.getMstId()); - } - if (a.getLaborMstId() != null) { - messstellen.add(a.getLaborMstId()); - } - if (a.getFunktionId() != null) { - funktionen.add(a.getFunktionId()); - } - } UserInfo userInfo = new UserInfo(); - userInfo.setNetzbetreiber(netzbetreiber); - userInfo.setMessstellen(messstellen); - userInfo.setFunktionen(funktionen); + userInfo.setAuth(auth); return userInfo; } @@ -213,7 +192,7 @@ List<LMessung> messungen = (List<LMessung>) response.getData(); for (int i = 0; i < messungen.size(); i++) { if (messungen.get(i).getStatus() == null) { - return false; + continue; } LStatusProtokoll status = repository.getByIdPlain( LStatusProtokoll.class, messungen.get(i).getStatus(), "land");
--- a/src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/ProbeAuthorizer.java Thu Jan 21 09:01:57 2016 +0100 @@ -17,14 +17,11 @@ Class<T> clazz ) { LProbe probe = (LProbe)data; - if (method == RequestMethod.POST) { - return getAuthorization(userInfo, probe); - } - else if (method == RequestMethod.PUT || - method == RequestMethod.DELETE) { + if (method == RequestMethod.PUT || + method == RequestMethod.DELETE) { return !isProbeReadOnly(probe.getId()); } - return false; + return getAuthorization(userInfo, probe); } @SuppressWarnings("unchecked")
--- a/src/main/java/de/intevation/lada/util/auth/TestAuthorization.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/TestAuthorization.java Thu Jan 21 09:01:57 2016 +0100 @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.List; +import de.intevation.lada.model.stamm.Auth; import de.intevation.lada.util.annotation.AuthorizationConfig; import de.intevation.lada.util.rest.RequestMethod; import de.intevation.lada.util.rest.Response; @@ -21,19 +22,28 @@ public UserInfo getInfo(Object source) { UserInfo info = new UserInfo(); info.setName("testeins"); + List<Auth> auth = new ArrayList<Auth>(); + Auth a1 = new Auth(); + a1.setFunktionId(0); + a1.setLdapGroup("mst_06010"); + a1.setMstId("06010"); + a1.setNetzbetreiberId("06"); + auth.add(a1); + Auth a2 = new Auth(); + a2.setFunktionId(0); + a2.setLdapGroup("mst_11010"); + a2.setNetzbetreiberId("11"); + a2.setMstId("11010"); + auth.add(a2); + Auth a3 = new Auth(); + a3.setLdapGroup("Imis_world"); + a3.setFunktionId(0); + auth.add(a3); List<String> roles = new ArrayList<String>(); roles.add("mst_06010"); roles.add("mst_11010"); roles.add("ImisWorld"); - info.setRoles(roles); - List<String> netz = new ArrayList<String>(); - netz.add("06"); - netz.add("11"); - info.setNetzbetreiber(netz); - List<String> mess = new ArrayList<String>(); - mess.add("06010"); - mess.add("11010"); - info.setMessstellen(mess); + info.setAuth(auth); return info; }
--- a/src/main/java/de/intevation/lada/util/auth/UserInfo.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/UserInfo.java Thu Jan 21 09:01:57 2016 +0100 @@ -10,6 +10,8 @@ import java.util.ArrayList; import java.util.List; +import de.intevation.lada.model.stamm.Auth; + /** * Container for user specific information. * @@ -21,6 +23,7 @@ private List<String> netzbetreiber; private List<String> roles; private List<Integer> funktionen; + private List<Auth> auth; private Integer statusRole; public UserInfo() { @@ -46,49 +49,63 @@ * @return the messstellen */ public List<String> getMessstellen() { - return messstellen; - } - - /** - * @param messstellen the messstellen to set - */ - public void setMessstellen(List<String> messstellen) { - this.messstellen = messstellen; + List<String> ret = new ArrayList<String>(); + for (Auth a : auth) { + if (a.getMstId() != null) { + ret.add(a.getMstId()); + } + } + return ret; } /** * @return the netzbetreiber */ public List<String> getNetzbetreiber() { - return netzbetreiber; - } - - /** - * @param netzbetreiber the netzbetreiber to set - */ - public void setNetzbetreiber(List<String> netzbetreiber) { - this.netzbetreiber = netzbetreiber; + List<String> ret = new ArrayList<String>(); + for (Auth a : auth) { + if (a.getNetzbetreiberId() != null) { + ret.add(a.getNetzbetreiberId()); + } + } + return ret; } - /** - * @return the roles - */ - public List<String> getRoles() { - return roles; - } - - /** - * @param roles the roles to set - */ - public void setRoles(List<String> roles) { - this.roles = roles; + public List<Integer> getFunktionen() { + List<Integer> ret = new ArrayList<Integer>(); + for (Auth a : auth) { + if (a.getFunktionId() != null) { + ret.add(a.getFunktionId()); + } + } + return ret; } /** * @return the funktionen */ - public List<Integer> getFunktionen() { - return this.funktionen; + public List<Integer> getFunktionenForMst(String mstId) { + List<Integer> ret = new ArrayList<Integer>(); + for (Auth a : auth) { + if (a.getMstId() != null && a.getMstId().equals(mstId)) { + ret.add(a.getFunktionId()); + } + } + return ret; + } + + /** + * @return the funktionen + */ + public List<Integer> getFunktionenForNetzbetreiber(String nId) { + List<Integer> ret = new ArrayList<Integer>(); + for (Auth a : auth) { + if (a.getNetzbetreiberId() != null && + a.getNetzbetreiberId().equals(nId)) { + ret.add(a.getFunktionId()); + } + } + return ret; } /** @@ -102,11 +119,14 @@ return retVal; } - /** - * @param funktionen the funktionen to set - */ - public void setFunktionen(List<Integer> funktionen) { - this.funktionen = funktionen; + public List<String> getRoles() { + List<String> ret = new ArrayList<String>(); + for (Auth a : auth) { + if (a.getLdapGroup() != null) { + ret.add(a.getLdapGroup()); + } + } + return ret; } /** @@ -122,4 +142,8 @@ public void setStatusRole(Integer statusRole) { this.statusRole = statusRole; } + + public void setAuth(List<Auth> auth) { + this.auth = auth; + } }
--- a/src/test/java/de/intevation/lada/test/ServiceTest.java Fri Jan 08 12:20:31 2016 +0100 +++ b/src/test/java/de/intevation/lada/test/ServiceTest.java Thu Jan 21 09:01:57 2016 +0100 @@ -236,6 +236,7 @@ .header("X-SHIB-roles", BaseTest.TEST_ROLES) .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON)); String entity = response.readEntity(String.class); + System.out.println(entity); /* Try to parse the response*/ JsonReader fromServiceReader = Json.createReader(new StringReader(entity));