| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectatg.nucleus.logging.VariableArgumentApplicationLoggingImpl
atg.nucleus.GenericService
atg.commerce.order.edit.CloneEditHandler
atg.commerce.order.edit.CollectionEditHandler
public class CollectionEditHandler
This handler implements a pattern to support automatic reconciling of objects in a collection.
 
 The CloneEditHandler interface is implemented as follows:
 
keyPropertyName, and saves the maps in the CloneEditState. There are two maps created by 
 this step. One maps the clone to original objects and the other maps original to clone objects. The maps
 are stored in the CloneEditState/code>. These pre-edit snapshots of items in the collection  
 provide the necessary information to identify changes to the collection once the edit is complete.  
 - applyChanges
 
- This step executes once the edit process is complete and the changes in the clone order must be reconciled
 with the original order. This handler, using the maps created by initializeCloneEditState, reconciles the
 objects between the clone and original collections. Each add, update and delete is identified and automatically 
 applied. An object representing each add AddItem, updateUpdateItemand deleteDeleteItemis created and stored in the CloneEditState.
 An UpdateItem object is created for each object that exists in the clone collection
 and has a matching counterpart in the original collection. Objects that fall into this 
 category are reconciled by copying properties from the clone to original objects. Properties 
 are configurable using propertiesToCopyOnUpdate.
 
 An AddItem object is created for each object that exists in the clone collection
 but doesn't have a matching counterpart in the original collection. Objects that fall
 into this category are added to the original collection at the same index they are found in 
 the clone collection.  
  
 A DeleteItem object is created for each object that was mapped in the original
 collection, but its counterpart no longer exists in the clone collection.
 Objects that fall into this category are removed from the original collection. 
  
Configurable properties:
SubPropertyHandler handlers defined here
 are execute according to the SubPropertyHandler
 interface.  
 
| Field Summary | |
|---|---|
| static java.lang.String | CLASS_VERSION | 
| protected  java.lang.String | mCollectionPropertyName | 
| protected  java.lang.String | mSortPropertyName | 
| protected  atg.commerce.order.edit.SubPropertyHandler[] | mSubPropertyHandlers | 
| protected  boolean | mThrowExceptionsForCollectionChanges | 
| protected static java.lang.String | STATE_CLONETOORIGINAL_MAPthe key used for storing the clone to original object map in the clone order state | 
| protected static java.lang.String | STATE_ORIGINALTOCLONE_MAPthe key used for storing the original to clone object map in the clone order state | 
| Fields inherited from class atg.commerce.order.edit.CloneEditHandler | 
|---|
| mFulfillmentMessageSender, mKeyPropertyName, mOrderFulfillmentTools, mPropertiesToCopyOnUpdate, STATE_ADD_ITEMS, STATE_DELETE_ITEMS, STATE_UPDATE_ITEMS | 
| Fields inherited from class atg.nucleus.GenericService | 
|---|
| SERVICE_INFO_KEY | 
| 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 | |
|---|---|
| CollectionEditHandler() | |
| Method Summary | |
|---|---|
| protected  void | addItem(CloneEditState pCloneEditState,
        AddItem pAddItem)Reconciles the AddItemby adding the object it to
 the original container's collection property. | 
|  void | applyChanges(CloneEditState pCloneEditState)This method is called during the reconciliation process to reconcile the data between the original and clone object. | 
| protected  void | deleteItem(CloneEditState pCloneEditState,
           DeleteItem pDeleteItem)Reconciles the DeleteItemby deleting the original object from the
 original container. | 
|  void | detectChanges(CloneEditState pCloneEditState)Detects updates, adds and deletes in the collection. | 
| protected  void | detectChangesToCollection(CloneEditState pCloneEditState,
                          java.lang.Object pOriginalCollectionContainer,
                          java.lang.Object pCloneCollectionContainer)Detects changes to the collections using the maps created when the CloneEditState was initialized. | 
| protected  void | detectDeletes(CloneEditState pCloneEditState,
              java.lang.Object pOriginalContainer,
              java.lang.Object pCloneContainer)A DeleteItemobject is created for each object in the original container 
 that was mapped to a counterpart that no longer exists in the clone container. | 
| protected  void | executeSubPropertyHandlerInitialization(CloneEditState pCloneEditState,
                                        java.lang.Object pOriginalParent,
                                        java.lang.Object pCloneParent)Executes the initialization interface for each SubPropertyHandlerattached to this
 handler. | 
| protected  void | executeSubPropertyHandlerUpdates(CloneEditState pCloneEditState,
                                 java.lang.Object pOriginalParent,
                                 java.lang.Object pCloneParent)Executes the update interface for each SubPropertyHandlerattached to this
 handler. | 
| protected  void | executeSubPropertyHandlerValidation(java.lang.Object pOriginalParent,
                                    java.lang.Object pCloneParent)Executes the validation interface for each SubPropertyHandlerattached to this
 handler. | 
| protected  java.lang.Object | findCounterpartObject(CloneEditState pCloneEditState,
                      java.lang.Object pObject,
                      java.util.Collection pCounterpartCollection,
                      java.util.Map pCounterpartMap)Finds the counter part object for the given object. | 
|  java.util.Map | getCloneToOriginalMap(CloneEditState pCloneEditState)Returns the clone to original map stored in the CloneEditState. | 
| protected  java.util.Collection | getCollection(java.lang.Object pCollectionContainer)gets the collection in property defined by CollectionPropertyName | 
|  java.lang.String | getCollectionPropertyName()This property on the order that contains the collection of objects | 
| protected  java.lang.Object | getMatchingCloneKey(CloneEditState pCloneEditState,
                    java.lang.Object pOriginalKey)Returns the matching clone key for the given original key. | 
| protected  java.lang.Object | getMatchingOriginalKey(CloneEditState pCloneEditState,
                       java.lang.Object pCloneKey)Returns the matching original key for the given clone key. | 
|  java.util.Map | getOriginalToCloneMap(CloneEditState pCloneEditState)Returns the original to clone map stored in the CloneEditState. | 
| protected  java.util.Collection | getSortedCollection(java.lang.Object pCollectionContainer)Returns the sorted Collection from the container. | 
|  java.lang.String | getSortPropertyName()The value of this property is used to sort the collection before mapping the original to clone object in the collection | 
|  atg.commerce.order.edit.SubPropertyHandler[] | getSubPropertyHandlers()Returns the handlers that manage sub properties of the items managed by this collection handler | 
| protected  boolean | handleMissingOriginalObject(CloneEditState pCloneEditState,
                            java.lang.Object pCloneContainer,
                            java.lang.Object pCloneObject,
                            java.lang.Object pOriginalContainer,
                            java.lang.Object pOriginalCounterPartKey)This API is called by detectChangesToCollectionif an object in the clone container 
 was mapped to an original object in the original container, but the original could not be found
 in the original container as expected. | 
|  void | initializeCloneEditState(CloneEditState pCloneEditState)This maps the objects in the original collection to the object in the clone collection and stores the maps in the clone edit state in the CloneEditState | 
| protected  boolean | isSubPropertyHandlers()Returns true if there are any sub property handlers attached to this handler | 
|  boolean | isThrowExceptionsForCollectionChanges()determines if exceptions are thrown when the reconciliation process detects that the original collection has changed after it was cloned. | 
| protected  void | mapOriginalToClone(CloneEditState pCloneEditState,
                   Order pOriginalOrder,
                   Order pCloneOrder)Maps the objects in the original collection to objects in the clone collection. | 
| protected  java.util.Map | mapOriginalToCloneCollection(CloneEditState pCloneEditState,
                             java.util.Collection pOriginalCollection,
                             java.util.Collection pCloneCollection)Maps objects in the original collection to the clone collection and saves the map in the clone edit state. | 
| protected  void | saveOriginalToCloneObjectMappings(CloneEditState pCloneEditState,
                                  java.util.Map pOriginalToCloneObjectMap)Saves the map of originalToClone objects in the clone edit state | 
|  void | setCollectionPropertyName(java.lang.String pCollectionPropertyName) | 
|  void | setSortPropertyName(java.lang.String pSortPropertyName) | 
|  void | setSubPropertyHandlers(atg.commerce.order.edit.SubPropertyHandler[] pSubPropertyHandlers) | 
|  void | setThrowExceptionsForCollectionChanges(boolean pThrowExceptionsForCollectionChanges) | 
| protected  java.util.Collection | sortCollection(java.util.Collection pCollection)This method is called for both the original and clone collections before attempting to map the objects in the collection. | 
|  void | validateCloneOrder(Order pOriginalOrder,
                   Order pCloneOrder)Validates the collections after the cloning process | 
| protected  void | validateCollection(java.lang.Object pOriginalCollectionContainer,
                   java.lang.Object pCloneCollectionContainer)Validates the collection referenced by the given container. | 
| protected  void | validateCollection(Order pOriginalOrder,
                   Order pCloneOrder)Validates the collection | 
| protected  void | validateCollectionSize(java.lang.Object pOriginalCollectionContainer,
                       java.lang.Object pCloneCollectionContainer)Ensures that the collections in the property defined by collectionPropertyNameare the same size. | 
| 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 | 
|---|
public static final java.lang.String CLASS_VERSION
protected static final java.lang.String STATE_CLONETOORIGINAL_MAP
protected static final java.lang.String STATE_ORIGINALTOCLONE_MAP
protected atg.commerce.order.edit.SubPropertyHandler[] mSubPropertyHandlers
protected boolean mThrowExceptionsForCollectionChanges
protected java.lang.String mSortPropertyName
protected java.lang.String mCollectionPropertyName
| Constructor Detail | 
|---|
public CollectionEditHandler()
| Method Detail | 
|---|
public atg.commerce.order.edit.SubPropertyHandler[] getSubPropertyHandlers()
public void setSubPropertyHandlers(atg.commerce.order.edit.SubPropertyHandler[] pSubPropertyHandlers)
public boolean isThrowExceptionsForCollectionChanges()
public void setThrowExceptionsForCollectionChanges(boolean pThrowExceptionsForCollectionChanges)
public java.lang.String getSortPropertyName()
public void setSortPropertyName(java.lang.String pSortPropertyName)
public java.lang.String getCollectionPropertyName()
public void setCollectionPropertyName(java.lang.String pCollectionPropertyName)
protected void mapOriginalToClone(CloneEditState pCloneEditState,
                                  Order pOriginalOrder,
                                  Order pCloneOrder)
                           throws CommerceException
collectionPropertyName
pCloneEditState - 
CommerceExceptionmapOriginalToCloneCollection(CloneEditState, Collection, Collection)
protected java.lang.Object findCounterpartObject(CloneEditState pCloneEditState,
                                                 java.lang.Object pObject,
                                                 java.util.Collection pCounterpartCollection,
                                                 java.util.Map pCounterpartMap)
pCloneEditState - pObject - the object for which the counterpart is to be foundpCounterpartCollection - the collection of counter parts to search for the counterpartpCounterpartMap - the counter part map for pObject
protected java.util.Collection sortCollection(java.util.Collection pCollection)
 The default behavior is to return the given collection sort is ascending order using the
 property defined by sortPropertyName. If sortPropertyName
 is not valued, pCollection is returned unchanged.
pCollection - 
protected java.util.Map mapOriginalToCloneCollection(CloneEditState pCloneEditState,
                                                     java.util.Collection pOriginalCollection,
                                                     java.util.Collection pCloneCollection)
pCloneEditState - pOriginalCollection - pCloneCollection - 
public void initializeCloneEditState(CloneEditState pCloneEditState)
                              throws CommerceException
initializeCloneEditState in class CloneEditHandlerCommerceException
protected java.lang.Object getMatchingCloneKey(CloneEditState pCloneEditState,
                                               java.lang.Object pOriginalKey)
pCloneEditState - pOriginalKey - 
protected java.lang.Object getMatchingOriginalKey(CloneEditState pCloneEditState,
                                                  java.lang.Object pCloneKey)
pCloneEditState - pCloneKey - 
public void applyChanges(CloneEditState pCloneEditState)
                  throws CommerceException
 First, all DeleteItem, UpdateItem and AddItem objects 
 are created by calling detectChanges.
 
 After the reconciliation items are created, they are processed by calling processDeleteItems,
 processAddItems and processUpdateItems.
applyChanges in class CloneEditHandlerpCloneEditState - 
CommerceExceptiondetectChanges(CloneEditState), 
CloneEditHandler.processDeleteItems(CloneEditState), 
CloneEditHandler.processAddItems(CloneEditState), 
CloneEditHandler.processUpdateItems(CloneEditState)
public void detectChanges(CloneEditState pCloneEditState)
                   throws CommerceException
CommerceExceptiondetectChangesToCollection(CloneEditState, Object, Object)
protected java.util.Collection getCollection(java.lang.Object pCollectionContainer)
                                      throws PropertyNotFoundException
CollectionPropertyName
pCollectionContainer - 
PropertyNotFoundException
protected java.util.Collection getSortedCollection(java.lang.Object pCollectionContainer)
                                            throws PropertyNotFoundException
pCollectionContainer - 
PropertyNotFoundExceptiongetCollection(Object), 
sortCollection(Collection)
protected void detectDeletes(CloneEditState pCloneEditState,
                             java.lang.Object pOriginalContainer,
                             java.lang.Object pCloneContainer)
                      throws CommerceException
DeleteItem object is created for each object in the original container 
 that was mapped to a counterpart that no longer exists in the clone container.
 
pCloneEditState - pOriginalContainer - pCloneContainer - 
CommerceException
protected void saveOriginalToCloneObjectMappings(CloneEditState pCloneEditState,
                                                 java.util.Map pOriginalToCloneObjectMap)
pCloneEditState - pOriginalToCloneObjectMap - 
protected void detectChangesToCollection(CloneEditState pCloneEditState,
                                         java.lang.Object pOriginalCollectionContainer,
                                         java.lang.Object pCloneCollectionContainer)
                                  throws CommerceException
 The collection are obtained from the original and clone containers using the configured collections
 property name defined by collectionPropertyName. 
 
This is where the UpdateItem, AddItem and DeleteItem objects are created for objects processed.
An UpdateItem object is created for each object that exists in the clone collection container and has a matching counterpart in the original collection container. The cloneToOrigMap for this handler is used to determine the objects that fall in this category.
pCloneEditState - the CloneEditState that was created at the beginning of the clone process.pOriginalCollectionContainer - the object that has the original collection in the property defined by collectionPropertyNamepCloneCollectionContainer - the object that has the clone collection in the property defined by collectionPropertyName
CommerceException
protected boolean handleMissingOriginalObject(CloneEditState pCloneEditState,
                                              java.lang.Object pCloneContainer,
                                              java.lang.Object pCloneObject,
                                              java.lang.Object pOriginalContainer,
                                              java.lang.Object pOriginalCounterPartKey)
                                       throws CommerceException
detectChangesToCollection if an object in the clone container 
 was mapped to an original object in the original container, but the original could not be found
 in the original container as expected. Handlers can insert custom handling of this situtation 
 by implementing this method. 
 This default implementation returns false.
pCloneEditState - pCloneContainer - the container where the clone object is locatedpCloneObject - the clone object for which the original object is missingpOriginalContainer - the original container from which the original object is missingpOriginalCounterPartKey - the key of the missing original object.
CommerceException
protected void deleteItem(CloneEditState pCloneEditState,
                          DeleteItem pDeleteItem)
                   throws CommerceException
DeleteItem by deleting the original object from the
 original container.
 
deleteItem in class CloneEditHandlerpCloneEditState - pDeleteItem - the DeleteItem object
CommerceException
protected void addItem(CloneEditState pCloneEditState,
                       AddItem pAddItem)
                throws CommerceException
AddItem by adding the object it to
 the original container's collection property.
addItem in class CloneEditHandlerpCloneEditState - pAddItem - 
CommerceExceptionpublic java.util.Map getOriginalToCloneMap(CloneEditState pCloneEditState)
CloneEditState. 
 This method will lazily create the map if one doesn't already exist.
pCloneEditState - 
public java.util.Map getCloneToOriginalMap(CloneEditState pCloneEditState)
CloneEditState. 
 This method will lazily create the map if one doesn't already exist.
pCloneEditState - 
public void validateCloneOrder(Order pOriginalOrder,
                               Order pCloneOrder)
                        throws CommerceException
validateCloneOrder in class CloneEditHandlerpOriginalOrder - pCloneOrder - 
CommerceExceptionvalidateCollectionSize(Object, Object)
protected void validateCollection(java.lang.Object pOriginalCollectionContainer,
                                  java.lang.Object pCloneCollectionContainer)
                           throws CommerceException
 If there are SubPropertyHandlers
pOriginalCollectionContainer - pCloneCollectionContainer - 
CommerceExceptionvalidateCollectionSize(Object, Object)
protected void validateCollection(Order pOriginalOrder,
                                  Order pCloneOrder)
                           throws CommerceException
pOriginalOrder - pCloneOrder - 
CommerceExceptionvalidateCollectionSize(Object, Object)
protected void validateCollectionSize(java.lang.Object pOriginalCollectionContainer,
                                      java.lang.Object pCloneCollectionContainer)
                               throws CommerceException
collectionPropertyName
 are the same size.
pOriginalCollectionContainer - pCloneCollectionContainer - 
CommerceExceptionprotected boolean isSubPropertyHandlers()
protected void executeSubPropertyHandlerInitialization(CloneEditState pCloneEditState,
                                                       java.lang.Object pOriginalParent,
                                                       java.lang.Object pCloneParent)
                                                throws CommerceException
SubPropertyHandler attached to this
 handler.
pCloneEditState - the current clone edit state for this modificationpOriginalParent - an original object in the collection managed by this handlerpCloneParent - the corresponding clone object in the collection managed by this handler
CommerceException
protected void executeSubPropertyHandlerUpdates(CloneEditState pCloneEditState,
                                                java.lang.Object pOriginalParent,
                                                java.lang.Object pCloneParent)
                                         throws CommerceException
SubPropertyHandler attached to this
 handler.
pCloneEditState - the current clone edit state for this modificationpOriginalParent - an original object in the collection managed by this handlerpCloneParent - the corresponding clone object in the collection managed by this handler
CommerceException
protected void executeSubPropertyHandlerValidation(java.lang.Object pOriginalParent,
                                                   java.lang.Object pCloneParent)
                                            throws CommerceException
SubPropertyHandler attached to this
 handler.
pOriginalParent - an original object in the collection managed by this handlerpCloneParent - the corresponding clone object in the collection managed by this handler
CommerceException| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||