# HG changeset patch # User Raimund Renkert # Date 1372942268 -7200 # Node ID c9a1da2e159d4653b5c4d642bf2d46ce31b71aad # Parent d9d1a46af55d13aa8e3433f7d37b1be90d219475# Parent c8cd17181c9fc9802c93aeb0e45903d2e2ce2ae8 Merged. diff -r c8cd17181c9f -r c9a1da2e159d src/main/java/de/intevation/lada/authentication/Authentication.java --- 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; } diff -r c8cd17181c9f -r c9a1da2e159d src/main/java/de/intevation/lada/authentication/LdapAuthentication.java --- 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. diff -r c8cd17181c9f -r c9a1da2e159d src/main/java/de/intevation/lada/rest/LProbeService.java --- 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()); } } + + /** + * Determine if the LProbe identified by probeId is writeable for the user. + * + * @param probeId The probe id. + */ + public boolean isReadOnly(String probeId) { + QueryBuilder builder = + new QueryBuilder( + repository.getEntityManager(), + LMessung.class); + builder.and("probeId", probeId); + Response response = messungRepository.filter(builder.getQuery()); + List messungen = (List) response.getData(); + if (messungen.isEmpty()) { + return false; + } + for(LMessung messung : messungen) { + if (messung.isFertig()) { + return true; + } + } + return false; + } }