svn commit: r528292 - in /ofbiz/trunk/applications/product/src/org/ofbiz/product/category: CategoryServices.java CategoryWorker.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r528292 - in /ofbiz/trunk/applications/product/src/org/ofbiz/product/category: CategoryServices.java CategoryWorker.java

jaz-3
Author: jaz
Date: Thu Apr 12 17:26:38 2007
New Revision: 528292

URL: http://svn.apache.org/viewvc?view=rev&rev=528292
Log:
fixed category query to take in account the view allow category; seems to have been broken for quite some time

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java?view=diff&rev=528292&r1=528291&r2=528292
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java Thu Apr 12 17:26:38 2007
@@ -184,8 +184,15 @@
 
         boolean useCacheForMembers = (context.get("useCacheForMembers") == null || ((Boolean) context.get("useCacheForMembers")).booleanValue());
         boolean activeOnly = (context.get("activeOnly") == null || ((Boolean) context.get("activeOnly")).booleanValue());
+
         // checkViewAllow defaults to false, must be set to true and pass the prodCatalogId to enable
-        boolean checkViewAllow = (context.get("checkViewAllow") != null && ((Boolean) context.get("checkViewAllow")).booleanValue());
+        boolean checkViewAllow = (prodCatalogId != null && context.get("checkViewAllow") != null &&
+                ((Boolean) context.get("checkViewAllow")).booleanValue());
+
+        String viewProductCategoryId = null;
+        if (checkViewAllow) {
+            viewProductCategoryId = CatalogWorker.getCatalogViewAllowCategoryId(delegator, prodCatalogId);
+        }
         
         Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
 
@@ -232,11 +239,20 @@
                     if (activeOnly) {
                         productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true);
                     }
+
+                    // filter out the view allow before getting the sublist
+                    if (viewProductCategoryId != null && productCategoryMembers.size() > 0) {
+                        productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
+                        listSize = productCategoryMembers.size();
+                    }
+
+                    // set the index and size
                     listSize = productCategoryMembers.size();
                     if (highIndex > listSize) {
                         highIndex = listSize;
                     }
 
+                    // get only between low and high indexes
                     if (limitView) {
                         productCategoryMembers = productCategoryMembers.subList(lowIndex-1, highIndex);
                     } else {
@@ -251,23 +267,50 @@
                     }
                     EntityCondition mainCond = new EntityConditionList(mainCondList, EntityOperator.AND);
                 
-                    // set distinct on so we only get one row per order
+                    // set distinct on
                     EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);
                     // using list iterator
                     EntityListIterator pli = delegator.findListIteratorByCondition(entityName, mainCond, null, null, orderByFields, findOpts);
                 
                     // get the partial list for this page
                     if (limitView) {
-                        productCategoryMembers = pli.getPartialList(lowIndex, viewSize);
-                        // attempt to get the full size
-                        pli.last();
-                        listSize = pli.currentIndex();
+                        if (viewProductCategoryId != null) {
+                            // do manual checking to filter view allow
+                            productCategoryMembers = FastList.newInstance();
+                            GenericValue nextValue;
+                            int chunkSize = 0;
+                            listSize = 0;
+
+                            while ((nextValue = (GenericValue) pli.next()) != null) {
+                                String productId = nextValue.getString("productId");
+                                if (CategoryWorker.isProductInCategory(delegator, productId, viewProductCategoryId)) {
+                                    if (listSize + 1 >= lowIndex && chunkSize < viewSize) {
+                                        productCategoryMembers.add(nextValue);
+                                        chunkSize++;
+                                    }
+                                    listSize++;
+                                }
+                            }
+                        } else {
+                            productCategoryMembers = pli.getPartialList(lowIndex, viewSize);
+
+                            // attempt to get the full size
+                            pli.last();
+                            listSize = pli.currentIndex();
+                        }
                     } else {
                         productCategoryMembers = pli.getCompleteList();
+                        if (viewProductCategoryId != null && productCategoryMembers.size() > 0) {
+                            // fiter out the view allow
+                            productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
+                        }
+                        
                         listSize = productCategoryMembers.size();
                         lowIndex = 1;
                         highIndex = listSize;
                     }
+
+                    // null safety
                     if (productCategoryMembers == null) {
                         productCategoryMembers = FastList.newInstance();
                     }
@@ -278,18 +321,6 @@
                 
                     // close the list iterator
                     pli.close();
-                }
-                
-                // first check to see if there is a view allow category and if this product is in it...
-                if (checkViewAllow && prodCatalogId != null && productCategoryMembers != null && productCategoryMembers.size() > 0) {
-                    String viewProductCategoryId = CatalogWorker.getCatalogViewAllowCategoryId(delegator, prodCatalogId);
-                    if (viewProductCategoryId != null) {
-                        productCategoryMembers = CategoryWorker.filterProductsInCategory(delegator, productCategoryMembers, viewProductCategoryId);
-                        listSize = productCategoryMembers.size();
-                        if (highIndex > listSize) {
-                            highIndex = listSize;
-                        }
-                    }
                 }
             } catch (GenericEntityException e) {
                 Debug.logError(e, module);

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java?view=diff&rev=528292&r1=528291&r2=528292
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryWorker.java Thu Apr 12 17:26:38 2007
@@ -416,10 +416,11 @@
     }
 
     public static List filterProductsInCategory(GenericDelegator delegator, List valueObjects, String productCategoryId, String productIdFieldName) throws GenericEntityException {
-        if (productCategoryId == null) return new LinkedList();
-        if (valueObjects == null) return null;
-
         List newList = FastList.newInstance();
+
+        if (productCategoryId == null) return newList;
+        if (valueObjects == null) return null;
+        
         Iterator valIter = valueObjects.iterator();
         while (valIter.hasNext()) {
             GenericValue curValue = (GenericValue) valIter.next();