Class DefaultSynchronizationFacade
- java.lang.Object
-
- com.hybris.backoffice.sync.facades.DefaultSynchronizationFacade
-
- All Implemented Interfaces:
SynchronizationFacade
public class DefaultSynchronizationFacade extends java.lang.Object implements SynchronizationFacade
Default implementation using theCatalogSynchronizationService. The synchronizations are done asynchronously using a background process (cron job).
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringBACKOFFICE_SYNC_CONFIG_ABORT_ON_COLLIDINGprotected static java.lang.StringSYNC_CONFIG_CREATE_SAVED_VALUESprotected static java.lang.StringSYNC_CONFIG_ERROR_MODEprotected static java.lang.StringSYNC_CONFIG_FORCE_UPDATEprotected static java.lang.StringSYNC_CONFIG_KEEP_CRON_JOBprotected static java.lang.StringSYNC_CONFIG_LOG_LEVEL_DATABASEprotected static java.lang.StringSYNC_CONFIG_LOG_LEVEL_FILEprotected static java.lang.StringSYNC_CONFIG_LOG_TO_DATABASEprotected static java.lang.StringSYNC_CONFIG_LOG_TO_FILEprotected static java.lang.StringSYNC_CONFIG_SYNCHRONOUS
-
Constructor Summary
Constructors Constructor Description DefaultSynchronizationFacade()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanSync(SyncItemJobModel sync)Tells whether current user can perform given sync.protected java.util.List<ItemModel>collectRelatedItems(java.util.List<ItemModel> items, java.util.Map<java.lang.String,java.lang.Object> ctxMap)protected voidcopyCronJobData(CatalogVersionSyncCronJobModel newCronJob, CatalogVersionSyncCronJobModel cronJobForRerun)protected CatalogVersionSyncCronJobModelcopyCronJobSafely(java.util.function.Supplier<CatalogVersionSyncCronJobModel> copySupplier)protected voidcopyScheduledMedia(CatalogVersionSyncCronJobModel newCronJob, CatalogVersionSyncCronJobModel cronJobForRerun)protected CatalogVersionSyncCronJobModelcreateCronJobForRerun(CatalogVersionSyncCronJobModel cronJobForRerun)protected SyncConfigcreateSyncConfigWithDefaults(SyncItemJobModel syncJob)Creates sync config based on project properties and syncJob settings.protected <T> TexecuteInTransaction(java.util.function.Supplier<T> toExecute)protected java.util.Optional<java.lang.String>executeSync(SyncTask syncTask, java.util.function.BiFunction<SyncItemJobModel,SyncConfig,SyncResult> syncRunner)protected <T> TexecuteWithoutTypeInterceptors(java.util.function.Supplier<T> toExecute)java.util.Optional<ItemModel>findSyncCounterpart(ItemModel item, SyncItemJobModel syncItemJob)Finds a counterpart of given item in respective catalog version defined by the syncItemJob.protected java.lang.BooleangetBooleanFromSystemConfig(java.lang.String property, java.lang.Boolean defaultValue)CatalogSynchronizationServicegetCatalogSynchronizationService()CatalogTypeServicegetCatalogTypeService()java.util.List<ItemModel>getCatalogVersionAwareItems(java.util.List<? extends ItemModel> items)Extract catalog version aware itemsCatalogTypeService.isCatalogVersionAwareModel(ItemModel)CatalogVersionServicegetCatalogVersionService()protected java.lang.StringgetConfigValue(java.lang.String property, java.lang.String defaultValue)CronJobServicegetCronJobService()protected java.util.Map<java.lang.String,java.lang.Object>getCtxWithMaxRecursionDepth(java.util.Map<java.lang.String,java.lang.Object> ctx)protected <T extends java.lang.Enum>
TgetEnumValueFromSystemConfig(java.lang.Class<T> enumType, java.lang.String property, T defaultValue)java.util.List<SyncItemJobModel>getInboundSynchronizations(CatalogVersionModel catalogVersion)Gets inbound sync jobs for given catalog version.java.util.List<CatalogVersionModel>getItemsCatalogVersions(java.util.List<? extends ItemModel> items)Extracts from given list items which are CatalogVersionMediaServicegetMediaService()ModelServicegetModelService()java.util.List<SyncItemJobModel>getOutboundSynchronizations(CatalogVersionModel catalogVersion)Gets outbound sync jobs for given catalog version.java.util.Optional<PartialSyncInfo>getPartialSyncStatusInfo(ItemModel itemModel, SyncItemStatus status, java.util.Map<java.lang.String,java.lang.Object> ctxMap)ChecksItemModel's status in all available synchronizations.RelatedItemsCollectorgetRelatedItemsCollector()SessionServicegetSessionService()java.util.Optional<CatalogVersionModel>getSyncCatalogVersion(java.util.Collection<ItemModel> items)Returns catalog version for given items if they are from the same catalog version or are CatalogVersion itself.protected java.util.List<SyncItemJobModel>getSynchronizations(CatalogVersionModel syncCatalogVersion)SynchronizationStatusServicegetSynchronizationStatusService()protected SyncJobApplicableTypesStrategygetSyncJobApplicableTypesStrategy()UserServicegetUserService()booleanisApplicableForItems(SyncItemJobModel jobModel, java.util.Collection<ItemModel> items)Checks ifSyncItemJobModelis applicable forItemModelsprotected java.util.Optional<java.lang.Boolean>isInSync(ItemModel syncItem)protected java.util.Optional<java.lang.Boolean>isInSync(ItemModel syncItem, java.util.Collection<SyncItemJobModel> syncJobs)java.util.Optional<java.lang.Boolean>isInSync(ItemModel itemModel, java.util.Map<java.lang.String,java.lang.Object> ctxMap)ChecksItemModel's status in all available synchronizations.java.util.Optional<java.lang.Boolean>isInSync(java.util.List<ItemModel> itemModels, SyncItemJobModel jobModel, java.util.Map<java.lang.String,java.lang.Object> ctxMap)Checks if allItemModels are sync according to source and target fromSyncItemJobModel.booleanisSyncInProgress(ItemModel item)Tells if given item is being synchronized.protected java.util.Optional<java.lang.Boolean>matchesSyncStatus(java.util.List<ItemModel> syncItems, java.util.List<SyncItemJobModel> allJobs, SyncItemStatus inSync)protected java.util.Optional<java.lang.String>performCatalogSync(SyncTask syncTask)java.util.Optional<java.lang.String>performSynchronization(SyncTask syncTask)Performs synchronization based on given sync task.protected java.util.Optional<java.lang.String>preformItemsSync(SyncTask syncTask)protected SyncConfigprepareSyncConfig(SyncConfig syncConfig, SyncItemJobModel syncJob)Prepares sync config.voidreRunCronJob(CatalogVersionSyncCronJobModel cronJob)Runs given sync cron job again omitting items already processed in the previous run.voidsetCatalogSynchronizationService(CatalogSynchronizationService catalogSynchronizationService)voidsetCatalogTypeService(CatalogTypeService catalogTypeService)voidsetCatalogVersionService(CatalogVersionService catalogVersionService)voidsetCronJobService(CronJobService cronJobService)voidsetMediaService(MediaService mediaService)voidsetModelService(ModelService modelService)voidsetRelatedItemsCollector(RelatedItemsCollector relatedItemsCollector)voidsetSessionService(SessionService sessionService)voidsetSynchronizationStatusService(SynchronizationStatusService synchronizationStatusService)voidsetSyncJobApplicableTypesStrategy(SyncJobApplicableTypesStrategy syncJobApplicableTypesStrategy)voidsetUserService(UserService userService)
-
-
-
Field Detail
-
SYNC_CONFIG_CREATE_SAVED_VALUES
protected static final java.lang.String SYNC_CONFIG_CREATE_SAVED_VALUES
- See Also:
- Constant Field Values
-
SYNC_CONFIG_FORCE_UPDATE
protected static final java.lang.String SYNC_CONFIG_FORCE_UPDATE
- See Also:
- Constant Field Values
-
SYNC_CONFIG_SYNCHRONOUS
protected static final java.lang.String SYNC_CONFIG_SYNCHRONOUS
- See Also:
- Constant Field Values
-
SYNC_CONFIG_LOG_TO_FILE
protected static final java.lang.String SYNC_CONFIG_LOG_TO_FILE
- See Also:
- Constant Field Values
-
SYNC_CONFIG_LOG_TO_DATABASE
protected static final java.lang.String SYNC_CONFIG_LOG_TO_DATABASE
- See Also:
- Constant Field Values
-
SYNC_CONFIG_KEEP_CRON_JOB
protected static final java.lang.String SYNC_CONFIG_KEEP_CRON_JOB
- See Also:
- Constant Field Values
-
SYNC_CONFIG_LOG_LEVEL_DATABASE
protected static final java.lang.String SYNC_CONFIG_LOG_LEVEL_DATABASE
- See Also:
- Constant Field Values
-
SYNC_CONFIG_LOG_LEVEL_FILE
protected static final java.lang.String SYNC_CONFIG_LOG_LEVEL_FILE
- See Also:
- Constant Field Values
-
SYNC_CONFIG_ERROR_MODE
protected static final java.lang.String SYNC_CONFIG_ERROR_MODE
- See Also:
- Constant Field Values
-
BACKOFFICE_SYNC_CONFIG_ABORT_ON_COLLIDING
protected static final java.lang.String BACKOFFICE_SYNC_CONFIG_ABORT_ON_COLLIDING
- See Also:
- Constant Field Values
-
-
Method Detail
-
performSynchronization
public java.util.Optional<java.lang.String> performSynchronization(SyncTask syncTask)
Description copied from interface:SynchronizationFacadePerforms synchronization based on given sync task.- Specified by:
performSynchronizationin interfaceSynchronizationFacade- Parameters:
syncTask- - defines sync jobs and items to sync.- Returns:
- executed sync cron job code
CronJobModel.getCode()if sync has been started.
-
performCatalogSync
protected java.util.Optional<java.lang.String> performCatalogSync(SyncTask syncTask)
-
preformItemsSync
protected java.util.Optional<java.lang.String> preformItemsSync(SyncTask syncTask)
-
executeSync
protected java.util.Optional<java.lang.String> executeSync(SyncTask syncTask, java.util.function.BiFunction<SyncItemJobModel,SyncConfig,SyncResult> syncRunner)
-
getItemsCatalogVersions
public java.util.List<CatalogVersionModel> getItemsCatalogVersions(java.util.List<? extends ItemModel> items)
Description copied from interface:SynchronizationFacadeExtracts from given list items which are CatalogVersion- Specified by:
getItemsCatalogVersionsin interfaceSynchronizationFacade- Parameters:
items- list of items- Returns:
- list of catalog version items
-
getCatalogVersionAwareItems
public java.util.List<ItemModel> getCatalogVersionAwareItems(java.util.List<? extends ItemModel> items)
Description copied from interface:SynchronizationFacadeExtract catalog version aware itemsCatalogTypeService.isCatalogVersionAwareModel(ItemModel)- Specified by:
getCatalogVersionAwareItemsin interfaceSynchronizationFacade- Parameters:
items- list of items- Returns:
- list of catalog version aware items
-
getSynchronizations
protected java.util.List<SyncItemJobModel> getSynchronizations(CatalogVersionModel syncCatalogVersion)
-
getInboundSynchronizations
public java.util.List<SyncItemJobModel> getInboundSynchronizations(CatalogVersionModel catalogVersion)
Description copied from interface:SynchronizationFacadeGets inbound sync jobs for given catalog version.- Specified by:
getInboundSynchronizationsin interfaceSynchronizationFacade- Parameters:
catalogVersion- - catalog version for which outbound synchronizations will be returned. To obtain catalog version please useSynchronizationFacade.getSyncCatalogVersion(Collection)- Returns:
- list of sync jobs
-
getOutboundSynchronizations
public java.util.List<SyncItemJobModel> getOutboundSynchronizations(CatalogVersionModel catalogVersion)
Description copied from interface:SynchronizationFacadeGets outbound sync jobs for given catalog version.- Specified by:
getOutboundSynchronizationsin interfaceSynchronizationFacade- Parameters:
catalogVersion- - catalog version for which outbound synchronizations will be returned. To obtain catalog version please useSynchronizationFacade.getSyncCatalogVersion(Collection)- Returns:
- list of sync jobs
-
getSyncCatalogVersion
public java.util.Optional<CatalogVersionModel> getSyncCatalogVersion(java.util.Collection<ItemModel> items)
Description copied from interface:SynchronizationFacadeReturns catalog version for given items if they are from the same catalog version or are CatalogVersion itself.- Specified by:
getSyncCatalogVersionin interfaceSynchronizationFacade- Parameters:
items- items for which catalog version will be extracted.- Returns:
- catalog version for given items.
-
isInSync
public java.util.Optional<java.lang.Boolean> isInSync(java.util.List<ItemModel> itemModels, SyncItemJobModel jobModel, java.util.Map<java.lang.String,java.lang.Object> ctxMap)
Description copied from interface:SynchronizationFacadeChecks if allItemModels are sync according to source and target fromSyncItemJobModel.- Specified by:
isInSyncin interfaceSynchronizationFacade- Parameters:
itemModels- defines items for which sync status is checkedjobModel- defines sync item job model from which source and target is taken to perform status checkctxMap- defines additional context- Returns:
- true if all itemModels are in sync
-
isInSync
public java.util.Optional<java.lang.Boolean> isInSync(ItemModel itemModel, java.util.Map<java.lang.String,java.lang.Object> ctxMap)
Description copied from interface:SynchronizationFacadeChecksItemModel's status in all available synchronizations.- Specified by:
isInSyncin interfaceSynchronizationFacade- Parameters:
itemModel- defines item for which sync status is checkedctxMap- defines additional context- Returns:
- true if all itemModel are in sync, Optional.empty if sync status is not available e.g. item is not catalog version aware
-
isInSync
protected java.util.Optional<java.lang.Boolean> isInSync(ItemModel syncItem)
-
isInSync
protected java.util.Optional<java.lang.Boolean> isInSync(ItemModel syncItem, java.util.Collection<SyncItemJobModel> syncJobs)
-
matchesSyncStatus
protected java.util.Optional<java.lang.Boolean> matchesSyncStatus(java.util.List<ItemModel> syncItems, java.util.List<SyncItemJobModel> allJobs, SyncItemStatus inSync)
-
isApplicableForItems
public boolean isApplicableForItems(SyncItemJobModel jobModel, java.util.Collection<ItemModel> items)
Description copied from interface:SynchronizationFacadeChecks ifSyncItemJobModelis applicable forItemModels- Specified by:
isApplicableForItemsin interfaceSynchronizationFacade- Parameters:
jobModel- define sync job which will be checked if is applicable for itemsitems- defines items for which sync job is checked- Returns:
- true if sync job is applicable for items, false if it is not applicable
-
isSyncInProgress
public boolean isSyncInProgress(ItemModel item)
Description copied from interface:SynchronizationFacadeTells if given item is being synchronized.- Specified by:
isSyncInProgressin interfaceSynchronizationFacade- Parameters:
item- item to check- Returns:
- true if item is being synchronized.
-
reRunCronJob
public void reRunCronJob(CatalogVersionSyncCronJobModel cronJob)
Description copied from interface:SynchronizationFacadeRuns given sync cron job again omitting items already processed in the previous run.- Specified by:
reRunCronJobin interfaceSynchronizationFacade- Parameters:
cronJob- sync cron job to rerun.
-
copyCronJobSafely
protected CatalogVersionSyncCronJobModel copyCronJobSafely(java.util.function.Supplier<CatalogVersionSyncCronJobModel> copySupplier)
-
executeInTransaction
protected <T> T executeInTransaction(java.util.function.Supplier<T> toExecute)
-
executeWithoutTypeInterceptors
protected <T> T executeWithoutTypeInterceptors(java.util.function.Supplier<T> toExecute)
-
createCronJobForRerun
protected CatalogVersionSyncCronJobModel createCronJobForRerun(CatalogVersionSyncCronJobModel cronJobForRerun)
-
copyCronJobData
protected void copyCronJobData(CatalogVersionSyncCronJobModel newCronJob, CatalogVersionSyncCronJobModel cronJobForRerun)
-
copyScheduledMedia
protected void copyScheduledMedia(CatalogVersionSyncCronJobModel newCronJob, CatalogVersionSyncCronJobModel cronJobForRerun)
-
getPartialSyncStatusInfo
public java.util.Optional<PartialSyncInfo> getPartialSyncStatusInfo(ItemModel itemModel, SyncItemStatus status, java.util.Map<java.lang.String,java.lang.Object> ctxMap)
Description copied from interface:SynchronizationFacadeChecksItemModel's status in all available synchronizations.- Specified by:
getPartialSyncStatusInfoin interfaceSynchronizationFacade- Parameters:
itemModel- defines item for which sync status is checkedstatus- defines target status for partial sync infoPartialSyncInfoctxMap- defines additional context- Returns:
- partial sync information if item is catalog version aware.
-
findSyncCounterpart
public java.util.Optional<ItemModel> findSyncCounterpart(ItemModel item, SyncItemJobModel syncItemJob)
Description copied from interface:SynchronizationFacadeFinds a counterpart of given item in respective catalog version defined by the syncItemJob.- Specified by:
findSyncCounterpartin interfaceSynchronizationFacade- Parameters:
item- item of which counterpart will be found.syncItemJob- synchronization job which defines source and target catalog version.- Returns:
- counterpart item if found.
-
collectRelatedItems
protected java.util.List<ItemModel> collectRelatedItems(java.util.List<ItemModel> items, java.util.Map<java.lang.String,java.lang.Object> ctxMap)
-
canSync
public boolean canSync(SyncItemJobModel sync)
Description copied from interface:SynchronizationFacadeTells whether current user can perform given sync.- Specified by:
canSyncin interfaceSynchronizationFacade- Parameters:
sync- synchronization job.- Returns:
- true if user can synchronize.
-
getCtxWithMaxRecursionDepth
protected java.util.Map<java.lang.String,java.lang.Object> getCtxWithMaxRecursionDepth(java.util.Map<java.lang.String,java.lang.Object> ctx)
-
prepareSyncConfig
protected SyncConfig prepareSyncConfig(SyncConfig syncConfig, SyncItemJobModel syncJob)
Prepares sync config. If given sync config is null then then it will be created usingcreateSyncConfigWithDefaults(SyncItemJobModel)- Parameters:
syncConfig- sync config from sync taskSyncTask.getSyncConfig();syncJob- sync job to be executed.- Returns:
- sync config
-
createSyncConfigWithDefaults
protected SyncConfig createSyncConfigWithDefaults(SyncItemJobModel syncJob)
Creates sync config based on project properties and syncJob settings. If one of the settings is not defined in project properties then default from given syncJob is taken- Parameters:
syncJob- sync job to be executed.- Returns:
- sync config with default values
-
getBooleanFromSystemConfig
protected java.lang.Boolean getBooleanFromSystemConfig(java.lang.String property, java.lang.Boolean defaultValue)
-
getEnumValueFromSystemConfig
protected <T extends java.lang.Enum> T getEnumValueFromSystemConfig(java.lang.Class<T> enumType, java.lang.String property, T defaultValue)
-
getConfigValue
protected java.lang.String getConfigValue(java.lang.String property, java.lang.String defaultValue)
-
getCatalogSynchronizationService
public CatalogSynchronizationService getCatalogSynchronizationService()
-
setCatalogSynchronizationService
public void setCatalogSynchronizationService(CatalogSynchronizationService catalogSynchronizationService)
-
getSynchronizationStatusService
public SynchronizationStatusService getSynchronizationStatusService()
-
setSynchronizationStatusService
public void setSynchronizationStatusService(SynchronizationStatusService synchronizationStatusService)
-
getSyncJobApplicableTypesStrategy
protected SyncJobApplicableTypesStrategy getSyncJobApplicableTypesStrategy()
-
setSyncJobApplicableTypesStrategy
public void setSyncJobApplicableTypesStrategy(SyncJobApplicableTypesStrategy syncJobApplicableTypesStrategy)
-
getCatalogTypeService
public CatalogTypeService getCatalogTypeService()
-
setCatalogTypeService
public void setCatalogTypeService(CatalogTypeService catalogTypeService)
-
getRelatedItemsCollector
public RelatedItemsCollector getRelatedItemsCollector()
-
setRelatedItemsCollector
public void setRelatedItemsCollector(RelatedItemsCollector relatedItemsCollector)
-
getCronJobService
public CronJobService getCronJobService()
-
setCronJobService
public void setCronJobService(CronJobService cronJobService)
-
getModelService
public ModelService getModelService()
-
setModelService
public void setModelService(ModelService modelService)
-
getMediaService
public MediaService getMediaService()
-
setMediaService
public void setMediaService(MediaService mediaService)
-
getSessionService
public SessionService getSessionService()
-
setSessionService
public void setSessionService(SessionService sessionService)
-
getCatalogVersionService
public CatalogVersionService getCatalogVersionService()
-
setCatalogVersionService
public void setCatalogVersionService(CatalogVersionService catalogVersionService)
-
getUserService
public UserService getUserService()
-
setUserService
public void setUserService(UserService userService)
-
-