Mercurial > lada > lada-server
changeset 254:dc41bddf67c0
Added DELETE
author | Torsten Irländer <torsten.irlaender@intevation.de> |
---|---|
date | Mon, 15 Jul 2013 17:05:26 +0200 (2013-07-15) |
parents | 8265c5de15cb |
children | a3ef7a5f2be8 |
files | src/main/java/de/intevation/lada/rest/LMessungService.java |
diffstat | 1 files changed, 42 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 17:04:09 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 17:05:26 2013 +0200 @@ -11,11 +11,13 @@ import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.DELETE; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.PathParam; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; @@ -169,4 +171,44 @@ } return messungen.get(0).isFertig(); } + + /** + * Delete a LMessung object identified by 'probeId' and 'messungsId'. + * + * @param messungsId The object id. + * @param probeId The LProbe object id. + * @param headers The HTTP headers containing authorization information. + * @return Response object. + */ + @DELETE + @Path("/{messungsId}/{probeId}") + @Produces("text/json") + public Response delete( + @PathParam("messungsId") String messungsId, + @PathParam("probeId") String probeId, + @Context HttpHeaders headers + ) { + try { + if (!authentication.isAuthorizedUser(headers)) { + return new Response(false, 699, new ArrayList<LMessung>()); + } + if (authentication.hasAccess(headers, probeId)) { + QueryBuilder<LMessung> builder = + new QueryBuilder<LMessung>( + repository.getEntityManager(), LMessung.class); + builder.and("probeId", probeId).and("messungsId", messungsId); + Response response = repository.filter(builder.getQuery()); + List<LMessung> list = (List<LMessung>)response.getData(); + if (!list.isEmpty()) { + repository.delete(list.get(0)); + return new Response(true, 200, null); + } + return new Response(false, 600, null); + } + return new Response(false, 698, new ArrayList<LMessung>()); + } + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList<LMessung>()); + } + } }