Class ComponentRollbackConverter
- java.lang.Object
-
- de.hybris.platform.cms2.version.converter.rollback.impl.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 Summary
Constructors Constructor Description ComponentRollbackConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CMSComponentServicegetCmsComponentService()protected CMSItemCloningServicegetCmsItemCloningService()protected CMSPageServicegetCmsPageService()protected CMSVersionServicegetCmsVersionService()java.util.function.Predicate<ItemModel>getConstrainedBy()Predicate to verify whether current converter is applicable to providedItemModel.protected ItemModelgetItemModelFromPk(java.lang.String pk)This method retrieves theItemModelrepresented by the provided PK.protected ModelServicegetModelService()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).protected TypeServicegetTypeService()protected java.util.Set<java.lang.String>getVersionedSlotsUids(AuditPayload componentPayload)This method retrieves the uid of the versioned slots stored in the provided payload.protected booleanisAssignableFromVersion(java.lang.String itemTypeCode)This method checks if the the itemTypeCode is a super type ofCMSVersionModelOR the same type.protected booleanisPkSlotInPage(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.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.protected voidremoveSlotsOutsidePageFromPayload(java.util.Set<ContentSlotModel> slotsInPage, AuditPayload componentPayload)This method removes from the payload any slot outside the current page.protected AbstractCMSComponentModelreplaceComponentWithCloneInPage(AbstractCMSComponentModel originalComponent, AbstractPageModel page, AuditPayload componentPayload)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.protected voidrollbackComponentOnlyInPage(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.AbstractCMSComponentModelrollbackItem(ItemModel itemModel, CMSVersionModel version, AuditPayload auditPayload)Rollbacks the itemModel to a desired version based on the information specified in the audit payload.voidsetCmsComponentService(CMSComponentService cmsComponentService)voidsetCmsItemCloningService(CMSItemCloningService cmsItemCloningService)voidsetCmsPageService(CMSPageService cmsPageService)voidsetCmsVersionService(CMSVersionService cmsVersionService)voidsetConstrainedBy(java.util.function.Predicate<ItemModel> constrainedBy)voidsetModelService(ModelService modelService)voidsetTypeService(TypeService typeService)protected voidupdatePayloadForClonedComponent(AbstractCMSComponentModel clonedComponent, AuditPayload componentPayload)This method updates the component payload to match the cloned component information.
-
-
-
Method Detail
-
rollbackItem
public AbstractCMSComponentModel rollbackItem(ItemModel itemModel, CMSVersionModel version, AuditPayload auditPayload) throws ItemRollbackException
Description copied from interface:ItemRollbackConverterRollbacks the itemModel to a desired version based on the information specified in the audit payload.- Specified by:
rollbackItemin interfaceItemRollbackConverter- Parameters:
itemModel- TheItemModelto rollback.version- TheCMSVersionModelthat identifies the version of the item to rollback to.auditPayload- The serialized payload that specifies the information that the versioned item must contain.- Returns:
- the rollbacked
ItemModel. - Throws:
ItemRollbackException- if theItemModelreferenced cannot be rolled back.
-
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 clonecomponentPayload- - 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
Setcontaining 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
Setcontaining 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 theItemModelrepresented 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 ofCMSVersionModelOR the same type.- Parameters:
itemTypeCode- - The type code to check.- Returns:
- Returns
trueif the itemTypeCode is a super type ofCMSVersionModelOR the same type,falseotherwise.
-
getCmsVersionService
protected CMSVersionService getCmsVersionService()
-
setCmsVersionService
public void setCmsVersionService(CMSVersionService cmsVersionService)
-
getCmsItemCloningService
protected CMSItemCloningService getCmsItemCloningService()
-
setCmsItemCloningService
public void setCmsItemCloningService(CMSItemCloningService cmsItemCloningService)
-
getCmsComponentService
protected CMSComponentService getCmsComponentService()
-
setCmsComponentService
public void setCmsComponentService(CMSComponentService cmsComponentService)
-
getCmsPageService
protected CMSPageService getCmsPageService()
-
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)
-
getConstrainedBy
public java.util.function.Predicate<ItemModel> getConstrainedBy()
Description copied from interface:ItemRollbackConverterPredicate to verify whether current converter is applicable to providedItemModel.- Specified by:
getConstrainedByin interfaceItemRollbackConverter- Returns:
- the
Predicate.
-
setConstrainedBy
public void setConstrainedBy(java.util.function.Predicate<ItemModel> constrainedBy)
-
-