changeset 773:c151b09af33b

Return only reachable status values.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 12 Nov 2015 12:15:18 +0100
parents 46e0523bbd80
children 2719c9602f2c
files src/main/java/de/intevation/lada/rest/stamm/StatusWertService.java
diffstat 1 files changed, 41 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/StatusWertService.java	Thu Nov 12 12:14:46 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/StatusWertService.java	Thu Nov 12 12:15:18 2015 +0100
@@ -23,12 +23,20 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.log4j.Logger;
+
+import de.intevation.lada.model.bund.StatusProtokoll;
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.stamm.StatusErreichbar;
+import de.intevation.lada.model.stamm.StatusKombi;
+import de.intevation.lada.model.stamm.StatusReihenfolge;
 import de.intevation.lada.model.stamm.StatusWert;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 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;
 import de.intevation.lada.util.rest.Response;
@@ -61,6 +69,8 @@
 @RequestScoped
 public class StatusWertService {
 
+    @Inject
+    private Logger logger = Logger.getLogger(StatusWertService.class);
     /**
      * The data repository granting read access.
      */
@@ -122,8 +132,37 @@
 
     private List<StatusWert> getReachable(int messungsId, UserInfo user) {
         List<StatusWert> list = new ArrayList<StatusWert>();
-        // TODO get reachable status values from db using the current status and
-        // the user info.
+        LMessung messung =
+            defaultRepo.getByIdPlain(LMessung.class, messungsId, "land");
+        StatusProtokoll status = defaultRepo.getByIdPlain(
+            StatusProtokoll.class,
+            messung.getStatus(),
+            "land");
+        boolean allowed = false;
+        for (int i = 0; i < user.getFunktionen().size(); i++) {
+            if (user.getFunktionen().get(i) >= status.getStatusStufe()) {
+                allowed = true;
+                break;
+            }
+        }
+        if (!allowed) {
+            return list;
+        }
+        QueryBuilder<StatusErreichbar> errFilter =
+            new QueryBuilder<StatusErreichbar>(
+                defaultRepo.entityManager("stamm"),
+                StatusErreichbar.class);
+        errFilter.and("curStufe", status.getStatusStufe());
+        errFilter.and("curWert", status.getStatusWert());
+        List<StatusErreichbar> erreichbare = defaultRepo.filterPlain(errFilter.getQuery(), "stamm");
+        QueryBuilder<StatusWert> werteFilter =
+            new QueryBuilder<StatusWert>(
+                defaultRepo.entityManager("stamm"),
+                StatusWert.class);
+        for (int i = 0; i < erreichbare.size(); i++) {
+            werteFilter.or("id", erreichbare.get(i).getWertId());
+        }
+        list = defaultRepo.filterPlain(werteFilter.getQuery(), "stamm");
         return list;
     }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)