Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/MesswertService.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 | f92c96efa976 |
comparison
equal
deleted
inserted
replaced
1027:9971471d562c | 1028:1c41c7b8f7c2 |
---|---|
29 import org.apache.log4j.Logger; | 29 import org.apache.log4j.Logger; |
30 | 30 |
31 import de.intevation.lada.lock.LockConfig; | 31 import de.intevation.lada.lock.LockConfig; |
32 import de.intevation.lada.lock.LockType; | 32 import de.intevation.lada.lock.LockType; |
33 import de.intevation.lada.lock.ObjectLocker; | 33 import de.intevation.lada.lock.ObjectLocker; |
34 import de.intevation.lada.model.land.LMessung; | 34 import de.intevation.lada.model.land.Messung; |
35 import de.intevation.lada.model.land.LMesswert; | 35 import de.intevation.lada.model.land.Messwert; |
36 import de.intevation.lada.util.annotation.AuthorizationConfig; | 36 import de.intevation.lada.util.annotation.AuthorizationConfig; |
37 import de.intevation.lada.util.annotation.RepositoryConfig; | 37 import de.intevation.lada.util.annotation.RepositoryConfig; |
38 import de.intevation.lada.util.auth.Authorization; | 38 import de.intevation.lada.util.auth.Authorization; |
39 import de.intevation.lada.util.auth.AuthorizationType; | 39 import de.intevation.lada.util.auth.AuthorizationType; |
40 import de.intevation.lada.util.data.QueryBuilder; | 40 import de.intevation.lada.util.data.QueryBuilder; |
149 id = Integer.valueOf(messungId); | 149 id = Integer.valueOf(messungId); |
150 } | 150 } |
151 catch(NumberFormatException nfe) { | 151 catch(NumberFormatException nfe) { |
152 return new Response(false, 698, null); | 152 return new Response(false, 698, null); |
153 } | 153 } |
154 LMessung messung = defaultRepo.getByIdPlain( | 154 Messung messung = defaultRepo.getByIdPlain( |
155 LMessung.class, | 155 Messung.class, |
156 id, | 156 id, |
157 "land"); | 157 "land"); |
158 if (!authorization.isAuthorized( | 158 if (!authorization.isAuthorized( |
159 request, | 159 request, |
160 messung, | 160 messung, |
161 RequestMethod.GET, | 161 RequestMethod.GET, |
162 LMessung.class) | 162 Messung.class) |
163 ) { | 163 ) { |
164 return new Response(false, 697, null); | 164 return new Response(false, 697, null); |
165 } | 165 } |
166 QueryBuilder<LMesswert> builder = | 166 QueryBuilder<Messwert> builder = |
167 new QueryBuilder<LMesswert>( | 167 new QueryBuilder<Messwert>( |
168 defaultRepo.entityManager("land"), | 168 defaultRepo.entityManager("land"), |
169 LMesswert.class); | 169 Messwert.class); |
170 builder.and("messungsId", messungId); | 170 builder.and("messungsId", messungId); |
171 return authorization.filter( | 171 return authorization.filter( |
172 request, | 172 request, |
173 defaultRepo.filter(builder.getQuery(), "land"), | 173 defaultRepo.filter(builder.getQuery(), "land"), |
174 LMesswert.class); | 174 Messwert.class); |
175 } | 175 } |
176 | 176 |
177 /** | 177 /** |
178 * Get a Messwert object by id. | 178 * Get a Messwert object by id. |
179 * <p> | 179 * <p> |
190 @Context HttpHeaders headers, | 190 @Context HttpHeaders headers, |
191 @Context HttpServletRequest request, | 191 @Context HttpServletRequest request, |
192 @PathParam("id") String id | 192 @PathParam("id") String id |
193 ) { | 193 ) { |
194 Response response = | 194 Response response = |
195 defaultRepo.getById(LMesswert.class, Integer.valueOf(id), "land"); | 195 defaultRepo.getById(Messwert.class, Integer.valueOf(id), "land"); |
196 LMesswert messwert = (LMesswert)response.getData(); | 196 Messwert messwert = (Messwert)response.getData(); |
197 LMessung messung = defaultRepo.getByIdPlain( | 197 Messung messung = defaultRepo.getByIdPlain( |
198 LMessung.class, | 198 Messung.class, |
199 messwert.getMessungsId(), | 199 messwert.getMessungsId(), |
200 "land"); | 200 "land"); |
201 if (!authorization.isAuthorized( | 201 if (!authorization.isAuthorized( |
202 request, | 202 request, |
203 messung, | 203 messung, |
204 RequestMethod.GET, | 204 RequestMethod.GET, |
205 LMessung.class) | 205 Messung.class) |
206 ) { | 206 ) { |
207 return new Response(false, 699, null); | 207 return new Response(false, 699, null); |
208 } | 208 } |
209 Violation violation = validator.validate(messwert); | 209 Violation violation = validator.validate(messwert); |
210 if (violation.hasErrors() || violation.hasWarnings()) { | 210 if (violation.hasErrors() || violation.hasWarnings()) { |
212 response.setWarnings(violation.getWarnings()); | 212 response.setWarnings(violation.getWarnings()); |
213 } | 213 } |
214 return authorization.filter( | 214 return authorization.filter( |
215 request, | 215 request, |
216 response, | 216 response, |
217 LMesswert.class); | 217 Messwert.class); |
218 } | 218 } |
219 | 219 |
220 /** | 220 /** |
221 * Create a Messwert object. | 221 * Create a Messwert object. |
222 * <p> | 222 * <p> |
247 @Path("/") | 247 @Path("/") |
248 @Produces(MediaType.APPLICATION_JSON) | 248 @Produces(MediaType.APPLICATION_JSON) |
249 public Response create( | 249 public Response create( |
250 @Context HttpHeaders headers, | 250 @Context HttpHeaders headers, |
251 @Context HttpServletRequest request, | 251 @Context HttpServletRequest request, |
252 LMesswert messwert | 252 Messwert messwert |
253 ) { | 253 ) { |
254 if (!authorization.isAuthorized( | 254 if (!authorization.isAuthorized( |
255 request, | 255 request, |
256 messwert, | 256 messwert, |
257 RequestMethod.POST, | 257 RequestMethod.POST, |
258 LMesswert.class) | 258 Messwert.class) |
259 ) { | 259 ) { |
260 return new Response(false, 699, null); | 260 return new Response(false, 699, null); |
261 } | 261 } |
262 Violation violation = validator.validate(messwert); | 262 Violation violation = validator.validate(messwert); |
263 if (violation.hasErrors()) { | 263 if (violation.hasErrors()) { |
273 response.setWarnings(violation.getWarnings()); | 273 response.setWarnings(violation.getWarnings()); |
274 } | 274 } |
275 return authorization.filter( | 275 return authorization.filter( |
276 request, | 276 request, |
277 response, | 277 response, |
278 LMesswert.class); | 278 Messwert.class); |
279 } | 279 } |
280 | 280 |
281 /** | 281 /** |
282 * Update an existing Messwert object. | 282 * Update an existing Messwert object. |
283 * <p> | 283 * <p> |
308 @Path("/{id}") | 308 @Path("/{id}") |
309 @Produces(MediaType.APPLICATION_JSON) | 309 @Produces(MediaType.APPLICATION_JSON) |
310 public Response update( | 310 public Response update( |
311 @Context HttpHeaders headers, | 311 @Context HttpHeaders headers, |
312 @Context HttpServletRequest request, | 312 @Context HttpServletRequest request, |
313 LMesswert messwert | 313 Messwert messwert |
314 ) { | 314 ) { |
315 if (!authorization.isAuthorized( | 315 if (!authorization.isAuthorized( |
316 request, | 316 request, |
317 messwert, | 317 messwert, |
318 RequestMethod.PUT, | 318 RequestMethod.PUT, |
319 LMesswert.class) | 319 Messwert.class) |
320 ) { | 320 ) { |
321 return new Response(false, 699, null); | 321 return new Response(false, 699, null); |
322 } | 322 } |
323 if (lock.isLocked(messwert)) { | 323 if (lock.isLocked(messwert)) { |
324 return new Response(false, 697, null); | 324 return new Response(false, 697, null); |
334 Response response = defaultRepo.update(messwert, "land"); | 334 Response response = defaultRepo.update(messwert, "land"); |
335 if (!response.getSuccess()) { | 335 if (!response.getSuccess()) { |
336 return response; | 336 return response; |
337 } | 337 } |
338 Response updated = defaultRepo.getById( | 338 Response updated = defaultRepo.getById( |
339 LMesswert.class, | 339 Messwert.class, |
340 ((LMesswert)response.getData()).getId(), "land"); | 340 ((Messwert)response.getData()).getId(), "land"); |
341 if(violation.hasWarnings()) { | 341 if(violation.hasWarnings()) { |
342 updated.setWarnings(violation.getWarnings()); | 342 updated.setWarnings(violation.getWarnings()); |
343 } | 343 } |
344 | 344 |
345 return authorization.filter( | 345 return authorization.filter( |
346 request, | 346 request, |
347 updated, | 347 updated, |
348 LMesswert.class); | 348 Messwert.class); |
349 } | 349 } |
350 | 350 |
351 /** | 351 /** |
352 * Delete an existing Messwert object by id. | 352 * Delete an existing Messwert object by id. |
353 * <p> | 353 * <p> |
365 @Context HttpServletRequest request, | 365 @Context HttpServletRequest request, |
366 @PathParam("id") String id | 366 @PathParam("id") String id |
367 ) { | 367 ) { |
368 /* Get the messwert object by id*/ | 368 /* Get the messwert object by id*/ |
369 Response messwert = | 369 Response messwert = |
370 defaultRepo.getById(LMesswert.class, Integer.valueOf(id), "land"); | 370 defaultRepo.getById(Messwert.class, Integer.valueOf(id), "land"); |
371 LMesswert messwertObj = (LMesswert)messwert.getData(); | 371 Messwert messwertObj = (Messwert)messwert.getData(); |
372 if (!authorization.isAuthorized( | 372 if (!authorization.isAuthorized( |
373 request, | 373 request, |
374 messwertObj, | 374 messwertObj, |
375 RequestMethod.DELETE, | 375 RequestMethod.DELETE, |
376 LMesswert.class) | 376 Messwert.class) |
377 ) { | 377 ) { |
378 return new Response(false, 699, null); | 378 return new Response(false, 699, null); |
379 } | 379 } |
380 if (lock.isLocked(messwert)) { | 380 if (lock.isLocked(messwert)) { |
381 return new Response(false, 697, null); | 381 return new Response(false, 697, null); |