Mercurial > lada > lada-server
changeset 129:dbb7064c1290
New service for LMessung. Provides GET(all, filter by 'probe'), POST(create) and PUT(update).
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 13 Jun 2013 09:30:12 +0200 |
parents | 4b7784416090 |
children | 7ea3ea59e971 |
files | src/main/java/de/intevation/lada/rest/LMessungService.java |
diffstat | 1 files changed, 85 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/LMessungService.java Thu Jun 13 09:30:12 2013 +0200 @@ -0,0 +1,85 @@ +package de.intevation.lada.rest; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.UriInfo; + +import de.intevation.lada.data.LMessungRepository; +import de.intevation.lada.model.LMessung; + +/** +* This class produces a RESTful service to read the contents of LProbe table. +* +* @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> +*/ +@Path("/messung") +@RequestScoped +public class LMessungService +{ + /** + * The Repository for LMessung. + */ + @Inject + private LMessungRepository repository; + + /** + * Request a LMessung via its id. + * + * @param id The LMessung id + * @return JSON Object via REST service. + */ + @GET + @Path("/{id}") + @Produces("text/json") + public Response findById(@PathParam("id") String id) { + return repository.findById(LMessung.class, id); + } + + /** + * Request LMessung via a filter. + * + * Query parameters are used for the filter in form of key-value pairs. + * This filter can take the three parameters + * probe=$PROBEID (String) + * + * @param info The URL query parameters. + * @return JSON Object via Rest service. + */ + @GET + @Produces("text/json") + public Response filter(@Context UriInfo info) { + MultivaluedMap<String, String> params = info.getQueryParameters(); + if (params.isEmpty()) { + return repository.findAll(LMessung.class); + } + String probeId = ""; + if (params.containsKey("probe")) { + probeId = params.getFirst("probe"); + } + return repository.filter(probeId); + } + + @PUT + @Path("/{id}") + @Produces("text/json") + @Consumes("application/json") + public Response update(LMessung messung) { + return repository.update(messung); + } + + @POST + @Produces("text/json") + @Consumes("application/json") + public Response create(LMessung messung) { + return repository.create(messung); + } +}