changeset 224:c9a1da2e159d

Merged.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 04 Jul 2013 14:51:08 +0200
parents d9d1a46af55d (diff) c8cd17181c9f (current diff)
children a1c1ec27224a
files
diffstat 3 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/authentication/Authentication.java	Thu Jul 04 14:18:18 2013 +0200
+++ b/src/main/java/de/intevation/lada/authentication/Authentication.java	Thu Jul 04 14:51:08 2013 +0200
@@ -15,7 +15,4 @@
 
     public boolean hasAccess(HttpHeaders headers, String probeId)
     throws AuthenticationException;
-
-    public boolean isReadOnly(HttpHeaders headers, String probeId)
-    throws AuthenticationException;
 }
--- a/src/main/java/de/intevation/lada/authentication/LdapAuthentication.java	Thu Jul 04 14:18:18 2013 +0200
+++ b/src/main/java/de/intevation/lada/authentication/LdapAuthentication.java	Thu Jul 04 14:51:08 2013 +0200
@@ -17,8 +17,11 @@
 import javax.persistence.criteria.Root;
 import javax.ws.rs.core.HttpHeaders;
 
+import org.omg.PortableServer.LifespanPolicyOperations;
+
 import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.model.Auth;
+import de.intevation.lada.model.LMessung;
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LProbeInfo;
 
@@ -107,16 +110,6 @@
         return false;
     }
 
-    /**
-     * Determine if the LProbe identified by probeId is writeable for the user.
-     *
-     * @param headers   The HTTP header containing LDAP user information.
-     * @param probeId   The probe id.
-     */
-    public boolean isReadOnly(HttpHeaders headers, String probeId) {
-        //TODO: test if probe has messung with status 'fertig'.
-        return false;
-    }
 
     /**
      * Get the user from HTTP header.
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java	Thu Jul 04 14:18:18 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LProbeService.java	Thu Jul 04 14:51:08 2013 +0200
@@ -25,6 +25,7 @@
 import de.intevation.lada.authentication.AuthenticationResponse;
 import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
+import de.intevation.lada.model.LMessung;
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LProbeInfo;
 
@@ -45,6 +46,10 @@
     @Named("lproberepository")
     private Repository repository;
 
+    @Inject
+    @Named("lmessungrepository")
+    private Repository messungRepository;
+
     /**
      * The authorization module.
      */
@@ -85,7 +90,7 @@
             String mstId = probe.get(0).getMstId();
             if (auth.getNetzbetreiber().contains(nbId)) {
                 if (auth.getMst().contains(mstId)) {
-                    //TODO: Test if probe has a messung that has status 'ready'.
+                    response.setReadonly(isReadOnly(id));
                     return response;
                 }
                 response.setReadonly(true);
@@ -208,4 +213,28 @@
             return new Response(false, 699, new ArrayList<LProbeInfo>());
         }
     }
+
+    /**
+     * Determine if the LProbe identified by probeId is writeable for the user.
+     *
+     * @param probeId   The probe id.
+     */
+    public boolean isReadOnly(String probeId) {
+        QueryBuilder<LMessung> builder =
+            new QueryBuilder<LMessung>(
+                repository.getEntityManager(),
+                LMessung.class);
+        builder.and("probeId", probeId);
+        Response response = messungRepository.filter(builder.getQuery());
+        List<LMessung> messungen = (List<LMessung>) response.getData();
+        if (messungen.isEmpty()) {
+            return false;
+        }
+        for(LMessung messung : messungen) {
+            if (messung.isFertig()) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)