|
Author: adrianc
Date: Sat May 19 13:08:17 2012 New Revision: 1340465 URL: http://svn.apache.org/viewvc?rev=1340465&view=rev Log: Overhauled Mini-language <entity-and> and <entity-condition> elements. Modified: ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityAnd.java ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCondition.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=1340465&r1=1340464&r2=1340465&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd (original) +++ ofbiz/trunk/framework/minilang/dtd/simple-methods-v2.xsd Sat May 19 13:08:17 2012 @@ -206,6 +206,82 @@ under the License. </xs:simpleType> </xs:attribute> + <xs:attributeGroup name="attlist.entityFindOperations"> + <xs:attribute name="entity-name" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation> + Name of entity to search in. + <br/><br/> + Required. Attribute type: constant, ${expression}. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="list" type="xs:string" use="required"> + <xs:annotation> + <xs:documentation> + Name of the list where to put results. + <br/><br/> + Required. Attribute type: expression. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="filter-by-date" default="false"> + <xs:annotation> + <xs:documentation> + Look for from-date and through-date fields in the list of results coming back + and filters by the current date and time if set to true. + Defaults to "false". + <br/><br/> + Optional. Attribute type: constant, ${expression}. + </xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true" /> + <xs:enumeration value="false" /> + <xs:enumeration value="by-name" /> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="distinct" default="false"> + <xs:annotation> + <xs:documentation> + Filter the results making sure that all of them are unique. + Defaults to "false". + <br/><br/> + Optional. Attribute type: constant, ${expression}. + </xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + <xs:attribute name="use-cache" type="xs:string" default="false"> + <xs:annotation> + <xs:documentation> + Specifies whether or not the delegator's cache should be searched before going to the database. + This results in much faster retrieval times, but can return stale data that is not the most current in the database. + Must be "true" or "false", defaults to "false". + <br/><br/> + Optional. Attribute type: constant, ${expression}. + </xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="delegator-name" type="xs:string"> + <xs:annotation> + <xs:documentation> + Name of a delegator to use. + By default uses the delegator associated with that instance of the service engine. + <br/><br/> + Optional. Attribute type: constant, ${expression}. + </xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:attributeGroup> + <!-- ELEMENTS start here --> <xs:element name="field"> <xs:annotation> @@ -587,7 +663,7 @@ under the License. <xs:documentation> Name of the service to call. <br/><br/> - Required. Attribute type: constant, expression. + Required. Attribute type: constant, ${expression}. </xs:documentation> </xs:annotation> </xs:attribute> @@ -906,7 +982,7 @@ under the License. <xs:documentation> Name of the service to call. <br/><br/> - Required. Attribute type: constant, expression. + Required. Attribute type: constant, ${expression}. </xs:documentation> </xs:annotation> </xs:attribute> @@ -2203,75 +2279,39 @@ under the License. <xs:element name="entity-and" substitutionGroup="EntityFindOperations"> <xs:annotation> <xs:documentation> - Does a find-by-and, returns a list of GenericValues if any are found, otherwise returns an empty list. + Does a find-by-and, returns a list of entity values if any are found, otherwise returns an empty list. Uses name/value pairs, that will be used for the query and will all be "anded" together. - The result-set-type by default is scroll which is flexible so you can go forward. + The result-set-type by default is scroll which is flexible so you can go + forward. </xs:documentation> </xs:annotation> <xs:complexType> <xs:sequence> - <xs:element maxOccurs="unbounded" ref="field-map"/> + <xs:element maxOccurs="unbounded" ref="field-map" /> <xs:element minOccurs="0" maxOccurs="unbounded" ref="select-field"> - <xs:annotation><xs:documentation>Specify fields to select, otherwise all fields will be selected.</xs:documentation></xs:annotation> + <xs:annotation> + <xs:documentation>Specify fields to select, otherwise all fields will be selected.</xs:documentation> + </xs:annotation> </xs:element> <xs:element minOccurs="0" maxOccurs="unbounded" ref="order-by"> - <xs:annotation><xs:documentation>Defines fields to order list by.</xs:documentation></xs:annotation> + <xs:annotation> + <xs:documentation>Defines fields to order list by.</xs:documentation> + </xs:annotation> </xs:element> <xs:choice minOccurs="0"> - <xs:element ref="limit-range"/> - <xs:element ref="limit-view"/> - <xs:element ref="use-iterator"/> + <xs:element ref="limit-range" /> + <xs:element ref="limit-view" /> + <xs:element ref="use-iterator" /> </xs:choice> </xs:sequence> - <xs:attributeGroup ref="attlist.entity-and"/> + <xs:attributeGroup ref="attlist.entityFindOperations"/> </xs:complexType> </xs:element> - <xs:attributeGroup name="attlist.entity-and"> - <xs:attribute name="entity-name" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation> - Name of entity to search in. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute name="use-cache" type="xs:string" default="false"> - <xs:annotation> - <xs:documentation> - Specifies whether or not the delegator's cache should be searched before going to the database. - This results in much faster retrieval times, but can return stale data that is not the most current in the database. - Must be "true" or "false", defaults to "false". - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute name="filter-by-date" default="false"> - <xs:annotation> - <xs:documentation> - Look for from-date and through-date fields in the list of results coming back - and filters by the current date and time if set to true. - Defaults to false. - </xs:documentation> - </xs:annotation> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true"/> - <xs:enumeration value="false"/> - <xs:enumeration value="by-name"/> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="list" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation> - Name of the list where to put results. - </xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:attributeGroup> <xs:element name="entity-condition" substitutionGroup="EntityFindOperations"> <xs:annotation> <xs:documentation> - Like entity-and returns a list of Generic values if any are found, otherwise returns an empty list. + Returns a list of entity values based on a condition expression, otherwise returns an empty list. Uses any of condition-expression, condition-list and condition-object. </xs:documentation> </xs:annotation> @@ -2297,72 +2337,9 @@ under the License. <xs:element ref="use-iterator"/> </xs:choice> </xs:sequence> - <xs:attributeGroup ref="attlist.entity-condition"/> + <xs:attributeGroup ref="attlist.entityFindOperations"/> </xs:complexType> </xs:element> - <xs:attributeGroup name="attlist.entity-condition"> - <xs:attribute name="entity-name" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation> - Name of entity to search in. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute type="xs:string" name="use-cache" default="false"> - <xs:annotation> - <xs:documentation> - Specifies whether or not the delegator's cache should be searched before going to the database. - This results in much faster retrieval times, but can return stale data that is not the most current in the database. - Must be "true" or "false", defaults to "false". - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute name="filter-by-date" default="false"> - <xs:annotation> - <xs:documentation> - Look for from date and through date fields in the list of results coming back - and filters by the current date and time if set to true. - Defaults to false. - </xs:documentation> - </xs:annotation> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true"/> - <xs:enumeration value="false"/> - <xs:enumeration value="by-name"/> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="distinct" default="false"> - <xs:annotation> - <xs:documentation> - Filter the results making sure that all of them are unique. - Defaults to false. - </xs:documentation> - </xs:annotation> - <xs:simpleType> - <xs:restriction base="xs:token"> - <xs:enumeration value="true"/> - <xs:enumeration value="false"/> - </xs:restriction> - </xs:simpleType> - </xs:attribute> - <xs:attribute name="delegator-name" type="xs:string"> - <xs:annotation> - <xs:documentation> - Name of a delegator to use. - By default uses the delegator associated with that instance of the service engine. - </xs:documentation> - </xs:annotation> - </xs:attribute> - <xs:attribute name="list" type="xs:string" use="required"> - <xs:annotation> - <xs:documentation> - Name of the list where to put results. - </xs:documentation> - </xs:annotation> - </xs:attribute> - </xs:attributeGroup> <xs:element name="condition-list"> <xs:annotation> <xs:documentation> @@ -3324,7 +3301,7 @@ under the License. <xs:documentation> The name of the entity. <br/><br/> - Required. Attribute type: constant, expression. + Required. Attribute type: constant, ${expression}. </xs:documentation> </xs:annotation> </xs:attribute> Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityAnd.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityAnd.java?rev=1340465&r1=1340464&r2=1340465&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityAnd.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityAnd.java Sat May 19 13:08:17 2012 @@ -21,25 +21,34 @@ package org.ofbiz.minilang.method.entity import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.finder.ByAndFinder; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; 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 a condition + * Implements the <entity-and> element. */ -public class EntityAnd extends MethodOperation { +public final class EntityAnd extends MethodOperation { public static final String module = EntityAnd.class.getName(); - protected ByAndFinder finder; + private final ByAndFinder finder; public EntityAnd(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "entity-name", "use-cache", "filter-by-date", "list", "distinct", "delegator-name"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "entity-name", "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "list"); + MiniLangValidate.childElements(simpleMethod, element, "field-map", "order-by", "limit-range", "limit-view", "use-iterator"); + MiniLangValidate.requiredChildElements(simpleMethod, element, "field-map"); + } this.finder = new ByAndFinder(element); } @@ -49,15 +58,9 @@ public class EntityAnd extends MethodOpe Delegator delegator = methodContext.getDelegator(); this.finder.runFind(methodContext.getEnvMap(), delegator); } catch (GeneralException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process: " + e.getMessage(); - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while performing entity find: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -65,8 +68,7 @@ public class EntityAnd extends MethodOpe @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override @@ -76,10 +78,19 @@ public class EntityAnd extends MethodOpe @Override public String rawString() { - // TODO: something more than the empty tag - return "<entity-and/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<entity-and "); + sb.append("entity-name=\"").append(this.finder.getEntityName()).append("\" />"); + return sb.toString(); } + /** + * A factory for the <entity-and> element. + */ public static final class EntityAndFactory implements Factory<EntityAnd> { public EntityAnd createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new EntityAnd(element, simpleMethod); Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCondition.java?rev=1340465&r1=1340464&r2=1340465&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCondition.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/EntityCondition.java Sat May 19 13:08:17 2012 @@ -21,25 +21,34 @@ package org.ofbiz.minilang.method.entity import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.finder.ByConditionFinder; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; 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 a condition + * Implements the <entity-and> element. */ -public class EntityCondition extends MethodOperation { +public final class EntityCondition extends MethodOperation { public static final String module = EntityCondition.class.getName(); - protected ByConditionFinder finder; + private final ByConditionFinder finder; public EntityCondition(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "entity-name", "use-cache", "filter-by-date", "list", "distinct", "delegator-name"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "entity-name", "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "list"); + MiniLangValidate.childElements(simpleMethod, element, "condition-expr", "condition-list", "condition-object", "having-condition-list", "select-field", "order-by", "limit-range", "limit-view", "use-iterator"); + MiniLangValidate.requireAnyChildElement(simpleMethod, element, "condition-expr", "condition-list", "condition-object"); + } this.finder = new ByConditionFinder(element); } @@ -49,15 +58,9 @@ public class EntityCondition extends Met Delegator delegator = methodContext.getDelegator(); this.finder.runFind(methodContext.getEnvMap(), delegator); } catch (GeneralException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process: " + e.getMessage(); - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while performing entity find: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -65,8 +68,7 @@ public class EntityCondition extends Met @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override @@ -76,8 +78,14 @@ public class EntityCondition extends Met @Override public String rawString() { - // TODO: something more than the empty tag - return "<entity-condition/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<entity-condition "); + sb.append("entity-name=\"").append(this.finder.getEntityName()).append("\" />"); + return sb.toString(); } public static final class EntityConditionFactory implements Factory<EntityCondition> { |
| Free forum by Nabble | Edit this page |
