[Lada-commits] [PATCH 4 of 4] Filter messgroessen by messmethode if mmtId is set
Wald Commits
scm-commit at wald.intevation.org
Wed Jul 8 09:42:33 CEST 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1436341342 -7200
# Node ID c0da629ba69dc5b1eb465fea7c1c8564f06de32a
# Parent ca536cd501207728552b598807005c33ae6ba9f3
Filter messgroessen by messmethode if mmtId is set.
diff -r ca536cd50120 -r c0da629ba69d src/main/java/de/intevation/lada/rest/stamm/MessgroesseService.java
--- 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");
}
/**
More information about the Lada-commits
mailing list