Mercurial > lada > lada-server
changeset 587:54a95a587093
Updated authorization for probe list. Performance is much better now!
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 24 Mar 2015 11:47:44 +0100 |
parents | 7f5e2e68c765 |
children | 7e9336df0aeb |
files | src/main/java/de/intevation/lada/query/QueryTools.java src/main/java/de/intevation/lada/rest/ProbeService.java src/main/java/de/intevation/lada/util/auth/OpenIdAuthorization.java |
diffstat | 3 files changed, 14 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/query/QueryTools.java Mon Mar 23 17:59:29 2015 +0100 +++ b/src/main/java/de/intevation/lada/query/QueryTools.java Tue Mar 24 11:47:44 2015 +0100 @@ -24,9 +24,6 @@ import javax.persistence.Query; import javax.ws.rs.core.MultivaluedMap; -import de.intevation.lada.util.auth.Authorization; -import de.intevation.lada.util.auth.UserInfo; - /** * Utility class to handle the SQL query configuration. @@ -162,19 +159,13 @@ public static List<Map<String, Object>> prepareResult( List<Object[]> result, - List<String> names, - Authorization authorization, - UserInfo userInfo + List<String> names ) { List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>(); for (Object[] row: result) { Map<String, Object> set = new HashMap<String, Object>(); for (int i = 0; i < row.length; i++) { set.put(names.get(i), row[i]); - if (names.get(i).toString().equals("id")) { - boolean readOnly = authorization.isReadOnly((Integer)row[i]); - set.put("readonly", readOnly); - } } ret.add(set); }
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java Mon Mar 23 17:59:29 2015 +0100 +++ b/src/main/java/de/intevation/lada/rest/ProbeService.java Tue Mar 24 11:47:44 2015 +0100 @@ -137,11 +137,20 @@ params, defaultRepo.entityManager("land")); List<Map<String, Object>> result = - QueryTools.prepareResult(query.getResultList(), results, authorization, authorization.getInfo(request)); + QueryTools.prepareResult(query.getResultList(), results); if (params.containsKey("start") && params.containsKey("limit")) { int start = Integer.valueOf(params.getFirst("start")); int limit = Integer.valueOf(params.getFirst("limit")); - List<Map<String, Object>> subList = result.subList(start, limit + start); + int end = limit + start; + if (start + limit > result.size()) { + end = result.size(); + } + List<Map<String, Object>> subList = result.subList(start, end); + for (Map<String, Object> entry: subList) { + boolean readOnly = + authorization.isReadOnly((Integer)entry.get("id")); + entry.put("readonly", readOnly); + } return new Response(true, 200, subList, result.size()); } return new Response(true, 200, result, result.size());
--- a/src/main/java/de/intevation/lada/util/auth/OpenIdAuthorization.java Mon Mar 23 17:59:29 2015 +0100 +++ b/src/main/java/de/intevation/lada/util/auth/OpenIdAuthorization.java Tue Mar 24 11:47:44 2015 +0100 @@ -323,17 +323,13 @@ manager, LMessung.class); builder.and("probeId", probeId); + builder.and("fertig", true); Response response = repository.filter(builder.getQuery(), "land"); @SuppressWarnings("unchecked") List<LMessung> messungen = (List<LMessung>) response.getData(); if (messungen.isEmpty()) { return false; } - for(LMessung messung : messungen) { - if (messung.getFertig()) { - return true; - } - } - return false; + return true; } }