Mercurial > lada > lada-server
annotate src/main/java/de/intevation/lada/rest/KommentarPService.java @ 1034:61354a9fa58d schema-update
Make dynamic inserts on probe and messung objects to avoid 'not null'-constraint error.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 31 Aug 2016 15:50:54 +0200 |
parents | 1c41c7b8f7c2 |
children | 3a5a9a0492d1 |
rev | line source |
---|---|
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 * |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 */ |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.lada.rest; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import javax.enterprise.context.RequestScoped; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 import javax.inject.Inject; |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
12 import javax.servlet.http.HttpServletRequest; |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
13 import javax.ws.rs.DELETE; |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 import javax.ws.rs.GET; |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
15 import javax.ws.rs.POST; |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
16 import javax.ws.rs.PUT; |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 import javax.ws.rs.Path; |
469
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
18 import javax.ws.rs.PathParam; |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 import javax.ws.rs.Produces; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 import javax.ws.rs.core.Context; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 import javax.ws.rs.core.HttpHeaders; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 import javax.ws.rs.core.MediaType; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 import javax.ws.rs.core.MultivaluedMap; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 import javax.ws.rs.core.UriInfo; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 import org.apache.log4j.Logger; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
28 import de.intevation.lada.model.land.KommentarP; |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 import de.intevation.lada.util.annotation.AuthorizationConfig; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 import de.intevation.lada.util.annotation.RepositoryConfig; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 import de.intevation.lada.util.auth.Authorization; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 import de.intevation.lada.util.auth.AuthorizationType; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 import de.intevation.lada.util.data.QueryBuilder; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 import de.intevation.lada.util.data.Repository; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 import de.intevation.lada.util.data.RepositoryType; |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
36 import de.intevation.lada.util.rest.RequestMethod; |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 import de.intevation.lada.util.rest.Response; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
39 /** |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
40 * REST service to operate on KommentarP objects. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
41 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
42 * The services produce data in the application/json media type. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
43 * All HTTP methods use the authorization module to determine if the user is |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
44 * allowed to perform the requested action. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
45 * A typical response holds information about the action performed and the data. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
46 * <pre> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
47 * <code> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
48 * { |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
49 * "success": [boolean], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
50 * "message": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
51 * "data":[{ |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
52 * "datum": [timestamp], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
53 * "erzeuger": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
54 * "id": [number], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
55 * "text": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
56 * "probeId": [number], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
57 * "owner": [boolean], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
58 * "readonly": [boolean] |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
59 * }], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
60 * "errors": [object], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
61 * "warnings": [object], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
62 * "readonly": [boolean], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
63 * "totalCount": [number] |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
64 * } |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
65 * </code> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
66 * </pre> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
67 * |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
68 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
69 */ |
827
5bdd1631a451
!!!CAUTION!!! changed services path!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
722
diff
changeset
|
70 @Path("rest/pkommentar") |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
71 @RequestScoped |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
72 public class KommentarPService { |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
73 |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
74 /** |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
75 * The logger used in this class. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
76 */ |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
77 @Inject |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
78 private Logger logger; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
79 |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
80 /** |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
81 * The data repository granting read/write access. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
82 */ |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
83 @Inject |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
84 @RepositoryConfig(type=RepositoryType.RW) |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
85 private Repository defaultRepo; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
86 |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
87 /** |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
88 * The authorization module. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
89 */ |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
90 @Inject |
722
c81881dac97e
Switch to shibboleth authorization in all REST-services.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
627
diff
changeset
|
91 @AuthorizationConfig(type=AuthorizationType.HEADER) |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
92 private Authorization authorization; |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
93 |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
94 /** |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
95 * Get all KommentarP objects. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
96 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
97 * The requested objects can be filtered using a URL parameter named |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
98 * probeId. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
99 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
100 * Example: http://example.com/pkommentar?probeId=[ID] |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
101 * |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
102 * @return Response object containing all KommentarP objects. |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
103 */ |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
104 @GET |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
105 @Path("/") |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
106 @Produces(MediaType.APPLICATION_JSON) |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
107 public Response get( |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
108 @Context HttpHeaders headers, |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
109 @Context UriInfo info, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
110 @Context HttpServletRequest request |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
111 ) { |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
112 MultivaluedMap<String, String> params = info.getQueryParameters(); |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
113 if (params.isEmpty() || !params.containsKey("probeId")) { |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
114 return defaultRepo.getAll(KommentarP.class, "land"); |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
115 } |
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
116 String probeId = params.getFirst("probeId"); |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
117 QueryBuilder<KommentarP> builder = |
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
118 new QueryBuilder<KommentarP>( |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
119 defaultRepo.entityManager("land"), |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
120 KommentarP.class); |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
121 builder.and("probeId", probeId); |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
122 return authorization.filter( |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
123 request, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
124 defaultRepo.filter(builder.getQuery(), "land"), |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
125 KommentarP.class); |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
126 } |
469
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
127 |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
128 /** |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
129 * Get a single KommentarP object by id. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
130 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
131 * The id is appended to the URL as a path parameter. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
132 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
133 * Example: http://example.com/pkommentar/{id} |
469
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
134 * |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
135 * @return Response object containing a single KommentarP. |
469
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
136 */ |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
137 @GET |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
138 @Path("/{id}") |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
139 @Produces(MediaType.APPLICATION_JSON) |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
140 public Response getById( |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
141 @Context HttpHeaders headers, |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
142 @Context HttpServletRequest request, |
469
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
143 @PathParam("id") String id |
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
144 ) { |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
145 return authorization.filter( |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
146 request, |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
147 defaultRepo.getById(KommentarP.class,Integer.valueOf(id), "land"), |
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
148 KommentarP.class); |
469
d416f0a8277c
Added probekommentar getById service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
467
diff
changeset
|
149 } |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
150 |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
151 /** |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
152 * Create a new KommentarP object. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
153 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
154 * The new object is embedded in the post data as JSON formatted string. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
155 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
156 * <pre> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
157 * <code> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
158 * { |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
159 * "probeId": [number], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
160 * "erzeuger": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
161 * "text": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
162 * "datum": [date], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
163 * "owner": [boolean] |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
164 * } |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
165 * </code> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
166 * </pre> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
167 * |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
168 * @return Response object containing the new KommentarP. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
169 */ |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
170 @POST |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
171 @Path("/") |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
172 @Produces(MediaType.APPLICATION_JSON) |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
173 public Response create( |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
174 @Context HttpHeaders headers, |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
175 @Context HttpServletRequest request, |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
176 KommentarP kommentar |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
177 ) { |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
178 if (!authorization.isAuthorized( |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
179 request, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
180 kommentar, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
181 RequestMethod.POST, |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
182 KommentarP.class) |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
183 ) { |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
184 return new Response(false, 699, null); |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
185 } |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
186 /* Persist the new object*/ |
601
ddab1ecb2898
Use the authorization filter in all REST operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
582
diff
changeset
|
187 return authorization.filter( |
ddab1ecb2898
Use the authorization filter in all REST operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
582
diff
changeset
|
188 request, |
ddab1ecb2898
Use the authorization filter in all REST operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
582
diff
changeset
|
189 defaultRepo.create(kommentar, "land"), |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
190 KommentarP.class); |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
191 } |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
192 |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
193 /** |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
194 * Update an existing KommentarP object. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
195 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
196 * The object to update should come as JSON formatted string. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
197 * <pre> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
198 * <code> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
199 * { |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
200 * "id": [number], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
201 * "owner": [boolean], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
202 * "probeId": [number], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
203 * "erzeuger": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
204 * "text": [string], |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
205 * "datum": [date] |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
206 * } |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
207 * </code> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
208 * </pre> |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
209 * |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
210 * @return Response object containing the updated KommentarP object. |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
211 */ |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
212 @PUT |
557
61ce3ce0100e
Allow /{id} in urls on PUT requests.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
473
diff
changeset
|
213 @Path("/{id}") |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
214 @Produces(MediaType.APPLICATION_JSON) |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
215 public Response update( |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
216 @Context HttpHeaders headers, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
217 @Context HttpServletRequest request, |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
218 KommentarP kommentar |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
219 ) { |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
220 if (!authorization.isAuthorized( |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
221 request, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
222 kommentar, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
223 RequestMethod.PUT, |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
224 KommentarP.class) |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
225 ) { |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
226 logger.debug("User is not authorized!"); |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
227 return new Response(false, 699, null); |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
228 } |
601
ddab1ecb2898
Use the authorization filter in all REST operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
582
diff
changeset
|
229 return authorization.filter( |
ddab1ecb2898
Use the authorization filter in all REST operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
582
diff
changeset
|
230 request, |
ddab1ecb2898
Use the authorization filter in all REST operations.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
582
diff
changeset
|
231 defaultRepo.update(kommentar, "land"), |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
232 KommentarP.class); |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
233 } |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
234 |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
235 /** |
627
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
236 * Delete an existing KommentarP by id. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
237 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
238 * The id is appended to the URL as a path parameter. |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
239 * <p> |
9a6d8c174e78
Code documentation.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
601
diff
changeset
|
240 * Example: http://example.com/pkommentar/{id} |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
241 * |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
242 * @return Response object. |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
243 */ |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
244 @DELETE |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
245 @Path("/{id}") |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
246 @Produces(MediaType.APPLICATION_JSON) |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
247 public Response delete( |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
248 @Context HttpHeaders headers, |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
249 @Context HttpServletRequest request, |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
250 @PathParam("id") String id |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
251 ) { |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
252 /* Get the object by id*/ |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
253 Response kommentar = |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
254 defaultRepo.getById(KommentarP.class, Integer.valueOf(id), "land"); |
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
255 KommentarP kommentarObj = (KommentarP)kommentar.getData(); |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
256 if (!authorization.isAuthorized( |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
257 request, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
258 kommentarObj, |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
259 RequestMethod.DELETE, |
1028
1c41c7b8f7c2
Updated server application to new database model. THIS IS STILL WIP!!!
Raimund Renkert <raimund.renkert@intevation.de>
parents:
827
diff
changeset
|
260 KommentarP.class) |
582
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
261 ) { |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
262 logger.debug("User is not authorized!"); |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
263 return new Response(false, 699, null); |
a04658486ede
Use authentication info for authorization of requested objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
557
diff
changeset
|
264 } |
473
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
265 return defaultRepo.delete(kommentarObj, "land"); |
8d703ac5ad65
Added services for proben kommentar.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
469
diff
changeset
|
266 } |
467
e147de48162a
Added proben kommentar service.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
267 } |