Mercurial > lada > lada-server
changeset 694:c0da629ba69d
Filter messgroessen by messmethode if mmtId is set.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 08 Jul 2015 09:42:22 +0200 |
parents | ca536cd50120 |
children | b8afbf6c1b5d |
files | src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java |
diffstat | 1 files changed, 33 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java Wed Jul 08 09:41:47 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java Wed Jul 08 09:42:22 2015 +0200 @@ -7,8 +7,12 @@ */ package de.intevation.lada.rest.stamm; +import java.util.ArrayList; +import java.util.List; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; +import javax.persistence.Query; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -16,10 +20,15 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; +import org.apache.log4j.Logger; + import de.intevation.lada.model.stamm.Messgroesse; +import de.intevation.lada.model.stamm.MmtMessgroesse; import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.data.QueryBuilder; import de.intevation.lada.util.data.Repository; import de.intevation.lada.util.data.RepositoryType; import de.intevation.lada.util.rest.Response; @@ -58,6 +67,9 @@ @RequestScoped public class MessgroesseService { + @Inject + private Logger logger = Logger.getLogger(MessgroesseService.class); + /** * The data repository granting read access. */ @@ -79,7 +91,27 @@ @Context HttpHeaders headers, @Context UriInfo info ) { - return defaultRepo.getAll(Messgroesse.class, "stamm"); + MultivaluedMap<String, String> params = info.getQueryParameters(); + if (params.isEmpty() || !params.containsKey("mmtId")) { + logger.debug("no filter"); + return defaultRepo.getAll(Messgroesse.class, "stamm"); + } + String mmtId = params.getFirst("mmtId"); + if (mmtId.length() > 3) { + return new Response(false, 400, "bad request"); + } + + Query query = + defaultRepo.queryFromString( + "select messgroesse_id from mmt_messgroesse where mmt_id = '" + + mmtId + "'", "stamm"); + List<Integer> ids = query.getResultList(); + QueryBuilder<Messgroesse> builder2 = + new QueryBuilder<Messgroesse>( + defaultRepo.entityManager("stamm"), + Messgroesse.class); + builder2.orIntList("id", ids); + return defaultRepo.filter(builder2.getQuery(), "stamm"); } /**