comparison src/main/java/de/intevation/lada/rest/LMesswertService.java @ 147:2dd2c36a3b32

New Service for LMesswert objects. A valid request for getting objects contains the URL-parameters - probe=$PROBEID - messung=$MESSUNGSID
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 14 Jun 2013 10:38:28 +0200
parents
children a2e04ab2cd44
comparison
equal deleted inserted replaced
146:0a9bbc93d4e9 147:2dd2c36a3b32
1 package de.intevation.lada.rest;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import javax.enterprise.context.RequestScoped;
8 import javax.inject.Inject;
9 import javax.inject.Named;
10 import javax.ws.rs.Consumes;
11 import javax.ws.rs.GET;
12 import javax.ws.rs.POST;
13 import javax.ws.rs.PUT;
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.Repository;
22 import de.intevation.lada.model.LMesswert;
23
24 /**
25 * This class produces a RESTful service to read the contents of
26 * l_messert table.
27 *
28 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
29 */
30 @Path("/messwert")
31 @RequestScoped
32 public class LMesswertService
33 {
34 /**
35 * The Repository for SUmwelt.
36 */
37 @Inject
38 @Named("lmesswertrepository")
39 private Repository repository;
40
41 /**
42 * Request a LProbe via its id.
43 *
44 * @param id The LProbe id
45 * @return JSON Object via REST service.
46 */
47 @GET
48 @Path("/{id}")
49 @Produces("text/json")
50 public Response findById(@PathParam("id") String id) {
51 return repository.findById(LMesswert.class, id);
52 }
53
54 /**
55 * Request LMessert via a filter.
56 *
57 * Query parameters are used for the filter in form of key-value pairs.
58 *
59 * @param info The URL query parameters.
60 * @return JSON Object via Rest service.
61 */
62 @GET
63 @Produces("text/json")
64 public Response filter(@Context UriInfo info) {
65 MultivaluedMap<String, String> params = info.getQueryParameters();
66 if (params.isEmpty()) {
67 return new Response(false, 609, new ArrayList<LMesswert>());
68 }
69 Map<String, String> filter = new HashMap<String, String>();
70 if (!params.containsKey("probe") || !params.containsKey("messung")) {
71 return new Response(false, 609, new ArrayList<LMesswert>());
72 }
73 for (String key: params.keySet()) {
74 filter.put(key, params.getFirst(key));
75 }
76
77 return repository.filter(filter);
78 }
79
80 @PUT
81 @Produces("text/json")
82 @Consumes("application/json")
83 public Response update(LMesswert messwert) {
84 return repository.update(messwert);
85 }
86
87 @POST
88 @Produces("text/json")
89 @Consumes("application/json")
90 public Response create(LMesswert messwert) {
91 return repository.create(messwert);
92 }
93 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)