Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/stamm/ProbenehmerService.java @ 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 | 313bd1d227f1 |
children | c2725534f08b |
comparison
equal
deleted
inserted
replaced
842:9f4be0bc724d | 843:670f58112734 |
---|---|
4 * This file is Free Software under the GNU GPL (v>=3) | 4 * This file is Free Software under the GNU GPL (v>=3) |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | 5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
6 * the documentation coming with IMIS-Labordaten-Application for details. | 6 * the documentation coming with IMIS-Labordaten-Application for details. |
7 */ | 7 */ |
8 package de.intevation.lada.rest.stamm; | 8 package de.intevation.lada.rest.stamm; |
9 | |
10 import java.util.List; | |
9 | 11 |
10 import javax.enterprise.context.RequestScoped; | 12 import javax.enterprise.context.RequestScoped; |
11 import javax.inject.Inject; | 13 import javax.inject.Inject; |
12 import javax.servlet.http.HttpServletRequest; | 14 import javax.servlet.http.HttpServletRequest; |
13 import javax.ws.rs.DELETE; | 15 import javax.ws.rs.DELETE; |
18 import javax.ws.rs.PathParam; | 20 import javax.ws.rs.PathParam; |
19 import javax.ws.rs.Produces; | 21 import javax.ws.rs.Produces; |
20 import javax.ws.rs.core.Context; | 22 import javax.ws.rs.core.Context; |
21 import javax.ws.rs.core.HttpHeaders; | 23 import javax.ws.rs.core.HttpHeaders; |
22 import javax.ws.rs.core.MediaType; | 24 import javax.ws.rs.core.MediaType; |
25 import javax.ws.rs.core.MultivaluedMap; | |
23 import javax.ws.rs.core.UriInfo; | 26 import javax.ws.rs.core.UriInfo; |
24 | 27 |
25 import de.intevation.lada.model.stamm.DatensatzErzeuger; | |
26 import de.intevation.lada.model.stamm.Probenehmer; | 28 import de.intevation.lada.model.stamm.Probenehmer; |
27 import de.intevation.lada.util.annotation.AuthorizationConfig; | 29 import de.intevation.lada.util.annotation.AuthorizationConfig; |
28 import de.intevation.lada.util.annotation.RepositoryConfig; | 30 import de.intevation.lada.util.annotation.RepositoryConfig; |
29 import de.intevation.lada.util.auth.Authorization; | 31 import de.intevation.lada.util.auth.Authorization; |
30 import de.intevation.lada.util.auth.AuthorizationType; | 32 import de.intevation.lada.util.auth.AuthorizationType; |
82 */ | 84 */ |
83 @GET | 85 @GET |
84 @Path("/") | 86 @Path("/") |
85 @Produces(MediaType.APPLICATION_JSON) | 87 @Produces(MediaType.APPLICATION_JSON) |
86 public Response get( | 88 public Response get( |
87 @Context HttpHeaders headers, | 89 @Context HttpServletRequest request, |
88 @Context UriInfo info | 90 @Context UriInfo info |
89 ) { | 91 ) { |
90 return repository.getAll(Probenehmer.class, "stamm"); | 92 MultivaluedMap<String, String> params = info.getQueryParameters(); |
93 List<Probenehmer> nehmer = | |
94 repository.getAllPlain(Probenehmer.class, "stamm"); | |
95 int size = nehmer.size(); | |
96 if (params.containsKey("start") && params.containsKey("limit")) { | |
97 int start = Integer.valueOf(params.getFirst("start")); | |
98 int limit = Integer.valueOf(params.getFirst("limit")); | |
99 int end = limit + start; | |
100 if (start + limit > nehmer.size()) { | |
101 end = nehmer.size(); | |
102 } | |
103 nehmer = nehmer.subList(start, end); | |
104 } | |
105 | |
106 for (Probenehmer p : nehmer) { | |
107 p.setReadonly( | |
108 !authorization.isAuthorized( | |
109 request, | |
110 p, | |
111 RequestMethod.POST, | |
112 Probenehmer.class)); | |
113 } | |
114 return new Response(true, 200, nehmer, size); | |
91 } | 115 } |
92 | 116 |
93 /** | 117 /** |
94 * Get a single Datenbasis object by id. | 118 * Get a single Datenbasis object by id. |
95 * <p> | 119 * <p> |