[Lada-commits] [PATCH 1 of 2] Updated authorization for probe list. Performance is much better now!
Wald Commits
scm-commit at wald.intevation.org
Tue Mar 24 11:47:29 CET 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1427194064 -3600
# Node ID 54a95a587093ea92fa693e554c8e8901e6246d16
# Parent 7f5e2e68c765a1cd9f600a902f1e21aed8b0ed2f
Updated authorization for probe list. Performance is much better now!
diff -r 7f5e2e68c765 -r 54a95a587093 src/main/java/de/intevation/lada/query/QueryTools.java
--- 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);
}
diff -r 7f5e2e68c765 -r 54a95a587093 src/main/java/de/intevation/lada/rest/ProbeService.java
--- 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());
diff -r 7f5e2e68c765 -r 54a95a587093 src/main/java/de/intevation/lada/util/auth/OpenIdAuthorization.java
--- 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;
}
}
More information about the Lada-commits
mailing list