Mercurial > lada > lada-server
changeset 45:a5ee8d69c0b4
Renamed existing rest services and make use of the generic repository.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 24 May 2013 11:53:46 +0200 |
parents | 2d89a04d5ad9 |
children | ff802c5e77f7 |
files | src/main/java/de/intevation/lada/rest/LProbeRESTService.java src/main/java/de/intevation/lada/rest/LProbeService.java src/main/java/de/intevation/lada/rest/SMessstelleRESTService.java src/main/java/de/intevation/lada/rest/SMessstelleService.java src/main/java/de/intevation/lada/rest/SUmweltRESTService.java src/main/java/de/intevation/lada/rest/SUmweltService.java |
diffstat | 6 files changed, 217 insertions(+), 218 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/LProbeRESTService.java Fri May 24 11:51:51 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -package de.intevation.lada.rest; - -import java.util.List; -import java.util.logging.Logger; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.UriInfo; - -import de.intevation.lada.data.LProbeRepository; -import de.intevation.lada.model.LProbe; -import de.intevation.lada.service.LProbeService; - -/** - * This class produces a RESTful service to read the contents of LProbe table. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -@Path("/proben") -@RequestScoped -public class LProbeRESTService { - - /** - * The Repository for LProbe. - */ - @Inject - private LProbeRepository repository; - - /** - * The logger for this class. - */ - @Inject - private Logger log; - - /** - * Request a LProbe via its id. - * - * @param id The LProbe id - * @return JSON Object via REST service. - */ - @GET - @Path("/{id}") - @Produces("text/json") - public LProbe loadById(@PathParam("id") String id) { - return repository.findById(id); - } - - /** - * Request LProbe via a filter. - * - * Query parameters are used for the filter in form of key-value pairs. - * This filter can take the three parameters - * mst=$MSTID (String) - * uwb=$UWBID (String) - * begin=$PROBEENTNAHMEBEGIN (Timestamp) - * - * @param info The URL query parameters. - * @return JSON Object via Rest service. - */ - @GET - @Produces("text/json") - public List<LProbe> filter(@Context UriInfo info) { - MultivaluedMap<String, String> params = info.getQueryParameters(); - if (params.isEmpty()) { - return repository.findAll(); - } - String mstId = ""; - String uwbId = ""; - Long begin = null; - if (params.containsKey("mst")) { - mstId = params.getFirst("mst"); - } - if (params.containsKey("uwb")) { - uwbId = params.getFirst("uwb"); - } - if (params.containsKey("begin")) { - String tmp = params.getFirst("begin"); - try { - begin = Long.valueOf(tmp); - } - catch (NumberFormatException nfe) { - begin = null; - } - } - return repository.filter(mstId, uwbId, begin); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/LProbeService.java Fri May 24 11:53:46 2013 +0200 @@ -0,0 +1,92 @@ +package de.intevation.lada.rest; + +import java.util.List; +import java.util.logging.Logger; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +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.LProbeRepository; +import de.intevation.lada.model.LProbe; + +/** + * This class produces a RESTful service to read the contents of LProbe table. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +@Path("/proben") +@RequestScoped +public class LProbeService { + + /** + * The Repository for LProbe. + */ + @Inject + private LProbeRepository repository; + + /** + * The logger for this class. + */ + @Inject + private Logger log; + + /** + * Request a LProbe via its id. + * + * @param id The LProbe id + * @return JSON Object via REST service. + */ + @GET + @Path("/{id}") + @Produces("text/json") + public LProbe loadById(@PathParam("id") String id) { + return repository.findById(LProbe.class, id); + } + + /** + * Request LProbe via a filter. + * + * Query parameters are used for the filter in form of key-value pairs. + * This filter can take the three parameters + * mst=$MSTID (String) + * uwb=$UWBID (String) + * begin=$PROBEENTNAHMEBEGIN (Timestamp) + * + * @param info The URL query parameters. + * @return JSON Object via Rest service. + */ + @GET + @Produces("text/json") + public List<LProbe> filter(@Context UriInfo info) { + MultivaluedMap<String, String> params = info.getQueryParameters(); + if (params.isEmpty()) { + return repository.findAll(LProbe.class); + } + String mstId = ""; + String uwbId = ""; + Long begin = null; + if (params.containsKey("mst")) { + mstId = params.getFirst("mst"); + } + if (params.containsKey("uwb")) { + uwbId = params.getFirst("uwb"); + } + if (params.containsKey("begin")) { + String tmp = params.getFirst("begin"); + try { + begin = Long.valueOf(tmp); + } + catch (NumberFormatException nfe) { + begin = null; + } + } + return repository.filter(mstId, uwbId, begin); + } +}
--- a/src/main/java/de/intevation/lada/rest/SMessstelleRESTService.java Fri May 24 11:51:51 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -package de.intevation.lada.rest; - -import java.util.List; -import java.util.logging.Logger; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import de.intevation.lada.data.SMessstelleRepository; -import de.intevation.lada.model.SMessStelle; - -/** - * This class produces a RESTful service to read the contents of s_messstelle - * table. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -@Path("/mst") -@RequestScoped -public class SMessstelleRESTService -{ - /** - * The Repository for SMessStelle. - */ - @Inject - private SMessstelleRepository repository; - - /** - * The logger for this class - */ - @Inject - private Logger logger; - - /** - * Request all SMessStelle objects. - * - * @return JSON Object via Rest service - */ - @GET - @Produces("text/json") - public List<SMessStelle> findAll() { - final List<SMessStelle> result = repository.findAll(); - return result; - } - - /** - * Request a single SMessStelle via its id. - * - * @param id The mst_id - * @return JSON Object via REST service. - */ - @GET - @Path("/{id:[0-9][0-9]*}") - @Produces("text/json") - public SMessStelle findById(@PathParam("id") String id) { - return repository.findById(id); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/SMessstelleService.java Fri May 24 11:53:46 2013 +0200 @@ -0,0 +1,63 @@ +package de.intevation.lada.rest; + +import java.util.List; +import java.util.logging.Logger; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import de.intevation.lada.data.Repository; +import de.intevation.lada.model.SMessStelle; +import javax.inject.Named; + +/** + * This class produces a RESTful service to read the contents of s_messstelle + * table. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +@Path("/mst") +@RequestScoped +public class SMessstelleService +{ + /** + * The Repository for SMessStelle. + */ + @Inject @Named + private Repository repository; + + /** + * The logger for this class + */ + @Inject + private Logger logger; + + /** + * Request all SMessStelle objects. + * + * @return JSON Object via Rest service + */ + @GET + @Produces("text/json") + public List<SMessStelle> findAll() { + List<SMessStelle> result = repository.findAll(SMessStelle.class); + return result; + } + + /** + * Request a single SMessStelle via its id. + * + * @param id The mst_id + * @return JSON Object via REST service. + */ + @GET + @Path("/{id}") + @Produces("text/json") + public SMessStelle findById(@PathParam("id") String id) { + return repository.findById(SMessStelle.class, id); + } +}
--- a/src/main/java/de/intevation/lada/rest/SUmweltRESTService.java Fri May 24 11:51:51 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -package de.intevation.lada.rest; - -import java.util.List; -import java.util.logging.Logger; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import de.intevation.lada.data.SUmweltRepository; -import de.intevation.lada.model.SUmwelt; - -/** - * This class produces a RESTful service to read the contents of s_umwelt table. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -@Path("/uwb") -@RequestScoped -public class SUmweltRESTService { - - /** - * The Repository for SUmwelt. - */ - @Inject - private SUmweltRepository repository; - - /** - * The logger for this class. - */ - @Inject - private Logger log; - - /** - * Request all SUmwelt objects. - * - * @return JSON Object via Rest service - */ - @GET - @Produces("text/json") - public List<SUmwelt> findAll() { - final List<SUmwelt> result = repository.findAll(); - return result; - } - - /** - * Request a SUmwelt object via its id. - * - * @param id The SUmwelt id - * @return JSON Object via REST service. - */ - @GET - @Path("/{id:[0-9][0-9]*}") - @Produces("text/json") - public SUmwelt loadById(@PathParam("id") String id) { - return repository.findById(id); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/rest/SUmweltService.java Fri May 24 11:53:46 2013 +0200 @@ -0,0 +1,62 @@ +package de.intevation.lada.rest; + +import java.util.List; +import java.util.logging.Logger; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import de.intevation.lada.data.Repository; +import de.intevation.lada.model.SUmwelt; +import javax.inject.Named; + +/** + * This class produces a RESTful service to read the contents of s_umwelt table. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +@Path("/uwb") +@RequestScoped +public class SUmweltService { + + /** + * The Repository for SUmwelt. + */ + @Inject @Named + private Repository repository; + + /** + * The logger for this class. + */ + @Inject + private Logger log; + + /** + * Request all SUmwelt objects. + * + * @return JSON Object via Rest service + */ + @GET + @Produces("text/json") + public List<SUmwelt> findAll() { + List<SUmwelt> result = repository.findAll(SUmwelt.class); + return result; + } + + /** + * Request a SUmwelt object via its id. + * + * @param id The SUmwelt id + * @return JSON Object via REST service. + */ + @GET + @Path("/{id:[0-9][0-9]*}") + @Produces("text/json") + public SUmwelt loadById(@PathParam("id") String id) { + return repository.findById(SUmwelt.class, id); + } +}