# HG changeset patch # User Raimund Renkert # Date 1371213849 -7200 # Node ID a7ddd34dd8f934124ba9e3ce0bac10af37219249 # Parent 32f5c27883beec32b5c836d92d6483d382a66b48 New service for LStatus objects. A valid get request contains the follwing parameters: - probe=$PROBEID - messung=$MESSUNGSID diff -r 32f5c27883be -r a7ddd34dd8f9 src/main/java/de/intevation/lada/rest/LStatusService.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/LStatusService.java Fri Jun 14 14:44:09 2013 +0200 @@ -0,0 +1,93 @@ +package de.intevation.lada.rest; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.inject.Named; +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.Repository; +import de.intevation.lada.model.LStatus; + +/** + * This class produces a RESTful service to read the contents of + * l_status table. + * + * @author Raimund Renkert + */ +@Path("/status") +@RequestScoped +public class LStatusService +{ + /** + * The Repository for SUmwelt. + */ + @Inject + @Named("lstatusrepository") + private Repository repository; + + /** + * Request a LStatus via its id. + * + * @param id The LStatus id + * @return JSON Object via REST service. + */ + @GET + @Path("/{id}") + @Produces("text/json") + public Response findById(@PathParam("id") String id) { + return repository.findById(LStatus.class, id); + } + + /** + * Request LStatus via a filter. + * + * Query parameters are used for the filter in form of key-value pairs. + * + * @param info The URL query parameters. + * @return JSON Object via Rest service. + */ + @GET + @Produces("text/json") + public Response filter(@Context UriInfo info) { + MultivaluedMap params = info.getQueryParameters(); + if (params.isEmpty()) { + return new Response(false, 609, new ArrayList()); + } + Map filter = new HashMap(); + if (!params.containsKey("probe") || !params.containsKey("messung")) { + return new Response(false, 609, new ArrayList()); + } + for (String key: params.keySet()) { + filter.put(key, params.getFirst(key)); + } + + return repository.filter(filter); + } + + @PUT + @Produces("text/json") + @Consumes("application/json") + public Response update(LStatus status) { + return repository.update(status); + } + + @POST + @Produces("text/json") + @Consumes("application/json") + public Response create(LStatus status) { + return repository.create(status); + } +}