Author: jonesde
Date: Fri Apr 13 15:12:31 2007 New Revision: 528686 URL: http://svn.apache.org/viewvc?view=rev&rev=528686 Log: Fixed problem with category search in sub-categories caused by the include/exclude/alwaysInclude stuff added a while back; note that there is still a problem with excludes in certain circumstances Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java 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=528686&r1=528685&r2=528686 ============================================================================== --- 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 13 15:12:31 2007 @@ -163,6 +163,9 @@ public Set excludeCategoryIds = FastSet.newInstance(); public Set alwaysIncludeCategoryIds = FastSet.newInstance(); + public List includeCategoryIdOrSetAndList = FastList.newInstance(); + public List alwaysIncludeCategoryIdOrSetAndList = FastList.newInstance(); + public Set includeFeatureIds = FastSet.newInstance(); public Set excludeFeatureIds = FastSet.newInstance(); public Set alwaysIncludeFeatureIds = FastSet.newInstance(); @@ -326,8 +329,9 @@ public void finishCategoryAndFeatureConstraints() { if (includeCategoryIds.size() == 0 && excludeCategoryIds.size() == 0 && alwaysIncludeCategoryIds.size() == 0 && + includeCategoryIdOrSetAndList.size() == 0 && alwaysIncludeCategoryIdOrSetAndList.size() == 0 && includeFeatureIds.size() == 0 && excludeFeatureIds.size() == 0 && alwaysIncludeFeatureIds.size() == 0 && - includeFeatureIdOrSetAndList.size() == 0) { + includeFeatureIdOrSetAndList.size() == 0 && alwaysIncludeFeatureIdOrSetAndList.size() == 0) { return; } @@ -342,41 +346,44 @@ EntityCondition topCond = null; - Iterator includeCategoryIdIter = includeCategoryIds.iterator(); - while (includeCategoryIdIter.hasNext()) { - String includeCategoryId = (String) includeCategoryIdIter.next(); - String categoryPrefix = "pcm" + this.index; - String entityAlias = "PCM" + this.index; - this.index++; - - this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember"); - this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ProductCategoryId", "productCategoryId", null, null, null, null); - this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "FromDate", "fromDate", null, null, null, null); - this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ThruDate", "thruDate", null, null, null, null); - this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - incExcCondList.add(new EntityExpr(new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); - incExcCondList.add(new EntityExpr(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); - incExcCondList.add(new EntityExpr(categoryPrefix + "ProductCategoryId", EntityOperator.EQUALS, includeCategoryId)); - } - Iterator includeFeatureIdIter = includeFeatureIds.iterator(); - while (includeFeatureIdIter.hasNext()) { - String includeFeatureId = (String) includeFeatureIdIter.next(); - String featurePrefix = "pfa" + this.index; - String entityAlias = "PFA" + this.index; - this.index++; - - this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); - this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ProductFeatureId", "productFeatureId", 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.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - 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(featurePrefix + "ProductFeatureId", EntityOperator.EQUALS, includeFeatureId)); + if (includeCategoryIds.size() > 0) { + Iterator includeCategoryIdIter = includeCategoryIds.iterator(); + while (includeCategoryIdIter.hasNext()) { + String includeCategoryId = (String) includeCategoryIdIter.next(); + String categoryPrefix = "pcm" + this.index; + String entityAlias = "PCM" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember"); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ProductCategoryId", "productCategoryId", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + incExcCondList.add(new EntityExpr(new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + incExcCondList.add(new EntityExpr(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + incExcCondList.add(new EntityExpr(categoryPrefix + "ProductCategoryId", EntityOperator.EQUALS, includeCategoryId)); + } + } + if (includeFeatureIds.size() > 0) { + Iterator includeFeatureIdIter = includeFeatureIds.iterator(); + while (includeFeatureIdIter.hasNext()) { + String includeFeatureId = (String) includeFeatureIdIter.next(); + String featurePrefix = "pfa" + this.index; + String entityAlias = "PFA" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ProductFeatureId", "productFeatureId", 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.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + 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(featurePrefix + "ProductFeatureId", EntityOperator.EQUALS, includeFeatureId)); + } } - - if (excludeCategoryIds.size() != 0) { + if (excludeCategoryIds.size() > 0) { String categoryPrefix = "pcm" + this.index; String entityAlias = "PCM" + this.index; this.index++; @@ -390,7 +397,7 @@ incExcCondList.add(new EntityExpr(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); incExcCondList.add(new EntityExpr(categoryPrefix + "ProductCategoryId", EntityOperator.NOT_IN, excludeCategoryIds)); } - if (excludeFeatureIds.size() != 0) { + if (excludeFeatureIds.size() > 0) { String featurePrefix = "pfa" + this.index; String entityAlias = "PFA" + this.index; this.index++; @@ -405,7 +412,7 @@ incExcCondList.add(new EntityExpr(featurePrefix + "ProductFeatureId", EntityOperator.NOT_IN, excludeFeatureIds)); } - if (alwaysIncludeCategoryIds.size() != 0) { + if (alwaysIncludeCategoryIds.size() > 0) { String categoryPrefix = "pcm" + this.index; String entityAlias = "PCM" + this.index; this.index++; @@ -419,7 +426,7 @@ alwIncCondList.add(new EntityExpr(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); alwIncCondList.add(new EntityExpr(categoryPrefix + "ProductCategoryId", EntityOperator.IN, alwaysIncludeCategoryIds)); } - if (alwaysIncludeFeatureIds.size() != 0) { + if (alwaysIncludeFeatureIds.size() > 0) { String featurePrefix = "pfa" + this.index; String entityAlias = "PFA" + this.index; this.index++; @@ -435,39 +442,79 @@ } // handle includeFeatureIdOrSetAndList and alwaysIncludeFeatureIdOrSetAndList - - Iterator includeFeatureIdOrSetAndIter = includeFeatureIdOrSetAndList.iterator(); - while (includeFeatureIdOrSetAndIter.hasNext()) { - Set includeFeatureIdOrSet = (Set) includeFeatureIdOrSetAndIter.next(); - String featurePrefix = "pfa" + this.index; - String entityAlias = "PFA" + this.index; - this.index++; - - this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); - this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ProductFeatureId", "productFeatureId", 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.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - 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(featurePrefix + "ProductFeatureId", EntityOperator.EQUALS, includeFeatureIdOrSet)); - } - - Iterator alwaysIncludeFeatureIdOrSetAndIter = alwaysIncludeFeatureIdOrSetAndList.iterator(); - while (alwaysIncludeFeatureIdOrSetAndIter.hasNext()) { - Set alwaysIncludeFeatureIdOrSet = (Set) alwaysIncludeFeatureIdOrSetAndIter.next(); - String featurePrefix = "pfa" + this.index; - String entityAlias = "PFA" + this.index; - this.index++; - - this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); - this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ProductFeatureId", "productFeatureId", 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.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - 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(featurePrefix + "ProductFeatureId", EntityOperator.EQUALS, alwaysIncludeFeatureIdOrSet)); + if (includeFeatureIdOrSetAndList.size() > 0) { + Iterator includeFeatureIdOrSetAndIter = includeFeatureIdOrSetAndList.iterator(); + while (includeFeatureIdOrSetAndIter.hasNext()) { + Set includeFeatureIdOrSet = (Set) includeFeatureIdOrSetAndIter.next(); + String featurePrefix = "pfa" + this.index; + String entityAlias = "PFA" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ProductFeatureId", "productFeatureId", 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.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + 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(featurePrefix + "ProductFeatureId", EntityOperator.IN, includeFeatureIdOrSet)); + } + } + if (alwaysIncludeFeatureIdOrSetAndList.size() > 0) { + Iterator alwaysIncludeFeatureIdOrSetAndIter = alwaysIncludeFeatureIdOrSetAndList.iterator(); + while (alwaysIncludeFeatureIdOrSetAndIter.hasNext()) { + Set alwaysIncludeFeatureIdOrSet = (Set) alwaysIncludeFeatureIdOrSetAndIter.next(); + String featurePrefix = "pfa" + this.index; + String entityAlias = "PFA" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); + this.dynamicViewEntity.addAlias(entityAlias, featurePrefix + "ProductFeatureId", "productFeatureId", 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.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + 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(featurePrefix + "ProductFeatureId", EntityOperator.IN, alwaysIncludeFeatureIdOrSet)); + } + } + + // handle includeCategoryIdOrSetAndList and alwaysIncludeCategoryIdOrSetAndList + if (includeCategoryIdOrSetAndList.size() > 0) { + Iterator includeCategoryIdOrSetAndIter = includeCategoryIdOrSetAndList.iterator(); + while (includeCategoryIdOrSetAndIter.hasNext()) { + Set includeCategoryIdOrSet = (Set) includeCategoryIdOrSetAndIter.next(); + String categoryPrefix = "pcm" + this.index; + String entityAlias = "PCM" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember"); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ProductCategoryId", "productCategoryId", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + incExcCondList.add(new EntityExpr(new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + incExcCondList.add(new EntityExpr(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + incExcCondList.add(new EntityExpr(categoryPrefix + "ProductCategoryId", EntityOperator.IN, includeCategoryIdOrSet)); + } + } + if (alwaysIncludeCategoryIdOrSetAndList.size() > 0) { + Iterator alwaysIncludeCategoryIdOrSetAndIter = alwaysIncludeCategoryIdOrSetAndList.iterator(); + while (alwaysIncludeCategoryIdOrSetAndIter.hasNext()) { + Set alwaysIncludeCategoryIdOrSet = (Set) alwaysIncludeCategoryIdOrSetAndIter.next(); + String categoryPrefix = "pcm" + this.index; + String entityAlias = "PCM" + this.index; + this.index++; + + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember"); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ProductCategoryId", "productCategoryId", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "FromDate", "fromDate", null, null, null, null); + this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ThruDate", "thruDate", null, null, null, null); + this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); + alwIncCondList.add(new EntityExpr(new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(categoryPrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); + alwIncCondList.add(new EntityExpr(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); + alwIncCondList.add(new EntityExpr(categoryPrefix + "ProductCategoryId", EntityOperator.IN, alwaysIncludeCategoryIdOrSet)); + } } if (incExcCondList.size() > 0) { @@ -779,24 +826,21 @@ } public void addConstraint(ProductSearchContext productSearchContext) { - List productCategoryIdList = null; + Set productCategoryIdSet = FastSet.newInstance(); if (includeSubCategories) { // find all sub-categories recursively, make a Set of productCategoryId - Set productCategoryIdSet = FastSet.newInstance(); ProductSearch.getAllSubCategoryIds(productCategoryId, productCategoryIdSet, productSearchContext.getDelegator(), productSearchContext.nowTimestamp); - productCategoryIdList = FastList.newInstance(); - productCategoryIdList.addAll(productCategoryIdSet); } else { - productCategoryIdList = UtilMisc.toList(productCategoryId); + productCategoryIdSet.add(productCategoryId); } // just add to global sets if (exclude == null) { - productSearchContext.includeCategoryIds.addAll(productCategoryIdList); + productSearchContext.includeCategoryIdOrSetAndList.add(productCategoryIdSet); } else if (exclude.equals(Boolean.TRUE)) { - productSearchContext.excludeCategoryIds.addAll(productCategoryIdList); + productSearchContext.excludeCategoryIds.addAll(productCategoryIdSet); } else if (exclude.equals(Boolean.FALSE)) { - productSearchContext.alwaysIncludeCategoryIds.addAll(productCategoryIdList); + productSearchContext.alwaysIncludeCategoryIdOrSetAndList.add(productCategoryIdSet); } // add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later |
Free forum by Nabble | Edit this page |