changeset 843:670f58112734

Allow paging for editable stammdaten and set readonly attribute.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 21 Jan 2016 15:37:06 +0100
parents 9f4be0bc724d
children 47dc3c4e42dd
files src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java src/main/java/de/intevation/lada/rest/stamm/OrtService.java src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java
diffstat 4 files changed, 104 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java	Thu Jan 21 15:36:33 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java	Thu Jan 21 15:37:06 2016 +0100
@@ -7,6 +7,8 @@
  */
 package de.intevation.lada.rest.stamm;
 
+import java.util.List;
+
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
@@ -20,6 +22,7 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
 import de.intevation.lada.model.stamm.DatensatzErzeuger;
@@ -86,10 +89,32 @@
     @Path("/")
     @Produces(MediaType.APPLICATION_JSON)
     public Response get(
-        @Context HttpHeaders headers,
+        @Context HttpServletRequest request,
         @Context UriInfo info
     ) {
-        return repository.getAll(DatensatzErzeuger.class, "stamm");
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        List<DatensatzErzeuger> erzeuger =
+            repository.getAllPlain(DatensatzErzeuger.class, "stamm");
+        int size = erzeuger.size();
+        if (params.containsKey("start") && params.containsKey("limit")) {
+            int start = Integer.valueOf(params.getFirst("start"));
+            int limit = Integer.valueOf(params.getFirst("limit"));
+            int end = limit + start;
+            if (start + limit > erzeuger.size()) {
+                end = erzeuger.size();
+            }
+            erzeuger = erzeuger.subList(start, end);
+        }
+
+        for (DatensatzErzeuger erz : erzeuger) {
+            erz.setReadonly(
+                !authorization.isAuthorized(
+                    request,
+                    erz,
+                    RequestMethod.POST,
+                    DatensatzErzeuger.class));
+        }
+        return new Response (true, 200, erzeuger, size);
     }
 
     /**
--- a/src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java	Thu Jan 21 15:36:33 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java	Thu Jan 21 15:37:06 2016 +0100
@@ -7,6 +7,8 @@
  */
 package de.intevation.lada.rest.stamm;
 
+import java.util.List;
+
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
@@ -20,9 +22,9 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
-import de.intevation.lada.model.stamm.DatensatzErzeuger;
 import de.intevation.lada.model.stamm.MessprogrammKategorie;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -87,10 +89,32 @@
     @Path("/")
     @Produces(MediaType.APPLICATION_JSON)
     public Response get(
-        @Context HttpHeaders headers,
+        @Context HttpServletRequest request,
         @Context UriInfo info
     ) {
-        return repository.getAll(MessprogrammKategorie.class, "stamm");
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        List<MessprogrammKategorie> kategorie =
+            repository.getAllPlain(MessprogrammKategorie.class, "stamm");
+        int size = kategorie.size();
+        if (params.containsKey("start") && params.containsKey("limit")) {
+            int start = Integer.valueOf(params.getFirst("start"));
+            int limit = Integer.valueOf(params.getFirst("limit"));
+            int end = limit + start;
+            if (start + limit > kategorie.size()) {
+                end = kategorie.size();
+            }
+            kategorie = kategorie.subList(start, end);
+        }
+
+        for (MessprogrammKategorie mk : kategorie) {
+            mk.setReadonly(
+                !authorization.isAuthorized(
+                    request,
+                    mk,
+                    RequestMethod.POST,
+                    MessprogrammKategorie.class));
+        }
+        return new Response(true, 200, kategorie, size);
     }
 
     /**
--- a/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Thu Jan 21 15:36:33 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Thu Jan 21 15:37:06 2016 +0100
@@ -7,6 +7,8 @@
  */
 package de.intevation.lada.rest.stamm;
 
+import java.util.List;
+
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
@@ -101,12 +103,31 @@
     @Path("/")
     @Produces(MediaType.APPLICATION_JSON)
     public Response get(
-        @Context HttpHeaders headers,
+        @Context HttpServletRequest request,
         @Context UriInfo info
     ) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
         if (params.isEmpty() || !params.containsKey("ortId")) {
-            return defaultRepo.getAll(Ort.class, "stamm");
+            List<Ort> orte = defaultRepo.getAllPlain(Ort.class, "stamm");
+            int size = orte.size();
+            if (params.containsKey("start") && params.containsKey("limit")) {
+                int start = Integer.valueOf(params.getFirst("start"));
+                int limit = Integer.valueOf(params.getFirst("limit"));
+                int end = limit + start;
+                if (start + limit > orte.size()) {
+                    end = orte.size();
+                }
+                orte = orte.subList(start, end);
+            }
+            for (Ort o : orte) {
+                o.setReadonly(
+                    !authorization.isAuthorized(
+                        request,
+                        o,
+                        RequestMethod.POST,
+                        Ort.class));
+            }
+            return new Response(true, 200, orte, size);
         }
         String ortId = params.getFirst("ortId");
         QueryBuilder<Ort> builder =
--- a/src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java	Thu Jan 21 15:36:33 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java	Thu Jan 21 15:37:06 2016 +0100
@@ -7,6 +7,8 @@
  */
 package de.intevation.lada.rest.stamm;
 
+import java.util.List;
+
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.servlet.http.HttpServletRequest;
@@ -20,9 +22,9 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
-import de.intevation.lada.model.stamm.DatensatzErzeuger;
 import de.intevation.lada.model.stamm.Probenehmer;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -84,10 +86,32 @@
     @Path("/")
     @Produces(MediaType.APPLICATION_JSON)
     public Response get(
-        @Context HttpHeaders headers,
+        @Context HttpServletRequest request,
         @Context UriInfo info
     ) {
-        return repository.getAll(Probenehmer.class, "stamm");
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        List<Probenehmer> nehmer =
+            repository.getAllPlain(Probenehmer.class, "stamm");
+        int size = nehmer.size();
+        if (params.containsKey("start") && params.containsKey("limit")) {
+            int start = Integer.valueOf(params.getFirst("start"));
+            int limit = Integer.valueOf(params.getFirst("limit"));
+            int end = limit + start;
+            if (start + limit > nehmer.size()) {
+                end = nehmer.size();
+            }
+            nehmer = nehmer.subList(start, end);
+        }
+
+        for (Probenehmer p : nehmer) {
+            p.setReadonly(
+                !authorization.isAuthorized(
+                    request,
+                    p,
+                    RequestMethod.POST,
+                    Probenehmer.class));
+        }
+        return new Response(true, 200, nehmer, size);
     }
 
     /**
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)