Mercurial > lada > lada-server
changeset 139:fda177c59d1f
Updated service and repository to use the extended LProbeInfo object.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 13 Jun 2013 18:28:00 +0200 |
parents | b1846985da6c |
children | 4ff6903306cb |
files | src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/rest/LProbeService.java |
diffstat | 2 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java Thu Jun 13 18:27:24 2013 +0200 +++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java Thu Jun 13 18:28:00 2013 +0200 @@ -47,6 +47,28 @@ @Named("lprobevalidator") private Validator validator; + @Override + public <T> Response findAll(Class<T> clazz) { + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<LProbeInfo> criteria = cb.createQuery(LProbeInfo.class); + Root<LProbeInfo> member = criteria.from(LProbeInfo.class); + criteria.distinct(true); + List<LProbeInfo> result = filter(criteria); + return new Response(true, 200, result); + } + + @Override + public <T> Response findById(Class<T> clazz, String id) { + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery<LProbeInfo> criteria = cb.createQuery(LProbeInfo.class); + Root<LProbeInfo> member = criteria.from(LProbeInfo.class); + Predicate pid = cb.equal(member.get("probeId"), id); + criteria.where(pid); + criteria.distinct(true); + List<LProbeInfo> result = filter(criteria); + return new Response(true, 200, result); + } + /** * Filter for LProbe objects used for calls from a service. * @@ -76,6 +98,7 @@ //ignore filter parameter. } } + criteria.distinct(true); criteria.where(andFilter.toArray(new Predicate[andFilter.size()])); List<LProbeInfo> result = filter(criteria); return new Response(true, 200, result);
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java Thu Jun 13 18:27:24 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LProbeService.java Thu Jun 13 18:28:00 2013 +0200 @@ -20,6 +20,7 @@ import de.intevation.lada.data.Repository; import de.intevation.lada.model.LProbe; +import de.intevation.lada.model.LProbeInfo; /** * This class produces a RESTful service to read the contents of LProbe table. @@ -53,7 +54,7 @@ @Path("/{id}") @Produces("text/json") public Response findById(@PathParam("id") String id) { - return repository.findById(LProbe.class, id); + return repository.findById(LProbeInfo.class, id); } /** @@ -73,7 +74,7 @@ public Response filter(@Context UriInfo info) { MultivaluedMap<String, String> params = info.getQueryParameters(); if (params.isEmpty()) { - return repository.findAll(LProbe.class); + return repository.findAll(LProbeInfo.class); } Map<String, String> filter = new HashMap<String, String>(); for (String key: params.keySet()) {