annotate src/main/java/de/intevation/lada/rest/stamm/OrtService.java @ 919:e5a9c27047a4

Updated stammdaten services: allow multiselect filters and check duplicates before update or insert
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 13 Apr 2016 17:37:12 +0200
parents 2ce24e2baf20
children 539eb174bf23
rev   line source
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 *
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU GPL (v>=3)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 * the documentation coming with IMIS-Labordaten-Application for details.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 package de.intevation.lada.rest.stamm;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9
843
670f58112734 Allow paging for editable stammdaten and set readonly attribute.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 837
diff changeset
10 import java.util.List;
670f58112734 Allow paging for editable stammdaten and set readonly attribute.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 837
diff changeset
11
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import javax.enterprise.context.RequestScoped;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import javax.inject.Inject;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import javax.servlet.http.HttpServletRequest;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import javax.ws.rs.DELETE;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import javax.ws.rs.GET;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import javax.ws.rs.POST;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import javax.ws.rs.PUT;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import javax.ws.rs.Path;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import javax.ws.rs.PathParam;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import javax.ws.rs.Produces;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 import javax.ws.rs.core.Context;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 import javax.ws.rs.core.HttpHeaders;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 import javax.ws.rs.core.MediaType;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 import javax.ws.rs.core.MultivaluedMap;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 import javax.ws.rs.core.UriInfo;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
28 import de.intevation.lada.model.stamm.Filter;
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 import de.intevation.lada.model.stamm.Ort;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 import de.intevation.lada.util.annotation.AuthorizationConfig;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 import de.intevation.lada.util.annotation.RepositoryConfig;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 import de.intevation.lada.util.auth.Authorization;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 import de.intevation.lada.util.auth.AuthorizationType;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 import de.intevation.lada.util.data.QueryBuilder;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 import de.intevation.lada.util.data.Repository;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 import de.intevation.lada.util.data.RepositoryType;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 import de.intevation.lada.util.rest.RequestMethod;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 import de.intevation.lada.util.rest.Response;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 * REST service for SOrt objects.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 * The services produce data in the application/json media type.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 * A typical response holds information about the action performed and the data.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 * <pre>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 * <code>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 * {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 * "success": [boolean];
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 * "message": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 * "data":[{
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 * "id": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 * "beschreibung": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 * "bezeichnung": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 * "hoeheLand": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 * "koordXExtern": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 * "koordYExtern": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 * "latitude": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 * "letzteAenderung": [timestamp],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 * "longitude": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 * "nutsCode": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 * "unscharf": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 * "koordinatenartId": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 * "netzbetreiberId": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 * "staatId": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 * "verwaltungseinheitId": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 * "otyp": [string]
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 * }],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 * "errors": [object],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 * "warnings": [object],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 * "readonly": [boolean],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 * "totalCount": [number]
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 * }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 * </code>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 * </pre>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 *
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 @Path("rest/ort")
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 @RequestScoped
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 public class OrtService {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 * The data repository granting read/write access.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 @Inject
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 @RepositoryConfig(type=RepositoryType.RW)
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
87 private Repository repository;
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 @Inject
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 @AuthorizationConfig(type=AuthorizationType.HEADER)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 private Authorization authorization;
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 * Get all SOrt objects.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 * The requested objects can be filtered using a URL parameter named
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 * ortId.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 * Example: http://example.com/location?ortId=[ID]
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 *
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 * @return Response object containing all (filtered) SOrt objects.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 @GET
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 @Path("/")
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 @Produces(MediaType.APPLICATION_JSON)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 public Response get(
843
670f58112734 Allow paging for editable stammdaten and set readonly attribute.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 837
diff changeset
107 @Context HttpServletRequest request,
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 @Context UriInfo info
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 MultivaluedMap<String, String> params = info.getQueryParameters();
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
111 List<Ort> orte = repository.getAllPlain(Ort.class, "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
112 if (params.containsKey("ortId")) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
113 Integer id;
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
114 try {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
115 id = Integer.valueOf(params.getFirst("qid"));
843
670f58112734 Allow paging for editable stammdaten and set readonly attribute.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 837
diff changeset
116 }
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
117 catch (NumberFormatException e) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
118 return new Response(false, 603, "Not a valid filter id");
843
670f58112734 Allow paging for editable stammdaten and set readonly attribute.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 837
diff changeset
119 }
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
120
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
121 Ort o = repository.getByIdPlain(Ort.class, id, "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
122 o.setReadonly(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
123 !authorization.isAuthorized(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
124 request,
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
125 o,
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
126 RequestMethod.POST,
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
127 Ort.class));
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
128 return new Response(true, 200, o);
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 }
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
130 if (params.containsKey("qid")) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
131 Integer id = null;
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
132 try {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
133 id = Integer.valueOf(params.getFirst("qid"));
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
134 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
135 catch (NumberFormatException e) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
136 return new Response(false, 603, "Not a valid filter id");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
137 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
138 QueryBuilder<Filter> fBuilder = new QueryBuilder<Filter>(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
139 repository.entityManager("stamm"),
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
140 Filter.class
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
141 );
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
142 fBuilder.and("query", id);
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
143 List<Filter> filters = repository.filterPlain(fBuilder.getQuery(), "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
144 QueryBuilder<Ort> builder =
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
145 new QueryBuilder<Ort>(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
146 repository.entityManager("stamm"),
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
147 Ort.class
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
148 );
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
149 for (Filter filter: filters) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
150 String param = params.get(filter.getDataIndex()).get(0);
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
151 if (param == null || param.isEmpty()) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
152 continue;
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
153 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
154 if (filter.getMultiselect()) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
155 param = param.trim();
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
156 String[] parts = param.split(",");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
157 for (String part: parts) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
158 builder.or(filter.getDataIndex(), part);
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
159 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
160 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
161 else {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
162 builder.or(filter.getDataIndex(), param);
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
163 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
164 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
165
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
166 orte = repository.filterPlain(builder.getQuery(), "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
167 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
168
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
169 int size = orte.size();
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
170 if (params.containsKey("start") && params.containsKey("limit")) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
171 int start = Integer.valueOf(params.getFirst("start"));
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
172 int limit = Integer.valueOf(params.getFirst("limit"));
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
173 int end = limit + start;
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
174 if (limit == 0) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
175 end = orte.size();
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
176 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
177 else if (start + limit > orte.size()) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
178 end = orte.size();
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
179 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
180 orte = orte.subList(start, end);
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
181 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
182 for (Ort o : orte) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
183 o.setReadonly(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
184 !authorization.isAuthorized(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
185 request,
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
186 o,
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
187 RequestMethod.POST,
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
188 Ort.class));
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
189 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
190 return new Response(true, 200, orte, size);
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191 }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
193 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
194 * Get a single SOrt object by id.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196 * The id is appended to the URL as a path parameter.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 * Example: http://example.com/location/{id}
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199 *
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200 * @return Response object containing a single SOrt.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 @GET
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
203 @Path("/{id}")
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 @Produces(MediaType.APPLICATION_JSON)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
205 public Response getById(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
206 @Context HttpHeaders headers,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
207 @PathParam("id") String id
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
208 ) {
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
209 return repository.getById(
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
210 Ort.class,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
211 Integer.valueOf(id),
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
212 "stamm");
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
213 }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
214
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
215 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
216 * Create a SOrt object.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
217 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
218 * The new object is embedded in the post data as JSON formatted string.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
219 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
220 * <pre>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
221 * <code>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
222 * {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
223 * "bezeichnung": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
224 * "beschreibung": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
225 * "unscharf": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
226 * "nutsCode": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
227 * "koordXExtern": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
228 * "koordYExtern": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
229 * "hoeheLand": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
230 * "longitude": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
231 * "latitude": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
232 * "staatId": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
233 * "verwaltungseinheitId": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
234 * "otyp": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
235 * "letzteAenderung": [date]
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
236 * }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
237 * </code>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
238 * </pre>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
239 * @return A response object containing the created SOrt.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
240 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
241 @POST
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
242 @Path("/")
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
243 @Produces(MediaType.APPLICATION_JSON)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
244 public Response create(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
245 @Context HttpServletRequest request,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
246 Ort ort
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
247 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
248 if (!authorization.isAuthorized(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
249 request,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
250 ort,
837
9dd9a3de7a61 Fixed request methods.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 836
diff changeset
251 RequestMethod.POST,
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
252 Ort.class)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
253 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
254 return new Response(false, 699, ort);
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
255 }
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
256 QueryBuilder<Ort> builder =
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
257 new QueryBuilder<Ort>(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
258 repository.entityManager("stamm"),
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
259 Ort.class
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
260 );
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
261 builder.and("ortId", ort.getOrtId());
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
262 builder.and("netzbetreiberId", ort.getNetzbetreiberId());
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
263
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
264 List<Ort> orte =
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
265 repository.filterPlain(builder.getQuery(), "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
266 if (orte.isEmpty() ||
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
267 orte.get(0).getId() == ort.getId()) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
268 return repository.create(ort, "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
269 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
270 return new Response(false, 672, null);
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
271 }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
272
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
273 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
274 * Update an existing SOrt object.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
275 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
276 * The object to update should come as JSON formatted string.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
277 * <pre>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
278 * <code>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
279 * {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
280 * "id": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
281 * "bezeichnung": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
282 * "beschreibung": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
283 * "unscharf": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
284 * "nutsCode": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
285 * "koordXExtern": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
286 * "koordYExtern": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
287 * "hoeheLand": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
288 * "longitude": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
289 * "latitude": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
290 * "staatId": [number],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
291 * "verwaltungseinheitId": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
292 * "otyp": [string],
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
293 * "letzteAenderung": [date]
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
294 * }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
295 * </code>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
296 * </pre>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
297 *
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
298 * @return Response object containing the updated SOrt object.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
299 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
300 @PUT
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
301 @Path("/{id}")
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
302 @Produces(MediaType.APPLICATION_JSON)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
303 public Response update(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
304 @Context HttpServletRequest request,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
305 Ort ort
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
306 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
307 if (!authorization.isAuthorized(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
308 request,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
309 ort,
837
9dd9a3de7a61 Fixed request methods.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 836
diff changeset
310 RequestMethod.PUT,
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
311 Ort.class)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
312 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
313 return new Response(false, 699, ort);
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
314 }
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
315 QueryBuilder<Ort> builder =
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
316 new QueryBuilder<Ort>(
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
317 repository.entityManager("stamm"),
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
318 Ort.class
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
319 );
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
320 builder.and("ortId", ort.getOrtId());
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
321 builder.and("netzbetreiberId", ort.getNetzbetreiberId());
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
322
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
323 List<Ort> orte =
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
324 repository.filterPlain(builder.getQuery(), "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
325 if (orte.isEmpty() ||
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
326 orte.get(0).getId() == ort.getId()) {
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
327 return repository.update(ort, "stamm");
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
328 }
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
329 return new Response(false, 672, null);
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
330 }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
331
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
332 /**
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
333 * Delete an existing SOrt object by id.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
334 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
335 * The id is appended to the URL as a path parameter.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
336 * <p>
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
337 * Example: http://example.com/location/{id}
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
338 *
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
339 * @return Response object.
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
340 */
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
341 @DELETE
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
342 @Path("/{id}")
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
343 @Produces(MediaType.APPLICATION_JSON)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
344 public Response delete(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
345 @Context HttpServletRequest request,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
346 @PathParam("id") String id
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
347 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
348 /* Get the object by id*/
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
349 Ort ort =
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
350 repository.getByIdPlain(Ort.class, Integer.valueOf(id), "stamm");
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
351 if (!authorization.isAuthorized(
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
352 request,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
353 ort,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
354 RequestMethod.DELETE,
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
355 Ort.class)
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
356 ) {
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
357 return new Response(false, 699, ort);
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
358 }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
359 /* Delete the object*/
919
e5a9c27047a4 Updated stammdaten services: allow multiselect filters and check duplicates
Raimund Renkert <raimund.renkert@intevation.de>
parents: 853
diff changeset
360 return repository.delete(ort, "stamm");
836
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
361 }
313bd1d227f1 Added services for stammdaten and updated models.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
362 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)