changeset 681:9a9241275ee6

Check if the messung object has child objects in delete service.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 29 May 2015 11:47:29 +0200
parents a5e6580e8016
children 0015e96a6454
files src/main/java/de/intevation/lada/rest/MessungService.java
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/MessungService.java	Fri May 29 11:46:45 2015 +0200
+++ b/src/main/java/de/intevation/lada/rest/MessungService.java	Fri May 29 11:47:29 2015 +0200
@@ -27,10 +27,15 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.log4j.Logger;
+
 import de.intevation.lada.lock.LockConfig;
 import de.intevation.lada.lock.LockType;
 import de.intevation.lada.lock.ObjectLocker;
+import de.intevation.lada.model.land.LKommentarM;
 import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.land.LMesswert;
+import de.intevation.lada.model.land.LStatus;
 import de.intevation.lada.model.land.MessungTranslation;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -87,6 +92,9 @@
 @RequestScoped
 public class MessungService {
 
+    @Inject
+    private Logger logger;
+
     /**
      * The data repository granting read/write access.
      */
@@ -346,6 +354,34 @@
         if (lock.isLocked(messung)) {
             return new Response(false, 697, null);
         }
+
+        QueryBuilder<LMesswert> mwBuilder =
+            new QueryBuilder<LMesswert>(
+                defaultRepo.entityManager("land"), LMesswert.class);
+        mwBuilder.and("messungsId", messungObj.getId());
+        QueryBuilder<LKommentarM> mkBuilder =
+            new QueryBuilder<LKommentarM>(
+                defaultRepo.entityManager("land"), LKommentarM.class);
+        mkBuilder.and("messungsId", messungObj.getId());
+        QueryBuilder<LStatus> msBuilder =
+            new QueryBuilder<LStatus>(
+                defaultRepo.entityManager("land"), LStatus.class);
+        msBuilder.and("messungsId", messungObj.getId());
+
+        List<LMesswert> messwerte =
+            (List<LMesswert>)defaultRepo.filter(mwBuilder.getQuery(), "land").getData();
+        List<LKommentarM> kommentare =
+            (List<LKommentarM>)defaultRepo.filter(mkBuilder.getQuery(), "land").getData();
+        List<LStatus> status =
+            (List<LStatus>)defaultRepo.filter(msBuilder.getQuery(), "land").getData();
+
+        if (!messwerte.isEmpty() ||
+            !kommentare.isEmpty() ||
+            !status.isEmpty()
+        ) {
+            return new Response(false, 696, messung);
+        }
+
         /* Create a query and request the messungTranslation object for the
          * messung*/
         QueryBuilder<MessungTranslation> builder =
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)