Skip navigation links
atg.commerce.order.edit

Class CollectionEditHandler

    • Field Detail

      • STATE_CLONETOORIGINAL_MAP

        protected static final java.lang.String STATE_CLONETOORIGINAL_MAP
        the key used for storing the clone to original object map in the clone order state
        See Also:
        Constant Field Values
      • STATE_ORIGINALTOCLONE_MAP

        protected static final java.lang.String STATE_ORIGINALTOCLONE_MAP
        the key used for storing the original to clone object map in the clone order state
        See Also:
        Constant Field Values
      • mSubPropertyHandlers

        protected atg.commerce.order.edit.SubPropertyHandler[] mSubPropertyHandlers
      • mThrowExceptionsForCollectionChanges

        protected boolean mThrowExceptionsForCollectionChanges
      • mSortPropertyName

        protected java.lang.String mSortPropertyName
      • mCollectionPropertyName

        protected java.lang.String mCollectionPropertyName
    • Constructor Detail

      • CollectionEditHandler

        public CollectionEditHandler()
    • Method Detail

      • getSubPropertyHandlers

        public atg.commerce.order.edit.SubPropertyHandler[] getSubPropertyHandlers()
        Returns the handlers that manage sub properties of the items managed by this collection handler
      • setSubPropertyHandlers

        public void setSubPropertyHandlers(atg.commerce.order.edit.SubPropertyHandler[] pSubPropertyHandlers)
      • isThrowExceptionsForCollectionChanges

        public boolean isThrowExceptionsForCollectionChanges()
        determines if exceptions are thrown when the reconciliation process detects that the original collection has changed after it was cloned.
        Returns:
        true by default
      • setThrowExceptionsForCollectionChanges

        public void setThrowExceptionsForCollectionChanges(boolean pThrowExceptionsForCollectionChanges)
      • getSortPropertyName

        public 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
        Returns:
        sort property name
      • setSortPropertyName

        public void setSortPropertyName(java.lang.String pSortPropertyName)
      • getCollectionPropertyName

        public java.lang.String getCollectionPropertyName()
        This property on the order that contains the collection of objects
        Returns:
        String
      • setCollectionPropertyName

        public void setCollectionPropertyName(java.lang.String pCollectionPropertyName)
      • findCounterpartObject

        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.
        Parameters:
        pCloneEditState -
        pObject - the object for which the counterpart is to be found
        pCounterpartCollection - the collection of counter parts to search for the counterpart
        pCounterpartMap - the counter part map for pObject
        Returns:
        the counterpart object
      • sortCollection

        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. If the collection order is a not guaranteed, as with a List, this method should produce a sorted colletion so the objects can be successfully mapped.

        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.

        Parameters:
        pCollection -
        Returns:
        a sorted collection.
      • mapOriginalToCloneCollection

        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.

        Parameters:
        pCloneEditState -
        pOriginalCollection -
        pCloneCollection -
        Returns:
        Map of original to clone objects
      • getMatchingCloneKey

        protected java.lang.Object getMatchingCloneKey(CloneEditState pCloneEditState,
                                                       java.lang.Object pOriginalKey)
        Returns the matching clone key for the given original key.
        Parameters:
        pCloneEditState -
        pOriginalKey -
        Returns:
        clone key. null if not found.
      • getMatchingOriginalKey

        protected java.lang.Object getMatchingOriginalKey(CloneEditState pCloneEditState,
                                                          java.lang.Object pCloneKey)
        Returns the matching original key for the given clone key.
        Parameters:
        pCloneEditState -
        pCloneKey -
        Returns:
        original key. null if not found.
      • getCollection

        protected java.util.Collection getCollection(java.lang.Object pCollectionContainer)
                                              throws PropertyNotFoundException
        gets the collection in property defined by CollectionPropertyName
        Parameters:
        pCollectionContainer -
        Returns:
        Collection
        Throws:
        PropertyNotFoundException
      • detectDeletes

        protected void detectDeletes(CloneEditState pCloneEditState,
                                     java.lang.Object pOriginalContainer,
                                     java.lang.Object pCloneContainer)
                              throws CommerceException
        A 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.

        Parameters:
        pCloneEditState -
        pOriginalContainer -
        pCloneContainer -
        Throws:
        CommerceException
      • saveOriginalToCloneObjectMappings

        protected void saveOriginalToCloneObjectMappings(CloneEditState pCloneEditState,
                                                         java.util.Map pOriginalToCloneObjectMap)
        Saves the map of originalToClone objects in the clone edit state
        Parameters:
        pCloneEditState -
        pOriginalToCloneObjectMap -
      • detectChangesToCollection

        protected void detectChangesToCollection(CloneEditState pCloneEditState,
                                                 java.lang.Object pOriginalCollectionContainer,
                                                 java.lang.Object pCloneCollectionContainer)
                                          throws CommerceException
        Detects changes to the collections using the maps created when the CloneEditState was initialized.

        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.

        Parameters:
        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 collectionPropertyName
        pCloneCollectionContainer - the object that has the clone collection in the property defined by collectionPropertyName
        Throws:
        CommerceException
      • handleMissingOriginalObject

        protected boolean handleMissingOriginalObject(CloneEditState pCloneEditState,
                                                      java.lang.Object pCloneContainer,
                                                      java.lang.Object pCloneObject,
                                                      java.lang.Object pOriginalContainer,
                                                      java.lang.Object pOriginalCounterPartKey)
                                               throws CommerceException
        This API is called by 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.

        Parameters:
        pCloneEditState -
        pCloneContainer - the container where the clone object is located
        pCloneObject - the clone object for which the original object is missing
        pOriginalContainer - the original container from which the original object is missing
        pOriginalCounterPartKey - the key of the missing original object.
        Returns:
        true if the condition was successfully handled.
        Throws:
        CommerceException
      • getOriginalToCloneMap

        public java.util.Map getOriginalToCloneMap(CloneEditState pCloneEditState)
        Returns the original to clone map stored in the CloneEditState. This method will lazily create the map if one doesn't already exist.
        Parameters:
        pCloneEditState -
        Returns:
        the original to clone object map
      • getCloneToOriginalMap

        public java.util.Map getCloneToOriginalMap(CloneEditState pCloneEditState)
        Returns the clone to original map stored in the CloneEditState. This method will lazily create the map if one doesn't already exist.
        Parameters:
        pCloneEditState -
        Returns:
        the clone to original object map
      • validateCollection

        protected void validateCollection(java.lang.Object pOriginalCollectionContainer,
                                          java.lang.Object pCloneCollectionContainer)
                                   throws CommerceException
        Validates the collection referenced by the given container.

        If there are SubPropertyHandlers

        Parameters:
        pOriginalCollectionContainer -
        pCloneCollectionContainer -
        Throws:
        CommerceException
        See Also:
        validateCollectionSize(Object, Object)
      • validateCollectionSize

        protected void validateCollectionSize(java.lang.Object pOriginalCollectionContainer,
                                              java.lang.Object pCloneCollectionContainer)
                                       throws CommerceException
        Ensures that the collections in the property defined by collectionPropertyName are the same size.
        Parameters:
        pOriginalCollectionContainer -
        pCloneCollectionContainer -
        Throws:
        CommerceException
      • isSubPropertyHandlers

        protected boolean isSubPropertyHandlers()
        Returns true if there are any sub property handlers attached to this handler
      • executeSubPropertyHandlerInitialization

        protected void executeSubPropertyHandlerInitialization(CloneEditState pCloneEditState,
                                                               java.lang.Object pOriginalParent,
                                                               java.lang.Object pCloneParent)
                                                        throws CommerceException
        Executes the initialization interface for each SubPropertyHandler attached to this handler.
        Parameters:
        pCloneEditState - the current clone edit state for this modification
        pOriginalParent - an original object in the collection managed by this handler
        pCloneParent - the corresponding clone object in the collection managed by this handler
        Throws:
        CommerceException
      • executeSubPropertyHandlerUpdates

        protected void executeSubPropertyHandlerUpdates(CloneEditState pCloneEditState,
                                                        java.lang.Object pOriginalParent,
                                                        java.lang.Object pCloneParent)
                                                 throws CommerceException
        Executes the update interface for each SubPropertyHandler attached to this handler.
        Parameters:
        pCloneEditState - the current clone edit state for this modification
        pOriginalParent - an original object in the collection managed by this handler
        pCloneParent - the corresponding clone object in the collection managed by this handler
        Throws:
        CommerceException
      • executeSubPropertyHandlerValidation

        protected void executeSubPropertyHandlerValidation(java.lang.Object pOriginalParent,
                                                           java.lang.Object pCloneParent)
                                                    throws CommerceException
        Executes the validation interface for each SubPropertyHandler attached to this handler.
        Parameters:
        pOriginalParent - an original object in the collection managed by this handler
        pCloneParent - the corresponding clone object in the collection managed by this handler
        Throws:
        CommerceException