Author: tchemit Date: 2012-09-14 12:02:42 +0200 (Fri, 14 Sep 2012) New Revision: 2665 Url: http://nuiton.org/repositories/revision/topia/2665 Log: refs #2313: Use new PageBean API from nuiton-utils (improve Topia Filter api) Added: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleGroupOperator.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleOperator.java Removed: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperation.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperationGroup.java Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRule.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBean.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBeanBuilder.java Deleted: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperation.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperation.java 2012-09-14 09:51:06 UTC (rev 2664) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperation.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -1,152 +0,0 @@ -package org.nuiton.topia.persistence.pager; - -import java.util.Map; - -/** -* TODO -* -* @author tchemit <chemit@codelutin.com> -* @since 2.6.14 -*/ -public enum FilterOperation { - /** Equals operator. */ - eq { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " = :" + paramName; - filterParams.put(paramName, data); - return ruleFilter; - } - }, - /** Not equals operator. */ - ne { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " != :" + paramName; - filterParams.put(paramName, data); - return ruleFilter; - } - }, - /** Contains operator. */ - cn { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " like :" + paramName; - filterParams.put(paramName, "%" + data + "%"); - return ruleFilter; - } - }, - /** Not contains operator. */ - nc { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " not like :" + paramName; - filterParams.put(paramName, "%" + data + "%"); - return ruleFilter; - } - }, - /** Begins with operator. */ - bw { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " like :" + paramName; - filterParams.put(paramName, data + "%"); - return ruleFilter; - } - }, - /** Not between with operator. */ - bn { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " not like :" + paramName; - filterParams.put(paramName, data + "%"); - return ruleFilter; - } - }, - /** Ends with operator. */ - ew { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " like :" + paramName; - filterParams.put(paramName, "%" + data); - return ruleFilter; - } - }, - /** Not End with operator. */ - en { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " not like :" + paramName; - filterParams.put(paramName, "%" + data); - return ruleFilter; - } - }, - /** Lesser than operator. */ - lt { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " < :" + paramName; - filterParams.put(paramName, data); - return ruleFilter; - } - }, - /** Lesser or equals operator. */ - le { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " <= :" + paramName; - filterParams.put(paramName, data); - return ruleFilter; - } - }, - /** Greater than operator. */ - gt { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " > :" + paramName; - filterParams.put(paramName, data); - return ruleFilter; - } - }, - /** Greater or equals operator. */ - ge { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " >= :" + paramName; - filterParams.put(paramName, data); - return ruleFilter; - } - }, - /** Is null operator. */ - nu { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " is null"; - return ruleFilter; - } - }, - /** Is not null operator. */ - nn { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - String ruleFilter = propertyName + " is not null"; - return ruleFilter; - } - }, - /** Is among operator. */ - in { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - throw new UnsupportedOperationException(); - } - }, - /** Not is among operator. */ - ni { - @Override - public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { - throw new UnsupportedOperationException(); - } - }; - - public abstract String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams); -} Deleted: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperationGroup.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperationGroup.java 2012-09-14 09:51:06 UTC (rev 2664) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperationGroup.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -1,11 +0,0 @@ -package org.nuiton.topia.persistence.pager; - -/** -* TODO -* -* @author tchemit <chemit@codelutin.com> -* @since 2.6.14 -*/ -public enum FilterOperationGroup { - OR, AND -} Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRule.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRule.java 2012-09-14 09:51:06 UTC (rev 2664) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRule.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -1,9 +1,33 @@ package org.nuiton.topia.persistence.pager; +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import java.io.Serializable; /** - * TODO + * Rule for a filtered pager. * * @author tchemit <chemit@codelutin.com> * @since 2.6.14 @@ -12,19 +36,19 @@ private static final long serialVersionUID = 1L; - protected final FilterOperation op; + protected final FilterRuleOperator op; protected final String field; protected final String data; - public FilterRule(FilterOperation op, String field, String data) { + public FilterRule(FilterRuleOperator op, String field, String data) { this.op = op; this.field = field; this.data = data; } - public FilterOperation getOp() { + public FilterRuleOperator getOp() { return op; } Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRule.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Copied: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleGroupOperator.java (from rev 2664, branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperationGroup.java) =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleGroupOperator.java (rev 0) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleGroupOperator.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -0,0 +1,35 @@ +package org.nuiton.topia.persistence.pager; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/** + * Define the operator to apply between some rules. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.6.14 + */ +public enum FilterRuleGroupOperator { + OR, AND +} Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleGroupOperator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleOperator.java (from rev 2664, branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterOperation.java) =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleOperator.java (rev 0) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleOperator.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -0,0 +1,176 @@ +package org.nuiton.topia.persistence.pager; + +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import java.util.Map; + +/** + * Operator used in a rule. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.6.14 + */ +public enum FilterRuleOperator { + /** Equals operator. */ + eq { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " = :" + paramName; + filterParams.put(paramName, data); + return ruleFilter; + } + }, + /** Not equals operator. */ + ne { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " != :" + paramName; + filterParams.put(paramName, data); + return ruleFilter; + } + }, + /** Contains operator. */ + cn { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " like :" + paramName; + filterParams.put(paramName, "%" + data + "%"); + return ruleFilter; + } + }, + /** Not contains operator. */ + nc { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " not like :" + paramName; + filterParams.put(paramName, "%" + data + "%"); + return ruleFilter; + } + }, + /** Begins with operator. */ + bw { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " like :" + paramName; + filterParams.put(paramName, data + "%"); + return ruleFilter; + } + }, + /** Not between with operator. */ + bn { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " not like :" + paramName; + filterParams.put(paramName, data + "%"); + return ruleFilter; + } + }, + /** Ends with operator. */ + ew { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " like :" + paramName; + filterParams.put(paramName, "%" + data); + return ruleFilter; + } + }, + /** Not End with operator. */ + en { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " not like :" + paramName; + filterParams.put(paramName, "%" + data); + return ruleFilter; + } + }, + /** Lesser than operator. */ + lt { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " < :" + paramName; + filterParams.put(paramName, data); + return ruleFilter; + } + }, + /** Lesser or equals operator. */ + le { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " <= :" + paramName; + filterParams.put(paramName, data); + return ruleFilter; + } + }, + /** Greater than operator. */ + gt { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " > :" + paramName; + filterParams.put(paramName, data); + return ruleFilter; + } + }, + /** Greater or equals operator. */ + ge { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " >= :" + paramName; + filterParams.put(paramName, data); + return ruleFilter; + } + }, + /** Is null operator. */ + nu { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " is null"; + return ruleFilter; + } + }, + /** Is not null operator. */ + nn { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + String ruleFilter = propertyName + " is not null"; + return ruleFilter; + } + }, + /** Is among operator. */ + in { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + throw new UnsupportedOperationException(); + } + }, + /** Not is among operator. */ + ni { + @Override + public String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams) { + throw new UnsupportedOperationException(); + } + }; + + public abstract String toHql(String paramName, String propertyName, Object data, Map<String, Object> filterParams); +} Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/FilterRuleOperator.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBean.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBean.java 2012-09-14 09:51:06 UTC (rev 2664) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBean.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -1,12 +1,36 @@ package org.nuiton.topia.persistence.pager; +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.PagerBean; import java.util.List; /** - * Extension of a {@link PagerBean} to add filter capacity. + * Extension of a {@link PagerBean} to add filter and ordering capacities. * * @author tchemit <chemit@codelutin.com> * @since 2.6.14 @@ -21,7 +45,7 @@ // get index row - i.e. user click to sort. protected String sortColumn; - protected FilterOperationGroup groupOp; + protected FilterRuleGroupOperator groupOp; private List<FilterRule> rules; @@ -29,11 +53,11 @@ return groupOp != null && CollectionUtils.isNotEmpty(rules); } - public FilterOperationGroup getGroupOp() { + public FilterRuleGroupOperator getGroupOp() { return groupOp; } - public void setGroupOp(FilterOperationGroup groupOp) { + public void setGroupOp(FilterRuleGroupOperator groupOp) { this.groupOp = groupOp; } Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBean.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBeanBuilder.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBeanBuilder.java 2012-09-14 09:51:06 UTC (rev 2664) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBeanBuilder.java 2012-09-14 10:02:42 UTC (rev 2665) @@ -1,5 +1,29 @@ package org.nuiton.topia.persistence.pager; +/* + * #%L + * ToPIA :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -23,7 +47,7 @@ this.bean = bean; } - public TopiaPagerBeanBuilder setFilterOperationGroup(FilterOperationGroup groupOp) { + public TopiaPagerBeanBuilder setFilterRuleGroup(FilterRuleGroupOperator groupOp) { bean.setGroupOp(groupOp); return this; } @@ -39,19 +63,19 @@ } public TopiaPagerBeanBuilder setFilterOperationGroup(String groupOp) { - setFilterOperationGroup(FilterOperationGroup.valueOf(groupOp)); + setFilterRuleGroup(FilterRuleGroupOperator.valueOf(groupOp)); return this; } - public TopiaPagerBeanBuilder addOperations(Collection<Map<String, String>> operations) { - for (Map<String, String> operation : operations) { - addRule(operation); + public TopiaPagerBeanBuilder addRules(Collection<Map<String, String>> rules) { + for (Map<String, String> rule : rules) { + addRule(rule); } return this; } public TopiaPagerBeanBuilder addRule(String op, String property, String value) { - FilterOperation operator = FilterOperation.valueOf(op); + FilterRuleOperator operator = FilterRuleOperator.valueOf(op); return addRule(new FilterRule(operator, property, value)); } Property changes on: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/pager/TopiaPagerBeanBuilder.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL