atg.commerce.order
Class OrderHolder

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.logging.ApplicationLoggingImpl
          extended by atg.commerce.order.OrderHolder
All Implemented Interfaces:
ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, atg.servlet.sessionsaver.Restoreable

public class OrderHolder
extends ApplicationLoggingImpl
implements atg.servlet.sessionsaver.Restoreable

This component, typically session-scope, keeps track of the Order objects that are associated with a user. A shopping cart in DCS 5 is merely an Order in an INCOMPLETE state. The default Nucleus component which represents this object is /atg/commerce/ShoppingCart. From this component one can reference the current Order (aka shopping cart) that the user is actively adding and removing items to be purchased. Other components such as the ShoppingCartFormHandler are configured to reference the current order. In addition this class keeps track of a collection of saved carts, to allow the user to have multiple shopping carts. The component provides several form handler methods which allow one to give control to the user to create, switch and delete orders.

Here is an example of a form which allows one to manage multiple shopping carts.

 <importbean bean="/atg/commerce/ShoppingCart">

 <form action="shoppingcart.jhtml" method="post">
 <droplet bean="/atg/dynamo/droplet/Switch">
   <param name="value" value="bean:ShoppingCart.savedEmpty">
   <oparam name="true">
     <!-- since there are no saved carts, we cannot switch to another so we only
          give them the option to create a new cart -->
     <input type=submit bean="ShoppingCart.create" value="Create"> another shopping cart
   </oparam>
   <oparam name="false">
     <!-- We have other shopping carts, so let them do everything -->
     Shopping Cart <select bean="ShoppingCart.handlerOrderId">
     <droplet bean="ForEach">
       <param name="array" value="bean:ShoppingCart.saved">
       <param name="elementName" value="savedcart">
       <oparam name="output">
         <option value="param:savedcart.id"><valueof param="savedcart.id"></valueof>
       </oparam>
     </droplet>
     </select>:
     <input type=submit bean="ShoppingCart.switch" value="Switch"> to,
     <input type=submit bean="ShoppingCart.delete" value="Delete"> or
     <input type=submit bean="ShoppingCart.create" value="Create"> another shopping cart.<BR>
     <input type=submit bean="ShoppingCart.deleteAll" value="Delete All Shopping Carts">
   </oparam>
 </droplet>
 </form>
 
These are a listing of the important properties of the class and their behavior.
current
Returns the current Order (aka shopping cart). If the current order is null, then when this property is retrieved a new order is automatically created.
saved
Returns a collection of Order objects which are the user's saved list of shopping carts. An application should use the provided handler methods to move any cart from the saved list into the current Order property.
last
Returns the last completed Order. During the checkout process the "current order" is moved to the last order and the current order is reinitialized.

See Also:
Order

Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
OrderHolder()
          Constructs an instanceof OrderHolder
 
Method Summary
protected  Order createInitialOrder(RepositoryItem pProfile)
          Creates the initial order for the given user.
 boolean deleteOrder(java.lang.String pOrderId)
          Delete the order with the given id from the current or saved orders.
 Order getCurrent()
          Returns the current Order (aka shopping cart).
 Order getCurrent(boolean pEnsureOrder)
          Returns the current Order (aka shopping cart), optionally loading or creating an order if the current order is null.
 java.lang.String getFailoverRecoveryPricingOperation()
          Returns property FailoverRecoveryPricingOperation
 java.lang.String getHandlerOrderId()
          Returns property HandlerOrderId
 Order getLast()
          Returns the last completed Order.
 java.lang.String getLoggingIdentifier()
          Returns property LoggingIdentifier
 MessageSender getMessageSender()
          Returns Message Sender to send scenario Events
 OrderManager getOrderManager()
          Returns property OrderManager
 java.lang.String getOrderType()
          Returns the type of order to create when we need to construct a new shopping cart order.
 RepositoryItem getProfile()
          Returns property Profile
 CommerceProfileTools getProfileTools()
          Returns property ProfileTools
 RestorableOrders getRestorableOrders()
          Returns property RestorableOrders
 java.util.Collection getSaved()
          Returns a collection of Order objects which are the user's saved list of shopping carts.
 javax.transaction.TransactionManager getTransactionManager()
           
 boolean handleCreate(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This form handler moves the current order into the saved order collection.
 boolean handleDelete(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          The handler method takes the order id as specified in the handlerOrderId property and deletes that order through invoking the deleteOrder method.
 boolean handleDeleteAll(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          This handler will delete all the shopping carts (current and saved)
 boolean handleSwitch(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
          The handler method takes the order id as specified in the handlerOrderId property and makes that the current order through invoking the switchCurrentOrder method.
 boolean isCurrentEmpty()
          Returns true if the current order is null or has no commerce items
 boolean isCurrentExists()
          Return true if the current order even exists.
 boolean isCurrentTransient()
          Return true if the current order is null or transient
 boolean isEmpty()
          Returns true if both the current and the collection of saved orders is empty
 boolean isPersistOrders()
          Returns property PersistOrders
 boolean isPersistOrdersForAnonymousUsers()
          Returns the persistOrdersForAnonymousUsers
 boolean isRepriceAfterFailoverRecovery()
          Returns property RepriceAfterFailoverRecovery
 boolean isSavedEmpty()
          Returns true if the collection of saved orders is null or empty
 boolean isSaveEmptyOrders()
           
 void removeSavedOrder(java.lang.String pOrderId)
          This method removes the order with the given id from the collection of saved orders.
protected  void repriceRestoredShoppingCart(Order pOrder, DynamoHttpServletRequest pRequest)
          Fetch the request and response objects through JNDI (e.g.
protected  void repriceRestoredShoppingCarts(java.util.Collection pOrders, DynamoHttpServletRequest pRequest)
          Reprice the collection of orders by calling repriceRestoredShoppingCart on each one.
protected  void resetOrderProfileId(Order pOrder)
          When a session recovers from failover, if the user is anonymous, then typically they will get a new profile object, and as such a new profile id.
 void sendScenarioEvent(CommerceMessage pMessage)
          Send the scenario event with the message passed.
protected  void sendSwitchOrderMessage(Order pOldOrder, Order pNewOrder)
           
 void sessionRestored()
          This method is invoked during the recovery phase of a session backup.
 void setCurrent(Order pCurrent)
          Sets property Current
 void setFailoverRecoveryPricingOperation(java.lang.String pFailoverRecoveryPricingOperation)
          Sets property FailoverRecoveryPricingOperation
 void setHandlerOrderId(java.lang.String pHandlerOrderId)
          Sets property HandlerOrderId
 void setLast(Order pLast)
          Sets property Last
 void setLoggingIdentifier(java.lang.String pLoggingIdentifier)
          Sets property LoggingIdentifier
 void setMessageSender(MessageSender pMessageSender)
          Sets Message Sender to send scenario Events
 void setOrderManager(OrderManager pOrderManager)
          Sets property OrderManager
 void setOrderType(java.lang.String pOrderType)
          Sets property OrderType
 void setPersistOrders(boolean pPersistOrders)
          Sets property PersistOrders
 void setPersistOrdersForAnonymousUsers(boolean pPersistOrdersForAnonymousUsers)
          Sets the persistOrdersForAnonymousUsers
 void setProfile(RepositoryItem pProfile)
          Sets property Profile
 void setProfileTools(CommerceProfileTools pProfileTools)
          Sets property ProfileTools
 void setRepriceAfterFailoverRecovery(boolean pRepriceAfterFailoverRecovery)
          Sets property RepriceAfterFailoverRecovery
 void setRestorableOrders(RestorableOrders pRestorableOrders)
          Sets property RestorableOrders
 void setSaved(java.util.Collection pSaved)
           
 void setSaveEmptyOrders(boolean pSaveEmptyOrders)
           
 void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)
           
protected  boolean shouldSaveOnSwitch(Order pOrder)
          Return true if we should save the specified order when doing a switch order operation, false otherwise.
 boolean switchCurrentOrder(java.lang.String pNewCurrentId)
          Switch the current order to the order with the given id, move the old current order into the saved orders
protected  boolean validActiveShoppingCart(Order pOrder)
          Return true if the order can be used for a shopping cart.
protected  boolean validRestoredShoppingCart(Order pOrder)
          Returns true if the order is still valid after a session has been restored.
 
Methods inherited from class atg.nucleus.logging.ApplicationLoggingImpl
addGlobalLogListeners, addLogListener, getLoggingForVlogging, getLoggingIdentifer, getLogListenerCount, getLogListeners, initializeFromServiceEvent, isAutoInitListeners, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, removeLogListener, sendLogEvent, setAutoInitListeners, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

OrderHolder

public OrderHolder()
Constructs an instanceof OrderHolder

Method Detail

setLoggingIdentifier

public void setLoggingIdentifier(java.lang.String pLoggingIdentifier)
Sets property LoggingIdentifier

Overrides:
setLoggingIdentifier in class ApplicationLoggingImpl

getLoggingIdentifier

public java.lang.String getLoggingIdentifier()
Returns property LoggingIdentifier

Overrides:
getLoggingIdentifier in class ApplicationLoggingImpl

setPersistOrders

public void setPersistOrders(boolean pPersistOrders)
Sets property PersistOrders


isPersistOrders

public boolean isPersistOrders()
Returns property PersistOrders


isSaveEmptyOrders

public boolean isSaveEmptyOrders()
Returns:
true if it's okay to save empty current orders when switching to a previously saved order, false otherwise.

setSaveEmptyOrders

public void setSaveEmptyOrders(boolean pSaveEmptyOrders)
Parameters:
pSaveEmptyOrders - Specify whether or not to save the current order if it's empty when switching to a previously saved order. Defaults to false, but can be set to true to preserve backward compatibility with ATG Commerce version 7.0 and earlier.

shouldSaveOnSwitch

protected boolean shouldSaveOnSwitch(Order pOrder)
Return true if we should save the specified order when doing a switch order operation, false otherwise. By default we save only non-empty orders, unless saveEmptyOrders is set to true.

Subclasses may override this method to implement different behavior if necessary.


isPersistOrdersForAnonymousUsers

public boolean isPersistOrdersForAnonymousUsers()
Returns the persistOrdersForAnonymousUsers


setPersistOrdersForAnonymousUsers

public void setPersistOrdersForAnonymousUsers(boolean pPersistOrdersForAnonymousUsers)
Sets the persistOrdersForAnonymousUsers


setOrderType

public void setOrderType(java.lang.String pOrderType)
Sets property OrderType


getOrderType

public java.lang.String getOrderType()
Returns the type of order to create when we need to construct a new shopping cart order. This defaults to "shoppingcart".


setTransactionManager

public void setTransactionManager(javax.transaction.TransactionManager pTransactionManager)

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()

setRepriceAfterFailoverRecovery

public void setRepriceAfterFailoverRecovery(boolean pRepriceAfterFailoverRecovery)
Sets property RepriceAfterFailoverRecovery


isRepriceAfterFailoverRecovery

public boolean isRepriceAfterFailoverRecovery()
Returns property RepriceAfterFailoverRecovery


setFailoverRecoveryPricingOperation

public void setFailoverRecoveryPricingOperation(java.lang.String pFailoverRecoveryPricingOperation)
Sets property FailoverRecoveryPricingOperation


getFailoverRecoveryPricingOperation

public java.lang.String getFailoverRecoveryPricingOperation()
Returns property FailoverRecoveryPricingOperation


setProfile

public void setProfile(RepositoryItem pProfile)
Sets property Profile


getProfile

public RepositoryItem getProfile()
Returns property Profile


setOrderManager

public void setOrderManager(OrderManager pOrderManager)
Sets property OrderManager


getOrderManager

public OrderManager getOrderManager()
Returns property OrderManager


setProfileTools

public void setProfileTools(CommerceProfileTools pProfileTools)
Sets property ProfileTools


getProfileTools

public CommerceProfileTools getProfileTools()
Returns property ProfileTools


isCurrentEmpty

public boolean isCurrentEmpty()
Returns true if the current order is null or has no commerce items


isCurrentTransient

public boolean isCurrentTransient()
Return true if the current order is null or transient


isCurrentExists

public boolean isCurrentExists()
Return true if the current order even exists.


isSavedEmpty

public boolean isSavedEmpty()
Returns true if the collection of saved orders is null or empty


isEmpty

public boolean isEmpty()
Returns true if both the current and the collection of saved orders is empty


setCurrent

public void setCurrent(Order pCurrent)
Sets property Current


getCurrent

public Order getCurrent(boolean pEnsureOrder)
Returns the current Order (aka shopping cart), optionally loading or creating an order if the current order is null.

Parameters:
pEnsureOrder - If true and the current order is null, attempt to load previously saved order or create and return a new order for the user. If false and the current order is null, simply return null.

getCurrent

public Order getCurrent()
Returns the current Order (aka shopping cart). If the current order is null this method will automatically load the user's saved orders and make one of them the current order, or create a new order if no suitabe saved orders are found.

See Also:
CommerceProfileTools.loadShoppingCarts(atg.repository.RepositoryItem, atg.commerce.order.OrderHolder)

setSaved

public void setSaved(java.util.Collection pSaved)

getSaved

public java.util.Collection getSaved()
Returns a collection of Order objects which are the user's saved list of shopping carts. An application should use the provided handler methods to move any cart from the saved list into the current Order property.


setRestorableOrders

public void setRestorableOrders(RestorableOrders pRestorableOrders)
Sets property RestorableOrders


getRestorableOrders

public RestorableOrders getRestorableOrders()
Returns property RestorableOrders


setLast

public void setLast(Order pLast)
Sets property Last


getLast

public Order getLast()
Returns the last completed Order. During the checkout process the "current order" is moved to the last order and the current order is reinitialized.


setHandlerOrderId

public void setHandlerOrderId(java.lang.String pHandlerOrderId)
Sets property HandlerOrderId


getHandlerOrderId

public java.lang.String getHandlerOrderId()
Returns property HandlerOrderId


setMessageSender

public void setMessageSender(MessageSender pMessageSender)
Sets Message Sender to send scenario Events


getMessageSender

public MessageSender getMessageSender()
Returns Message Sender to send scenario Events


deleteOrder

public boolean deleteOrder(java.lang.String pOrderId)
Delete the order with the given id from the current or saved orders. If the order is non-transient then we also remove it from the database.

Returns:
true if the order was found and deleted

switchCurrentOrder

public boolean switchCurrentOrder(java.lang.String pNewCurrentId)
Switch the current order to the order with the given id, move the old current order into the saved orders

Returns:
true if the order was found, and was switched to be the current order

removeSavedOrder

public void removeSavedOrder(java.lang.String pOrderId)
This method removes the order with the given id from the collection of saved orders. If an order with the given id is not found this method does nothing.


createInitialOrder

protected Order createInitialOrder(RepositoryItem pProfile)
                            throws CommerceException
Creates the initial order for the given user. If the user is non-transient and the persistOrders property is true then we also automatically save the order in the database so it can be loaded in the future.

Throws:
CommerceException

handleSwitch

public boolean handleSwitch(DynamoHttpServletRequest pRequest,
                            DynamoHttpServletResponse pResponse)
                     throws javax.servlet.ServletException,
                            java.io.IOException
The handler method takes the order id as specified in the handlerOrderId property and makes that the current order through invoking the switchCurrentOrder method.

Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

handleCreate

public boolean handleCreate(DynamoHttpServletRequest pRequest,
                            DynamoHttpServletResponse pResponse)
                     throws javax.servlet.ServletException,
                            java.io.IOException
This form handler moves the current order into the saved order collection. Then a new empty is order is set to the current.

Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

handleDelete

public boolean handleDelete(DynamoHttpServletRequest pRequest,
                            DynamoHttpServletResponse pResponse)
                     throws javax.servlet.ServletException,
                            java.io.IOException
The handler method takes the order id as specified in the handlerOrderId property and deletes that order through invoking the deleteOrder method.

Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

handleDeleteAll

public boolean handleDeleteAll(DynamoHttpServletRequest pRequest,
                               DynamoHttpServletResponse pResponse)
                        throws javax.servlet.ServletException,
                               java.io.IOException
This handler will delete all the shopping carts (current and saved)

Parameters:
pRequest - the servlet's request
pResponse - the servlet's response
Throws:
javax.servlet.ServletException - if there was an error while executing the code
java.io.IOException - if there was an error with servlet io

validActiveShoppingCart

protected boolean validActiveShoppingCart(Order pOrder)
Return true if the order can be used for a shopping cart. This checks to see if the state of the Order is INCOMPLETE, which means it has not been submitted for purchasing


validRestoredShoppingCart

protected boolean validRestoredShoppingCart(Order pOrder)
Returns true if the order is still valid after a session has been restored. An order may no longer be valid if the order has been removed from the system before the session is restored. Any transient orders are assumed to be valid, but a persistent order is checked to make sure that the backing repository items still exist in the repository.


resetOrderProfileId

protected void resetOrderProfileId(Order pOrder)
When a session recovers from failover, if the user is anonymous, then typically they will get a new profile object, and as such a new profile id. Therefore this method is run when we restored transient orders during recovery and we reset the order's profile id to the current user's profile id. Persistent users should have the correct profile id, so therefore we do not attempt to update the order. Later on in the validation process we check to make sure the profile id of the recovered profile matches the orders.


sessionRestored

public void sessionRestored()
This method is invoked during the recovery phase of a session backup. This method uses the restored RestorableOrders component to put the shopping carts of the user in place. For persistent users this means we use their profile id and query for all of their persistent orders (if persistOrders is true). Otherwise we reattach the deserialized transient orders back into the current and saved properties of this component.

Specified by:
sessionRestored in interface atg.servlet.sessionsaver.Restoreable

repriceRestoredShoppingCarts

protected void repriceRestoredShoppingCarts(java.util.Collection pOrders,
                                            DynamoHttpServletRequest pRequest)
Reprice the collection of orders by calling repriceRestoredShoppingCart on each one.


repriceRestoredShoppingCart

protected void repriceRestoredShoppingCart(Order pOrder,
                                           DynamoHttpServletRequest pRequest)
Fetch the request and response objects through JNDI (e.g. java:dynamo/Request) and then call the CommerceProfileTools.repriceShoppingCarts method. This method will then lookup the UserPricingModels, the user's locale, and then reprice the order.


sendSwitchOrderMessage

protected void sendSwitchOrderMessage(Order pOldOrder,
                                      Order pNewOrder)

sendScenarioEvent

public void sendScenarioEvent(CommerceMessage pMessage)
Send the scenario event with the message passed. This will get the message sender from MessageSender property and fires the event.

Parameters:
pMessage - the message to fire.