Class DefaultCMSVersionService
- java.lang.Object
-
- de.hybris.platform.cms2.version.service.impl.DefaultCMSVersionService
-
- All Implemented Interfaces:
CMSVersionService
public class DefaultCMSVersionService extends java.lang.Object implements CMSVersionService
Default implementation of theCMSVersionService
-
-
Constructor Summary
Constructors Constructor Description DefaultCMSVersionService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
belongsToPage(CMSItemModel itemModel)
Determines if the item is a content slot defined for the page (ContentSlotForPage relation) or the page template (ContentSlotForTemplate relation).protected void
checkChangeTypePermission(java.lang.String typeCode)
Checks whether current user has CHANGE type permission for typeCode;protected void
checkCreateTypePermission(java.lang.String typeCode)
Checks whether current user has CREATE type permission for typeCode;protected void
checkReadTypePermission(java.lang.String typeCode)
Checks whether current user has READ type permission for typeCode;protected void
checkRemoveTypePermission(java.lang.String typeCode)
Checks whether current user has REMOVE type permission for typeCode;ItemModel
createItemFromVersion(CMSVersionModel version)
Creates a newItemModel
and populates the item model using the data saved in theCMSVersionModel
.protected CMSVersionModel
createPartialVersionForItem(CMSItemModel itemModel)
Generates a partial version for ItemModel.CMSVersionModel
createRevisionForItem(CMSItemModel itemModel)
Creates a revision for the given item and updates its payload.CMSVersionModel
createVersionForItem(CMSItemModel itemModel, java.lang.String label, java.lang.String description)
Creates a version for the given item and updates its payload.void
deleteVersionsForItem(CMSItemModel itemModel)
Deletes all tagged versions for aCMSItemModel
.java.util.Optional<AbstractPageModel>
findPageVersionedByTransactionId(java.lang.String transactionId)
Finds the page associated to a transaction ID.protected java.lang.String
generatePayloadForVersion(CMSVersionModel version)
Generates a payload for a version.protected java.lang.String
generateTransactionId()
Generates transaction id using transactionIdGenerator.java.lang.String
generateVersionUid()
Generates version uid using versionUidGenerator.CMSAdminContentSlotService
getCmsAdminContentSlotService()
protected CMSAdminItemService
getCmsAdminItemService()
protected CMSAdminSiteService
getCmsAdminSiteService()
protected CMSItemModel
getCMSItemByVersion(CMSVersionModel version)
SessionSearchRestrictionsDisabler
getCmsSessionSearchRestrictionsDisabler()
protected CMSVersionDao
getCmsVersionDao()
protected CMSVersionSessionContextProvider
getCmsVersionSessionContextProvider()
protected Converter<ItemModel,java.lang.String>
getCmsVersionToDataConverter()
protected Converter<CMSVersionModel,ItemModel>
getCmsVersionToModelPreviewConverter()
Converter<CMSVersionModel,ItemModel>
getCmsVersionToModelRollbackConverter()
protected java.util.function.Predicate<ItemModel>
getContentPageTypePredicate()
ItemModel
getItemFromVersion(CMSVersionModel version)
Retrieves an existingItemModel
and populates the item model using the data saved in theCMSVersionModel
.protected ModelService
getModelService()
protected java.util.function.Predicate<ItemModel>
getPageTypePredicate()
protected PermissionCRUDService
getPermissionCRUDService()
protected SessionService
getSessionService()
java.lang.String
getTransactionId()
Returns the version ID stored in the session attributeSessionService
Cms2Constants.SESSION_VERSION_TRANSACTION_ID
.protected PersistentKeyGenerator
getTransactionIdGenerator()
protected TypeService
getTypeService()
java.util.Optional<CMSVersionModel>
getVersionByLabel(CMSItemModel itemModel, java.lang.String label)
Finds the {code CMSVersionModel} containing the provided label for a given item.java.util.Optional<CMSVersionModel>
getVersionByUid(java.lang.String uid)
Finds the {code CMSVersionModel} by uid.protected java.util.List<CMSVersionModel>
getVersionsForItem(CMSItemModel itemModel)
Finds allCMSVersionModel
versions for a givenCMSItemModel
protected PersistentKeyGenerator
getVersionUidGenerator()
protected boolean
isInActiveSessionCatalog(CMSItemModel itemModel)
Determines if the item is defined in the current (active session) catalog version or in a parent catalog (multi-country).protected boolean
isPreview()
protected boolean
isTaggedVersion(CMSVersionModel cmsVersionModel)
Determines if the cms version is taggedboolean
isVersionable(CMSItemModel itemModel)
Determines if an itemModel is versionableprotected void
restoreHomepageAttribute(ItemModel itemModel)
Restore homepage attribute for Content pages to use the value from the original page.java.util.Optional<ItemModel>
rollbackVersionForUid(java.lang.String uid)
Rolls back anItemModel
to a specific version.void
setCmsAdminContentSlotService(CMSAdminContentSlotService cmsAdminContentSlotService)
void
setCmsAdminItemService(CMSAdminItemService cmsAdminItemService)
void
setCmsAdminSiteService(CMSAdminSiteService cmsAdminSiteService)
void
setCmsSessionSearchRestrictionsDisabler(SessionSearchRestrictionsDisabler cmsSessionSearchRestrictionsDisabler)
void
setCmsVersionDao(CMSVersionDao cmsVersionDao)
void
setCmsVersionSessionContextProvider(CMSVersionSessionContextProvider cmsVersionSessionContextProvider)
void
setCmsVersionToDataConverter(Converter<ItemModel,java.lang.String> cmsVersionToDataConverter)
void
setCmsVersionToModelPreviewConverter(Converter<CMSVersionModel,ItemModel> cmsVersionToModelPreviewConverter)
void
setCmsVersionToModelRollbackConverter(Converter<CMSVersionModel,ItemModel> cmsVersionToModelRollbackConverter)
void
setContentPageTypePredicate(java.util.function.Predicate<ItemModel> contentPageTypePredicate)
void
setModelService(ModelService modelService)
void
setPageTypePredicate(java.util.function.Predicate<ItemModel> pageTypePredicate)
void
setPermissionCRUDService(PermissionCRUDService permissionCRUDService)
void
setSessionService(SessionService sessionService)
void
setTransactionIdGenerator(PersistentKeyGenerator transactionIdGenerator)
void
setTypeService(TypeService typeService)
void
setVersionUidGenerator(PersistentKeyGenerator versionUidGenerator)
protected void
throwTypePermissionException(java.lang.String permissionName, java.lang.String typeCode)
ThrowsTypePermissionException
if current user does not have permission for typeCode.protected void
updatePageApprovalStatus(ItemModel itemModel)
Updates the approval status attribute for any pages toCHECK
, to indicate that the page was modified.
-
-
-
Method Detail
-
generatePayloadForVersion
protected java.lang.String generatePayloadForVersion(CMSVersionModel version)
Generates a payload for a version.- Parameters:
version
- The CMSVersion model.- Returns:
- The payload for a version.
-
createItemFromVersion
public ItemModel createItemFromVersion(CMSVersionModel version)
Creates a newItemModel
and populates the item model using the data saved in theCMSVersionModel
.
Primary key field values will be created on saving theItemModel
to the persistence store, including anyItemModel
's that are in relationship with the targetItemModel
.- Specified by:
createItemFromVersion
in interfaceCMSVersionService
- Parameters:
version
- The version used to create anItemModel
- Returns:
- The new
ItemModel
created from the version payload
-
getItemFromVersion
public ItemModel getItemFromVersion(CMSVersionModel version)
Retrieves an existingItemModel
and populates the item model using the data saved in theCMSVersionModel
.
Primary keys will be preserved for the retrievedItemModel
and anyItemModel
's that are in relationship with the target.- Specified by:
getItemFromVersion
in interfaceCMSVersionService
- Parameters:
version
- The version used to retrieve anItemModel
- Returns:
- The existing
ItemModel
updated with the data from the version payload
-
getVersionByUid
public java.util.Optional<CMSVersionModel> getVersionByUid(java.lang.String uid)
Description copied from interface:CMSVersionService
Finds the {code CMSVersionModel} by uid.- Specified by:
getVersionByUid
in interfaceCMSVersionService
- Parameters:
uid
- The uid of the CMSVersion model- Returns:
- The CMSVersion model; can be
Optional#empty()
-
getVersionByLabel
public java.util.Optional<CMSVersionModel> getVersionByLabel(CMSItemModel itemModel, java.lang.String label)
Description copied from interface:CMSVersionService
Finds the {code CMSVersionModel} containing the provided label for a given item.- Specified by:
getVersionByLabel
in interfaceCMSVersionService
- Parameters:
itemModel
- the item model containing all the versions to search inlabel
- the label on the cms version to search for- Returns:
- The CMSVersion model; can be
Optional#empty()
-
getVersionsForItem
protected java.util.List<CMSVersionModel> getVersionsForItem(CMSItemModel itemModel)
Finds allCMSVersionModel
versions for a givenCMSItemModel
- Parameters:
itemModel
- the item model for which to return all versions- Returns:
- A List of
CMSVersionModel
-
getTransactionId
public java.lang.String getTransactionId()
Description copied from interface:CMSVersionService
Returns the version ID stored in the session attributeSessionService
Cms2Constants.SESSION_VERSION_TRANSACTION_ID
.- Specified by:
getTransactionId
in interfaceCMSVersionService
- Returns:
- The Version ID.
-
createRevisionForItem
public CMSVersionModel createRevisionForItem(CMSItemModel itemModel)
Description copied from interface:CMSVersionService
Creates a revision for the given item and updates its payload.Note that a "revision" is a
CMSVersionModel
without a label.- Specified by:
createRevisionForItem
in interfaceCMSVersionService
- Parameters:
itemModel
- The item model for versioning.- Returns:
- The CMSVersion model.
-
createVersionForItem
public CMSVersionModel createVersionForItem(CMSItemModel itemModel, java.lang.String label, java.lang.String description)
Description copied from interface:CMSVersionService
Creates a version for the given item and updates its payload.Note that a "version" is a
CMSVersionModel
with an existing label.- Specified by:
createVersionForItem
in interfaceCMSVersionService
- Parameters:
itemModel
- The item model for versioning.label
- The label for the versiondescription
- The description for the version- Returns:
- The CMSVersion model.
-
rollbackVersionForUid
public java.util.Optional<ItemModel> rollbackVersionForUid(java.lang.String uid)
Description copied from interface:CMSVersionService
Rolls back anItemModel
to a specific version. If no version is found, anOptional#empty()
is returned.- Specified by:
rollbackVersionForUid
in interfaceCMSVersionService
- Parameters:
uid
- The uid of theCMSVersionModel
which theItemModel
will be rolled back to- Returns:
- an
Optional
containing the updatedItemModel
after it was rolled back; can beOptional#empty()
when no version is found to perform the rollback operation.
-
isPreview
protected boolean isPreview()
-
restoreHomepageAttribute
protected void restoreHomepageAttribute(ItemModel itemModel)
Restore homepage attribute for Content pages to use the value from the original page.- Parameters:
itemModel
- the item model.
-
updatePageApprovalStatus
protected void updatePageApprovalStatus(ItemModel itemModel)
Updates the approval status attribute for any pages toCHECK
, to indicate that the page was modified.- Parameters:
itemModel
- the item model.
-
createPartialVersionForItem
protected CMSVersionModel createPartialVersionForItem(CMSItemModel itemModel)
Generates a partial version for ItemModel. Note: A version entry is considered as partially field when the payload attribute is not populated.- Parameters:
itemModel
- The item model for versioning.- Returns:
- The partially filled CMSVersion model.
-
generateVersionUid
public java.lang.String generateVersionUid()
Generates version uid using versionUidGenerator.- Specified by:
generateVersionUid
in interfaceCMSVersionService
- Returns:
- The uid of the version.
-
isVersionable
public boolean isVersionable(CMSItemModel itemModel)
Determines if an itemModel is versionable An item is versionable when:- ItemModel is a CMSItemModel
- CMSItemModel is in the currently active CatalogVersion
- CMSItemModel is not a shared content slot
- Specified by:
isVersionable
in interfaceCMSVersionService
- Parameters:
itemModel
- The item model.- Returns:
- TRUE if the item is versionable; FALSE otherwise.
-
deleteVersionsForItem
public void deleteVersionsForItem(CMSItemModel itemModel)
Description copied from interface:CMSVersionService
Deletes all tagged versions for aCMSItemModel
. Does not delete orphaned aggregated types linked to the item by relations. They will be deleted by garbage collection if enabled.- Specified by:
deleteVersionsForItem
in interfaceCMSVersionService
- Parameters:
itemModel
- the item model for which all related tagged versions will be deleted
-
findPageVersionedByTransactionId
public java.util.Optional<AbstractPageModel> findPageVersionedByTransactionId(java.lang.String transactionId)
Description copied from interface:CMSVersionService
Finds the page associated to a transaction ID.When a page is versioned, the page and all its associated items are versioned. Each of them has a different version, but they all share the same transactionId; only one page can be associated to a transaction ID.
- Specified by:
findPageVersionedByTransactionId
in interfaceCMSVersionService
- Parameters:
transactionId
- The ID of the transaction for which to find its associated page.- Returns:
- an
Optional
containing the page associated to the given transactionId; can beOptional#empty()
when the transactionId identifies a transaction where a page was not versioned.
-
isTaggedVersion
protected boolean isTaggedVersion(CMSVersionModel cmsVersionModel)
Determines if the cms version is tagged- Parameters:
cmsVersionModel
- the cms version- Returns:
- true if the cms version has a valid label
-
isInActiveSessionCatalog
protected boolean isInActiveSessionCatalog(CMSItemModel itemModel)
Determines if the item is defined in the current (active session) catalog version or in a parent catalog (multi-country).- Parameters:
itemModel
- the item to be evaluated- Returns:
- TRUE when the item is defined in the active catalog version; FALSE otherwise.
-
belongsToPage
protected boolean belongsToPage(CMSItemModel itemModel)
Determines if the item is a content slot defined for the page (ContentSlotForPage relation) or the page template (ContentSlotForTemplate relation).- Parameters:
itemModel
- the item to be evaluated- Returns:
- TRUE when the item is defined for the page; FALSE otherwise.
-
generateTransactionId
protected java.lang.String generateTransactionId()
Generates transaction id using transactionIdGenerator.
-
getCMSItemByVersion
protected CMSItemModel getCMSItemByVersion(CMSVersionModel version)
-
checkReadTypePermission
protected void checkReadTypePermission(java.lang.String typeCode)
Checks whether current user has READ type permission for typeCode;- Parameters:
typeCode
- the type code
-
checkCreateTypePermission
protected void checkCreateTypePermission(java.lang.String typeCode)
Checks whether current user has CREATE type permission for typeCode;- Parameters:
typeCode
- the type code
-
checkRemoveTypePermission
protected void checkRemoveTypePermission(java.lang.String typeCode)
Checks whether current user has REMOVE type permission for typeCode;- Parameters:
typeCode
- the type code
-
checkChangeTypePermission
protected void checkChangeTypePermission(java.lang.String typeCode)
Checks whether current user has CHANGE type permission for typeCode;- Parameters:
typeCode
- the type code
-
throwTypePermissionException
protected void throwTypePermissionException(java.lang.String permissionName, java.lang.String typeCode)
ThrowsTypePermissionException
if current user does not have permission for typeCode.- Parameters:
permissionName
-typeCode
-
-
getVersionUidGenerator
protected PersistentKeyGenerator getVersionUidGenerator()
-
setVersionUidGenerator
public void setVersionUidGenerator(PersistentKeyGenerator versionUidGenerator)
-
getTransactionIdGenerator
protected PersistentKeyGenerator getTransactionIdGenerator()
-
setTransactionIdGenerator
public void setTransactionIdGenerator(PersistentKeyGenerator transactionIdGenerator)
-
getSessionService
protected SessionService getSessionService()
-
setSessionService
public void setSessionService(SessionService sessionService)
-
getModelService
protected ModelService getModelService()
-
setModelService
public void setModelService(ModelService modelService)
-
getTypeService
protected TypeService getTypeService()
-
setTypeService
public void setTypeService(TypeService typeService)
-
getCmsAdminItemService
protected CMSAdminItemService getCmsAdminItemService()
-
setCmsAdminItemService
public void setCmsAdminItemService(CMSAdminItemService cmsAdminItemService)
-
getCmsVersionDao
protected CMSVersionDao getCmsVersionDao()
-
setCmsVersionDao
public void setCmsVersionDao(CMSVersionDao cmsVersionDao)
-
getCmsAdminContentSlotService
public CMSAdminContentSlotService getCmsAdminContentSlotService()
-
setCmsAdminContentSlotService
public void setCmsAdminContentSlotService(CMSAdminContentSlotService cmsAdminContentSlotService)
-
getCmsAdminSiteService
protected CMSAdminSiteService getCmsAdminSiteService()
-
setCmsAdminSiteService
public void setCmsAdminSiteService(CMSAdminSiteService cmsAdminSiteService)
-
getCmsVersionToDataConverter
protected Converter<ItemModel,java.lang.String> getCmsVersionToDataConverter()
-
setCmsVersionToDataConverter
public void setCmsVersionToDataConverter(Converter<ItemModel,java.lang.String> cmsVersionToDataConverter)
-
getCmsVersionToModelPreviewConverter
protected Converter<CMSVersionModel,ItemModel> getCmsVersionToModelPreviewConverter()
-
setCmsVersionToModelPreviewConverter
public void setCmsVersionToModelPreviewConverter(Converter<CMSVersionModel,ItemModel> cmsVersionToModelPreviewConverter)
-
getCmsVersionSessionContextProvider
protected CMSVersionSessionContextProvider getCmsVersionSessionContextProvider()
-
setCmsVersionSessionContextProvider
public void setCmsVersionSessionContextProvider(CMSVersionSessionContextProvider cmsVersionSessionContextProvider)
-
getCmsSessionSearchRestrictionsDisabler
public SessionSearchRestrictionsDisabler getCmsSessionSearchRestrictionsDisabler()
-
setCmsSessionSearchRestrictionsDisabler
public void setCmsSessionSearchRestrictionsDisabler(SessionSearchRestrictionsDisabler cmsSessionSearchRestrictionsDisabler)
-
getCmsVersionToModelRollbackConverter
public Converter<CMSVersionModel,ItemModel> getCmsVersionToModelRollbackConverter()
-
setCmsVersionToModelRollbackConverter
public void setCmsVersionToModelRollbackConverter(Converter<CMSVersionModel,ItemModel> cmsVersionToModelRollbackConverter)
-
getPermissionCRUDService
protected PermissionCRUDService getPermissionCRUDService()
-
setPermissionCRUDService
public void setPermissionCRUDService(PermissionCRUDService permissionCRUDService)
-
getPageTypePredicate
protected java.util.function.Predicate<ItemModel> getPageTypePredicate()
-
setPageTypePredicate
public void setPageTypePredicate(java.util.function.Predicate<ItemModel> pageTypePredicate)
-
getContentPageTypePredicate
protected java.util.function.Predicate<ItemModel> getContentPageTypePredicate()
-
setContentPageTypePredicate
public void setContentPageTypePredicate(java.util.function.Predicate<ItemModel> contentPageTypePredicate)
-
-