# HG changeset patch # User Raimund Renkert # Date 1373878076 -7200 # Node ID 04021a8122ba055bdb4e215463651aec5a70e88d # Parent c00ee4e49d7def6a19dc77dd72930a471b6c029d# Parent a31daefe49eab7f195da7d746659518fb8a77ea3 merged. diff -r a31daefe49ea -r 04021a8122ba src/main/java/de/intevation/lada/rest/LOrtService.java --- a/src/main/java/de/intevation/lada/rest/LOrtService.java Fri Jul 12 15:55:54 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LOrtService.java Mon Jul 15 10:47:56 2013 +0200 @@ -7,10 +7,12 @@ 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; @@ -153,4 +155,41 @@ return new Response(false, 699, new ArrayList()); } } + + /** + * Delete a LZusatzwert object. + * + * @param pzsId The object id. + * @param probeId The LProbe id. + * @param headers The HTTP header containing authorization information. + * @return Response object. + */ + @DELETE + @Path("/{ortId}") + public Response delete( + @PathParam("ortId") String ortId, + @Context HttpHeaders headers + ) { + try { + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), + LOrt.class); + builder.and("POrtId", ortId); + Response response = repository.filter(builder.getQuery()); + List list = (List)response.getData(); + if (!list.isEmpty()) { + LOrt ort = list.get(0); + if (authentication.hasAccess(headers, ort.getProbeId())) { + repository.delete(list.get(0)); + return new Response(true, 200, null); + } + return new Response(false, 698, null); + } + return new Response(false, 600, null); + } + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList()); + } + } }