[Lada-commits] [PATCH 12 of 13] Check if the messung object has child objects in delete service

Wald Commits scm-commit at wald.intevation.org
Fri May 29 11:48:22 CEST 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1432892849 -7200
# Node ID 9a9241275ee6280df584c8cf2ab2491efe260547
# Parent  a5e6580e80169d3f498d4d7d70b52e3e68e4a2a4
Check if the messung object has child objects in delete service.

diff -r a5e6580e8016 -r 9a9241275ee6 src/main/java/de/intevation/lada/rest/MessungService.java
--- 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 =


More information about the Lada-commits mailing list