Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/stamm/DatensatzErzeugerService.java @ 836:313bd1d227f1
Added services for stammdaten and updated models.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Jan 2016 12:10:09 +0100 |
parents | |
children | 670f58112734 |
comparison
equal
deleted
inserted
replaced
835:075f511243d5 | 836:313bd1d227f1 |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 package de.intevation.lada.rest.stamm; | |
9 | |
10 import javax.enterprise.context.RequestScoped; | |
11 import javax.inject.Inject; | |
12 import javax.servlet.http.HttpServletRequest; | |
13 import javax.ws.rs.DELETE; | |
14 import javax.ws.rs.GET; | |
15 import javax.ws.rs.POST; | |
16 import javax.ws.rs.PUT; | |
17 import javax.ws.rs.Path; | |
18 import javax.ws.rs.PathParam; | |
19 import javax.ws.rs.Produces; | |
20 import javax.ws.rs.core.Context; | |
21 import javax.ws.rs.core.HttpHeaders; | |
22 import javax.ws.rs.core.MediaType; | |
23 import javax.ws.rs.core.UriInfo; | |
24 | |
25 import de.intevation.lada.model.stamm.DatensatzErzeuger; | |
26 import de.intevation.lada.util.annotation.AuthorizationConfig; | |
27 import de.intevation.lada.util.annotation.RepositoryConfig; | |
28 import de.intevation.lada.util.auth.Authorization; | |
29 import de.intevation.lada.util.auth.AuthorizationType; | |
30 import de.intevation.lada.util.data.Repository; | |
31 import de.intevation.lada.util.data.RepositoryType; | |
32 import de.intevation.lada.util.rest.RequestMethod; | |
33 import de.intevation.lada.util.rest.Response; | |
34 | |
35 /** | |
36 * REST service for DatensatzErzeuger objects. | |
37 * <p> | |
38 * The services produce data in the application/json media type. | |
39 * A typical response holds information about the action performed and the data. | |
40 * <pre> | |
41 * <code> | |
42 * { | |
43 * "success": [boolean]; | |
44 * "message": [string], | |
45 * "data":[{ | |
46 * "id": [number], | |
47 * "bezeichnung": [string], | |
48 * "daErzeugerId": [string], | |
49 * "letzteAenderung": [timestamp], | |
50 * "mstId": [string], | |
51 * "netzbetreiberId": [string] | |
52 * }], | |
53 * "errors": [object], | |
54 * "warnings": [object], | |
55 * "readonly": [boolean], | |
56 * "totalCount": [number] | |
57 * } | |
58 * </code> | |
59 * </pre> | |
60 * | |
61 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> | |
62 */ | |
63 @Path("rest/datensatzerzeuger") | |
64 @RequestScoped | |
65 public class DatensatzErzeugerService { | |
66 | |
67 /** | |
68 * The data repository granting read access. | |
69 */ | |
70 @Inject | |
71 @RepositoryConfig(type=RepositoryType.RW) | |
72 private Repository repository; | |
73 | |
74 @Inject | |
75 @AuthorizationConfig(type=AuthorizationType.HEADER) | |
76 private Authorization authorization; | |
77 | |
78 /** | |
79 * Get all Datenbasis objects. | |
80 * <p> | |
81 * Example: http://example.com/datenbasis | |
82 * | |
83 * @return Response object containing all Datenbasis objects. | |
84 */ | |
85 @GET | |
86 @Path("/") | |
87 @Produces(MediaType.APPLICATION_JSON) | |
88 public Response get( | |
89 @Context HttpHeaders headers, | |
90 @Context UriInfo info | |
91 ) { | |
92 return repository.getAll(DatensatzErzeuger.class, "stamm"); | |
93 } | |
94 | |
95 /** | |
96 * Get a single Datenbasis object by id. | |
97 * <p> | |
98 * The id is appended to the URL as a path parameter. | |
99 * <p> | |
100 * Example: http://example.com/datenbasis/{id} | |
101 * | |
102 * @return Response object containing a single Datenabasis. | |
103 */ | |
104 @GET | |
105 @Path("/{id}") | |
106 @Produces(MediaType.APPLICATION_JSON) | |
107 public Response getById( | |
108 @Context HttpHeaders headers, | |
109 @PathParam("id") String id | |
110 ) { | |
111 return repository.getById( | |
112 DatensatzErzeuger.class, | |
113 Integer.valueOf(id), | |
114 "stamm"); | |
115 } | |
116 | |
117 @POST | |
118 @Path("/") | |
119 @Produces(MediaType.APPLICATION_JSON) | |
120 public Response create( | |
121 @Context HttpServletRequest request, | |
122 DatensatzErzeuger datensatzerzeuger | |
123 ) { | |
124 if (!authorization.isAuthorized( | |
125 request, | |
126 datensatzerzeuger, | |
127 RequestMethod.POST, | |
128 DatensatzErzeuger.class) | |
129 ) { | |
130 return new Response(false, 699, datensatzerzeuger); | |
131 } | |
132 | |
133 return repository.create(datensatzerzeuger, "stamm"); | |
134 } | |
135 | |
136 @PUT | |
137 @Path("/{id}") | |
138 @Produces(MediaType.APPLICATION_JSON) | |
139 public Response update( | |
140 @Context HttpServletRequest request, | |
141 DatensatzErzeuger datensatzerzeuger | |
142 ) { | |
143 if (!authorization.isAuthorized( | |
144 request, | |
145 datensatzerzeuger, | |
146 RequestMethod.PUT, | |
147 DatensatzErzeuger.class) | |
148 ) { | |
149 return new Response(false, 699, datensatzerzeuger); | |
150 } | |
151 | |
152 return repository.update(datensatzerzeuger, "stamm"); | |
153 } | |
154 | |
155 @DELETE | |
156 @Path("/{id}") | |
157 @Produces(MediaType.APPLICATION_JSON) | |
158 public Response delete( | |
159 @Context HttpServletRequest request, | |
160 @PathParam("id") String id | |
161 ) { | |
162 DatensatzErzeuger datensatzerzeuger = repository.getByIdPlain( | |
163 DatensatzErzeuger.class, Integer.valueOf(id), "stamm"); | |
164 if (datensatzerzeuger == null || | |
165 !authorization.isAuthorized( | |
166 request, | |
167 datensatzerzeuger, | |
168 RequestMethod.DELETE, | |
169 DatensatzErzeuger.class | |
170 ) | |
171 ) { | |
172 return new Response(false, 699, null); | |
173 } | |
174 return repository.delete(datensatzerzeuger, "stamm"); | |
175 } | |
176 } |