Class DefaultBulkUpdateManager
- java.lang.Object
-
- com.broadleafcommerce.bulk.service.DefaultBulkUpdateManager
-
- All Implemented Interfaces:
BulkUpdateManager
public class DefaultBulkUpdateManager extends Object implements BulkUpdateManager
- Author:
- Samarth Dhruva (samarthd)
-
-
Constructor Summary
Constructors Constructor Description DefaultBulkUpdateManager(BulkUpdateService<BulkUpdate> bulkUpdateService, BulkUpdateRequestValidator bulkUpdateRequestValidator, List<BulkUpdateProcessor<?>> bulkUpdateProcessors, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator> contextRequestHydrators, com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils trackablePolicyUtils, int batchSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BulkUpdategenerateBulkUpdateFromRequest(BulkUpdateRequest request)Builds aBulkUpdateand initializes its basic fields from the values in theBulkUpdateRequest.protected intgetBatchSize()protected List<BulkUpdateProcessor<?>>getBulkUpdateProcessors()protected BulkUpdateRequestValidatorgetBulkUpdateRequestValidator()protected BulkUpdateService<BulkUpdate>getBulkUpdateService()protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator>getContextRequestHydrators()protected Optional<BulkUpdateProcessor<?>>getProcessorForUpdate(BulkUpdate bulkUpdate)protected com.broadleafcommerce.common.extension.data.DataRouteReferencegetReference()protected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtilsgetTrackablePolicyUtils()Used to validate that the user initiating an operation is able to access and mutate the context in which the operation will apply.protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected voidinitializeContextFields(BulkUpdate target, BulkUpdateRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Initializes the context-related fields on the givenBulkUpdate, including the fields describing the context where the operation itself was initiated (such asBulkUpdate.getApplicationId()), and "updating context" fields describing the context where the operation will be performed (such asBulkUpdate.getUpdatingApplicationId()).protected voidinitializeGeneralFields(BulkUpdate toInitialize)BulkUpdateinitiateBulkUpdate(BulkUpdateRequest request, String target, String filterString, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)This method accepts a bulk update request and the context of the request to build aBulkUpdateand persist it in the data store.protected booleanisSandboxBulkUpdate(BulkUpdate bulkUpdate)protected BulkUpdatenotifyOfCreateSandboxRequest(String bulkUpdateId)voidprocessBulkUpdate(BulkUpdate bulkUpdate)Performs aBulkUpdate, processing the requested records in batches and updating the status for theBulkUpdateas it goes.protected <P> voidprocessInBatches(BulkUpdateProcessor<P> processor, BulkUpdate bulkUpdate)protected voidsetTotalRecordsToProcess(BulkUpdate update)protected voidvalidateBulkUpdateRequest(BulkUpdateRequest request)Validates theBulkUpdateRequest, throwing aValidationExceptionin the event that there is a validation failure.protected voidvalidateCanPerformBulkUpdate(BulkUpdate update)protected voidvalidateUpdatingContextAccessibility(BulkUpdate update)Builds aContextInfomatching the updating context fields fromupdate, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.
-
-
-
Constructor Detail
-
DefaultBulkUpdateManager
public DefaultBulkUpdateManager(BulkUpdateService<BulkUpdate> bulkUpdateService, BulkUpdateRequestValidator bulkUpdateRequestValidator, List<BulkUpdateProcessor<?>> bulkUpdateProcessors, com.broadleafcommerce.common.extension.TypeFactory typeFactory, @Nullable com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator> contextRequestHydrators, @Nullable com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils trackablePolicyUtils, int batchSize)
-
-
Method Detail
-
initiateBulkUpdate
public BulkUpdate initiateBulkUpdate(BulkUpdateRequest request, String target, @Nullable String filterString, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:BulkUpdateManagerThis method accepts a bulk update request and the context of the request to build aBulkUpdateand persist it in the data store.Will send a
ProcessBulkUpdateRequestmessage to request that the update be processed.- Specified by:
initiateBulkUpdatein interfaceBulkUpdateManager- Parameters:
request- a request to perform aBulkUpdate.For each of the "updating context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in
BulkUpdateRequest, and if not, use the value from theContextInfo.target- the target of the bulk update. This is some value that can be mapped to a particular domain by the logic performing an update, rather than explicitly requiring the fully qualified classname. Used to populateBulkUpdate.getTarget().filterString- the filter string that should be used to find the records to update. Used to populateBulkUpdate.getFilterString().contextInfo- context information surrounding sandboxing and multitenant state. This is the context from which the operation itself is being initiated.- Returns:
- The created
BulkUpdate.
-
validateBulkUpdateRequest
protected void validateBulkUpdateRequest(BulkUpdateRequest request)
Validates theBulkUpdateRequest, throwing aValidationExceptionin the event that there is a validation failure.- Parameters:
request- the user-supplied bulk update request- Throws:
com.broadleafcommerce.common.error.validation.ValidationException- in the event that there is a validation failure
-
generateBulkUpdateFromRequest
protected BulkUpdate generateBulkUpdateFromRequest(BulkUpdateRequest request)
Builds aBulkUpdateand initializes its basic fields from the values in theBulkUpdateRequest.Note that context-related fields such as
BulkUpdate.getUpdatingApplicationId(),BulkUpdate.getUpdatingCatalogId(), etc are not initialized in this method. This responsibility belongs toinitializeContextFields(BulkUpdate, BulkUpdateRequest, ContextInfo).- Parameters:
request- the bulk update request that was received- Returns:
- an
BulkUpdateobject initialized from theBulkUpdateRequest
-
initializeGeneralFields
protected void initializeGeneralFields(BulkUpdate toInitialize)
-
initializeContextFields
protected void initializeContextFields(BulkUpdate target, BulkUpdateRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Initializes the context-related fields on the givenBulkUpdate, including the fields describing the context where the operation itself was initiated (such asBulkUpdate.getApplicationId()), and "updating context" fields describing the context where the operation will be performed (such asBulkUpdate.getUpdatingApplicationId()).For each of the "updating context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in
BulkUpdateRequest, and if not, use the value from theContextInfo.- Parameters:
target- theBulkUpdatewhose context-related fields should be initializedrequest- theBulkUpdateRequestwhich should be checked as a potential source for context fieldscontextInfo- context information surrounding sandboxing and multitenant state. This is the context from which the operation itself is being initiated.
-
setTotalRecordsToProcess
protected void setTotalRecordsToProcess(BulkUpdate update)
-
validateCanPerformBulkUpdate
protected void validateCanPerformBulkUpdate(BulkUpdate update)
-
validateUpdatingContextAccessibility
protected void validateUpdatingContextAccessibility(BulkUpdate update)
Builds aContextInfomatching the updating context fields fromupdate, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.In the event that policy validation is disabled, the
TrackablePolicyUtilsbean will be unavailable and thus this step will be skipped.- Parameters:
update- the bulk update whose updating context fields should be checked for accessibility- Throws:
com.broadleafcommerce.data.tracking.core.exception.NotVisibleException- if the updating context is not visible by the current usercom.broadleafcommerce.data.tracking.core.exception.NotMutableException- if the updating context is not mutable by the current user
-
processBulkUpdate
public void processBulkUpdate(BulkUpdate bulkUpdate)
Description copied from interface:BulkUpdateManagerPerforms aBulkUpdate, processing the requested records in batches and updating the status for theBulkUpdateas it goes.Note: this method should always be called with the result of
BulkUpdateService.setProcessingStatus(String)if the value is not null.The
BulkUpdateManagerwill delegate processing to the firstBulkUpdateProcessorfor whichBulkUpdateProcessor.canHandle(BulkUpdate)returns true. Thus if more than oneBulkUpdateProcessorcan handle a request, the bean registered with the higher priority will be used.- Specified by:
processBulkUpdatein interfaceBulkUpdateManager- Parameters:
bulkUpdate- the bulk update to perform - this should always be the result ofBulkUpdateService.setProcessingStatus(String)if it is not null
-
getProcessorForUpdate
protected Optional<BulkUpdateProcessor<?>> getProcessorForUpdate(BulkUpdate bulkUpdate)
-
isSandboxBulkUpdate
protected boolean isSandboxBulkUpdate(@NonNull BulkUpdate bulkUpdate)
-
notifyOfCreateSandboxRequest
protected BulkUpdate notifyOfCreateSandboxRequest(String bulkUpdateId)
- Parameters:
bulkUpdateId-- Returns:
-
processInBatches
protected <P> void processInBatches(BulkUpdateProcessor<P> processor, BulkUpdate bulkUpdate)
-
getBulkUpdateService
@NonNull protected BulkUpdateService<BulkUpdate> getBulkUpdateService()
-
getBulkUpdateRequestValidator
@NonNull protected BulkUpdateRequestValidator getBulkUpdateRequestValidator()
-
getBulkUpdateProcessors
@NonNull protected List<BulkUpdateProcessor<?>> getBulkUpdateProcessors()
-
getTypeFactory
@NonNull protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getReference
@Nullable protected com.broadleafcommerce.common.extension.data.DataRouteReference getReference()
-
getContextRequestHydrators
protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator> getContextRequestHydrators()
-
getTrackablePolicyUtils
@Nullable protected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils getTrackablePolicyUtils()
Used to validate that the user initiating an operation is able to access and mutate the context in which the operation will apply.If policy validation is disabled, this bean will be unavailable and policy validation will be skipped.
-
getBatchSize
protected int getBatchSize()
-
-