Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/KommentarMService.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 | 2fe625c91ab3 |
children | 3a5a9a0492d1 |
comparison
equal
deleted
inserted
replaced
1027:9971471d562c | 1028:1c41c7b8f7c2 |
---|---|
21 import javax.ws.rs.core.HttpHeaders; | 21 import javax.ws.rs.core.HttpHeaders; |
22 import javax.ws.rs.core.MediaType; | 22 import javax.ws.rs.core.MediaType; |
23 import javax.ws.rs.core.MultivaluedMap; | 23 import javax.ws.rs.core.MultivaluedMap; |
24 import javax.ws.rs.core.UriInfo; | 24 import javax.ws.rs.core.UriInfo; |
25 | 25 |
26 import de.intevation.lada.model.land.LKommentarM; | 26 import de.intevation.lada.model.land.KommentarM; |
27 import de.intevation.lada.model.land.LMessung; | 27 import de.intevation.lada.model.land.Messung; |
28 import de.intevation.lada.util.annotation.AuthorizationConfig; | 28 import de.intevation.lada.util.annotation.AuthorizationConfig; |
29 import de.intevation.lada.util.annotation.RepositoryConfig; | 29 import de.intevation.lada.util.annotation.RepositoryConfig; |
30 import de.intevation.lada.util.auth.Authorization; | 30 import de.intevation.lada.util.auth.Authorization; |
31 import de.intevation.lada.util.auth.AuthorizationType; | 31 import de.intevation.lada.util.auth.AuthorizationType; |
32 import de.intevation.lada.util.data.QueryBuilder; | 32 import de.intevation.lada.util.data.QueryBuilder; |
114 id = Integer.valueOf(messungId); | 114 id = Integer.valueOf(messungId); |
115 } | 115 } |
116 catch(NumberFormatException nfe) { | 116 catch(NumberFormatException nfe) { |
117 return new Response(false, 699, null); | 117 return new Response(false, 699, null); |
118 } | 118 } |
119 LMessung messung = defaultRepo.getByIdPlain( | 119 Messung messung = defaultRepo.getByIdPlain( |
120 LMessung.class, | 120 Messung.class, |
121 id, | 121 id, |
122 "land"); | 122 "land"); |
123 if (!authorization.isAuthorized(request, messung, RequestMethod.GET, LMessung.class)) { | 123 if (!authorization.isAuthorized(request, messung, RequestMethod.GET, Messung.class)) { |
124 return new Response(false, 699, null); | 124 return new Response(false, 699, null); |
125 } | 125 } |
126 | 126 |
127 QueryBuilder<LKommentarM> builder = | 127 QueryBuilder<KommentarM> builder = |
128 new QueryBuilder<LKommentarM>( | 128 new QueryBuilder<KommentarM>( |
129 defaultRepo.entityManager("land"), | 129 defaultRepo.entityManager("land"), |
130 LKommentarM.class); | 130 KommentarM.class); |
131 builder.and("messungsId", messungId); | 131 builder.and("messungsId", messungId); |
132 return authorization.filter( | 132 return authorization.filter( |
133 request, | 133 request, |
134 defaultRepo.filter(builder.getQuery(), "land"), | 134 defaultRepo.filter(builder.getQuery(), "land"), |
135 LKommentarM.class); | 135 KommentarM.class); |
136 } | 136 } |
137 | 137 |
138 /** | 138 /** |
139 * Get a single KommentarM object by id. | 139 * Get a single KommentarM object by id. |
140 * <p> | 140 * <p> |
151 @Context HttpHeaders headers, | 151 @Context HttpHeaders headers, |
152 @Context HttpServletRequest request, | 152 @Context HttpServletRequest request, |
153 @PathParam("id") String id | 153 @PathParam("id") String id |
154 ) { | 154 ) { |
155 Response response = | 155 Response response = |
156 defaultRepo.getById(LKommentarM.class, Integer.valueOf(id), "land"); | 156 defaultRepo.getById(KommentarM.class, Integer.valueOf(id), "land"); |
157 LKommentarM kommentar = (LKommentarM)response.getData(); | 157 KommentarM kommentar = (KommentarM)response.getData(); |
158 LMessung messung = defaultRepo.getByIdPlain( | 158 Messung messung = defaultRepo.getByIdPlain( |
159 LMessung.class, | 159 Messung.class, |
160 kommentar.getMessungsId(), | 160 kommentar.getMessungsId(), |
161 "land"); | 161 "land"); |
162 if (!authorization.isAuthorized(request, messung, RequestMethod.GET, LMessung.class)) { | 162 if (!authorization.isAuthorized(request, messung, RequestMethod.GET, Messung.class)) { |
163 return new Response(false, 699, null); | 163 return new Response(false, 699, null); |
164 } | 164 } |
165 | 165 |
166 return authorization.filter( | 166 return authorization.filter( |
167 request, | 167 request, |
168 response, | 168 response, |
169 LKommentarM.class); | 169 KommentarM.class); |
170 } | 170 } |
171 | 171 |
172 /** | 172 /** |
173 * Create a KommentarM object. | 173 * Create a KommentarM object. |
174 * <p> | 174 * <p> |
191 @Path("/") | 191 @Path("/") |
192 @Produces(MediaType.APPLICATION_JSON) | 192 @Produces(MediaType.APPLICATION_JSON) |
193 public Response create( | 193 public Response create( |
194 @Context HttpHeaders headers, | 194 @Context HttpHeaders headers, |
195 @Context HttpServletRequest request, | 195 @Context HttpServletRequest request, |
196 LKommentarM kommentar | 196 KommentarM kommentar |
197 ) { | 197 ) { |
198 if (!authorization.isAuthorized( | 198 if (!authorization.isAuthorized( |
199 request, | 199 request, |
200 kommentar, | 200 kommentar, |
201 RequestMethod.POST, | 201 RequestMethod.POST, |
202 LKommentarM.class) | 202 KommentarM.class) |
203 ) { | 203 ) { |
204 return new Response(false, 699, null); | 204 return new Response(false, 699, null); |
205 } | 205 } |
206 /* Persist the new object*/ | 206 /* Persist the new object*/ |
207 return authorization.filter( | 207 return authorization.filter( |
208 request, | 208 request, |
209 defaultRepo.create(kommentar, "land"), | 209 defaultRepo.create(kommentar, "land"), |
210 LKommentarM.class); | 210 KommentarM.class); |
211 } | 211 } |
212 | 212 |
213 /** | 213 /** |
214 * Update an existing KommentarM object. | 214 * Update an existing KommentarM object. |
215 * <p> | 215 * <p> |
233 @Path("/{id}") | 233 @Path("/{id}") |
234 @Produces(MediaType.APPLICATION_JSON) | 234 @Produces(MediaType.APPLICATION_JSON) |
235 public Response update( | 235 public Response update( |
236 @Context HttpHeaders headers, | 236 @Context HttpHeaders headers, |
237 @Context HttpServletRequest request, | 237 @Context HttpServletRequest request, |
238 LKommentarM kommentar | 238 KommentarM kommentar |
239 ) { | 239 ) { |
240 if (!authorization.isAuthorized( | 240 if (!authorization.isAuthorized( |
241 request, | 241 request, |
242 kommentar, | 242 kommentar, |
243 RequestMethod.PUT, | 243 RequestMethod.PUT, |
244 LKommentarM.class) | 244 KommentarM.class) |
245 ) { | 245 ) { |
246 return new Response(false, 699, null); | 246 return new Response(false, 699, null); |
247 } | 247 } |
248 return authorization.filter( | 248 return authorization.filter( |
249 request, | 249 request, |
250 defaultRepo.update(kommentar, "land"), | 250 defaultRepo.update(kommentar, "land"), |
251 LKommentarM.class); | 251 KommentarM.class); |
252 } | 252 } |
253 | 253 |
254 /** | 254 /** |
255 * Delete an existing KommentarM object by id. | 255 * Delete an existing KommentarM object by id. |
256 * <p> | 256 * <p> |
268 @Context HttpServletRequest request, | 268 @Context HttpServletRequest request, |
269 @PathParam("id") String id | 269 @PathParam("id") String id |
270 ) { | 270 ) { |
271 /* Get the object by id*/ | 271 /* Get the object by id*/ |
272 Response kommentar = | 272 Response kommentar = |
273 defaultRepo.getById(LKommentarM.class, Integer.valueOf(id), "land"); | 273 defaultRepo.getById(KommentarM.class, Integer.valueOf(id), "land"); |
274 LKommentarM kommentarObj = (LKommentarM)kommentar.getData(); | 274 KommentarM kommentarObj = (KommentarM)kommentar.getData(); |
275 if (!authorization.isAuthorized( | 275 if (!authorization.isAuthorized( |
276 request, | 276 request, |
277 kommentarObj, | 277 kommentarObj, |
278 RequestMethod.DELETE, | 278 RequestMethod.DELETE, |
279 LKommentarM.class) | 279 KommentarM.class) |
280 ) { | 280 ) { |
281 return new Response(false, 699, null); | 281 return new Response(false, 699, null); |
282 } | 282 } |
283 return defaultRepo.delete(kommentarObj, "land"); | 283 return defaultRepo.delete(kommentarObj, "land"); |
284 } | 284 } |