From 4c94746dff2ec10f800148396f78f14aa4c3e1c0 Mon Sep 17 00:00:00 2001 From: Konstantin Krivopustov Date: Thu, 17 Dec 2009 05:33:59 +0000 Subject: [PATCH] Fixes #175 GenericFilter custom condition bug --- .../haulmont/cuba/security/global/UserSession.java | 9 ++++++--- .../gui/data/impl/AbstractCollectionDatasource.java | 5 +---- .../components/filter/CustomConditionEditDlg.java | 12 ++++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/modules/global/src/com/haulmont/cuba/security/global/UserSession.java b/modules/global/src/com/haulmont/cuba/security/global/UserSession.java index 5bedf3fd7f..535f9e769c 100644 --- a/modules/global/src/com/haulmont/cuba/security/global/UserSession.java +++ b/modules/global/src/com/haulmont/cuba/security/global/UserSession.java @@ -210,11 +210,14 @@ public class UserSession implements Serializable /** * Get user session attribute. Attribute is a named serializable object bound to session. - * @param name attribute name + * @param name attribute name, or userId to obtain current or substituted user ID * @return attribute value */ - public T getAttribute(String name) { - return (T) attributes.get(name); + public T getAttribute(String name) { + if ("userId".equals(name)) + return (T) (substitutedUser == null ? user.getId() : substitutedUser.getId()); + else + return (T) attributes.get(name); } /** diff --git a/modules/gui/src/com/haulmont/cuba/gui/data/impl/AbstractCollectionDatasource.java b/modules/gui/src/com/haulmont/cuba/gui/data/impl/AbstractCollectionDatasource.java index 06b6488277..d107a09f76 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/data/impl/AbstractCollectionDatasource.java +++ b/modules/gui/src/com/haulmont/cuba/gui/data/impl/AbstractCollectionDatasource.java @@ -192,10 +192,7 @@ public abstract class AbstractCollectionDatasource, K> case SESSION: { Object value; UserSession us = UserSessionClient.getUserSession(); - if ("userId".equals(path)) - value = us.getSubstitutedUser() != null ? us.getSubstitutedUser().getId() : us.getUser().getId(); - else - value = us.getAttribute(path); + value = us.getAttribute(path); if (value instanceof String && info.isCaseInsensitive()) { value = makeCaseInsensitive((String) value); diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/filter/CustomConditionEditDlg.java b/modules/web/src/com/haulmont/cuba/web/gui/components/filter/CustomConditionEditDlg.java index dfdf2033de..01bd52b788 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/filter/CustomConditionEditDlg.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/filter/CustomConditionEditDlg.java @@ -109,7 +109,7 @@ public class CustomConditionEditDlg extends Window { whereText = new TextField(); whereText.setWidth(FIELD_WIDTH); - whereText.setRows(2); + whereText.setRows(4); whereText.setNullRepresentation(""); String where = replaceParamWithQuestionMark(condition.getWhere()); whereText.setValue(where); @@ -238,7 +238,13 @@ public class CustomConditionEditDlg extends Window { String res = where.trim(); if (!StringUtils.isBlank(res)) { Matcher matcher = QueryParserRegex.PARAM_PATTERN.matcher(res); - res = matcher.replaceAll("?"); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + if (!matcher.group().startsWith(":session$")) + matcher.appendReplacement(sb, "?"); + } + matcher.appendTail(sb); + return sb.toString(); } return res; } @@ -329,6 +335,8 @@ public class CustomConditionEditDlg extends Window { select.setValue(ParamType.BOOLEAN); else if (Number.class.equals(param.getJavaClass())) select.setValue(ParamType.NUMBER); + else if (UUID.class.equals(param.getJavaClass())) + select.setValue(ParamType.UUID); else throw new UnsupportedOperationException("Unsupported param class: " + param.getJavaClass()); break;