changeset 182:a2e04ab2cd44

Use the new filter and query builder and have authentication for LProbeInfo objects.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 27 Jun 2013 15:03:18 +0200
parents bca4bda93a98
children 7043530e0e56
files src/main/java/de/intevation/lada/data/LKommentarMRepository.java src/main/java/de/intevation/lada/data/LKommentarPRepository.java src/main/java/de/intevation/lada/data/LMessungRepository.java src/main/java/de/intevation/lada/data/LMesswertRepository.java src/main/java/de/intevation/lada/data/LOrtRepository.java src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/data/LStatusRepository.java src/main/java/de/intevation/lada/data/LZusatzwertRepository.java src/main/java/de/intevation/lada/data/ReadOnlyRepository.java src/main/java/de/intevation/lada/data/Repository.java src/main/java/de/intevation/lada/rest/LKommentarMService.java src/main/java/de/intevation/lada/rest/LKommentarService.java src/main/java/de/intevation/lada/rest/LMessungService.java src/main/java/de/intevation/lada/rest/LMesswertService.java src/main/java/de/intevation/lada/rest/LOrtService.java src/main/java/de/intevation/lada/rest/LProbeService.java src/main/java/de/intevation/lada/rest/LStatusService.java src/main/java/de/intevation/lada/rest/LZusatzwertService.java src/main/java/de/intevation/lada/validation/LProbeValidator.java
diffstat 19 files changed, 161 insertions(+), 355 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LKommentarMRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LKommentarMRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,19 +1,11 @@
 package de.intevation.lada.data;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 import javax.ejb.EJBTransactionRolledbackException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LKommentarM;
@@ -101,24 +93,4 @@
         }
         return response;
     }
-
-    @Override
-    public Response filter(Map<String, String> filter) {
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LKommentarM> criteria = cb.createQuery(LKommentarM.class);
-        Root<LKommentarM> member = criteria.from(LKommentarM.class);
-        List<Predicate> andFilter = new ArrayList<Predicate>();
-        if (filter.containsKey("probe")) {
-            andFilter.add(cb.equal(member.get("probeId"), filter.get("probe")));
-        }
-        if (filter.containsKey("messung")) {
-            andFilter.add(cb.equal(member.get("messungsId"), filter.get("messung")));
-        }
-        criteria.distinct(true);
-        Predicate ap = cb.and(andFilter.toArray(new Predicate[andFilter.size()]));
-        criteria.where(ap);
-        List<LKommentarM> result = filter(criteria);
-        return new Response(true, 200, result);
-    }
-
 }
--- a/src/main/java/de/intevation/lada/data/LKommentarPRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LKommentarPRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,8 +1,6 @@
 package de.intevation.lada.data;
 
 import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -11,9 +9,6 @@
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LKommentarP;
@@ -37,25 +32,6 @@
     @Inject
     private Logger logger;
 
-    public Response filter(Map<String, String> filter) {
-        if (filter.isEmpty()) {
-            return findAll(LKommentarP.class);
-        }
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LKommentarP> criteria = cb.createQuery(LKommentarP.class);
-        Root<LKommentarP> member = criteria.from(LKommentarP.class);
-        if (filter.containsKey("probe")) {
-            criteria.where(
-                cb.equal(member.get("probeId"), filter.get("probe")));
-        }
-        else {
-            return new Response(false, 600, new ArrayList<LKommentarP>());
-        }
-
-        List<LKommentarP> result = filter(criteria);
-        return new Response(true, 200, result);
-    }
-
     public Response create(Object object) {
         if (!(object instanceof LKommentarP)) {
             return new Response(false, 602, object);
--- a/src/main/java/de/intevation/lada/data/LMessungRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LMessungRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,7 +1,5 @@
 package de.intevation.lada.data;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBTransactionRolledbackException;
@@ -10,9 +8,6 @@
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LMessung;
@@ -48,32 +43,6 @@
     private Validator validator;
 
     /**
-     * Filter for LProbe objects used for calls from a service.
-     *
-     * @param mstId mst_id
-     * @param uwbId umw_id
-     * @param begin probeentnahmebegin
-     * @return
-     */
-    public Response filter(Map<String, String> filter) {
-        if (filter.isEmpty()) {
-            return findAll(LMessung.class);
-        }
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LMessung> criteria = cb.createQuery(LMessung.class);
-        Root<LMessung> member = criteria.from(LMessung.class);
-        if (filter.containsKey("probe")) {
-            criteria.where(
-                cb.equal(member.get("LProbeId"), filter.get("probe")));
-        }
-        else {
-            return new Response(false, 600, new ArrayList<LMessung>());
-        }
-        List<LMessung> result = filter(criteria);
-        return new Response(true, 200, result);
-    }
-
-    /**
      * Validate and persist a new LProbe object.
      *
      * @param probe The new LProbe object
--- a/src/main/java/de/intevation/lada/data/LMesswertRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LMesswertRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,19 +1,11 @@
 package de.intevation.lada.data;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 import javax.ejb.EJBTransactionRolledbackException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LMesswert;
@@ -103,24 +95,5 @@
         }
         return response;
     }
+}
 
-    @Override
-    public Response filter(Map<String, String> filter) {
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LMesswert> criteria = cb.createQuery(LMesswert.class);
-        Root<LMesswert> member = criteria.from(LMesswert.class);
-        List<Predicate> andFilter = new ArrayList<Predicate>();
-        if (filter.containsKey("probe")) {
-            andFilter.add(cb.equal(member.get("probeId"), filter.get("probe")));
-        }
-        if (filter.containsKey("messung")) {
-            andFilter.add(cb.equal(member.get("messungsId"), filter.get("messung")));
-        }
-        criteria.distinct(true);
-        Predicate ap = cb.and(andFilter.toArray(new Predicate[andFilter.size()]));
-        criteria.where(ap);
-        List<LMesswert> result = filter(criteria);
-        return new Response(true, 200, result);
-    }
-
-}
--- a/src/main/java/de/intevation/lada/data/LOrtRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LOrtRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,7 +1,5 @@
 package de.intevation.lada.data;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBTransactionRolledbackException;
@@ -10,9 +8,6 @@
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LOrt;
@@ -37,31 +32,6 @@
     @Inject
     @Named("datamanager")
     private Manager manager;
-    /**
-     * Filter for LOrt objects used for calls from a service.
-     *
-     * @param probeId The id of the LProbe object.
-     *
-     * @return Response object containing LOrt objects.
-     */
-    public Response filter(Map<String, String> filter) {
-        if (filter.isEmpty()) {
-            return findAll(LOrt.class);
-        }
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LOrt> criteria = cb.createQuery(LOrt.class);
-        Root<LOrt> member = criteria.from(LOrt.class);
-        if (filter.containsKey("probe")) {
-            criteria.where(
-                cb.equal(member.get("probeId"), filter.get("probe")));
-        }
-        else {
-            return new Response(false, 600, new ArrayList<LOrt>());
-        }
-        List<LOrt> result = filter(criteria);
-
-        return new Response(true, 200, result);
-    }
 
     /**
      * Validate and persist a new LProbe object.
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,7 +1,5 @@
 package de.intevation.lada.data;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 
 import javax.ejb.EJBTransactionRolledbackException;
@@ -10,10 +8,6 @@
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LProbe;
@@ -50,59 +44,19 @@
 
     @Override
     public <T> Response findAll(Class<T> clazz) {
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LProbeInfo> criteria = cb.createQuery(LProbeInfo.class);
-        criteria.distinct(true);
-        List<LProbeInfo> result = filter(criteria);
-        return new Response(true, 200, result);
+        QueryBuilder<LProbeInfo> builder =
+            new QueryBuilder<LProbeInfo>(em, LProbeInfo.class);
+        builder.distinct();
+        return filter(builder.getQuery());
     }
 
     @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.
-     *
-     * @param mstId mst_id
-     * @param uwbId umw_id
-     * @param begin probeentnahmebegin
-     * @return
-     */
-    public Response filter(Map<String, String> filter) {
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LProbeInfo> criteria = cb.createQuery(LProbeInfo.class);
-        Root<LProbeInfo> member = criteria.from(LProbeInfo.class);
-        List<Predicate> andFilter = new ArrayList<Predicate>();
-        if (filter.containsKey("mst")) {
-            andFilter.add(cb.equal(member.get("mstId"), filter.get("mst")));
-        }
-        if (filter.containsKey("uwb")) {
-            andFilter.add(cb.equal(member.get("umwId"), filter.get("uwb")));
-        }
-        if (filter.containsKey("begin")) {
-            try {
-                Long date = Long.getLong(filter.get("begin"));
-                andFilter.add(
-                    cb.equal(member.get("probeentnahmeBeginn"), date));
-            }
-            catch(NumberFormatException nfe) {
-                //ignore filter parameter.
-            }
-        }
-        criteria.distinct(true);
-        Predicate af = cb.and(andFilter.toArray(new Predicate[andFilter.size()]));
-        criteria.where(af);
-        List<LProbeInfo> result = filter(criteria);
-        return new Response(true, 200, result);
+        QueryBuilder<LProbeInfo> builder =
+            new QueryBuilder<LProbeInfo>(em, LProbeInfo.class);
+        builder.and("probeId", id);
+        builder.distinct();
+        return filter(builder.getQuery());
     }
 
     /**
--- a/src/main/java/de/intevation/lada/data/LStatusRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LStatusRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,19 +1,11 @@
 package de.intevation.lada.data;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 import javax.ejb.EJBTransactionRolledbackException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LStatus;
@@ -102,24 +94,4 @@
         }
         return response;
     }
-
-    @Override
-    public Response filter(Map<String, String> filter) {
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LStatus> criteria = cb.createQuery(LStatus.class);
-        Root<LStatus> member = criteria.from(LStatus.class);
-        List<Predicate> andFilter = new ArrayList<Predicate>();
-        if (filter.containsKey("probe")) {
-            andFilter.add(cb.equal(member.get("probeId"), filter.get("probe")));
-        }
-        if (filter.containsKey("messung")) {
-            andFilter.add(cb.equal(member.get("messungsId"), filter.get("messung")));
-        }
-        criteria.distinct(true);
-        Predicate ap = cb.and(andFilter.toArray(new Predicate[andFilter.size()]));
-        criteria.where(ap);
-        List<LStatus> result = filter(criteria);
-        return new Response(true, 200, result);
-    }
-
 }
--- a/src/main/java/de/intevation/lada/data/LZusatzwertRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LZusatzwertRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,17 +1,11 @@
 package de.intevation.lada.data;
 
-import java.util.List;
-import java.util.Map;
-
 import javax.ejb.EJBTransactionRolledbackException;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
 import javax.persistence.TransactionRequiredException;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.Manager;
 import de.intevation.lada.model.LZusatzWert;
@@ -110,17 +104,4 @@
         }
         return response;
     }
-
-    @Override
-    public Response filter(Map<String, String> filter) {
-        CriteriaBuilder cb = em.getCriteriaBuilder();
-        CriteriaQuery<LZusatzWert> criteria = cb.createQuery(LZusatzWert.class);
-        Root<LZusatzWert> member = criteria.from(LZusatzWert.class);
-        if (filter.containsKey("probe")) {
-            criteria.where(cb.equal(member.get("probeId"), filter.get("probe")));
-        }
-        List<LZusatzWert> result = filter(criteria);
-        return new Response(true, 200, result);
-    }
-
 }
--- a/src/main/java/de/intevation/lada/data/ReadOnlyRepository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/ReadOnlyRepository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,7 +1,5 @@
 package de.intevation.lada.data;
 
-import java.util.Map;
-
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Named;
 
@@ -22,9 +20,4 @@
     public Response update(Object object) {
         return null;
     }
-
-    @Override
-    public Response filter(Map<String, String> keys) {
-        return null;
-    }
 }
--- a/src/main/java/de/intevation/lada/data/Repository.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/Repository.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,7 +1,6 @@
 package de.intevation.lada.data;
 
 import java.util.List;
-import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
@@ -31,7 +30,17 @@
 
     public abstract Response update(Object object);
 
-    public abstract Response filter(Map<String, String> keys);
+    /**
+     * Filter object list by the given criteria.
+     *
+     * @param criteria
+     * @return List of objects.
+     */
+    public <T> Response filter(CriteriaQuery<T> filter) {
+        List<T> result = em.createQuery(filter).getResultList();
+        return new Response(true, 200, result);
+    }
+
 
     /**
      * Get all objects of type <link>clazz</link>from database.
@@ -63,17 +72,7 @@
         return new Response(true, 200, item);
     }
 
-    /**
-     * Filter object list by the given criteria.
-     *
-     * @param criteria
-     * @return List of LProbe objects.
-     */
-    public <T> List<T> filter(CriteriaQuery<T> criteria) {
-        return em.createQuery(criteria).getResultList();
-    }
-
-    public CriteriaBuilder getCriteriaBuilder() {
-        return em.getCriteriaBuilder();
+    public EntityManager getEntityManager() {
+        return this.em;
     }
 }
--- a/src/main/java/de/intevation/lada/rest/LKommentarMService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LKommentarMService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,8 +1,6 @@
 package de.intevation.lada.rest;
 
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
@@ -18,6 +16,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LKommentarM;
 
@@ -63,18 +62,19 @@
     @Produces("text/json")
     public Response filter(@Context UriInfo info) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty()) {
+        if (params.isEmpty() ||
+            !params.containsKey("probeId") ||
+            !params.containsKey("messungsId")
+        ) {
             return new Response(false, 609, new ArrayList<LKommentarM>());
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        if (!params.containsKey("probe") || !params.containsKey("messung")) {
-            return new Response(false, 609, new ArrayList<LKommentarM>());
-        }
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
-        }
+        QueryBuilder<LKommentarM> builder =
+            new QueryBuilder<LKommentarM>(
+                repository.getEntityManager(), LKommentarM.class);
+        builder.and("probeId", params.getFirst("probeId"))
+            .and("messungsId", params.getFirst("messungsId"));
 
-        return repository.filter(filter);
+        return repository.filter(builder.getQuery());
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/rest/LKommentarService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LKommentarService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,7 +1,6 @@
 package de.intevation.lada.rest;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.ArrayList;
 import java.util.logging.Logger;
 
 import javax.enterprise.context.RequestScoped;
@@ -19,6 +18,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LKommentarP;
 
@@ -98,14 +98,16 @@
     @Produces("text/json")
     public Response filter(@Context UriInfo info) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty()) {
-            repository.findAll(LKommentarP.class);
+        if (params.isEmpty() ||
+            !params.containsKey("probeId")
+        ) {
+            return new Response(false, 609, new ArrayList<LKommentarP>());
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
-        }
-        return repository.filter(filter);
+        QueryBuilder<LKommentarP> builder =
+            new QueryBuilder<LKommentarP>(
+                repository.getEntityManager(), LKommentarP.class);
+        builder.and("probeId", params.getFirst("probeId"));
+        return repository.filter(builder.getQuery());
     }
 
     @POST
--- a/src/main/java/de/intevation/lada/rest/LMessungService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LMessungService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,8 +1,5 @@
 package de.intevation.lada.rest;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.ws.rs.Consumes;
@@ -17,6 +14,7 @@
 import javax.ws.rs.core.UriInfo;
 
 import de.intevation.lada.data.LMessungRepository;
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.model.LMessung;
 
 /**
@@ -64,11 +62,13 @@
         if (params.isEmpty()) {
             repository.findAll(LMessung.class);
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
+        QueryBuilder<LMessung> builder =
+            new QueryBuilder<LMessung>(
+                repository.getEntityManager(), LMessung.class);
+        if (params.containsKey("probeId")) {
+            builder.and("probeId", params.getFirst("probeId"));
         }
-        return repository.filter(filter);
+        return repository.filter(builder.getQuery());
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/rest/LMesswertService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LMesswertService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,8 +1,6 @@
 package de.intevation.lada.rest;
 
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
@@ -18,6 +16,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LMesswert;
 
@@ -63,18 +62,18 @@
     @Produces("text/json")
     public Response filter(@Context UriInfo info) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty()) {
+        if (params.isEmpty() ||
+            !params.containsKey("probeId") ||
+            !params.containsKey("messungsId")) {
             return new Response(false, 609, new ArrayList<LMesswert>());
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        if (!params.containsKey("probe") || !params.containsKey("messung")) {
-            return new Response(false, 609, new ArrayList<LMesswert>());
-        }
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
-        }
+        QueryBuilder<LMesswert> builder =
+            new QueryBuilder<LMesswert>(
+                repository.getEntityManager(), LMesswert.class);
+        builder.and("probeId", params.getFirst("probeId"))
+            .and("messungsId", params.getFirst("messungsId"));
 
-        return repository.filter(filter);
+        return repository.filter(builder.getQuery());
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/rest/LOrtService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LOrtService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,8 +1,5 @@
 package de.intevation.lada.rest;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -17,6 +14,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LOrt;
 
@@ -46,11 +44,13 @@
         if (params.isEmpty()) {
             repository.findAll(LOrt.class);
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
+        QueryBuilder<LOrt> builder =
+            new QueryBuilder<LOrt>(
+                repository.getEntityManager(), LOrt.class);
+        if (params.containsKey("probeId")) {
+            builder.and("probeId", params.getFirst("probeId"));
         }
-        return repository.filter(filter);
+        return repository.filter(builder.getQuery());
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,23 +1,35 @@
 package de.intevation.lada.rest;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
 
+import javax.annotation.Resource;
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 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.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
 
+import de.intevation.lada.authentication.Authentication;
+import de.intevation.lada.authentication.AuthenticationException;
+import de.intevation.lada.authentication.AuthenticationResponse;
+import de.intevation.lada.authentication.LdapAuthentication;
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LProbeInfo;
@@ -44,6 +56,9 @@
     @Inject
     private Logger log;
 
+    @Inject
+    @Named("ldapauth")
+    private Authentication authentication;
     /**
      * Request a LProbe via its id.
      *
@@ -71,17 +86,52 @@
      */
     @GET
     @Produces("text/json")
-    public Response filter(@Context UriInfo info) {
-        MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty()) {
-            return repository.findAll(LProbeInfo.class);
+    public Response filter(
+        @Context UriInfo info,
+        @Context HttpHeaders header
+    ) {
+        try {
+            AuthenticationResponse auth =
+                authentication.authorizedGroups(header);
+            QueryBuilder<LProbeInfo> builder =
+                new QueryBuilder<LProbeInfo>(
+                    repository.getEntityManager(),
+                    LProbeInfo.class);
+            builder.or("netzbetreiberId", auth.getNetzbetreiber());
+            MultivaluedMap<String, String> params = info.getQueryParameters();
+            if (params.isEmpty()) {
+                return repository.filter(builder.getQuery());
+            }
+            QueryBuilder<LProbeInfo> mstBuilder = builder.getEmptyBuilder();
+            if (params.keySet().contains("mst")) {
+                String[] paramValues = params.getFirst("mst").split(",");
+                for (String pv: paramValues) {
+                    mstBuilder.or("mstId", pv);
+                }
+                builder.and(mstBuilder);
+            }
+            QueryBuilder<LProbeInfo> umwBuilder = builder.getEmptyBuilder();
+            if (params.keySet().contains("uwb")) {
+                String[] paramValues = params.getFirst("uwb").split(",");
+                for (String pv: paramValues) {
+                    umwBuilder.or("umwId", pv);
+                }
+                builder.and(umwBuilder);
+            }
+            QueryBuilder<LProbeInfo> beginBuilder = builder.getEmptyBuilder();
+            if (params.keySet().contains("bedin")) {
+                String[] paramValues = params.getFirst("begin").split(",");
+                for (String pv: paramValues) {
+                    beginBuilder.or("probeentnahmeBegin", pv);
+                }
+                builder.and(beginBuilder);
+            }
+            builder.distinct();
+            return repository.filter(builder.getQuery());
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
+        catch(AuthenticationException ae) {
+            return new Response(false, 699, new ArrayList<LProbe>());
         }
-
-        return repository.filter(filter);
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/rest/LStatusService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LStatusService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
@@ -18,6 +19,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LStatus;
 
@@ -63,18 +65,17 @@
     @Produces("text/json")
     public Response filter(@Context UriInfo info) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty()) {
+        if (params.isEmpty() ||
+            !params.containsKey("probeId") ||
+            !params.containsKey("messungId")) {
             return new Response(false, 609, new ArrayList<LStatus>());
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        if (!params.containsKey("probe") || !params.containsKey("messung")) {
-            return new Response(false, 609, new ArrayList<LStatus>());
-        }
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
-        }
-
-        return repository.filter(filter);
+        QueryBuilder<LStatus> builder =
+            new QueryBuilder<LStatus>(
+                repository.getEntityManager(), LStatus.class);
+        builder.and("probeId", params.getFirst("probeId"))
+            .and("messungsId", params.getFirst("messungsId"));
+        return repository.filter(builder.getQuery());
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/rest/LZusatzwertService.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LZusatzwertService.java	Thu Jun 27 15:03:18 2013 +0200
@@ -1,8 +1,6 @@
 package de.intevation.lada.rest;
 
 import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
@@ -18,6 +16,7 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LZusatzWert;
 
@@ -63,18 +62,15 @@
     @Produces("text/json")
     public Response filter(@Context UriInfo info) {
         MultivaluedMap<String, String> params = info.getQueryParameters();
-        if (params.isEmpty()) {
+        if (params.isEmpty() || !params.containsKey("probeId")) {
             return new Response(false, 609, new ArrayList<LZusatzWert>());
         }
-        Map<String, String> filter = new HashMap<String, String>();
-        if (!params.containsKey("probe")) {
-            return new Response(false, 609, new ArrayList<LZusatzWert>());
-        }
-        for (String key: params.keySet()) {
-            filter.put(key, params.getFirst(key));
-        }
-
-        return repository.filter(filter);
+        String paramValue = params.getFirst("probeId");
+        QueryBuilder<LZusatzWert> builder =
+            new QueryBuilder<LZusatzWert>(
+                repository.getEntityManager(), LZusatzWert.class);
+        builder.and("probeId", paramValue);
+        return repository.filter(builder.getQuery());
     }
 
     @PUT
--- a/src/main/java/de/intevation/lada/validation/LProbeValidator.java	Thu Jun 27 15:02:29 2013 +0200
+++ b/src/main/java/de/intevation/lada/validation/LProbeValidator.java	Thu Jun 27 15:03:18 2013 +0200
@@ -16,8 +16,10 @@
 
 import de.intevation.lada.data.LOrtRepository;
 import de.intevation.lada.data.LProbeRepository;
+import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
+import de.intevation.lada.rest.Response;
 
 /**
  * Validator for LProbe objects.
@@ -63,15 +65,13 @@
     private void validateHauptProbenNummer(LProbe p, Map<String, Integer> warnings)
     throws ValidationException {
         String hpn = p.getHauptprobenNr();
-        CriteriaBuilder cb = probeRepository.getCriteriaBuilder();
-        CriteriaQuery<LProbe> criteria = cb.createQuery(LProbe.class);
-        Root<LProbe> member = criteria.from(LProbe.class);
-        Predicate mstId = cb.equal(member.get("mstId"), p.getMstId());
-        Predicate hpNr = cb.equal(member.get("hauptprobenNr"), hpn);
-        criteria.where(cb.and(mstId, hpNr));
+        QueryBuilder<LProbe> builder =
+            new QueryBuilder<LProbe>(
+                probeRepository.getEntityManager(), LProbe.class);
+        builder.and("mstId", p.getMstId()).and("hauptprobenNr", hpn);
 
-        List<LProbe> proben = probeRepository.filter(criteria);
-        if (!proben.isEmpty()) {
+        Response response = probeRepository.filter(builder.getQuery());
+        if (!((List<LProbe>)response.getData()).isEmpty()) {
             Map<String, Integer> errors = new HashMap<String, Integer>();
             errors.put("hauptprobenNr", 611);
             throw new ValidationException(errors, warnings);
@@ -81,14 +81,13 @@
     private void validateEntnahmeOrt(LProbe probe, Map<String, Integer> warnings) {
         String pid = probe.getProbeId();
 
-        CriteriaBuilder cb = ortRepository.getCriteriaBuilder();
-        CriteriaQuery<LOrt> criteria = cb.createQuery(LOrt.class);
-        Root<LOrt> member = criteria.from(LOrt.class);
-        Predicate probeId = cb.equal(member.get("probeId"), pid);
-        criteria.where(probeId);
+        QueryBuilder<LOrt> builder =
+            new QueryBuilder<LOrt>(
+                ortRepository.getEntityManager(), LOrt.class);
+        builder.and("probenId", pid);
 
-        List<LOrt> orte = ortRepository.filter(criteria);
-        if(orte.isEmpty()) {
+        Response response = ortRepository.filter(builder.getQuery());
+        if (((List<LOrt>)response.getData()).isEmpty()) {
             warnings.put("entnahmeOrt", 631);
         }
     }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)