You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ru...@apache.org on 2007/04/06 07:19:39 UTC

svn commit: r526058 - in /ofbiz/trunk/applications/product: src/org/ofbiz/product/feature/ParametricSearch.java src/org/ofbiz/product/product/ProductSearch.java src/org/ofbiz/product/product/ProductSearchSession.java webapp/catalog/find/advancedsearch.ftl

Author: ruppert
Date: Thu Apr  5 22:19:37 2007
New Revision: 526058

URL: http://svn.apache.org/viewvc?view=rev&rev=526058
Log:
Added ProductFeatureCategory Include and Exclude to advanced search mechanism

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java
    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/src/org/ofbiz/product/feature/ParametricSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java?view=diff&rev=526058&r1=526057&r2=526058
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ParametricSearch.java Thu Apr  5 22:19:37 2007
@@ -226,4 +226,26 @@
         
         return outSb.toString();
     }
+    
+    /**
+     *  Handles parameters coming in prefixed with "SEARCH_PROD_FEAT_CAT" 
+     *  where the parameter value is a productFeatureCategoryId; 
+     *  meant to be used with text entry boxes or check-boxes and such 
+     **/
+    public static List makeProductFeatureCategoryIdListFromPrefixed(Map parameters) {
+        List prodFeatureCategoryIdList = FastList.newInstance();
+        if (parameters == null) return prodFeatureCategoryIdList;
+        
+        Iterator parameterNameIter = parameters.keySet().iterator();
+        while (parameterNameIter.hasNext()) {
+            String parameterName = (String) parameterNameIter.next();
+            if (parameterName.startsWith("SEARCH_PROD_FEAT_CAT")) {
+                String productFeatureCategoryId = (String) parameters.get(parameterName);
+                if (productFeatureCategoryId != null && productFeatureCategoryId.length() > 0) {
+                   prodFeatureCategoryIdList.add(productFeatureCategoryId);
+                }
+            }
+        }
+        return prodFeatureCategoryIdList;
+    }
 }

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=526058&r1=526057&r2=526058
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Thu Apr  5 22:19:37 2007
@@ -925,6 +925,78 @@
         }
     }
 
+    
+    public static class ProductFeatureCategoryConstraint extends ProductSearchConstraint {
+        public static final String constraintName = "ProductFeatureCategory";
+        protected String productFeatureCategoryId;
+        /** This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */
+        protected Boolean exclude;
+
+        /**
+         * 
+         * @param productFeatureCategoryId
+         * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude
+         */
+        public ProductFeatureCategoryConstraint(String productFeatureCategoryId, Boolean exclude) {
+            this.productFeatureCategoryId = productFeatureCategoryId;
+            this.exclude = exclude;
+        }
+
+        public void addConstraint(ProductSearchContext productSearchContext) {
+            // just add to global sets
+            if (exclude == null) {
+                productSearchContext.includeFeatureIds.add(productFeatureCategoryId);
+            } else if (exclude.equals(Boolean.TRUE)) {
+                productSearchContext.excludeFeatureIds.add(productFeatureCategoryId);
+            } else if (exclude.equals(Boolean.FALSE)) {
+                productSearchContext.alwaysIncludeFeatureIds.add(productFeatureCategoryId);
+            }
+
+            // 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.productFeatureCategoryId)));
+        }
+
+        public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale) {
+            GenericValue productFeatureCategory = null;
+            try {
+                productFeatureCategory = delegator.findByPrimaryKeyCache("ProductFeatureCategory", UtilMisc.toMap("productFeatureCategoryId", productFeatureCategoryId));
+            } catch (GenericEntityException e) {
+                Debug.logError(e, "Error finding ProductFeatureCategory and Type information for constraint pretty print", module);
+            }
+            StringBuffer ppBuf = new StringBuffer();
+            if (productFeatureCategory != null) {                                
+                ppBuf.append(UtilProperties.getMessage(resource, "ProductFeatureCategory", locale)+": ");
+                if(productFeatureCategory.get("description") != null) {
+                    ppBuf.append("[" + productFeatureCategory.get("description") + "]");    
+                } else {
+                    ppBuf.append("[" + this.productFeatureCategoryId + "]");
+                }
+                
+            } 
+            return (ppBuf.toString());
+        }
+
+        public boolean equals(Object obj) {
+            ProductSearchConstraint psc = (ProductSearchConstraint) obj;
+            if (psc instanceof ProductFeatureCategoryConstraint) {
+                ProductFeatureCategoryConstraint that = (ProductFeatureCategoryConstraint) psc;
+                if (this.productFeatureCategoryId == null) {
+                    if (that.productFeatureCategoryId != null) {
+                        return false;
+                    }
+                } else {
+                    if (!this.productFeatureCategoryId.equals(that.productFeatureCategoryId)) {
+                        return false;
+                    }
+                }
+                return true;
+            } else {
+                return false;
+            }
+        }
+    }
+    
+    
     public static class FeatureSetConstraint extends ProductSearchConstraint {
         public static final String constraintName = "Feature Set";
         protected Set productFeatureIdSet;

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=526058&r1=526057&r2=526058
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchSession.java Thu Apr  5 22:19:37 2007
@@ -531,6 +531,21 @@
             searchAddFeatureIdConstraints(featureIdByType.values(), null, request);
         }
 
+        //if product features category were selected add a constraint for each
+        Iterator parameterProdFeatureCatNameIter = parameters.keySet().iterator();
+        while (parameterProdFeatureCatNameIter.hasNext()) {
+            String parameterName = (String) parameterProdFeatureCatNameIter.next();
+            if (parameterName.startsWith("SEARCH_PROD_FEAT_CAT")) {
+                String productFeatureCategoryId = (String) parameters.get(parameterName);
+                if (productFeatureCategoryId != null && productFeatureCategoryId.length() > 0) {
+                    String paramNameExt = parameterName.substring("SEARCH_PROD_FEAT_CAT".length() + 1);
+                    String searchProdFeatureCategoryExc = (String) parameters.get("SEARCH_PROD_FEAT_CAT_EXC" + paramNameExt);
+                    Boolean exclude = UtilValidate.isEmpty(searchProdFeatureCategoryExc) ? null : new Boolean(!"N".equals(searchProdFeatureCategoryExc));
+                    searchAddConstraint(new ProductSearch.ProductFeatureCategoryConstraint(productFeatureCategoryId, exclude), session);
+                }
+            }
+        }
+
         // add a supplier to the search
         if (UtilValidate.isNotEmpty((String) parameters.get("SEARCH_SUPPLIER_ID"))) {
             String supplierPartyId = (String) parameters.get("SEARCH_SUPPLIER_ID");

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=526058&r1=526057&r2=526058
==============================================================================
--- ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl (original)
+++ ofbiz/trunk/applications/product/webapp/catalog/find/advancedsearch.ftl Thu Apr  5 22:19:37 2007
@@ -87,6 +87,32 @@
     </tr>
     <tr>
       <td align="right" valign="middle">
+        <div class="tabletext">${uiLabelMap.ProductFeatureCategory} ${uiLabelMap.CommonIds}:</div>
+      </td>
+      <td valign="middle">
+        <div>
+          <input type="text" class="inputBox" name="SEARCH_PROD_FEAT_CAT1" size="15" value="${requestParameters.SEARCH_PROD_FEAT_CAT1?if_exists}"/>&nbsp;
+              ${uiLabelMap.CommonInclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC1" value="" checked="checked"/>
+              ${uiLabelMap.CommonExclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC1" value="Y"/>
+              ${uiLabelMap.CommonAlwaysInclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC1" value="N"/>
+        </div>
+        <div>
+          <input type="text" class="inputBox" name="SEARCH_PROD_FEAT_CAT2" size="15" value="${requestParameters.SEARCH_PROD_FEAT_CAT2?if_exists}"/>&nbsp;
+              ${uiLabelMap.CommonInclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC2" value="" checked="checked"/>
+              ${uiLabelMap.CommonExclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC2" value="Y"/>
+              ${uiLabelMap.CommonAlwaysInclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC2" value="N"/>
+        </div>
+        <div>
+          <input type="text" class="inputBox" name="SEARCH_PROD_FEAT_CAT3" size="15" value="${requestParameters.SEARCH_PROD_FEAT_CAT3?if_exists}"/>&nbsp;
+              ${uiLabelMap.CommonInclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC3" value="" checked="checked"/>
+              ${uiLabelMap.CommonExclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC3" value="Y"/>
+              ${uiLabelMap.CommonAlwaysInclude}<input type="radio" name="SEARCH_PROD_FEAT_CAT_EXC3" value="N"/>
+        </div>
+      </td>
+    </tr>
+    
+    <tr>
+      <td align="right" valign="middle">
         <div class="tabletext">${uiLabelMap.ProductFeatures} ${uiLabelMap.CommonIds}:</div>
       </td>
       <td valign="middle">