[Lada-commits] [PATCH 3 of 3] Allow paging for editable stammdaten and set readonly attribute

Wald Commits scm-commit at wald.intevation.org
Thu Jan 21 15:37:02 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1453387026 -3600
# Node ID 670f58112734f7ec46a66d27f3ca3118d2e5f411
# Parent  9f4be0bc724d48d1fba1a9fb3a0b4cbd9399671b
Allow paging for editable stammdaten and set readonly attribute.

diff -r 9f4be0bc724d -r 670f58112734 src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java
--- 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);
     }
 
     /**
diff -r 9f4be0bc724d -r 670f58112734 src/main/java/de/intevation/lada/rest/stamm/MessprogrammKategorieService.java
--- 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);
     }
 
     /**
diff -r 9f4be0bc724d -r 670f58112734 src/main/java/de/intevation/lada/rest/stamm/OrtService.java
--- 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 =
diff -r 9f4be0bc724d -r 670f58112734 src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java
--- 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);
     }
 
     /**


More information about the Lada-commits mailing list