Fixes #175 GenericFilter custom condition bug

This commit is contained in:
Konstantin Krivopustov 2009-12-17 05:33:59 +00:00
parent d39af52417
commit 4c94746dff
3 changed files with 17 additions and 9 deletions

View File

@ -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 <code>userId</code> to obtain current or substituted user ID
* @return attribute value
*/
public <T extends Serializable> T getAttribute(String name) {
return (T) attributes.get(name);
public <T> T getAttribute(String name) {
if ("userId".equals(name))
return (T) (substitutedUser == null ? user.getId() : substitutedUser.getId());
else
return (T) attributes.get(name);
}
/**

View File

@ -192,10 +192,7 @@ public abstract class AbstractCollectionDatasource<T extends Entity<K>, 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);

View File

@ -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;