annotate src/main/java/de/intevation/lada/rest/LOrtService.java @ 366:567ce7697fc7 0.5

Code documentation.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 10 Sep 2013 15:55:54 +0200
parents 2098db2e8fbd
children 183f8116d9a6
rev   line source
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.lada.rest;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
3 import java.util.ArrayList;
236
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
4 import java.util.List;
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
5
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import javax.enterprise.context.RequestScoped;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import javax.inject.Inject;
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
8 import javax.inject.Named;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import javax.ws.rs.Consumes;
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
10 import javax.ws.rs.DELETE;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import javax.ws.rs.GET;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import javax.ws.rs.POST;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import javax.ws.rs.PUT;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import javax.ws.rs.Path;
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
15 import javax.ws.rs.PathParam;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import javax.ws.rs.Produces;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 import javax.ws.rs.core.Context;
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
18 import javax.ws.rs.core.HttpHeaders;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 import javax.ws.rs.core.MultivaluedMap;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 import javax.ws.rs.core.UriInfo;
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21
232
d8a3d188046f Renamed package authentication to auth.
Raimund Renkert <rrenkert@intevation.de>
parents: 210
diff changeset
22 import de.intevation.lada.auth.Authentication;
d8a3d188046f Renamed package authentication to auth.
Raimund Renkert <rrenkert@intevation.de>
parents: 210
diff changeset
23 import de.intevation.lada.auth.AuthenticationException;
236
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
24 import de.intevation.lada.auth.Authorization;
182
a2e04ab2cd44 Use the new filter and query builder and have authentication for LProbeInfo objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 131
diff changeset
25 import de.intevation.lada.data.QueryBuilder;
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
26 import de.intevation.lada.data.Repository;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 import de.intevation.lada.model.LOrt;
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 263
diff changeset
28 import de.intevation.lada.model.LProbe;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29
210
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
30 /**
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
31 * This class produces a RESTful service to read, write and update
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
32 * LOrt objects.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
33 *
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
34 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
35 */
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
36 @Path("/ort")
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 @RequestScoped
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 public class LOrtService
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 {
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 /**
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 * The repository for LOrt.
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 */
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 @Inject
131
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
45 @Named("lortrepository")
4e181a4aaab0 Refactored the entity repositories.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
46 private Repository repository;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47
210
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
48 /**
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
49 * The authorization module.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
50 */
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
51 @Inject
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
52 @Named("ldapauth")
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
53 private Authentication authentication;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54
236
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
55 @Inject
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
56 @Named("dataauthorization")
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
57 private Authorization authorization;
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
58
210
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
59 /**
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
60 * Request LOrt via a filter.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
61 *
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
62 * Query parameters are used for the filter in form of key-value pairs.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
63 *
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
64 * @param info The URL query parameters.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
65 * @param headers The HTTP header containing authorization information.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
66 * @return Response object.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
67 */
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 @GET
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 @Produces("text/json")
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
70 public Response filter(
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
71 @Context UriInfo info,
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
72 @Context HttpHeaders headers
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
73 ) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
74 try {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
75 if (!authentication.isAuthorizedUser(headers)) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
76 return new Response(false, 699, new ArrayList<LOrt>());
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
77 }
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
78 MultivaluedMap<String, String> params = info.getQueryParameters();
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
79 if (params.isEmpty() ||
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
80 !params.containsKey("probeId")) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
81 return new Response(false, 609, new ArrayList<LOrt>());
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
82 }
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
83 String probeId = params.getFirst("probeId");
261
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
84 QueryBuilder<LOrt> builder =
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
85 new QueryBuilder<LOrt>(
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
86 repository.getEntityManager(), LOrt.class);
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
87 builder.and("probeId", probeId);
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
88 Response response = repository.filter(builder.getQuery());
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
89 List<LOrt> list = (List<LOrt>) response.getData();
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
90 boolean readonly = authorization.isReadOnly(probeId);
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
91 for (LOrt ort: list) {
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
92 ort.setReadonly(readonly);
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
93 }
261
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
94 response.setData(list);
07c4186cbfab Enable read access on all objects for authorized users.
Raimund Renkert <rrenkert@intevation.de>
parents: 251
diff changeset
95 return response;
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 }
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
97 catch(AuthenticationException ae) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
98 return new Response(false, 699, new ArrayList<LOrt>());
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 }
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 }
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101
210
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
102 /**
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
103 * Update LOrt objects.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
104 *
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
105 * @param ort The LOrt object to update.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
106 * @param headers The HTTP header containing authorization information.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
107 * @return Response object.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
108 */
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 @PUT
251
4635fa8de9f4 Fixed loading Lort
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
110 @Path("/{portId}/{probeId}")
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 @Produces("text/json")
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 @Consumes("application/json")
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
113 public Response update(
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
114 LOrt ort,
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
115 @Context HttpHeaders headers
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
116 ) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
117 try {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
118 String probeId = ort.getProbeId();
236
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
119 if (authentication.hasAccess(headers, probeId) &&
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
120 !authorization.isReadOnly(probeId)) {
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
121 return repository.update(ort);
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
122 }
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
123 return new Response(false, 698, new ArrayList<LOrt>());
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
124 }
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
125 catch(AuthenticationException ae) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
126 return new Response(false, 699, new ArrayList<LOrt>());
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
127 }
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 }
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129
210
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
130 /**
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
131 * Create a new LOrt object.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
132 *
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
133 * @param ort The new LOrt object.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
134 * @param headers The HTTP header containing authorization information.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
135 * @return Response object.
a305412206a3 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 208
diff changeset
136 */
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
137 @POST
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138 @Produces("text/json")
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
139 @Consumes("application/json")
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
140 public Response create(
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
141 LOrt ort,
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
142 @Context HttpHeaders headers
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
143 ) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
144 try {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
145 String probeId = ort.getProbeId();
236
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
146 if (authentication.hasAccess(headers, probeId) &&
2bf8ef754356 Mark LOrt objects as readonly.
Raimund Renkert <rrenkert@intevation.de>
parents: 232
diff changeset
147 !authorization.isReadOnly(probeId)) {
208
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
148 return repository.create(ort);
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
149 }
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
150 return new Response(false, 698, new ArrayList<LOrt>());
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
151 }
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
152 catch(AuthenticationException ae) {
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
153 return new Response(false, 699, new ArrayList<LOrt>());
832e67663fd9 Added authorization to all services.
Raimund Renkert <rrenkert@intevation.de>
parents: 182
diff changeset
154 }
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
155 }
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
156
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
157 /**
263
2098db2e8fbd Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 261
diff changeset
158 * Delete a LOrt object.
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
159 *
366
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 263
diff changeset
160 * @param ortId The {@link LOrt} id.
567ce7697fc7 Code documentation.
Raimund Renkert <rrenkert@intevation.de>
parents: 263
diff changeset
161 * @param probeId The {@link LProbe} id.
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
162 * @param headers The HTTP header containing authorization information.
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
163 * @return Response object.
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
164 */
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
165 @DELETE
251
4635fa8de9f4 Fixed loading Lort
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
166 @Produces("text/json")
4635fa8de9f4 Fixed loading Lort
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
167 @Path("/{ortId}/{probeId}")
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
168 public Response delete(
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
169 @PathParam("ortId") String ortId,
251
4635fa8de9f4 Fixed loading Lort
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
170 @PathParam("probeId") String probeId,
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
171 @Context HttpHeaders headers
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
172 ) {
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
173 try {
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
174 QueryBuilder<LOrt> builder =
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
175 new QueryBuilder<LOrt>(
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
176 repository.getEntityManager(),
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
177 LOrt.class);
251
4635fa8de9f4 Fixed loading Lort
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 241
diff changeset
178 builder.and("POrtId", ortId).and("probeId", probeId);
241
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
179 Response response = repository.filter(builder.getQuery());
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
180 List<LOrt> list = (List<LOrt>)response.getData();
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
181 if (!list.isEmpty()) {
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
182 LOrt ort = list.get(0);
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
183 if (authentication.hasAccess(headers, ort.getProbeId())) {
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
184 repository.delete(list.get(0));
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
185 return new Response(true, 200, null);
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
186 }
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
187 return new Response(false, 698, null);
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
188 }
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
189 return new Response(false, 600, null);
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
190 }
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
191 catch(AuthenticationException ae) {
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
192 return new Response(false, 699, new ArrayList<LOrt>());
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
193 }
c00ee4e49d7d Implemented service method 'DELETE' for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents: 236
diff changeset
194 }
124
3e8c089d90ed Added new service for LOrt objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
195 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)