Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/OrtService.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 | a3f9cf7e38c1 |
children | f92c96efa976 |
comparison
equal
deleted
inserted
replaced
1027:9971471d562c | 1028:1c41c7b8f7c2 |
---|---|
29 import org.apache.log4j.Logger; | 29 import org.apache.log4j.Logger; |
30 | 30 |
31 import de.intevation.lada.lock.LockConfig; | 31 import de.intevation.lada.lock.LockConfig; |
32 import de.intevation.lada.lock.LockType; | 32 import de.intevation.lada.lock.LockType; |
33 import de.intevation.lada.lock.ObjectLocker; | 33 import de.intevation.lada.lock.ObjectLocker; |
34 import de.intevation.lada.model.land.LOrtszuordnung; | 34 import de.intevation.lada.model.land.Ortszuordnung; |
35 import de.intevation.lada.util.annotation.AuthorizationConfig; | 35 import de.intevation.lada.util.annotation.AuthorizationConfig; |
36 import de.intevation.lada.util.annotation.RepositoryConfig; | 36 import de.intevation.lada.util.annotation.RepositoryConfig; |
37 import de.intevation.lada.util.auth.Authorization; | 37 import de.intevation.lada.util.auth.Authorization; |
38 import de.intevation.lada.util.auth.AuthorizationType; | 38 import de.intevation.lada.util.auth.AuthorizationType; |
39 import de.intevation.lada.util.data.QueryBuilder; | 39 import de.intevation.lada.util.data.QueryBuilder; |
134 @Context HttpServletRequest request | 134 @Context HttpServletRequest request |
135 ) { | 135 ) { |
136 MultivaluedMap<String, String> params = info.getQueryParameters(); | 136 MultivaluedMap<String, String> params = info.getQueryParameters(); |
137 if (params.isEmpty() || !params.containsKey("probeId")) { | 137 if (params.isEmpty() || !params.containsKey("probeId")) { |
138 logger.debug("get all"); | 138 logger.debug("get all"); |
139 return defaultRepo.getAll(LOrtszuordnung.class, "land"); | 139 return defaultRepo.getAll(Ortszuordnung.class, "land"); |
140 } | 140 } |
141 String probeId = params.getFirst("probeId"); | 141 String probeId = params.getFirst("probeId"); |
142 QueryBuilder<LOrtszuordnung> builder = | 142 QueryBuilder<Ortszuordnung> builder = |
143 new QueryBuilder<LOrtszuordnung>( | 143 new QueryBuilder<Ortszuordnung>( |
144 defaultRepo.entityManager("land"), | 144 defaultRepo.entityManager("land"), |
145 LOrtszuordnung.class); | 145 Ortszuordnung.class); |
146 builder.and("probeId", probeId); | 146 builder.and("probeId", probeId); |
147 return authorization.filter( | 147 return authorization.filter( |
148 request, | 148 request, |
149 defaultRepo.filter(builder.getQuery(), "land"), | 149 defaultRepo.filter(builder.getQuery(), "land"), |
150 LOrtszuordnung.class); | 150 Ortszuordnung.class); |
151 } | 151 } |
152 | 152 |
153 /** | 153 /** |
154 * Get a Ort object by id. | 154 * Get a Ort object by id. |
155 * <p> | 155 * <p> |
166 @Context HttpHeaders headers, | 166 @Context HttpHeaders headers, |
167 @Context HttpServletRequest request, | 167 @Context HttpServletRequest request, |
168 @PathParam("id") String id | 168 @PathParam("id") String id |
169 ) { | 169 ) { |
170 Response response = | 170 Response response = |
171 defaultRepo.getById(LOrtszuordnung.class, Integer.valueOf(id), "land"); | 171 defaultRepo.getById(Ortszuordnung.class, Integer.valueOf(id), "land"); |
172 LOrtszuordnung ort = (LOrtszuordnung)response.getData(); | 172 Ortszuordnung ort = (Ortszuordnung)response.getData(); |
173 Violation violation = validator.validate(ort); | 173 Violation violation = validator.validate(ort); |
174 if (violation.hasErrors() || violation.hasWarnings()) { | 174 if (violation.hasErrors() || violation.hasWarnings()) { |
175 response.setErrors(violation.getErrors()); | 175 response.setErrors(violation.getErrors()); |
176 response.setWarnings(violation.getWarnings()); | 176 response.setWarnings(violation.getWarnings()); |
177 } | 177 } |
178 return authorization.filter( | 178 return authorization.filter( |
179 request, | 179 request, |
180 response, | 180 response, |
181 LOrtszuordnung.class); | 181 Ortszuordnung.class); |
182 } | 182 } |
183 | 183 |
184 /** | 184 /** |
185 * Create a new Ort object. | 185 * Create a new Ort object. |
186 * <p> | 186 * <p> |
207 @Path("/") | 207 @Path("/") |
208 @Produces(MediaType.APPLICATION_JSON) | 208 @Produces(MediaType.APPLICATION_JSON) |
209 public Response create( | 209 public Response create( |
210 @Context HttpHeaders headers, | 210 @Context HttpHeaders headers, |
211 @Context HttpServletRequest request, | 211 @Context HttpServletRequest request, |
212 LOrtszuordnung ort | 212 Ortszuordnung ort |
213 ) { | 213 ) { |
214 if (!authorization.isAuthorized( | 214 if (!authorization.isAuthorized( |
215 request, | 215 request, |
216 ort, | 216 ort, |
217 RequestMethod.POST, | 217 RequestMethod.POST, |
218 LOrtszuordnung.class)) { | 218 Ortszuordnung.class)) { |
219 return new Response(false, 699, null); | 219 return new Response(false, 699, null); |
220 } | 220 } |
221 Violation violation = validator.validate(ort); | 221 Violation violation = validator.validate(ort); |
222 if (violation.hasErrors()) { | 222 if (violation.hasErrors()) { |
223 Response response = new Response(false, 604, ort); | 223 Response response = new Response(false, 604, ort); |
233 } | 233 } |
234 | 234 |
235 return authorization.filter( | 235 return authorization.filter( |
236 request, | 236 request, |
237 response, | 237 response, |
238 LOrtszuordnung.class); | 238 Ortszuordnung.class); |
239 } | 239 } |
240 | 240 |
241 /** | 241 /** |
242 * Update an existing Ort object. | 242 * Update an existing Ort object. |
243 * <p> | 243 * <p> |
264 @Path("/{id}") | 264 @Path("/{id}") |
265 @Produces(MediaType.APPLICATION_JSON) | 265 @Produces(MediaType.APPLICATION_JSON) |
266 public Response update( | 266 public Response update( |
267 @Context HttpHeaders headers, | 267 @Context HttpHeaders headers, |
268 @Context HttpServletRequest request, | 268 @Context HttpServletRequest request, |
269 LOrtszuordnung ort | 269 Ortszuordnung ort |
270 ) { | 270 ) { |
271 if (!authorization.isAuthorized( | 271 if (!authorization.isAuthorized( |
272 request, | 272 request, |
273 ort, | 273 ort, |
274 RequestMethod.PUT, | 274 RequestMethod.PUT, |
275 LOrtszuordnung.class)) { | 275 Ortszuordnung.class)) { |
276 return new Response(false, 699, null); | 276 return new Response(false, 699, null); |
277 } | 277 } |
278 if (lock.isLocked(ort)) { | 278 if (lock.isLocked(ort)) { |
279 return new Response(false, 697, null); | 279 return new Response(false, 697, null); |
280 } | 280 } |
289 Response response = defaultRepo.update(ort, "land"); | 289 Response response = defaultRepo.update(ort, "land"); |
290 if (!response.getSuccess()) { | 290 if (!response.getSuccess()) { |
291 return response; | 291 return response; |
292 } | 292 } |
293 Response updated = defaultRepo.getById( | 293 Response updated = defaultRepo.getById( |
294 LOrtszuordnung.class, | 294 Ortszuordnung.class, |
295 ((LOrtszuordnung)response.getData()).getId(), "land"); | 295 ((Ortszuordnung)response.getData()).getId(), "land"); |
296 if(violation.hasWarnings()) { | 296 if(violation.hasWarnings()) { |
297 updated.setWarnings(violation.getWarnings()); | 297 updated.setWarnings(violation.getWarnings()); |
298 } | 298 } |
299 | 299 |
300 return authorization.filter( | 300 return authorization.filter( |
301 request, | 301 request, |
302 updated, | 302 updated, |
303 LOrtszuordnung.class); | 303 Ortszuordnung.class); |
304 } | 304 } |
305 | 305 |
306 /** | 306 /** |
307 * Delete an existing Ort object by id. | 307 * Delete an existing Ort object by id. |
308 * <p> | 308 * <p> |
319 @Context HttpHeaders headers, | 319 @Context HttpHeaders headers, |
320 @Context HttpServletRequest request, | 320 @Context HttpServletRequest request, |
321 @PathParam("id") String id | 321 @PathParam("id") String id |
322 ) { | 322 ) { |
323 Response object = | 323 Response object = |
324 defaultRepo.getById(LOrtszuordnung.class, Integer.valueOf(id), "land"); | 324 defaultRepo.getById(Ortszuordnung.class, Integer.valueOf(id), "land"); |
325 LOrtszuordnung ortObj = (LOrtszuordnung)object.getData(); | 325 Ortszuordnung ortObj = (Ortszuordnung)object.getData(); |
326 if (!authorization.isAuthorized( | 326 if (!authorization.isAuthorized( |
327 request, | 327 request, |
328 ortObj, | 328 ortObj, |
329 RequestMethod.PUT, | 329 RequestMethod.PUT, |
330 LOrtszuordnung.class)) { | 330 Ortszuordnung.class)) { |
331 return new Response(false, 699, null); | 331 return new Response(false, 699, null); |
332 } | 332 } |
333 if (lock.isLocked(ortObj)) { | 333 if (lock.isLocked(ortObj)) { |
334 return new Response(false, 697, null); | 334 return new Response(false, 697, null); |
335 } | 335 } |