[Lada-commits] [PATCH 07 of 11] Allow parameter 'ortId' to filter locations

Wald Commits scm-commit at wald.intevation.org
Fri Mar 13 16:50:46 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1426261672 -3600
# Node ID fffee95c4cb621ca47545e34b052aaec34c16c00
# Parent  20016be6c07236a0565bfc9d0f2777e06a7a2acb
Allow parameter 'ortId' to filter locations.

diff -r 20016be6c072 -r fffee95c4cb6 src/main/java/de/intevation/lada/rest/stamm/LocationService.java
--- a/src/main/java/de/intevation/lada/rest/stamm/LocationService.java	Fri Mar 13 16:47:21 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/LocationService.java	Fri Mar 13 16:47:52 2015 +0100
@@ -19,6 +19,7 @@
 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;
@@ -31,6 +32,7 @@
 import de.intevation.lada.util.auth.AuthenticationType;
 import de.intevation.lada.util.auth.Authorization;
 import de.intevation.lada.util.auth.AuthorizationType;
+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;
@@ -74,7 +76,17 @@
             logger.debug("User is not authenticated!");
             return new Response(false, 699, null);
         }
-        return defaultRepo.getAll(SOrt.class, "stamm");
+        MultivaluedMap<String, String> params = info.getQueryParameters();
+        if (params.isEmpty() || !params.containsKey("ortId")) {
+            return defaultRepo.getAll(SOrt.class, "stamm");
+        }
+        String probeId = params.getFirst("ortId");
+        QueryBuilder<SOrt> builder =
+            new QueryBuilder<SOrt>(
+                defaultRepo.entityManager("land"),
+                SOrt.class);
+        builder.and("probeId", probeId);
+        return defaultRepo.filter(builder.getQuery(), "stamm");
     }
 
     /**


More information about the Lada-commits mailing list