|
Author: adrianc
Date: Tue May 22 10:44:31 2012 New Revision: 1341397 URL: http://svn.apache.org/viewvc?rev=1341397&view=rev Log: Overhauled Mini-language <filter-list-by-and> element. Modified: ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FilterListByAnd.java Modified: ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd?rev=1341397&r1=1341396&r2=1341397&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd (original) +++ ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd Tue May 22 10:44:31 2012 @@ -2864,38 +2864,41 @@ under the License. <xs:element name="filter-list-by-and" substitutionGroup="EntityFindOperations"> <xs:annotation> <xs:documentation> - The filter-list-by-and tag filters the given list by the fields in the specified map. + Filters a list of entity values by the fields in the specified map. + Each entity value in the list will be compared to the specified map, and + if the entity value's fields match the map, the entity value will be copied + to the target list. </xs:documentation> </xs:annotation> <xs:complexType> - <xs:attributeGroup ref="attlist.filter-list-by-and"/> + <xs:attribute type="xs:string" name="list" use="required"> + <xs:annotation> + <xs:documentation> + The name of the field that contains the list of entity values. + <br/><br/> + Required. Attribute type: expression. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="map" use="required"> + <xs:annotation> + <xs:documentation> + The name of the field that contains the map that will be used for the entity field comparison. + Required. Attribute type: expression. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute type="xs:string" name="to-list"> + <xs:annotation> + <xs:documentation> + The name of the field the filtered list will be put into. + Defaults to the value of the list-name attribute (replaces the old list). + Optional. Attribute type: expression. + </xs:documentation> + </xs:annotation> + </xs:attribute> </xs:complexType> </xs:element> - <xs:attributeGroup name="attlist.filter-list-by-and"> - <xs:attribute type="xs:string" name="list" use="required"> - <xs:annotation> - <xs:documentation> - The name of the method environment field that contains the list of GenericValue objects. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:string" name="to-list"> - <xs:annotation> - <xs:documentation> - The name of the method environment field the filtered list will be put into. - Defaults to the value of the list-name attribute (ie goes to the same place it came from, replacing the old list). - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:string" name="map"> - <xs:annotation> - <xs:documentation> - The name of a map in the method environment that will be used for the entity fields. - If no map is used this will just make a copy of the list. - </xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:attributeGroup> <xs:element name="filter-list-by-date" substitutionGroup="EntityFindOperations"> <xs:annotation> <xs:documentation> Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FilterListByAnd.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FilterListByAnd.java?rev=1341397&r1=1341396&r2=1341397&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FilterListByAnd.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/FilterListByAnd.java Tue May 22 10:44:31 2012 @@ -21,61 +21,74 @@ package org.ofbiz.minilang.method.entity import java.util.List; import java.util.Map; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to find entity values by anding the map fields + * Implements the <filter-list-by-and> element. */ -public class FilterListByAnd extends MethodOperation { +public final class FilterListByAnd extends MethodOperation { - ContextAccessor<List<GenericEntity>> listAcsr; - ContextAccessor<Map<String, ? extends Object>> mapAcsr; - ContextAccessor<List<GenericEntity>> toListAcsr; + private final FlexibleMapAccessor<List<GenericEntity>> listFma; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; + private final FlexibleMapAccessor<List<GenericEntity>> toListFma; public FilterListByAnd(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - listAcsr = new ContextAccessor<List<GenericEntity>>(element.getAttribute("list"), element.getAttribute("list-name")); - toListAcsr = new ContextAccessor<List<GenericEntity>>(element.getAttribute("to-list"), element.getAttribute("to-list-name")); - if (toListAcsr.isEmpty()) { - toListAcsr = listAcsr; + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); + String toListAttribute = element.getAttribute("to-list"); + if (toListAttribute.isEmpty()) { + toListFma = listFma; + } else { + toListFma = FlexibleMapAccessor.getInstance(toListAttribute); } - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - Map<String, ? extends Object> theMap = null; - if (!mapAcsr.isEmpty()) { - theMap = mapAcsr.get(methodContext); - } - toListAcsr.put(methodContext, EntityUtil.filterByAnd(listAcsr.get(methodContext), theMap)); + Map<String, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap()); + toListFma.put(methodContext.getEnvMap(), EntityUtil.filterByAnd(listFma.get(methodContext.getEnvMap()), theMap)); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<filter-list-by-and/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<filter-list-by-and "); + sb.append("list=\"").append(this.listFma).append("\" "); + sb.append("map=\"").append(this.mapFma).append("\" "); + sb.append("to-list=\"").append(this.toListFma).append("\" "); + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <filter-list-by-and> element. + */ public static final class FilterListByAndFactory implements Factory<FilterListByAnd> { + @Override public FilterListByAnd createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new FilterListByAnd(element, simpleMethod); } + @Override public String getName() { return "filter-list-by-and"; } |
| Free forum by Nabble | Edit this page |
