changeset 53:3a00c8fd5a8e

New path in 'proben' REST service: '/details/{id}'. Delivering more detials for a LProbe.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 24 May 2013 13:39:38 +0200
parents 8b29e54a44eb
children 1b4f9f4b3b57
files src/main/java/de/intevation/lada/data/LProbeRepository.java src/main/java/de/intevation/lada/rest/LProbeService.java
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/LProbeRepository.java	Fri May 24 13:38:32 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/LProbeRepository.java	Fri May 24 13:39:38 2013 +0200
@@ -12,7 +12,9 @@
 import javax.persistence.criteria.Root;
 
 import de.intevation.lada.manage.LProbeManager;
+import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
+import de.intevation.lada.model.LProbeDetails;
 
 /**
  * This Container is an interface to request, filter and select LProbe
@@ -77,4 +79,22 @@
         }
         return em.createQuery(criteria).getResultList();
     }
+
+    public LProbeDetails details(String probeId) {
+        LProbeDetails details = new LProbeDetails();
+        LProbe probe = em.find(LProbe.class, probeId);
+        if (probe == null) {
+            return new LProbeDetails();
+        }
+        details.setLprobe(probe);
+
+        CriteriaBuilder cbLorts = em.getCriteriaBuilder();
+        CriteriaQuery<LOrt> criteriaLorts = cbLorts.createQuery(LOrt.class);
+        Root<LOrt> member = criteriaLorts.from(LOrt.class);
+        criteriaLorts.where(cbLorts.equal(member.get("probeId"), probe.getProbeId()));
+        List<LOrt> lorts = em.createQuery(criteriaLorts).getResultList();
+        details.setLorts(lorts);
+
+        return details;
+    }
 }
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri May 24 13:38:32 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Fri May 24 13:39:38 2013 +0200
@@ -15,6 +15,7 @@
 
 import de.intevation.lada.data.LProbeRepository;
 import de.intevation.lada.model.LProbe;
+import de.intevation.lada.model.LProbeDetails;
 
 /**
  * This class produces a RESTful service to read the contents of LProbe table.
@@ -89,4 +90,11 @@
         }
         return repository.filter(mstId, uwbId, begin);
     }
+
+    @GET
+    @Path("/details/{id}")
+    @Produces("text/json")
+    public LProbeDetails details(@PathParam("id") String id) {
+        return repository.details(id);
+    }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)