changeset 700:d74b5b1190ae

fixed delete probe service.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 10 Jul 2015 18:29:27 +0200
parents 51d8d5bacf68
children cb344bc264d9
files src/main/java/de/intevation/lada/rest/ProbeService.java src/main/java/de/intevation/lada/util/data/DataTransaction.java src/main/java/de/intevation/lada/util/data/DefaultRepository.java
diffstat 3 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java	Fri Jul 10 14:54:21 2015 +0200
+++ b/src/main/java/de/intevation/lada/rest/ProbeService.java	Fri Jul 10 18:29:27 2015 +0200
@@ -14,6 +14,7 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.ejb.EJBTransactionRolledbackException;
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.json.Json;
@@ -22,6 +23,7 @@
 import javax.json.JsonObject;
 import javax.json.JsonReader;
 import javax.persistence.Query;
+import javax.persistence.TransactionRequiredException;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -507,7 +509,14 @@
         /* Delete the probe translation object*/
         defaultRepo.delete(probeTransObj, "land");
         /* Delete the probe object*/
-        Response response = defaultRepo.delete(probeObj, "land");
-        return response;
+        try {
+            Response response = defaultRepo.delete(probeObj, "land");
+            return response;
+        }
+        catch(IllegalArgumentException | EJBTransactionRolledbackException |
+            TransactionRequiredException e) {
+            defaultRepo.update(probeTransObj, "land");
+            return new Response(false, 600, "");
+        }
     }
 }
--- a/src/main/java/de/intevation/lada/util/data/DataTransaction.java	Fri Jul 10 14:54:21 2015 +0200
+++ b/src/main/java/de/intevation/lada/util/data/DataTransaction.java	Fri Jul 10 18:29:27 2015 +0200
@@ -14,6 +14,7 @@
 import javax.inject.Inject;
 import javax.persistence.EntityExistsException;
 import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 import javax.persistence.TransactionRequiredException;
 
@@ -84,7 +85,8 @@
     @TransactionAttribute(TransactionAttributeType.REQUIRED)
     public void removeFromDatabase(Object object, String dataSource)
     throws IllegalArgumentException,
-        TransactionRequiredException
+        TransactionRequiredException,
+        EJBTransactionRolledbackException
     {
         EntityManager em = emp.entityManager(dataSource);
         em.remove(
--- a/src/main/java/de/intevation/lada/util/data/DefaultRepository.java	Fri Jul 10 14:54:21 2015 +0200
+++ b/src/main/java/de/intevation/lada/util/data/DefaultRepository.java	Fri Jul 10 18:29:27 2015 +0200
@@ -118,7 +118,7 @@
      */
     @Override
     public Response delete(Object object, String dataSource) {
-        Response response = new Response(true, 200, null);
+        Response response = new Response(true, 200, "");
         try {
             transaction.removeFromDatabase(object, dataSource);
         }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)