Class ComponentRollbackConverter
java.lang.Object
de.hybris.platform.cms2.version.converter.rollback.impl.ComponentRollbackConverter
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected CMSComponentServiceprotected CMSItemCloningServiceprotected CMSPageServiceprotected CMSVersionServicePredicate to verify whether current converter is applicable to providedItemModel.protected ItemModelThis method retrieves theItemModelrepresented by the provided PK.protected ModelServiceprotected Set<ContentSlotModel>This method retrieves the content slots that directly belong to the provided page (it does not return slots coming from a template).protected TypeServicegetVersionedSlotsUids(AuditPayload componentPayload) This method retrieves the uid of the versioned slots stored in the provided payload.protected booleanisAssignableFromVersion(String itemTypeCode) This method checks if the the itemTypeCode is a super type ofCMSVersionModelOR the same type.protected booleanisPkSlotInPage(String slotPk, Set<String> slotsInPageUid) This method determines if the given pk represents one of the slots in the current page.readSlotsFromComponentPayload(AuditPayload componentPayload) This method returns a list containing the pk of each of the slots found in the given component payload.protected voidremoveSlotsOutsidePageFromPayload(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.rollbackItem(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(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.
-
Constructor Details
-
ComponentRollbackConverter
public ComponentRollbackConverter()
-
-
Method Details
-
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
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
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(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
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
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
This method retrieves theItemModelrepresented by the provided PK.- Parameters:
pk- - the pk whose item model to retrieve- Returns:
- the itemModel.
-
isAssignableFromVersion
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
-
setCmsVersionService
-
getCmsItemCloningService
-
setCmsItemCloningService
-
getCmsComponentService
-
setCmsComponentService
-
getCmsPageService
-
setCmsPageService
-
getModelService
-
setModelService
-
getTypeService
-
setTypeService
-
getConstrainedBy
Description copied from interface:ItemRollbackConverterPredicate to verify whether current converter is applicable to providedItemModel.- Specified by:
getConstrainedByin interfaceItemRollbackConverter- Returns:
- the
Predicate<ItemModel>.
-
setConstrainedBy
-