Author: mor
Date: Sat Jul 16 07:59:06 2011 New Revision: 1147376 URL: http://svn.apache.org/viewvc?rev=1147376&view=rev Log: Added a service that is schedule to run every midnight and will delete the auto-save shopping list for anonymous user that are not updated in last 30 days by default if no configuration is specified. The service is added to keep a check on the shopping list and shopping list items records for anonymous users that may grow quickly with time depending upon the visits to your website. Modified: ofbiz/trunk/applications/order/config/order.properties ofbiz/trunk/applications/order/data/OrderScheduledServices.xml ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java Modified: ofbiz/trunk/applications/order/config/order.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/order.properties?rev=1147376&r1=1147375&r2=1147376&view=diff ============================================================================== --- ofbiz/trunk/applications/order/config/order.properties (original) +++ ofbiz/trunk/applications/order/config/order.properties Sat Jul 16 07:59:06 2011 @@ -19,3 +19,6 @@ # Days Till Cancel Replacement Order daysTillCancelReplacementOrder=30 + +# Maximum age of auto-save shopping list for anonymous users (in days) +autosave.max.age=14 Modified: ofbiz/trunk/applications/order/data/OrderScheduledServices.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/data/OrderScheduledServices.xml?rev=1147376&r1=1147375&r2=1147376&view=diff ============================================================================== --- ofbiz/trunk/applications/order/data/OrderScheduledServices.xml (original) +++ ofbiz/trunk/applications/order/data/OrderScheduledServices.xml Sat Jul 16 07:59:06 2011 @@ -30,5 +30,6 @@ under the License. <JobSandbox jobId="8006" jobName="Cancels all orders after date" runTime="2009-12-03 03:00:00.000" serviceName="cancelAllBackOrders" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> <JobSandbox jobId="8007" jobName="Replacement Held Order Auto-Cancel" runTime="2000-01-01 00:00:00.000" serviceName="autoCancelReplacementOrders" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> <JobSandbox jobId="8008" jobName="Create Also Bought Product Associations" runTime="2000-01-01 00:00:00.000" serviceName="createAlsoBoughtProductAssocs" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> + <JobSandbox jobId="8009" jobName="Delete auto-save shopping list for anonymous users" runTime="2000-01-01 00:00:00.000" serviceName="autoDeleteAutoSaveShoppingList" poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/> </entity-engine-xml> Modified: ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml?rev=1147376&r1=1147375&r2=1147376&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml Sat Jul 16 07:59:06 2011 @@ -143,4 +143,12 @@ under the License. <attribute name="productId" type="String" mode="IN" optional="false"/> <attribute name="shoppingListItemSeqId" type="String" mode="OUT" optional="false"/> </service> + + <service name="autoDeleteAutoSaveShoppingList" engine="java" auth="true" max-retry="3" transaction-timeout="3600" + location="org.ofbiz.order.shoppinglist.ShoppingListServices" invoke="autoDeleteAutoSaveShoppingList"> + <description> + Automatic delete auto save shopping list for anonymous users that are not updated in last 30 days. + Default to 30 days unless no configuration is specified. + </description> + </service> </services> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java?rev=1147376&r1=1147375&r2=1147376&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppinglist/ShoppingListServices.java Sat Jul 16 07:59:06 2011 @@ -23,6 +23,7 @@ import java.sql.Timestamp; import java.util.Iterator; import java.util.List; import java.util.Locale; +import java.util.Date; import java.util.Map; import javolution.util.FastMap; @@ -58,6 +59,8 @@ import org.ofbiz.service.ServiceUtil; import org.ofbiz.service.calendar.RecurrenceInfo; import org.ofbiz.service.calendar.RecurrenceInfoException; +import com.ibm.icu.util.Calendar; + /** * Shopping List Services */ @@ -586,4 +589,62 @@ public class ShoppingListServices { } return result; } + + public static Map<String,Object> autoDeleteAutoSaveShoppingList(DispatchContext dctx, Map<String, ? extends Object> context) { + Delegator delegator = dctx.getDelegator(); + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + List<GenericValue> shoppingList = null; + try { + EntityCondition cond = EntityCondition.makeCondition(UtilMisc.toList( + EntityCondition.makeCondition("partyId", null), + EntityCondition.makeCondition("shoppingListTypeId", "SLT_SPEC_PURP")), EntityOperator.AND); + shoppingList = delegator.findList("ShoppingList", cond, null, null, null, false); + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + } + String maxDaysStr = UtilProperties.getPropertyValue("order.properties", "autosave.max.age", "30"); + int maxDays = 0; + try { + maxDays = Integer.parseInt(maxDaysStr); + } catch (NumberFormatException e) { + Debug.logError(e, "Unable to get maxDays", module); + } + for (GenericValue sl : shoppingList) { + if (maxDays > 0) { + Timestamp lastModified = sl.getTimestamp("lastAdminModified"); + if (lastModified == null) { + lastModified = sl.getTimestamp("lastUpdatedStamp"); + } + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(lastModified.getTime()); + cal.add(Calendar.DAY_OF_YEAR, maxDays); + Date expireDate = cal.getTime(); + Date nowDate = new Date(); + if (expireDate.equals(nowDate) || nowDate.after(expireDate)) { + List<GenericValue> shoppingListItems = null; + try { + shoppingListItems = sl.getRelated("ShoppingListItem"); + } catch (GenericEntityException e) { + Debug.logError(e.getMessage(), module); + } + for (GenericValue sli : shoppingListItems) { + try { + dispatcher.runSync("removeShoppingListItem", UtilMisc.toMap("shoppingListId", sl.getString("shoppingListId"), + "shoppingListItemSeqId", sli.getString("shoppingListItemSeqId"), + "userLogin", userLogin)); + } catch (GenericServiceException e) { + Debug.logError(e.getMessage(), module); + } + } + try { + dispatcher.runSync("removeShoppingList", UtilMisc.toMap("shoppingListId", sl.getString("shoppingListId"), "userLogin", userLogin)); + } catch (GenericServiceException e) { + Debug.logError(e.getMessage(), module); + } + } + } + } + return ServiceUtil.returnSuccess(); + } } |
Free forum by Nabble | Edit this page |