Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/rest/LKommentarService.java @ 56:9f3e902ce778
Added new entity, repository and service for 'LKommentarP'.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 27 May 2013 15:23:41 +0200 |
parents | |
children | f2c4d8a5f0d6 |
comparison
equal
deleted
inserted
replaced
55:ddcf13f7b6a0 | 56:9f3e902ce778 |
---|---|
1 package de.intevation.lada.rest; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 import java.util.logging.Level; | |
6 import java.util.logging.Logger; | |
7 | |
8 import javax.enterprise.context.RequestScoped; | |
9 import javax.inject.Inject; | |
10 import javax.inject.Named; | |
11 import javax.ws.rs.Consumes; | |
12 import javax.ws.rs.GET; | |
13 import javax.ws.rs.POST; | |
14 import javax.ws.rs.Path; | |
15 import javax.ws.rs.PathParam; | |
16 import javax.ws.rs.Produces; | |
17 import javax.ws.rs.core.Context; | |
18 import javax.ws.rs.core.MultivaluedMap; | |
19 import javax.ws.rs.core.UriInfo; | |
20 | |
21 import de.intevation.lada.data.LKommentarPRepository; | |
22 import de.intevation.lada.model.LKommentarP; | |
23 | |
24 /** | |
25 * This class produces a RESTful service to read the contents of LKommentarP table. | |
26 * | |
27 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> | |
28 */ | |
29 @Path("/kommentar") | |
30 @RequestScoped | |
31 public class LKommentarService | |
32 { | |
33 /** | |
34 * The Repository. | |
35 */ | |
36 @Inject @Named("lkommentarRepository") | |
37 private LKommentarPRepository repository; | |
38 | |
39 /** | |
40 * The logger for this class | |
41 */ | |
42 @Inject | |
43 private Logger logger; | |
44 | |
45 /** | |
46 * Request a single SKommentarP via its id. | |
47 * | |
48 * @param id The mst_id | |
49 * @return JSON Object via REST service. | |
50 */ | |
51 @GET | |
52 @Path("/{id}") | |
53 @Produces("text/json") | |
54 public LKommentarP findById(@PathParam("id") String id) { | |
55 return repository.findById(LKommentarP.class, id); | |
56 } | |
57 | |
58 /** | |
59 * Request a list of LKommentarP objects filtered by LProbe id. | |
60 * | |
61 * @param info The query parameters | |
62 * @return JSON object via REST service. | |
63 */ | |
64 @GET | |
65 @Produces("text/json") | |
66 public List<LKommentarP> filter(@Context UriInfo info) { | |
67 MultivaluedMap<String, String> params = info.getQueryParameters(); | |
68 if (params.isEmpty()) { | |
69 return new ArrayList<LKommentarP>(0); | |
70 } | |
71 if (params.containsKey("probe")) { | |
72 String probe = params.getFirst("probe"); | |
73 return repository.filter(probe); | |
74 } | |
75 else { | |
76 return new ArrayList<LKommentarP>(0); | |
77 } | |
78 } | |
79 | |
80 @POST | |
81 @Path("/create") | |
82 @Consumes("application/json") | |
83 public String create(LKommentarP kommentar) { | |
84 String response = repository.create(kommentar); | |
85 if (response.isEmpty()) { | |
86 return "[{success: true}]"; | |
87 } | |
88 else { | |
89 return "[{success: false," + | |
90 " error: " + response + "}]"; | |
91 } | |
92 } | |
93 } |