[OFBiz] SVN: r4982 - in trunk/applications:
order/webapp/ordermgr/entry/catalog product/servicedef
product/src/org/ofbiz/product/category
product/webapp/catalog/WEB-INF/actions/category
product/webapp/catalog/WEB-INF/actions/find
product/webapp/catalog/find
jonesde at svn.ofbiz.org
jonesde at svn.ofbiz.org
Wed May 11 05:13:04 EDT 2005
Author: jonesde
Date: 2005-05-11 04:12:48 -0500 (Wed, 11 May 2005)
New Revision: 4982
Modified:
trunk/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
trunk/applications/product/servicedef/services_view.xml
trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java
trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategoryProducts.bsh
trunk/applications/product/webapp/catalog/WEB-INF/actions/find/miniproductlist.bsh
trunk/applications/product/webapp/catalog/find/miniproductlist.ftl
Log:
Changed getProductCategoryAndLimitedMembers service to use an EntityListIterator if the cache is not being used; also changed the viewIndex from 0-based to 1-based, this in turn required a few small changes in other pages; this service is now used in the EditCategoryProducts page and the miniproductlist side bar box in the catalog manager
Modified: trunk/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl
===================================================================
--- trunk/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl 2005-05-11 07:13:31 UTC (rev 4981)
+++ trunk/applications/order/webapp/ordermgr/entry/catalog/categorydetail.ftl 2005-05-11 09:12:48 UTC (rev 4982)
@@ -58,17 +58,17 @@
<#-- Start Page Select Drop-Down -->
<#assign viewIndexMax = Static["java.lang.Math"].ceil(listSize?double / viewSize?double)>
<select name="pageSelect" class="selectBox" onchange="window.location=this[this.selectedIndex].value;">
- <option value="#">Page ${viewIndex?int + 1} of ${viewIndexMax}</option>
+ <option value="#">Page ${viewIndex?int} of ${viewIndexMax}</option>
<#list 1..viewIndexMax as curViewNum>
- <option value="<@ofbizUrl>/category/~category_id=${productCategoryId}/~VIEW_SIZE=${viewSize}/~VIEW_INDEX=${curViewNum?int - 1}</@ofbizUrl>">Go to Page ${curViewNum}</option>
+ <option value="<@ofbizUrl>/category/~category_id=${productCategoryId}/~VIEW_SIZE=${viewSize}/~VIEW_INDEX=${curViewNum?int}</@ofbizUrl>">Go to Page ${curViewNum}</option>
</#list>
</select>
<#-- End Page Select Drop-Down -->
<b>
- <#if 0 < viewIndex?int>
+ <#if (viewIndex?int > 1)>
<a href="<@ofbizUrl>/category/~category_id=${productCategoryId}/~VIEW_SIZE=${viewSize}/~VIEW_INDEX=${viewIndex?int - 1}</@ofbizUrl>" class="buttontext">[${uiLabelMap.CommonPrevious}]</a> |
</#if>
- <#if 0 < listSize?int>
+ <#if (listSize?int > 0)>
<span class="tabletext">${lowIndex} - ${highIndex} of ${listSize}</span>
</#if>
<#if highIndex?int < listSize?int>
@@ -78,13 +78,7 @@
</div>
<div class="productsummary-container">
- <#assign startIndex = viewSize * viewIndex/>
- <#if highIndex < listSize>
- <#assign endIndex = highIndex - 1/>
- <#else>
- <#assign endIndex = listSize - 1/>
- </#if>
- <#list productCategoryMembers[startIndex..endIndex] as productCategoryMember>
+ <#list productCategoryMembers as productCategoryMember>
${setRequestAttribute("optProductId", productCategoryMember.productId)}
${setRequestAttribute("productCategoryMember", productCategoryMember)}
${setRequestAttribute("listIndex", productCategoryMember_index)}
@@ -96,9 +90,9 @@
<#-- Start Page Select Drop-Down -->
<#assign viewIndexMax = Static["java.lang.Math"].ceil(listSize?double / viewSize?double)>
<select name="pageSelect" class="selectBox" onchange="window.location=this[this.selectedIndex].value;">
- <option value="#">Page ${viewIndex?int + 1} of ${viewIndexMax}</option>
+ <option value="#">Page ${viewIndex?int} of ${viewIndexMax}</option>
<#list 1..viewIndexMax as curViewNum>
- <option value="<@ofbizUrl>/category/~category_id=${productCategoryId}/~VIEW_SIZE=${viewSize}/~VIEW_INDEX=${curViewNum?int - 1}</@ofbizUrl>">Go to Page ${curViewNum}</option>
+ <option value="<@ofbizUrl>/category/~category_id=${productCategoryId}/~VIEW_SIZE=${viewSize}/~VIEW_INDEX=${curViewNum?int}</@ofbizUrl>">Go to Page ${curViewNum}</option>
</#list>
</select>
<#-- End Page Select Drop-Down -->
Modified: trunk/applications/product/servicedef/services_view.xml
===================================================================
--- trunk/applications/product/servicedef/services_view.xml 2005-05-11 07:13:31 UTC (rev 4981)
+++ trunk/applications/product/servicedef/services_view.xml 2005-05-11 09:12:48 UTC (rev 4982)
@@ -129,9 +129,10 @@
<attribute name="viewIndexString" type="String" mode="IN" optional="true"/>
<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="productCategory" type="org.ofbiz.entity.GenericValue" mode="OUT" optional="true"/>
- <attribute name="productCategoryMembers" type="java.util.Collection" mode="OUT" optional="true"/>
- <attribute name="viewIndex" type="Integer" mode="OUT" optional="false"/>
+ <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 -->
<attribute name="viewSize" type="Integer" mode="OUT" optional="false"/>
<attribute name="lowIndex" type="Integer" mode="OUT" optional="false"/>
<attribute name="highIndex" type="Integer" mode="OUT" optional="false"/>
Modified: trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java
===================================================================
--- trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java 2005-05-11 07:13:31 UTC (rev 4981)
+++ trunk/applications/product/src/org/ofbiz/product/category/CategoryServices.java 2005-05-11 09:12:48 UTC (rev 4982)
@@ -1,7 +1,8 @@
/*
* $Id$
*
- * Copyright (c) 2002 The Open For Business Project (www.ofbiz.org)
+ * Copyright (c) 2002-2005 The Open For Business Project (www.ofbiz.org)
+ *
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
@@ -22,6 +23,7 @@
*/
package org.ofbiz.product.category;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -29,11 +31,20 @@
import java.util.List;
import java.util.Map;
+import javolution.util.FastList;
+
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionList;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityFindOptions;
+import org.ofbiz.entity.util.EntityListIterator;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.product.catalog.CatalogWorker;
import org.ofbiz.service.DispatchContext;
@@ -144,21 +155,20 @@
boolean limitView = ((Boolean) context.get("limitView")).booleanValue();
int defaultViewSize = ((Integer) context.get("defaultViewSize")).intValue();
- // checkViewAllow defaults to false, must be set to true and pass the prodCatalogId to enable
- Boolean cvaBool = (Boolean) context.get("checkViewAllow");
- boolean checkViewAllow = (cvaBool == null ? false : cvaBool.booleanValue());
String prodCatalogId = (String) context.get("prodCatalogId");
- boolean useCacheForMembers = true;
- if (context.get("useCacheForMembers") != null) {
- useCacheForMembers = ((Boolean) context.get("useCacheForMembers")).booleanValue();
- }
+ boolean useCacheForMembers = (context.get("useCacheForMembers") != null ? ((Boolean) context.get("useCacheForMembers")).booleanValue() : true);
+ boolean activeOnly = (context.get("activeOnly") != null ? ((Boolean) context.get("activeOnly")).booleanValue() : true);
+ // 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() : false);
+
+ Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
- int viewIndex = 0;
+ int viewIndex = 1;
try {
viewIndex = Integer.valueOf((String) context.get("viewIndexString")).intValue();
} catch (Exception e) {
- viewIndex = 0;
+ viewIndex = 1;
}
int viewSize = defaultViewSize;
@@ -176,15 +186,71 @@
productCategory = null;
}
+ int listSize = 0;
+ int lowIndex = 0;
+ int highIndex = 0;
+
+ if (limitView) {
+ // get the indexes for the partial list
+ lowIndex = (((viewIndex - 1) * viewSize) + 1);
+ highIndex = viewIndex * viewSize;
+ }
+
List productCategoryMembers = null;
if (productCategory != null) {
try {
if (useCacheForMembers) {
productCategoryMembers = productCategory.getRelatedCache("ProductCategoryMember", null, UtilMisc.toList("sequenceNum"));
+ if (activeOnly) {
+ productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true);
+ }
+ listSize = productCategoryMembers.size();
+ if (highIndex > listSize) {
+ highIndex = listSize;
+ }
+
+ if (limitView) {
+ productCategoryMembers = productCategoryMembers.subList(lowIndex-1, highIndex);
+ } else {
+ lowIndex = 1;
+ highIndex = listSize;
+ }
} else {
- productCategoryMembers = productCategory.getRelated("ProductCategoryMember", null, UtilMisc.toList("sequenceNum"));
+ List mainCondList = UtilMisc.toList(new EntityExpr("productCategoryId", EntityOperator.EQUALS, productCategory.getString("productCategoryId")));
+ if (activeOnly) {
+ mainCondList.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp));
+ mainCondList.add(new EntityExpr(new EntityExpr("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("thruDate", EntityOperator.GREATER_THAN, nowTimestamp)));
+ }
+ EntityCondition mainCond = new EntityConditionList(mainCondList, EntityOperator.AND);
+
+ // 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);
+
+ // 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();
+ } else {
+ productCategoryMembers = pli.getCompleteList();
+ listSize = productCategoryMembers.size();
+ lowIndex = 1;
+ highIndex = listSize;
+ }
+ if (productCategoryMembers == null) {
+ productCategoryMembers = FastList.newInstance();
+ }
+
+ if (highIndex > listSize) {
+ highIndex = listSize;
+ }
+
+ // close the list iterator
+ pli.close();
}
- productCategoryMembers = EntityUtil.filterByDate(productCategoryMembers, true);
// 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) {
@@ -198,23 +264,6 @@
}
}
- int lowIndex;
- int highIndex;
- int listSize = 0;
-
- if (productCategoryMembers != null) {
- listSize = productCategoryMembers.size();
- }
-
- if (limitView) {
- lowIndex = viewIndex * viewSize + 1;
- highIndex = (viewIndex + 1) * viewSize;
- if (listSize < highIndex) highIndex = listSize;
- } else {
- lowIndex = 1;
- highIndex = listSize;
- }
-
Map result = new HashMap();
result.put("viewIndex", new Integer(viewIndex));
result.put("viewSize", new Integer(viewSize));
Modified: trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategoryProducts.bsh
===================================================================
--- trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategoryProducts.bsh 2005-05-11 07:13:31 UTC (rev 4981)
+++ trunk/applications/product/webapp/catalog/WEB-INF/actions/category/EditCategoryProducts.bsh 2005-05-11 09:12:48 UTC (rev 4982)
@@ -34,84 +34,23 @@
//default this to true, ie only show active
boolean activeOnly = !"false".equals(request.getParameter("activeOnly"));
-
context.put("activeOnly", activeOnly);
-int viewIndex = 1;
-int viewSize = 20;
-int highIndex = 0;
-int lowIndex = 0;
-int listSize = 0;
+paramInMap = new HashMap();
+paramInMap.put("productCategoryId", UtilFormatOut.checkNull(request.getParameter("productCategoryId")));
+paramInMap.put("defaultViewSize", 20);
+paramInMap.put("limitView", true);
+paramInMap.put("useCacheForMembers", false);
+paramInMap.put("checkViewAllow", false);
+paramInMap.put("activeOnly", activeOnly);
+paramInMap.put("viewIndexString", parameters.get("VIEW_INDEX"));
+paramInMap.put("viewSizeString", parameters.get("VIEW_SIZE"));
-try {
- viewIndex = Integer.valueOf((String) parameters.get("VIEW_INDEX")).intValue();
-} catch (Exception e) {
- viewIndex = 1;
-}
-
-try {
- viewSize = Integer.valueOf((String) parameters.get("VIEW_SIZE")).intValue();
-} catch (Exception e) {
- viewSize = 20;
-}
-
-if (productCategory != null) {
- boolean beganTransaction = false;
- try {
- beganTransaction = TransactionUtil.begin();
-
- mainCondList = UtilMisc.toList(new EntityExpr("productCategoryId", EntityOperator.EQUALS, productCategory.getString("productCategoryId")));
- if (activeOnly) {
- mainCondList.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp));
- mainCondList.add(new EntityExpr(new EntityExpr("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr("thruDate", EntityOperator.GREATER_THAN, nowTimestamp)));
- }
- mainCond = new EntityConditionList(mainCondList, EntityOperator.AND);
-
- // 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);
-
- // get the indexes for the partial list
- lowIndex = (((viewIndex - 1) * viewSize) + 1);
- highIndex = viewIndex * viewSize;
-
- // get the partial list for this page
- productCategoryMembers = pli.getPartialList(lowIndex, viewSize);
- if (productCategoryMembers == null) {
- productCategoryMembers = new ArrayList();
- }
-
- // attempt to get the full size
- pli.last();
- listSize = pli.currentIndex();
- if (highIndex > listSize) {
- highIndex = listSize;
- }
-
- // close the list iterator
- pli.close();
-
- context.put("productCategoryMembers", productCategoryMembers);
- } catch (GenericEntityException e) {
- String errMsg = "Failure in operation, rolling back transaction";
- Debug.logError(e, errMsg, module);
- try {
- // only rollback the transaction if we started one...
- TransactionUtil.rollback(beganTransaction, errMsg, e);
- } catch (GenericEntityException e2) {
- Debug.logError(e2, "Could not rollback transaction: " + e2.toString(), module);
- }
- // after rolling back, rethrow the exception
- throw e;
- } finally {
- // only commit the transaction if we started one... this will throw an exception if it fails
- TransactionUtil.commit(beganTransaction);
- }
-}
-
-context.put("viewIndex", viewIndex);
-context.put("viewSize", viewSize);
-context.put("lowIndex", lowIndex);
-context.put("listSize", listSize);
-context.put("highIndex", highIndex);
+// Returns: viewIndex, viewSize, lowIndex, highIndex, listSize, productCategory, productCategoryMembers
+outMap = dispatcher.runSync("getProductCategoryAndLimitedMembers", paramInMap);
+context.put("viewIndex", outMap.get("viewIndex"));
+context.put("viewSize", outMap.get("viewSize"));
+context.put("lowIndex", outMap.get("lowIndex"));
+context.put("highIndex", outMap.get("highIndex"));
+context.put("listSize", outMap.get("listSize"));
+context.put("productCategoryMembers", outMap.get("productCategoryMembers"));
Modified: trunk/applications/product/webapp/catalog/WEB-INF/actions/find/miniproductlist.bsh
===================================================================
--- trunk/applications/product/webapp/catalog/WEB-INF/actions/find/miniproductlist.bsh 2005-05-11 07:13:31 UTC (rev 4981)
+++ trunk/applications/product/webapp/catalog/WEB-INF/actions/find/miniproductlist.bsh 2005-05-11 09:12:48 UTC (rev 4982)
@@ -49,6 +49,7 @@
paramInMap.put("defaultViewSize", 30);
paramInMap.put("limitView", true);
paramInMap.put("useCacheForMembers", false);
+ paramInMap.put("checkViewAllow", false);
// Returns: viewIndex, viewSize, lowIndex, highIndex, listSize, productCategory, productCategoryMembers
outMap = dispatcher.runSync("getProductCategoryAndLimitedMembers", paramInMap);
Modified: trunk/applications/product/webapp/catalog/find/miniproductlist.ftl
===================================================================
--- trunk/applications/product/webapp/catalog/find/miniproductlist.ftl 2005-05-11 07:13:31 UTC (rev 4981)
+++ trunk/applications/product/webapp/catalog/find/miniproductlist.ftl 2005-05-11 09:12:48 UTC (rev 4982)
@@ -1,5 +1,5 @@
<#--
- * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
+ * Copyright (c) 2003-2005 The Open For Business Project - www.ofbiz.org
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -24,15 +24,14 @@
*@version $Rev$
*@since 2.1
-->
-<#if (requestAttributes.uiLabelMap)?exists><#assign uiLabelMap = requestAttributes.uiLabelMap></#if>
<div class="screenlet">
<div class="screenlet-header">
<div class="simple-right-small">
<#if isOpen>
- <a href='<@ofbizUrl>/main?CategoryProductsState=close</@ofbizUrl>' class='lightbuttontext'> _ </a>
+ <a href="<@ofbizUrl>/main?CategoryProductsState=close</@ofbizUrl>" class="lightbuttontext"> _ </a>
<#else>
- <a href='<@ofbizUrl>/main?CategoryProductsState=open</@ofbizUrl>' class='lightbuttontext'> [] </a>
+ <a href="<@ofbizUrl>/main?CategoryProductsState=open</@ofbizUrl>" class="lightbuttontext"> [] </a>
</#if>
</div>
<div class="boxhead">Category Products</div>
@@ -41,8 +40,7 @@
<div class="screenlet-body">
<#if productCategory?exists>
<#if productCategoryMembers?has_content>
- <#assign upperBound = highIndex - 1>
- <#list productCategoryMembers[0..upperBound] as productCategoryMember>
+ <#list productCategoryMembers as productCategoryMember>
<#assign product = productCategoryMember.getRelatedOneCache("Product")>
<div>
<a href='<@ofbizUrl>/EditProduct?productId=${product.productId}</@ofbizUrl>' class='buttontext'>
More information about the Svn
mailing list