# HG changeset patch # User Raimund Renkert # Date 1373895623 -7200 # Node ID 2dbe200b73f589086314244f6bc2cf8a2a305a1b # Parent 04b5f401e871d7b7a6b6bcaa8e47c25b01f19046 'DELETE' for LStatus service. diff -r 04b5f401e871 -r 2dbe200b73f5 src/main/java/de/intevation/lada/rest/LStatusService.java --- a/src/main/java/de/intevation/lada/rest/LStatusService.java Mon Jul 15 15:39:39 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LStatusService.java Mon Jul 15 15:40:23 2013 +0200 @@ -1,15 +1,18 @@ package de.intevation.lada.rest; import java.util.ArrayList; +import java.util.List; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; +import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; @@ -143,4 +146,45 @@ return new Response(false, 699, new ArrayList()); } } + + /** + * Delete a LStatus object. + * + * @param statusId The object id. + * @param messungsId The LProbe id. + * @param statusId The LStatus id + * @param headers The HTTP header containing authorization information. + * @return Response object. + */ + @DELETE + @Path("/{statusId}/{messungsId}/{probeId}") + public Response delete( + @PathParam("statusId") String statusId, + @PathParam("messungsId") String messungsId, + @PathParam("probeId") String probeId, + @Context HttpHeaders headers + ) { + try { + if (authentication.hasAccess(headers, probeId)) { + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), + LStatus.class); + builder.and("SId", statusId) + .and("messungsId", messungsId) + .and("probeId", probeId); + Response response = repository.filter(builder.getQuery()); + List list = (List)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()); + } + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList()); + } + } }