Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.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; | 28 import de.intevation.lada.model.stamm.DatensatzErzeuger; |
26 import de.intevation.lada.util.annotation.AuthorizationConfig; | 29 import de.intevation.lada.util.annotation.AuthorizationConfig; |
27 import de.intevation.lada.util.annotation.RepositoryConfig; | 30 import de.intevation.lada.util.annotation.RepositoryConfig; |
84 */ | 87 */ |
85 @GET | 88 @GET |
86 @Path("/") | 89 @Path("/") |
87 @Produces(MediaType.APPLICATION_JSON) | 90 @Produces(MediaType.APPLICATION_JSON) |
88 public Response get( | 91 public Response get( |
89 @Context HttpHeaders headers, | 92 @Context HttpServletRequest request, |
90 @Context UriInfo info | 93 @Context UriInfo info |
91 ) { | 94 ) { |
92 return repository.getAll(DatensatzErzeuger.class, "stamm"); | 95 MultivaluedMap<String, String> params = info.getQueryParameters(); |
96 List<DatensatzErzeuger> erzeuger = | |
97 repository.getAllPlain(DatensatzErzeuger.class, "stamm"); | |
98 int size = erzeuger.size(); | |
99 if (params.containsKey("start") && params.containsKey("limit")) { | |
100 int start = Integer.valueOf(params.getFirst("start")); | |
101 int limit = Integer.valueOf(params.getFirst("limit")); | |
102 int end = limit + start; | |
103 if (start + limit > erzeuger.size()) { | |
104 end = erzeuger.size(); | |
105 } | |
106 erzeuger = erzeuger.subList(start, end); | |
107 } | |
108 | |
109 for (DatensatzErzeuger erz : erzeuger) { | |
110 erz.setReadonly( | |
111 !authorization.isAuthorized( | |
112 request, | |
113 erz, | |
114 RequestMethod.POST, | |
115 DatensatzErzeuger.class)); | |
116 } | |
117 return new Response (true, 200, erzeuger, size); | |
93 } | 118 } |
94 | 119 |
95 /** | 120 /** |
96 * Get a single Datenbasis object by id. | 121 * Get a single Datenbasis object by id. |
97 * <p> | 122 * <p> |