Author: jacopoc
Date: Fri Apr 20 10:41:07 2007 New Revision: 530864 URL: http://svn.apache.org/viewvc?view=rev&rev=530864 Log: Implemented the ability to include / exclude ProductFeatureGroups in the advanced search. Modified: ofbiz/trunk/applications/product/entitydef/entitygroup.xml ofbiz/trunk/applications/product/entitydef/entitymodel.xml ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl Modified: ofbiz/trunk/applications/product/entitydef/entitygroup.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitygroup.xml?view=diff&rev=530864&r1=530863&r2=530864 ============================================================================== --- ofbiz/trunk/applications/product/entitydef/entitygroup.xml (original) +++ ofbiz/trunk/applications/product/entitydef/entitygroup.xml Fri Apr 20 10:41:07 2007 @@ -89,6 +89,7 @@ <entity-group group="org.ofbiz" entity="ProductFeatureDataResource" /> <entity-group group="org.ofbiz" entity="ProductFeatureGroup" /> <entity-group group="org.ofbiz" entity="ProductFeatureGroupAndAppl" /> + <entity-group group="org.ofbiz" entity="ProdFeaGrpAppAndProdFeaApp" /> <entity-group group="org.ofbiz" entity="ProductFeatureGroupAppl" /> <entity-group group="org.ofbiz" entity="ProductFeatureIactn" /> <entity-group group="org.ofbiz" entity="ProductFeatureIactnType" /> Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?view=diff&rev=530864&r1=530863&r2=530864 ============================================================================== --- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Fri Apr 20 10:41:07 2007 @@ -993,6 +993,26 @@ <key-map field-name="productFeatureId"/> </view-link> </view-entity> + <view-entity entity-name="ProdFeaGrpAppAndProdFeaApp" + package-name="org.ofbiz.product.feature" + title="ProductFeatureGroupAppl And ProductFeatureAppl View Entity"> + <member-entity entity-alias="PFGA" entity-name="ProductFeatureGroupAppl"/> + <member-entity entity-alias="PFA" entity-name="ProductFeatureAppl"/> + <alias entity-alias="PFGA" name="productFeatureGroupId"/> + <alias entity-alias="PFGA" name="productFeatureId"/> + <alias entity-alias="PFA" name="groupFromDate" field="fromDate"/> + <alias entity-alias="PFA" name="groupThruDate" field="thruDate"/> + <alias entity-alias="PFA" name="productId"/> + <alias entity-alias="PFA" name="productFeatureApplTypeId"/> + <alias entity-alias="PFA" name="fromDate"/> + <alias entity-alias="PFA" name="thruDate"/> + <alias entity-alias="PFA" name="sequenceNum"/> + <alias entity-alias="PFA" name="amount"/> + <alias entity-alias="PFA" name="recurringAmount"/> + <view-link entity-alias="PFGA" rel-entity-alias="PFA"> + <key-map field-name="productFeatureId"/> + </view-link> + </view-entity> <entity entity-name="ProductFeatureGroupAppl" package-name="org.ofbiz.product.feature" title="Product Feature Group Applicability Entity"> Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?view=diff&rev=530864&r1=530863&r2=530864 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Fri Apr 20 10:41:07 2007 @@ -180,6 +180,10 @@ public Set excludeFeatureCategoryIds = FastSet.newInstance(); public Set alwaysIncludeFeatureCategoryIds = FastSet.newInstance(); + public Set includeFeatureGroupIds = FastSet.newInstance(); + public Set excludeFeatureGroupIds = FastSet.newInstance(); + public Set alwaysIncludeFeatureGroupIds = FastSet.newInstance(); + public ProductSearchContext(GenericDelegator delegator, String visitId) { this.delegator = delegator; this.visitId = visitId; @@ -339,7 +343,8 @@ includeCategoryIdOrSetAndList.size() == 0 && alwaysIncludeCategoryIdOrSetAndList.size() == 0 && includeFeatureIds.size() == 0 && excludeFeatureIds.size() == 0 && alwaysIncludeFeatureIds.size() == 0 && includeFeatureIdOrSetAndList.size() == 0 && alwaysIncludeFeatureIdOrSetAndList.size() == 0 && - includeFeatureCategoryIds.size() == 0 && excludeFeatureCategoryIds.size() == 0 && alwaysIncludeFeatureCategoryIds.size() == 0) { + includeFeatureCategoryIds.size() == 0 && excludeFeatureCategoryIds.size() == 0 && alwaysIncludeFeatureCategoryIds.size() == 0 && + includeFeatureGroupIds.size() == 0 && excludeFeatureGroupIds.size() == 0 && alwaysIncludeFeatureGroupIds.size() == 0) { return; } @@ -412,6 +417,32 @@ incExcCondList.add(new EntityExpr(otherFeaturePrefix + "ProductFeatureCategoryId", EntityOperator.EQUALS, includeFeatureCategoryId)); } } + if (includeFeatureGroupIds.size() > 0) { + Iterator includeFeatureGroupIdIter = includeFeatureGroupIds.iterator(); + while (includeFeatureGroupIdIter.hasNext()) { + String includeFeatureGroupId = (String) includeFeatureGroupIdIter.next(); + String featurePrefix = "pfa" + this.index; + String entityAlias = "PFA" + this.index; + String otherFeaturePrefix = "pfga" + this.index; + String otherEntityAlias = "PFGA" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); + this.dynamicViewEntity.addMemberEntity(otherEntityAlias, "ProductFeatureGroupAppl"); + this.dynamicViewEntity.addAlias(otherEntityAlias, otherFeaturePrefix + "ProductFeatureGroupId", "productFeatureGroupId", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addAlias(otherEntityAlias, otherFeaturePrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(otherEntityAlias, otherFeaturePrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + this.dynamicViewEntity.addViewLink(entityAlias, otherEntityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productFeatureId")); + incExcCondList.add(new EntityExpr(new EntityExpr(featurePrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(featurePrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + incExcCondList.add(new EntityExpr(featurePrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + incExcCondList.add(new EntityExpr(new EntityExpr(otherFeaturePrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(otherFeaturePrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + incExcCondList.add(new EntityExpr(otherFeaturePrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + incExcCondList.add(new EntityExpr(otherFeaturePrefix + "ProductFeatureGroupId", EntityOperator.EQUALS, includeFeatureGroupId)); + } + } if (excludeCategoryIds.size() > 0) { List idExcludeCondList = FastList.newInstance(); @@ -437,6 +468,16 @@ EntityConditionValue subSelCond = new EntityConditionSubSelect("ProductFeatureAndAppl", "productId", new EntityConditionList(idExcludeCondList, EntityOperator.AND), true, delegator); incExcCondList.add(new EntityExpr("mainProductId", EntityOperator.NOT_EQUAL, subSelCond)); } + if (excludeFeatureGroupIds.size() > 0) { + List idExcludeCondList = FastList.newInstance(); + idExcludeCondList.add(new EntityExpr(new EntityExpr("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("thruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + idExcludeCondList.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + idExcludeCondList.add(new EntityExpr(new EntityExpr("groupThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("groupThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + idExcludeCondList.add(new EntityExpr("groupFromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + idExcludeCondList.add(new EntityExpr("productFeatureGroupId", EntityOperator.IN, excludeFeatureGroupIds)); + EntityConditionValue subSelCond = new EntityConditionSubSelect("ProdFeaGrpAppAndProdFeaApp", "productId", new EntityConditionList(idExcludeCondList, EntityOperator.AND), true, delegator); + incExcCondList.add(new EntityExpr("mainProductId", EntityOperator.NOT_EQUAL, subSelCond)); + } if (alwaysIncludeCategoryIds.size() > 0) { String categoryPrefix = "pcm" + this.index; @@ -488,6 +529,32 @@ alwIncCondList.add(new EntityExpr(otherFeaturePrefix + "ProductFeatureCategoryId", EntityOperator.EQUALS, alwaysIncludeFeatureCategoryId)); } } + if (alwaysIncludeFeatureGroupIds.size() > 0) { + Iterator alwaysIncludeFeatureGroupIdIter = alwaysIncludeFeatureGroupIds.iterator(); + while (alwaysIncludeFeatureGroupIdIter.hasNext()) { + String alwaysIncludeFeatureGroupId = (String) alwaysIncludeFeatureGroupIdIter.next(); + String featurePrefix = "pfa" + this.index; + String entityAlias = "PFA" + this.index; + String otherFeaturePrefix = "pfga" + this.index; + String otherEntityAlias = "PFGA" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); + this.dynamicViewEntity.addMemberEntity(otherEntityAlias, "ProductFeatureGroupAppl"); + this.dynamicViewEntity.addAlias(otherEntityAlias, otherFeaturePrefix + "ProductFeatureGroupId", "productFeatureGroupId", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addAlias(otherEntityAlias, otherFeaturePrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(otherEntityAlias, otherFeaturePrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + this.dynamicViewEntity.addViewLink(entityAlias, otherEntityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productFeatureId")); + alwIncCondList.add(new EntityExpr(new EntityExpr(featurePrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(featurePrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + alwIncCondList.add(new EntityExpr(featurePrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + alwIncCondList.add(new EntityExpr(new EntityExpr(otherFeaturePrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(otherFeaturePrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + alwIncCondList.add(new EntityExpr(otherFeaturePrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + alwIncCondList.add(new EntityExpr(otherFeaturePrefix + "ProductFeatureGroupId", EntityOperator.EQUALS, alwaysIncludeFeatureGroupId)); + } + } // handle includeFeatureIdOrSetAndList and alwaysIncludeFeatureIdOrSetAndList if (includeFeatureIdOrSetAndList.size() > 0) { @@ -1101,7 +1168,83 @@ } } } - + + public static class FeatureGroupConstraint extends ProductSearchConstraint { + public static final String constraintName = "FeatureGroup"; + protected String productFeatureGroupId; + /** This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */ + protected Boolean exclude; + + /** + * + * @param productFeatureGroupId + * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude + */ + public FeatureGroupConstraint(String productFeatureGroupId, Boolean exclude) { + this.productFeatureGroupId = productFeatureGroupId; + this.exclude = exclude; + } + + public void addConstraint(ProductSearchContext productSearchContext) { + // just add to global sets + if (exclude == null) { + productSearchContext.includeFeatureGroupIds.add(productFeatureGroupId); + } else if (exclude.equals(Boolean.TRUE)) { + productSearchContext.excludeFeatureGroupIds.add(productFeatureGroupId); + } else if (exclude.equals(Boolean.FALSE)) { + productSearchContext.alwaysIncludeFeatureGroupIds.add(productFeatureGroupId); + } + + // add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later + productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", this.productFeatureGroupId))); + } + + public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale) { + GenericValue productFeatureGroup = null; + try { + productFeatureGroup = delegator.findByPrimaryKeyCache("ProductFeatureGroup", UtilMisc.toMap("productFeatureGroupId", productFeatureGroupId)); + } catch (GenericEntityException e) { + Debug.logError(e, "Error finding ProductFeatureGroup and Type information for constraint pretty print", module); + } + StringBuffer ppBuf = new StringBuffer(); + if (productFeatureGroup != null) { + ppBuf.append(UtilProperties.getMessage(resource, "ProductFeatureGroup", locale) + ": "); + if(productFeatureGroup.get("description") != null) { + ppBuf.append(productFeatureGroup.get("description")); + } else { + ppBuf.append("[" + this.productFeatureGroupId + "]"); + } + } + if (this.exclude != null) { + if (Boolean.TRUE.equals(this.exclude)) { + ppBuf.append(" (Exclude)"); + } else { + ppBuf.append(" (Always Include)"); + } + } + return (ppBuf.toString()); + } + + public boolean equals(Object obj) { + ProductSearchConstraint psc = (ProductSearchConstraint) obj; + if (psc instanceof FeatureGroupConstraint) { + FeatureGroupConstraint that = (FeatureGroupConstraint) psc; + if (this.productFeatureGroupId == null) { + if (that.productFeatureGroupId != null) { + return false; + } + } else { + if (!this.productFeatureGroupId.equals(that.productFeatureGroupId)) { + return false; + } + } + return true; + } else { + return false; + } + } + } + public static class FeatureSetConstraint extends ProductSearchConstraint { public static final String constraintName = "Feature Set"; Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java?view=diff&rev=530864&r1=530863&r2=530864 ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Fri Apr 20 10:41:07 2007 @@ -571,6 +571,29 @@ constraintsChanged = true; } } + + //if product features group were selected add a constraint for each + if (parameterName.startsWith("SEARCH_PROD_FEAT_GRP") && !parameterName.startsWith("SEARCH_PROD_FEAT_GRP_EXC")) { + String productFeatureGroupId = (String) parameters.get(parameterName); + if (productFeatureGroupId != null && productFeatureGroupId.length() > 0) { + String paramNameExt = parameterName.substring("SEARCH_PROD_FEAT_GRP".length()); + String searchProdFeatureGroupExc = (String) parameters.get("SEARCH_PROD_FEAT_GRP_EXC" + paramNameExt); + Boolean exclude = UtilValidate.isEmpty(searchProdFeatureGroupExc) ? null : new Boolean(!"N".equals(searchProdFeatureGroupExc)); + searchAddConstraint(new ProductSearch.FeatureGroupConstraint(productFeatureGroupId, exclude), session); + constraintsChanged = true; + } + } + // a shorter variation for feature group + if (parameterName.startsWith("S_FGI")) { + String productFeatureGroupId = (String) parameters.get(parameterName); + if (productFeatureGroupId != null && productFeatureGroupId.length() > 0) { + String paramNameExt = parameterName.substring("S_FGI".length()); + String searchProdFeatureGroupExc = (String) parameters.get("S_FGX" + paramNameExt); + Boolean exclude = UtilValidate.isEmpty(searchProdFeatureGroupExc) ? null : new Boolean(!"N".equals(searchProdFeatureGroupExc)); + searchAddConstraint(new ProductSearch.FeatureGroupConstraint(productFeatureGroupId, exclude), session); + constraintsChanged = true; + } + } } // if features were selected add a constraint for each @@ -773,6 +796,7 @@ int categoriesCount = 0; int featuresCount = 0; int featureCategoriesCount = 0; + int featureGroupsCount = 0; int keywordsCount = 0; boolean isNotFirst = false; while (constraintIter.hasNext()) { @@ -838,6 +862,24 @@ searchParamString.append(featureCategoriesCount); searchParamString.append("="); searchParamString.append(pfcc.exclude.booleanValue() ? "Y" : "N"); + } + } else if (psc instanceof ProductSearch.FeatureGroupConstraint) { + ProductSearch.FeatureGroupConstraint pfgc = (ProductSearch.FeatureGroupConstraint) psc; + featureGroupsCount++; + if (isNotFirst) { + searchParamString.append("&"); + } else { + isNotFirst = true; + } + searchParamString.append("S_FGI"); + searchParamString.append(featureGroupsCount); + searchParamString.append("="); + searchParamString.append(pfgc.productFeatureGroupId); + if (pfgc.exclude != null) { + searchParamString.append("&S_FGX"); + searchParamString.append(featureGroupsCount); + searchParamString.append("="); + searchParamString.append(pfgc.exclude.booleanValue() ? "Y" : "N"); } } else if (psc instanceof ProductSearch.KeywordConstraint) { ProductSearch.KeywordConstraint kc = (ProductSearch.KeywordConstraint) psc; Modified: ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl?view=diff&rev=530864&r1=530863&r2=530864 ============================================================================== --- ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl (original) +++ ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl Fri Apr 20 10:41:07 2007 @@ -110,6 +110,31 @@ </div> </td> </tr> + <tr> + <td align="right" valign="top"> + <div class="tabletext">${uiLabelMap.ProductFeatureGroup} ${uiLabelMap.CommonIds}:</div> + </td> + <td valign="middle"> + <div> + <input type="text" class="inputBox" name="SEARCH_PROD_FEAT_GRP1" size="15" value="${requestParameters.SEARCH_PROD_FEAT_GRP1?if_exists}"/> + ${uiLabelMap.CommonInclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC1" value="" checked="checked"/> + ${uiLabelMap.CommonExclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC1" value="Y"/> + ${uiLabelMap.CommonAlwaysInclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC1" value="N"/> + </div> + <div> + <input type="text" class="inputBox" name="SEARCH_PROD_FEAT_GRP2" size="15" value="${requestParameters.SEARCH_PROD_FEAT_GRP2?if_exists}"/> + ${uiLabelMap.CommonInclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC2" value="" checked="checked"/> + ${uiLabelMap.CommonExclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC2" value="Y"/> + ${uiLabelMap.CommonAlwaysInclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC2" value="N"/> + </div> + <div> + <input type="text" class="inputBox" name="SEARCH_PROD_FEAT_GRP3" size="15" value="${requestParameters.SEARCH_PROD_FEAT_GRP3?if_exists}"/> + ${uiLabelMap.CommonInclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC3" value="" checked="checked"/> + ${uiLabelMap.CommonExclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC3" value="Y"/> + ${uiLabelMap.CommonAlwaysInclude}<input type="radio" name="SEARCH_PROD_FEAT_GRP_EXC3" value="N"/> + </div> + </td> + </tr> <tr> <td align="right" valign="top"> |
Free forum by Nabble | Edit this page |