# HG changeset patch # User Raimund Renkert # Date 1372338198 -7200 # Node ID a2e04ab2cd444b7ca078ea4a2c5faf21f5360fac # Parent bca4bda93a9873bfddff889eeccfc764731b33ab Use the new filter and query builder and have authentication for LProbeInfo objects. diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LKommentarMRepository.java --- 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 filter) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LKommentarM.class); - Root member = criteria.from(LKommentarM.class); - List andFilter = new ArrayList(); - 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 result = filter(criteria); - return new Response(true, 200, result); - } - } diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LKommentarPRepository.java --- 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 filter) { - if (filter.isEmpty()) { - return findAll(LKommentarP.class); - } - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LKommentarP.class); - Root 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()); - } - - List result = filter(criteria); - return new Response(true, 200, result); - } - public Response create(Object object) { if (!(object instanceof LKommentarP)) { return new Response(false, 602, object); diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LMessungRepository.java --- 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 filter) { - if (filter.isEmpty()) { - return findAll(LMessung.class); - } - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LMessung.class); - Root 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()); - } - List result = filter(criteria); - return new Response(true, 200, result); - } - - /** * Validate and persist a new LProbe object. * * @param probe The new LProbe object diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LMesswertRepository.java --- 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 filter) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LMesswert.class); - Root member = criteria.from(LMesswert.class); - List andFilter = new ArrayList(); - 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 result = filter(criteria); - return new Response(true, 200, result); - } - -} diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LOrtRepository.java --- 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 filter) { - if (filter.isEmpty()) { - return findAll(LOrt.class); - } - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LOrt.class); - Root 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()); - } - List result = filter(criteria); - - return new Response(true, 200, result); - } /** * Validate and persist a new LProbe object. diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LProbeRepository.java --- 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 Response findAll(Class clazz) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LProbeInfo.class); - criteria.distinct(true); - List result = filter(criteria); - return new Response(true, 200, result); + QueryBuilder builder = + new QueryBuilder(em, LProbeInfo.class); + builder.distinct(); + return filter(builder.getQuery()); } @Override public Response findById(Class clazz, String id) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LProbeInfo.class); - Root member = criteria.from(LProbeInfo.class); - Predicate pid = cb.equal(member.get("probeId"), id); - criteria.where(pid); - criteria.distinct(true); - List 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 filter) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LProbeInfo.class); - Root member = criteria.from(LProbeInfo.class); - List andFilter = new ArrayList(); - 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 result = filter(criteria); - return new Response(true, 200, result); + QueryBuilder builder = + new QueryBuilder(em, LProbeInfo.class); + builder.and("probeId", id); + builder.distinct(); + return filter(builder.getQuery()); } /** diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LStatusRepository.java --- 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 filter) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LStatus.class); - Root member = criteria.from(LStatus.class); - List andFilter = new ArrayList(); - 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 result = filter(criteria); - return new Response(true, 200, result); - } - } diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/LZusatzwertRepository.java --- 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 filter) { - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LZusatzWert.class); - Root member = criteria.from(LZusatzWert.class); - if (filter.containsKey("probe")) { - criteria.where(cb.equal(member.get("probeId"), filter.get("probe"))); - } - List result = filter(criteria); - return new Response(true, 200, result); - } - } diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/ReadOnlyRepository.java --- 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 keys) { - return null; - } } diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/data/Repository.java --- 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 keys); + /** + * Filter object list by the given criteria. + * + * @param criteria + * @return List of objects. + */ + public Response filter(CriteriaQuery filter) { + List result = em.createQuery(filter).getResultList(); + return new Response(true, 200, result); + } + /** * Get all objects of type clazzfrom 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 List filter(CriteriaQuery criteria) { - return em.createQuery(criteria).getResultList(); - } - - public CriteriaBuilder getCriteriaBuilder() { - return em.getCriteriaBuilder(); + public EntityManager getEntityManager() { + return this.em; } } diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LKommentarMService.java --- 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 params = info.getQueryParameters(); - if (params.isEmpty()) { + if (params.isEmpty() || + !params.containsKey("probeId") || + !params.containsKey("messungsId") + ) { return new Response(false, 609, new ArrayList()); } - Map filter = new HashMap(); - if (!params.containsKey("probe") || !params.containsKey("messung")) { - return new Response(false, 609, new ArrayList()); - } - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); - } + QueryBuilder builder = + new QueryBuilder( + 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 diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LKommentarService.java --- 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 params = info.getQueryParameters(); - if (params.isEmpty()) { - repository.findAll(LKommentarP.class); + if (params.isEmpty() || + !params.containsKey("probeId") + ) { + return new Response(false, 609, new ArrayList()); } - Map filter = new HashMap(); - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); - } - return repository.filter(filter); + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), LKommentarP.class); + builder.and("probeId", params.getFirst("probeId")); + return repository.filter(builder.getQuery()); } @POST diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LMessungService.java --- 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 filter = new HashMap(); - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), LMessung.class); + if (params.containsKey("probeId")) { + builder.and("probeId", params.getFirst("probeId")); } - return repository.filter(filter); + return repository.filter(builder.getQuery()); } @PUT diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LMesswertService.java --- 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 params = info.getQueryParameters(); - if (params.isEmpty()) { + if (params.isEmpty() || + !params.containsKey("probeId") || + !params.containsKey("messungsId")) { return new Response(false, 609, new ArrayList()); } - Map filter = new HashMap(); - if (!params.containsKey("probe") || !params.containsKey("messung")) { - return new Response(false, 609, new ArrayList()); - } - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); - } + QueryBuilder builder = + new QueryBuilder( + 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 diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LOrtService.java --- 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 filter = new HashMap(); - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), LOrt.class); + if (params.containsKey("probeId")) { + builder.and("probeId", params.getFirst("probeId")); } - return repository.filter(filter); + return repository.filter(builder.getQuery()); } @PUT diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LProbeService.java --- 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 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 builder = + new QueryBuilder( + repository.getEntityManager(), + LProbeInfo.class); + builder.or("netzbetreiberId", auth.getNetzbetreiber()); + MultivaluedMap params = info.getQueryParameters(); + if (params.isEmpty()) { + return repository.filter(builder.getQuery()); + } + QueryBuilder 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 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 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 filter = new HashMap(); - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); + catch(AuthenticationException ae) { + return new Response(false, 699, new ArrayList()); } - - return repository.filter(filter); } @PUT diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LStatusService.java --- 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 params = info.getQueryParameters(); - if (params.isEmpty()) { + if (params.isEmpty() || + !params.containsKey("probeId") || + !params.containsKey("messungId")) { return new Response(false, 609, new ArrayList()); } - Map filter = new HashMap(); - if (!params.containsKey("probe") || !params.containsKey("messung")) { - return new Response(false, 609, new ArrayList()); - } - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); - } - - return repository.filter(filter); + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), LStatus.class); + builder.and("probeId", params.getFirst("probeId")) + .and("messungsId", params.getFirst("messungsId")); + return repository.filter(builder.getQuery()); } @PUT diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/rest/LZusatzwertService.java --- 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 params = info.getQueryParameters(); - if (params.isEmpty()) { + if (params.isEmpty() || !params.containsKey("probeId")) { return new Response(false, 609, new ArrayList()); } - Map filter = new HashMap(); - if (!params.containsKey("probe")) { - return new Response(false, 609, new ArrayList()); - } - for (String key: params.keySet()) { - filter.put(key, params.getFirst(key)); - } - - return repository.filter(filter); + String paramValue = params.getFirst("probeId"); + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), LZusatzWert.class); + builder.and("probeId", paramValue); + return repository.filter(builder.getQuery()); } @PUT diff -r bca4bda93a98 -r a2e04ab2cd44 src/main/java/de/intevation/lada/validation/LProbeValidator.java --- 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 warnings) throws ValidationException { String hpn = p.getHauptprobenNr(); - CriteriaBuilder cb = probeRepository.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LProbe.class); - Root 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 builder = + new QueryBuilder( + probeRepository.getEntityManager(), LProbe.class); + builder.and("mstId", p.getMstId()).and("hauptprobenNr", hpn); - List proben = probeRepository.filter(criteria); - if (!proben.isEmpty()) { + Response response = probeRepository.filter(builder.getQuery()); + if (!((List)response.getData()).isEmpty()) { Map errors = new HashMap(); errors.put("hauptprobenNr", 611); throw new ValidationException(errors, warnings); @@ -81,14 +81,13 @@ private void validateEntnahmeOrt(LProbe probe, Map warnings) { String pid = probe.getProbeId(); - CriteriaBuilder cb = ortRepository.getCriteriaBuilder(); - CriteriaQuery criteria = cb.createQuery(LOrt.class); - Root member = criteria.from(LOrt.class); - Predicate probeId = cb.equal(member.get("probeId"), pid); - criteria.where(probeId); + QueryBuilder builder = + new QueryBuilder( + ortRepository.getEntityManager(), LOrt.class); + builder.and("probenId", pid); - List orte = ortRepository.filter(criteria); - if(orte.isEmpty()) { + Response response = ortRepository.filter(builder.getQuery()); + if (((List)response.getData()).isEmpty()) { warnings.put("entnahmeOrt", 631); } }