svn commit: r497944 - in /ofbiz/trunk/applications: order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh product/servicedef/services_view.xml product/src/org/ofbiz/product/category/CategoryServices.java

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

svn commit: r497944 - in /ofbiz/trunk/applications: order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh product/servicedef/services_view.xml product/src/org/ofbiz/product/category/CategoryServices.java

jonesde
Author: jonesde
Date: Fri Jan 19 12:32:58 2007
New Revision: 497944

URL: http://svn.apache.org/viewvc?view=rev&rev=497944
Log:
Added orderByFields feature to the getProductCategoryAndLimitedMembers entity, which also intelligently supports using the ProductCategoryAndMember view entity when needed rather than just the ProductCategoryMember entity

Modified:
    ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh
    ofbiz/trunk/applications/product/servicedef/services_view.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh?view=diff&rev=497944&r1=497943&r2=497944
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/categorydetail.bsh Fri Jan 19 12:32:58 2007
@@ -1,7 +1,4 @@
 /*
- *
- * Copyright 2001-2006 The Apache Software Foundation
- *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
@@ -16,7 +13,7 @@
  */
 
 /*
- * This script is also referenced by the ecommerce's screens and
+ * NOTE: This script is also referenced by the ecommerce's screens and
  * should not contain order component's specific code.
  */
 
@@ -51,6 +48,7 @@
         "defaultViewSize", defaultViewSize, "limitView", limitView);
 andMap.put("prodCatalogId", currentCatalogId);
 andMap.put("checkViewAllow", Boolean.TRUE);
+andMap.put("orderByFields", UtilMisc.toList("sequenceNum", "productId"));
 catResult = dispatcher.runSync("getProductCategoryAndLimitedMembers", andMap);
 
 productCategory = catResult.get("productCategory");

Modified: ofbiz/trunk/applications/product/servicedef/services_view.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_view.xml?view=diff&rev=497944&r1=497943&r2=497944
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_view.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_view.xml Fri Jan 19 12:32:58 2007
@@ -126,6 +126,7 @@
         <attribute name="viewSizeString" type="String" mode="IN" optional="true"/>
         <attribute name="useCacheForMembers" type="Boolean" mode="IN" optional="true"/>
         <attribute name="activeOnly" type="Boolean" mode="IN" optional="true"/>
+        <attribute name="orderByFields" type="List" mode="IN" optional="true"/>
         <attribute name="productCategory" type="org.ofbiz.entity.GenericValue" mode="OUT" optional="true"/>
         <attribute name="productCategoryMembers" type="java.util.Collection" mode="OUT" optional="true"/> <!-- this list will only contain the limited members if limitView=true -->
         <attribute name="viewIndex" type="Integer" mode="OUT" optional="false"/> <!-- this is a 1 based index, ie the first results are in index 1 -->

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=497944&r1=497943&r2=497944
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java Fri Jan 19 12:32:58 2007
@@ -38,6 +38,7 @@
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.model.ModelEntity;
 import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.util.EntityListIterator;
 import org.ofbiz.entity.util.EntityUtil;
@@ -146,6 +147,32 @@
         String productCategoryId = (String) context.get("productCategoryId");
         boolean limitView = ((Boolean) context.get("limitView")).booleanValue();
         int defaultViewSize = ((Integer) context.get("defaultViewSize")).intValue();
+        
+        List orderByFields = (List) context.get("orderByFields");
+        if (orderByFields == null || orderByFields.size() == 0) {
+            orderByFields = FastList.newInstance();
+            orderByFields.add("sequenceNum");
+            orderByFields.add("productId");
+        }
+        
+        // allow orderByFields to contain fields from the Product entity, if there are such fields
+        String entityName = "ProductCategoryMember";
+        ModelEntity productModel = delegator.getModelEntity("Product");
+        ModelEntity productCategoryMemberModel = delegator.getModelEntity("ProductCategoryMember");
+        Iterator orderByFieldIter = orderByFields.iterator();
+        while (orderByFieldIter.hasNext()) {
+            String orderByField = (String) orderByFieldIter.next();
+            if (!productCategoryMemberModel.isField(orderByField)) {
+                if (productModel.isField(orderByField)) {
+                    entityName = "ProductCategoryAndMember";
+                    // that's what we wanted to find out, so we can quit now
+                    break;
+                } else {
+                    // ahh!! bad field name, don't worry, it will blow up in the query
+                }
+            }
+        }
+        
 
         String prodCatalogId = (String) context.get("prodCatalogId");
 
@@ -192,7 +219,7 @@
         if (productCategory != null) {
             try {
                 if (useCacheForMembers) {
-                    productCategoryMembers = productCategory.getRelatedCache("ProductCategoryMember", null, UtilMisc.toList("sequenceNum"));
+                    productCategoryMembers = productCategory.getRelatedCache(entityName, null, orderByFields);
                     if (activeOnly) {
                         productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true);
                     }
@@ -218,7 +245,7 @@
                     // set distinct on so we only get one row per order
                     EntityFindOptions findOpts = new EntityFindOptions(true, EntityFindOptions.TYPE_SCROLL_INSENSITIVE, EntityFindOptions.CONCUR_READ_ONLY, true);
                     // using list iterator
-                    EntityListIterator pli = delegator.findListIteratorByCondition("ProductCategoryMember", mainCond, null, null, UtilMisc.toList("sequenceNum", "productId"), findOpts);
+                    EntityListIterator pli = delegator.findListIteratorByCondition(entityName, mainCond, null, null, orderByFields, findOpts);
                 
                     // get the partial list for this page
                     if (limitView) {