Author: erwan
Date: Tue Nov 22 20:41:14 2011 New Revision: 1205156 URL: http://svn.apache.org/viewvc?rev=1205156&view=rev Log: A patch from Youssef Khaye - OFBIZ-4573 - complex-alias does not allow to do (discountPercent * 100) as stated in xsd Modified: ofbiz/trunk/framework/entity/dtd/entitymodel.xsd ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Modified: ofbiz/trunk/framework/entity/dtd/entitymodel.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/dtd/entitymodel.xsd?rev=1205156&r1=1205155&r2=1205156&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/dtd/entitymodel.xsd (original) +++ ofbiz/trunk/framework/entity/dtd/entitymodel.xsd Tue Nov 22 20:41:14 2011 @@ -346,9 +346,10 @@ under the License. </xs:complexType> </xs:element> <xs:attributeGroup name="attlist.complex-alias-field"> - <xs:attribute name="entity-alias" type="xs:string" use="required"/> - <xs:attribute name="field" type="xs:string" use="required"/> + <xs:attribute name="entity-alias" type="xs:string"/> + <xs:attribute name="field" type="xs:string"/> <xs:attribute name="default-value" type="xs:string"/> + <xs:attribute name="value" type="xs:string"/> <xs:attribute name="function" type="aggregate-function"/> </xs:attributeGroup> <xs:element name="view-link"> Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java?rev=1205156&r1=1205155&r2=1205156&view=diff ============================================================================== --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java (original) +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/model/ModelViewEntity.java Tue Nov 22 20:41:14 2011 @@ -1045,12 +1045,14 @@ public class ModelViewEntity extends Mod protected final String field; protected final String defaultValue; protected final String function; + protected final String value; public ComplexAliasField(Element complexAliasFieldElement) { this.entityAlias = complexAliasFieldElement.getAttribute("entity-alias").intern(); this.field = complexAliasFieldElement.getAttribute("field").intern(); this.defaultValue = complexAliasFieldElement.getAttribute("default-value").intern(); this.function = complexAliasFieldElement.getAttribute("function").intern(); + this.value = complexAliasFieldElement.getAttribute("value").intern(); } public ComplexAliasField(String entityAlias, String field, String defaultValue, String function) { @@ -1058,36 +1060,49 @@ public class ModelViewEntity extends Mod this.field = field; this.defaultValue = defaultValue; this.function = function; + this.value = null; + } + public ComplexAliasField(String entityAlias, String field, String defaultValue, String function, String value) { + this.entityAlias = entityAlias; + this.field = field; + this.defaultValue = defaultValue; + this.function = function; + this.value = value; } /** * Make the alias as follows: function(coalesce(entityAlias.field, defaultValue)) */ public void makeAliasColName(StringBuilder colNameBuffer, StringBuilder fieldTypeBuffer, ModelViewEntity modelViewEntity, ModelReader modelReader) { - ModelEntity modelEntity = modelViewEntity.getAliasedEntity(entityAlias, modelReader); - ModelField modelField = modelViewEntity.getAliasedField(modelEntity, field, modelReader); - - String colName = entityAlias + "." + modelField.getColName(); - - if (UtilValidate.isNotEmpty(defaultValue)) { - colName = "COALESCE(" + colName + "," + defaultValue + ")"; - } - - if (UtilValidate.isNotEmpty(function)) { - String prefix = functionPrefixMap.get(function); - if (prefix == null) { - Debug.logWarning("[" + modelViewEntity.getEntityName() + "]: Specified alias function [" + function + "] not valid; must be: min, max, sum, avg, count or count-distinct; using a column name with no function function", module); - } else { - colName = prefix + colName + ")"; + if(UtilValidate.isEmpty(entityAlias) + && UtilValidate.isEmpty(field) + && UtilValidate.isNotEmpty(value)){ + colNameBuffer.append(value); + } + else { + ModelEntity modelEntity = modelViewEntity.getAliasedEntity(entityAlias, modelReader); + ModelField modelField = modelViewEntity.getAliasedField(modelEntity, field, modelReader); + String colName = entityAlias + "." + modelField.getColName(); + + if (UtilValidate.isNotEmpty(defaultValue)) { + colName = "COALESCE(" + colName + "," + defaultValue + ")"; + } + + if (UtilValidate.isNotEmpty(function)) { + String prefix = functionPrefixMap.get(function); + if (prefix == null) { + Debug.logWarning("[" + modelViewEntity.getEntityName() + "]: Specified alias function [" + function + "] not valid; must be: min, max, sum, avg, count or count-distinct; using a column name with no function function", module); + } else { + colName = prefix + colName + ")"; + } + } + + colNameBuffer.append(colName); + //set fieldTypeBuffer if not already set + if (fieldTypeBuffer.length() == 0) { + fieldTypeBuffer.append(modelField.type); } } - - colNameBuffer.append(colName); - - //set fieldTypeBuffer if not already set - if (fieldTypeBuffer.length() == 0) { - fieldTypeBuffer.append(modelField.type); - } } } |
Free forum by Nabble | Edit this page |