Class ComponentRollbackConverter

  • All Implemented Interfaces:
    ItemRollbackConverter

    public class ComponentRollbackConverter
    extends java.lang.Object
    implements ItemRollbackConverter
    This class provides a custom way to rollback components.
    • If the component was originally versioned in isolation, then the component is rollbacked as usual.
    • If the component was originally versioned as part of a page, and the component is shared, all references of the component in the page are replaced with a clone. References of the original component in other pages or shared slots are not affected.
    • If the component was originally versioned as part of a page, and the component is not shared, then the component is rollbacked and restored only in that page.
    • Constructor Detail

      • ComponentRollbackConverter

        public ComponentRollbackConverter()
    • Method Detail

      • replaceComponentWithCloneInPage

        protected AbstractCMSComponentModel replaceComponentWithCloneInPage​(AbstractCMSComponentModel originalComponent,
                                                                            AbstractPageModel page,
                                                                            AuditPayload componentPayload)
                                                                     throws ItemRollbackException
        This method creates a clone of the given component and uses it to replace all the references of the original component in the version of the page provided, as indicated by the payload.
        Parameters:
        originalComponent - - The component to clone.
        page - - The page where to replace the original component with a rollbacked clone
        componentPayload - - The serialized payload that specifies the information that the versioned component must contain.
        Returns:
        the cloned component.
        Throws:
        ItemRollbackException - if the original component cannot be cloned to be safely rolled back.
      • rollbackComponentOnlyInPage

        protected void rollbackComponentOnlyInPage​(AbstractCMSComponentModel component,
                                                   AbstractPageModel page,
                                                   AuditPayload componentPayload)
        This method rollbacks the component only in slots of the version of the page provided, as indicated by the payload. Note that this method makes emphasis not to add the component to a slot of any other page or to a shared slot.
        Parameters:
        component - - The component to rollback.
        page - - The page where to rollback the provided component.
        componentPayload - - The serialized payload that specifies the information that the versioned component must contain.
      • updatePayloadForClonedComponent

        protected void updatePayloadForClonedComponent​(AbstractCMSComponentModel clonedComponent,
                                                       AuditPayload componentPayload)
        This method updates the component payload to match the cloned component information. This step is important to ensure that populators will update the component with the right information.
        Parameters:
        clonedComponent - - The component instance that will be rollbacked.
        componentPayload - - The serialized payload that specifies the information that the versioned component must contain.
      • getPageSlots

        protected java.util.Set<ContentSlotModel> getPageSlots​(AbstractPageModel page)
        This method retrieves the content slots that directly belong to the provided page (it does not return slots coming from a template).
        Parameters:
        page - - The page whose slots to retrieve.
        Returns:
        a Set containing the slots in the page.
      • getVersionedSlotsUids

        protected java.util.Set<java.lang.String> getVersionedSlotsUids​(AuditPayload componentPayload)
        This method retrieves the uid of the versioned slots stored in the provided payload.
        Parameters:
        componentPayload - - The payload from where to read the list of versioned slots.
        Returns:
        a Set containing the uids of the versioned slots.
      • removeSlotsOutsidePageFromPayload

        protected void removeSlotsOutsidePageFromPayload​(java.util.Set<ContentSlotModel> slotsInPage,
                                                         AuditPayload componentPayload)
        This method removes from the payload any slot outside the current page. This is important to ensure the populators later in the chain will not try to rollback those slots too.
        Parameters:
        slotsInPage - - The slots of the current page. Doesn't contain any shared slot.
        componentPayload - - The payload where to remove slots outside the current page.
      • isPkSlotInPage

        protected boolean isPkSlotInPage​(java.lang.String slotPk,
                                         java.util.Set<java.lang.String> slotsInPageUid)
        This method determines if the given pk represents one of the slots in the current page.
        Parameters:
        slotPk - - the pk to check.
        slotsInPageUid - - the slots of the current page. Doesn't contain any shared slot.
        Returns:
        true if there pk represents a slot in the current page. false otherwise.
      • readSlotsFromComponentPayload

        protected java.util.List<java.lang.String> readSlotsFromComponentPayload​(AuditPayload componentPayload)
        This method returns a list containing the pk of each of the slots found in the given component payload. This pk might represent a slot (for external slots) or a version of a slot.
        Parameters:
        componentPayload - - the payload of the component from where to read the list of slots.
        Returns:
        a list with the pk of the slots found in the payload.
      • getItemModelFromPk

        protected ItemModel getItemModelFromPk​(java.lang.String pk)
        This method retrieves the ItemModel represented by the provided PK.
        Parameters:
        pk - - the pk whose item model to retrieve
        Returns:
        the itemModel.
      • isAssignableFromVersion

        protected boolean isAssignableFromVersion​(java.lang.String itemTypeCode)
        This method checks if the the itemTypeCode is a super type of CMSVersionModel OR the same type.
        Parameters:
        itemTypeCode - - The type code to check.
        Returns:
        Returns true if the itemTypeCode is a super type of CMSVersionModel OR the same type, false otherwise.
      • setCmsVersionService

        public void setCmsVersionService​(CMSVersionService cmsVersionService)
      • setCmsItemCloningService

        public void setCmsItemCloningService​(CMSItemCloningService cmsItemCloningService)
      • setCmsComponentService

        public void setCmsComponentService​(CMSComponentService cmsComponentService)
      • setCmsPageService

        public void setCmsPageService​(CMSPageService cmsPageService)
      • getModelService

        protected ModelService getModelService()
      • setModelService

        public void setModelService​(ModelService modelService)
      • getTypeService

        protected TypeService getTypeService()
      • setTypeService

        public void setTypeService​(TypeService typeService)
      • setConstrainedBy

        public void setConstrainedBy​(java.util.function.Predicate<ItemModel> constrainedBy)