changeset 595:746e03da9fad

Use timestamp locker in REST services.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 25 Mar 2015 16:20:01 +0100
parents b2af88e8eb15
children 31c4bd94d74e
files src/main/java/de/intevation/lada/rest/MessungService.java src/main/java/de/intevation/lada/rest/MesswertService.java src/main/java/de/intevation/lada/rest/OrtService.java src/main/java/de/intevation/lada/rest/ProbeService.java src/main/java/de/intevation/lada/rest/StatusService.java src/main/java/de/intevation/lada/rest/ZusatzwertService.java
diffstat 6 files changed, 79 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/MessungService.java	Wed Mar 25 16:18:34 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/MessungService.java	Wed Mar 25 16:20:01 2015 +0100
@@ -7,6 +7,8 @@
  */
 package de.intevation.lada.rest;
 
+import java.sql.Timestamp;
+import java.util.Date;
 import java.util.List;
 
 import javax.enterprise.context.RequestScoped;
@@ -25,6 +27,9 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.lock.LockConfig;
+import de.intevation.lada.lock.LockType;
+import de.intevation.lada.lock.ObjectLocker;
 import de.intevation.lada.model.land.LMessung;
 import de.intevation.lada.model.land.MessungTranslation;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
@@ -46,6 +51,10 @@
     @RepositoryConfig(type=RepositoryType.RW)
     private Repository defaultRepo;
 
+    @Inject
+    @LockConfig(type=LockType.TIMESTAMP)
+    private ObjectLocker lock;
+
     /* The authorization module.*/
     @Inject
     @AuthorizationConfig(type=AuthorizationType.OPEN_ID)
@@ -150,6 +159,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(messung)) {
+            return new Response(false, 697, null);
+        }
         Response response = defaultRepo.update(messung, "land");
         Response updated = defaultRepo.getById(
             LMessung.class,
@@ -182,6 +194,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(messung)) {
+            return new Response(false, 697, null);
+        }
         /* Create a query and request the messungTranslation object for the
          * messung*/
         QueryBuilder<MessungTranslation> builder =
--- a/src/main/java/de/intevation/lada/rest/MesswertService.java	Wed Mar 25 16:18:34 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/MesswertService.java	Wed Mar 25 16:20:01 2015 +0100
@@ -25,6 +25,9 @@
 
 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.LMesswert;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -49,6 +52,10 @@
     @RepositoryConfig(type=RepositoryType.RW)
     private Repository defaultRepo;
 
+    @Inject
+    @LockConfig(type=LockType.TIMESTAMP)
+    private ObjectLocker lock;
+
     /* The authorization module.*/
     @Inject
     @AuthorizationConfig(type=AuthorizationType.OPEN_ID)
@@ -144,6 +151,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(messwert)) {
+            return new Response(false, 697, null);
+        }
         Response response = defaultRepo.update(messwert, "land");
         Response updated = defaultRepo.getById(
             LMesswert.class,
@@ -176,6 +186,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(messwert)) {
+            return new Response(false, 697, null);
+        }
         /* Delete the messwert object*/
         return defaultRepo.delete(messwertObj, "land");
     }
--- a/src/main/java/de/intevation/lada/rest/OrtService.java	Wed Mar 25 16:18:34 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/OrtService.java	Wed Mar 25 16:20:01 2015 +0100
@@ -25,6 +25,9 @@
 
 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.LOrt;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -49,6 +52,10 @@
     @RepositoryConfig(type=RepositoryType.RW)
     private Repository defaultRepo;
 
+    @Inject
+    @LockConfig(type=LockType.TIMESTAMP)
+    private ObjectLocker lock;
+
     /* The authorization module.*/
     @Inject
     @AuthorizationConfig(type=AuthorizationType.OPEN_ID)
@@ -142,6 +149,9 @@
                 LOrt.class)) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(ort)) {
+            return new Response(false, 697, null);
+        }
         Response response = defaultRepo.update(ort, "land");
         Response updated = defaultRepo.getById(
             LOrt.class,
@@ -173,6 +183,9 @@
                 LOrt.class)) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(ortObj)) {
+            return new Response(false, 697, null);
+        }
         /* Delete the messwert object*/
         return defaultRepo.delete(ortObj, "land");
     }
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java	Wed Mar 25 16:18:34 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/ProbeService.java	Wed Mar 25 16:20:01 2015 +0100
@@ -8,7 +8,9 @@
 package de.intevation.lada.rest;
 
 import java.io.StringReader;
+import java.sql.Timestamp;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -36,6 +38,9 @@
 
 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.LProbe;
 import de.intevation.lada.model.land.ProbeTranslation;
 import de.intevation.lada.query.QueryTools;
@@ -77,6 +82,10 @@
     private Authorization authorization;
 
     @Inject
+    @LockConfig(type=LockType.TIMESTAMP)
+    private ObjectLocker lock;
+
+    @Inject
     @ValidationConfig(type="Probe")
     private Validator validator;
 
@@ -243,6 +252,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(probe)) {
+            return new Response(false, 697, null);
+        }
         Violation violation = validator.validate(probe);
         if (violation.hasErrors()) {
             Response response = new Response(false, 604, null);
--- a/src/main/java/de/intevation/lada/rest/StatusService.java	Wed Mar 25 16:18:34 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/StatusService.java	Wed Mar 25 16:20:01 2015 +0100
@@ -23,6 +23,9 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.lock.LockConfig;
+import de.intevation.lada.lock.LockType;
+import de.intevation.lada.lock.ObjectLocker;
 import de.intevation.lada.model.land.LStatus;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -43,6 +46,10 @@
     @RepositoryConfig(type=RepositoryType.RW)
     private Repository defaultRepo;
 
+    @Inject
+    @LockConfig(type=LockType.TIMESTAMP)
+    private ObjectLocker lock;
+
     /* The authorization module.*/
     @Inject
     @AuthorizationConfig(type=AuthorizationType.OPEN_ID)
@@ -137,6 +144,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(status)) {
+            return new Response(false, 697, null);
+        }
         Response response = defaultRepo.update(status, "land");
         Response updated = defaultRepo.getById(
             LStatus.class,
@@ -169,6 +179,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(obj)) {
+            return new Response(false, 697, null);
+        }
         /* Delete the object*/
         return defaultRepo.delete(obj, "land");
     }
--- a/src/main/java/de/intevation/lada/rest/ZusatzwertService.java	Wed Mar 25 16:18:34 2015 +0100
+++ b/src/main/java/de/intevation/lada/rest/ZusatzwertService.java	Wed Mar 25 16:20:01 2015 +0100
@@ -23,6 +23,9 @@
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
 
+import de.intevation.lada.lock.LockConfig;
+import de.intevation.lada.lock.LockType;
+import de.intevation.lada.lock.ObjectLocker;
 import de.intevation.lada.model.land.LZusatzWert;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
 import de.intevation.lada.util.annotation.RepositoryConfig;
@@ -43,6 +46,10 @@
     @RepositoryConfig(type=RepositoryType.RW)
     private Repository defaultRepo;
 
+    @Inject
+    @LockConfig(type=LockType.TIMESTAMP)
+    private ObjectLocker lock;
+
     /* The authorization module.*/
     @Inject
     @AuthorizationConfig(type=AuthorizationType.OPEN_ID)
@@ -137,6 +144,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(zusatzwert)) {
+            return new Response(false, 697, null);
+        }
         Response response = defaultRepo.update(zusatzwert, "land");
         Response updated = defaultRepo.getById(
             LZusatzWert.class,
@@ -169,6 +179,9 @@
         ) {
             return new Response(false, 699, null);
         }
+        if (lock.isLocked(obj)) {
+            return new Response(false, 697, null);
+        }
         /* Delete the object*/
         return defaultRepo.delete(obj, "land");
     }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)