Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/ZusatzwertService.java @ 1028:1c41c7b8f7c2 schema-update
Updated server application to new database model. THIS IS STILL WIP!!!
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Jul 2016 15:32:36 +0200 |
parents | 2c927b3edb97 |
children | 3a5a9a0492d1 |
comparison
equal
deleted
inserted
replaced
1027:9971471d562c | 1028:1c41c7b8f7c2 |
---|---|
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; | 8 package de.intevation.lada.rest; |
9 | |
10 import java.sql.Timestamp; | |
11 import java.util.Date; | |
12 | 9 |
13 import javax.enterprise.context.RequestScoped; | 10 import javax.enterprise.context.RequestScoped; |
14 import javax.inject.Inject; | 11 import javax.inject.Inject; |
15 import javax.servlet.http.HttpServletRequest; | 12 import javax.servlet.http.HttpServletRequest; |
16 import javax.ws.rs.DELETE; | 13 import javax.ws.rs.DELETE; |
27 import javax.ws.rs.core.UriInfo; | 24 import javax.ws.rs.core.UriInfo; |
28 | 25 |
29 import de.intevation.lada.lock.LockConfig; | 26 import de.intevation.lada.lock.LockConfig; |
30 import de.intevation.lada.lock.LockType; | 27 import de.intevation.lada.lock.LockType; |
31 import de.intevation.lada.lock.ObjectLocker; | 28 import de.intevation.lada.lock.ObjectLocker; |
32 import de.intevation.lada.model.land.LZusatzWert; | 29 import de.intevation.lada.model.land.ZusatzWert; |
33 import de.intevation.lada.util.annotation.AuthorizationConfig; | 30 import de.intevation.lada.util.annotation.AuthorizationConfig; |
34 import de.intevation.lada.util.annotation.RepositoryConfig; | 31 import de.intevation.lada.util.annotation.RepositoryConfig; |
35 import de.intevation.lada.util.auth.Authorization; | 32 import de.intevation.lada.util.auth.Authorization; |
36 import de.intevation.lada.util.auth.AuthorizationType; | 33 import de.intevation.lada.util.auth.AuthorizationType; |
37 import de.intevation.lada.util.data.QueryBuilder; | 34 import de.intevation.lada.util.data.QueryBuilder; |
119 @Context HttpServletRequest request, | 116 @Context HttpServletRequest request, |
120 @Context UriInfo info | 117 @Context UriInfo info |
121 ) { | 118 ) { |
122 MultivaluedMap<String, String> params = info.getQueryParameters(); | 119 MultivaluedMap<String, String> params = info.getQueryParameters(); |
123 if (params.isEmpty() || !params.containsKey("probeId")) { | 120 if (params.isEmpty() || !params.containsKey("probeId")) { |
124 return defaultRepo.getAll(LZusatzWert.class, "land"); | 121 return defaultRepo.getAll(ZusatzWert.class, "land"); |
125 } | 122 } |
126 String probeId = params.getFirst("probeId"); | 123 String probeId = params.getFirst("probeId"); |
127 QueryBuilder<LZusatzWert> builder = | 124 QueryBuilder<ZusatzWert> builder = |
128 new QueryBuilder<LZusatzWert>( | 125 new QueryBuilder<ZusatzWert>( |
129 defaultRepo.entityManager("land"), | 126 defaultRepo.entityManager("land"), |
130 LZusatzWert.class); | 127 ZusatzWert.class); |
131 builder.and("probeId", probeId); | 128 builder.and("probeId", probeId); |
132 return authorization.filter( | 129 return authorization.filter( |
133 request, | 130 request, |
134 defaultRepo.filter(builder.getQuery(), "land"), | 131 defaultRepo.filter(builder.getQuery(), "land"), |
135 LZusatzWert.class); | 132 ZusatzWert.class); |
136 } | 133 } |
137 | 134 |
138 /** | 135 /** |
139 * Get a Zusatzwert object by id. | 136 * Get a Zusatzwert object by id. |
140 * <p> | 137 * <p> |
152 @Context HttpServletRequest request, | 149 @Context HttpServletRequest request, |
153 @PathParam("id") String id | 150 @PathParam("id") String id |
154 ) { | 151 ) { |
155 return authorization.filter( | 152 return authorization.filter( |
156 request, | 153 request, |
157 defaultRepo.getById(LZusatzWert.class, Integer.valueOf(id), "land"), | 154 defaultRepo.getById(ZusatzWert.class, Integer.valueOf(id), "land"), |
158 LZusatzWert.class); | 155 ZusatzWert.class); |
159 } | 156 } |
160 | 157 |
161 /** | 158 /** |
162 * Create a Zusatzwert object. | 159 * Create a Zusatzwert object. |
163 * <p> | 160 * <p> |
185 @Path("/") | 182 @Path("/") |
186 @Produces(MediaType.APPLICATION_JSON) | 183 @Produces(MediaType.APPLICATION_JSON) |
187 public Response create( | 184 public Response create( |
188 @Context HttpHeaders headers, | 185 @Context HttpHeaders headers, |
189 @Context HttpServletRequest request, | 186 @Context HttpServletRequest request, |
190 LZusatzWert zusatzwert | 187 ZusatzWert zusatzwert |
191 ) { | 188 ) { |
192 if (!authorization.isAuthorized( | 189 if (!authorization.isAuthorized( |
193 request, | 190 request, |
194 zusatzwert, | 191 zusatzwert, |
195 RequestMethod.POST, | 192 RequestMethod.POST, |
196 LZusatzWert.class) | 193 ZusatzWert.class) |
197 ) { | 194 ) { |
198 return new Response(false, 699, null); | 195 return new Response(false, 699, null); |
199 } | 196 } |
200 /* Persist the new object*/ | 197 /* Persist the new object*/ |
201 return authorization.filter( | 198 return authorization.filter( |
202 request, | 199 request, |
203 defaultRepo.create(zusatzwert, "land"), | 200 defaultRepo.create(zusatzwert, "land"), |
204 LZusatzWert.class); | 201 ZusatzWert.class); |
205 } | 202 } |
206 | 203 |
207 /** | 204 /** |
208 * Update an existing Zusatzwert object. | 205 * Update an existing Zusatzwert object. |
209 * <p> | 206 * <p> |
231 @Path("/{id}") | 228 @Path("/{id}") |
232 @Produces(MediaType.APPLICATION_JSON) | 229 @Produces(MediaType.APPLICATION_JSON) |
233 public Response update( | 230 public Response update( |
234 @Context HttpHeaders headers, | 231 @Context HttpHeaders headers, |
235 @Context HttpServletRequest request, | 232 @Context HttpServletRequest request, |
236 LZusatzWert zusatzwert | 233 ZusatzWert zusatzwert |
237 ) { | 234 ) { |
238 if (!authorization.isAuthorized( | 235 if (!authorization.isAuthorized( |
239 request, | 236 request, |
240 zusatzwert, | 237 zusatzwert, |
241 RequestMethod.PUT, | 238 RequestMethod.PUT, |
242 LZusatzWert.class) | 239 ZusatzWert.class) |
243 ) { | 240 ) { |
244 return new Response(false, 699, null); | 241 return new Response(false, 699, null); |
245 } | 242 } |
246 if (lock.isLocked(zusatzwert)) { | 243 if (lock.isLocked(zusatzwert)) { |
247 return new Response(false, 697, null); | 244 return new Response(false, 697, null); |
249 Response response = defaultRepo.update(zusatzwert, "land"); | 246 Response response = defaultRepo.update(zusatzwert, "land"); |
250 if (!response.getSuccess()) { | 247 if (!response.getSuccess()) { |
251 return response; | 248 return response; |
252 } | 249 } |
253 Response updated = defaultRepo.getById( | 250 Response updated = defaultRepo.getById( |
254 LZusatzWert.class, | 251 ZusatzWert.class, |
255 ((LZusatzWert)response.getData()).getId(), "land"); | 252 ((ZusatzWert)response.getData()).getId(), "land"); |
256 return authorization.filter( | 253 return authorization.filter( |
257 request, | 254 request, |
258 updated, | 255 updated, |
259 LZusatzWert.class); | 256 ZusatzWert.class); |
260 } | 257 } |
261 | 258 |
262 /** | 259 /** |
263 * Delete an existing Zusatzwert object by id. | 260 * Delete an existing Zusatzwert object by id. |
264 * <p> | 261 * <p> |
276 @Context HttpServletRequest request, | 273 @Context HttpServletRequest request, |
277 @PathParam("id") String id | 274 @PathParam("id") String id |
278 ) { | 275 ) { |
279 /* Get the object by id*/ | 276 /* Get the object by id*/ |
280 Response object = | 277 Response object = |
281 defaultRepo.getById(LZusatzWert.class, Integer.valueOf(id), "land"); | 278 defaultRepo.getById(ZusatzWert.class, Integer.valueOf(id), "land"); |
282 LZusatzWert obj = (LZusatzWert)object.getData(); | 279 ZusatzWert obj = (ZusatzWert)object.getData(); |
283 if (!authorization.isAuthorized( | 280 if (!authorization.isAuthorized( |
284 request, | 281 request, |
285 obj, | 282 obj, |
286 RequestMethod.DELETE, | 283 RequestMethod.DELETE, |
287 LZusatzWert.class) | 284 ZusatzWert.class) |
288 ) { | 285 ) { |
289 return new Response(false, 699, null); | 286 return new Response(false, 699, null); |
290 } | 287 } |
291 if (lock.isLocked(obj)) { | 288 if (lock.isLocked(obj)) { |
292 return new Response(false, 697, null); | 289 return new Response(false, 697, null); |