Mercurial > lada > lada-server
annotate src/main/java/de/intevation/lada/rest/LZusatzwertService.java @ 152:53f6d290a559
New service for LZusatzWert objects.
A valid get request contains the following parameter:
- probe=$PROBEID
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 14 Jun 2013 14:11:06 +0200 |
parents | |
children | 0474c86a2f4a |
rev | line source |
---|---|
152
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.lada.rest; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 import java.util.HashMap; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 import java.util.Map; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
6 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import javax.enterprise.context.RequestScoped; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 import javax.inject.Inject; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
9 import javax.inject.Named; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
10 import javax.ws.rs.Consumes; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
11 import javax.ws.rs.GET; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
12 import javax.ws.rs.POST; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 import javax.ws.rs.PUT; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 import javax.ws.rs.Path; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 import javax.ws.rs.PathParam; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 import javax.ws.rs.Produces; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 import javax.ws.rs.core.Context; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 import javax.ws.rs.core.MultivaluedMap; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
19 import javax.ws.rs.core.UriInfo; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.lada.data.Repository; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.lada.model.LZusatzWert; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 /** |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 * This class produces a RESTful service to read the contents of |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 * l_zusatz_wert table. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 * |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 */ |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 @Path("/zusatzwert") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 @RequestScoped |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 public class LZusatzwertService |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
34 /** |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 * The Repository for SUmwelt. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 */ |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 @Inject |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 @Named("lzusatzwertrepository") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 private Repository repository; |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 /** |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 * Request a LZusatzWert via its id. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 * |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 * @param id The LProbe id |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 * @return JSON Object via REST service. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 */ |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 @GET |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 @Path("/{id}") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 @Produces("text/json") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 public Response findById(@PathParam("id") String id) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 return repository.findById(LZusatzWert.class, id); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 /** |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 * Request LMessert via a filter. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 * |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 * Query parameters are used for the filter in form of key-value pairs. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 * |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 * @param info The URL query parameters. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 * @return JSON Object via Rest service. |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 */ |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 @GET |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 @Produces("text/json") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 public Response filter(@Context UriInfo info) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 MultivaluedMap<String, String> params = info.getQueryParameters(); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 if (params.isEmpty()) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 return new Response(false, 609, new ArrayList<LZusatzWert>()); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 Map<String, String> filter = new HashMap<String, String>(); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 if (!params.containsKey("probe")) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 return new Response(false, 609, new ArrayList<LZusatzWert>()); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
72 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
73 for (String key: params.keySet()) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
74 filter.put(key, params.getFirst(key)); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 return repository.filter(filter); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 @PUT |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 @Produces("text/json") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 @Consumes("application/json") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 public Response update(LZusatzWert zusatzwert) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
84 return repository.update(zusatzwert); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 @POST |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 @Produces("text/json") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 @Consumes("application/json") |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 public Response create(LZusatzWert zusatzwert) { |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 return repository.create(zusatzwert); |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
92 } |
53f6d290a559
New service for LZusatzWert objects.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
93 } |