Class DefaultBulkUpdateService<P extends BulkUpdate>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P>
com.broadleafcommerce.bulk.service.DefaultBulkUpdateService<P>
- All Implemented Interfaces:
BulkUpdateService<P>,com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P>
public class DefaultBulkUpdateService<P extends BulkUpdate>
extends com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P>
implements BulkUpdateService<P>
- Author:
- Samarth Dhruva (samarthd)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConcept keys supplied toResourceLockRepository.lockResource(String, Class, String, String). -
Constructor Summary
ConstructorsConstructorDescriptionDefaultBulkUpdateService(BulkUpdateRepository<com.broadleafcommerce.data.tracking.core.Identifiable> repository, com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository, com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityHelper helper, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager) -
Method Summary
Modifier and TypeMethodDescription<D,R extends org.springframework.data.repository.CrudRepository<D, String> & com.broadleafcommerce.common.extension.DomainTypeAware>
POverriding to add notification behavior.protected com.broadleafcommerce.common.messaging.notification.NotificationManagerprotected BulkUpdateRepository<com.broadleafcommerce.data.tracking.core.Identifiable>protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> notifyOfCreateSandboxRequest(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId, and if the bulkUpdate is found and has aBulkUpdate.statusofBulkUpdateStatus.PROCESSING, atomically initializes itsNotificationStateforCreateSandboxRequestProducer.TYPEand renewsBulkUpdate.lastUpdated.notifyOfDeleteSandboxRequest(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId, and if the bulkUpdate is found and has aBulkUpdate.statusofBulkUpdateStatus.ERROR, atomically initializes itsNotificationStateforDeleteSandboxRequestProducer.TYPEand renewsBulkUpdate.lastUpdated.org.springframework.data.domain.Page<P>readByTargetAndApplicationId(String target, String applicationId, org.springframework.data.domain.Pageable pageable) Reads the bulk updates with the givenBulkUpdate.targetandBulkUpdate.applicationId.Reads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTEDorBulkUpdateStatus.PROCESSING) whoseBulkUpdate.lastUpdatedis before the givencutoff.readIncompleteLastUpdatedBeforeAndTenantId(Instant cutoff, String tenantId) Reads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTEDorBulkUpdateStatus.PROCESSING) whoseBulkUpdate.lastUpdatedis before the givencutoff.booleansetContainedErrors(P bulkUpdate) Atomically finds and updates the given bulk update: finds the bulk update with the ID matching the givenbulkUpdate, sets the bulk update'sBulkUpdate.errorsto the errors contained within the givenbulkUpdate, setsBulkUpdate.statustoBulkUpdateStatus.ERROR, and renewsBulkUpdate.lastUpdated.booleansetFinishedStatus(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId, and if the bulk update is found and has aBulkUpdate.statusofBulkUpdateStatus.PROCESSING, atomically sets theBulkUpdate.statustoBulkUpdateStatus.FINISHEDand renewsBulkUpdate.lastUpdatedbooleansetNumberOfRecordsProcessed(String bulkUpdateId, long numberOfRecordsProcessed) Acquires a lock on the givenbulkUpdateId, and if the bulk update is found and has aBulkUpdate.statusofBulkUpdateStatus.PROCESSING, atomically setsBulkUpdate.numberOfRecordsProcessedto the given value and renewsBulkUpdate.lastUpdated.setProcessingStatus(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId, and if it is found to have aBulkUpdate.statusofBulkUpdateStatus.REQUESTED, atomically updates theBulkUpdate.statustoBulkUpdateStatus.PROCESSINGand renewsBulkUpdate.lastUpdated.Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService
convertFromPersistentDomain, createAll, createAllAllowingPartialSuccess, delete, getHelper, readAll, readAll, readAll, readAllByIds, readById, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccessMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService
createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByIds, readById, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess
-
Constructor Details
-
DefaultBulkUpdateService
public DefaultBulkUpdateService(BulkUpdateRepository<com.broadleafcommerce.data.tracking.core.Identifiable> repository, com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?, ?> resourceLockRepository, com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityHelper helper, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager)
-
-
Method Details
-
create
public <D,R extends org.springframework.data.repository.CrudRepository<D, P createString> & com.broadleafcommerce.common.extension.DomainTypeAware> (P businessInstance) Overriding to add notification behavior.Will create the
BulkUpdateand emit anProcessBulkUpdateRequestmessage.- Specified by:
createin interfacecom.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P extends BulkUpdate>- Overrides:
createin classcom.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P extends BulkUpdate>
-
setProcessingStatus
Description copied from interface:BulkUpdateServiceAcquires a lock on the givenbulkUpdateId, and if it is found to have aBulkUpdate.statusofBulkUpdateStatus.REQUESTED, atomically updates theBulkUpdate.statustoBulkUpdateStatus.PROCESSINGand renewsBulkUpdate.lastUpdated.- Specified by:
setProcessingStatusin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
bulkUpdateId- the ID of the bulk update to find and update- Returns:
- the updated
BulkUpdateif successfully found and updated,nullotherwise
-
setContainedErrors
Description copied from interface:BulkUpdateServiceAtomically finds and updates the given bulk update: finds the bulk update with the ID matching the givenbulkUpdate, sets the bulk update'sBulkUpdate.errorsto the errors contained within the givenbulkUpdate, setsBulkUpdate.statustoBulkUpdateStatus.ERROR, and renewsBulkUpdate.lastUpdated. No other values frombulkUpdateare applied.The change is applied only if the bulk update is found to have a
BulkUpdate.statusofBulkUpdateStatus.REQUESTEDorBulkUpdateStatus.PROCESSING.- Specified by:
setContainedErrorsin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
bulkUpdate- a bulk update object containing the errors to set- Returns:
- true if the change was successfully applied, false otherwise
-
setNumberOfRecordsProcessed
Description copied from interface:BulkUpdateServiceAcquires a lock on the givenbulkUpdateId, and if the bulk update is found and has aBulkUpdate.statusofBulkUpdateStatus.PROCESSING, atomically setsBulkUpdate.numberOfRecordsProcessedto the given value and renewsBulkUpdate.lastUpdated.- Specified by:
setNumberOfRecordsProcessedin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
bulkUpdateId- the ID of the bulk update to modifynumberOfRecordsProcessed- the new value to set forBulkUpdate.numberOfRecordsProcessed- Returns:
- true if the update was successfully performed, false otherwise
-
setFinishedStatus
Description copied from interface:BulkUpdateServiceAcquires a lock on the givenbulkUpdateId, and if the bulk update is found and has aBulkUpdate.statusofBulkUpdateStatus.PROCESSING, atomically sets theBulkUpdate.statustoBulkUpdateStatus.FINISHEDand renewsBulkUpdate.lastUpdated- Specified by:
setFinishedStatusin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
bulkUpdateId- the ID of the bulk update to modify- Returns:
- true if the update was successfully performed, false otherwise
-
notifyOfCreateSandboxRequest
Description copied from interface:BulkUpdateServiceAcquires a lock on the givenbulkUpdateId, and if the bulkUpdate is found and has aBulkUpdate.statusofBulkUpdateStatus.PROCESSING, atomically initializes itsNotificationStateforCreateSandboxRequestProducer.TYPEand renewsBulkUpdate.lastUpdated.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)for theCreateSandboxRequestProducer.TYPE.- Specified by:
notifyOfCreateSandboxRequestin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
bulkUpdateId- the ID of the bulk update to modify- Returns:
- the updated
BulkUpdateif successfully found and updated,nullotherwise
-
notifyOfDeleteSandboxRequest
Description copied from interface:BulkUpdateServiceAcquires a lock on the givenbulkUpdateId, and if the bulkUpdate is found and has aBulkUpdate.statusofBulkUpdateStatus.ERROR, atomically initializes itsNotificationStateforDeleteSandboxRequestProducer.TYPEand renewsBulkUpdate.lastUpdated.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)for theDeleteSandboxRequestProducer.TYPE.- Specified by:
notifyOfDeleteSandboxRequestin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
bulkUpdateId- the ID of the bulk update to modify- Returns:
- the updated
BulkUpdateif successfully found and updated,nullotherwise
-
readByTargetAndApplicationId
public org.springframework.data.domain.Page<P> readByTargetAndApplicationId(@NonNull String target, @Nullable String applicationId, @NonNull org.springframework.data.domain.Pageable pageable) Description copied from interface:BulkUpdateServiceReads the bulk updates with the givenBulkUpdate.targetandBulkUpdate.applicationId.- Specified by:
readByTargetAndApplicationIdin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
target- theBulkUpdate.targetto filter byapplicationId- theBulkUpdate.applicationIdto filter results by. Note that if this isnull, only bulk updates withnullapplication IDs will be returned.pageable- information about which page of results to return from the database- Returns:
- the bulk updates with the given
BulkUpdate.target
-
readIncompleteLastUpdatedBefore
Description copied from interface:BulkUpdateServiceReads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTEDorBulkUpdateStatus.PROCESSING) whoseBulkUpdate.lastUpdatedis before the givencutoff.- Specified by:
readIncompleteLastUpdatedBeforein interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
cutoff- the results will be filtered to only include those updates whoseBulkUpdate.lastUpdatedis before this value- Returns:
- the bulk updates which are incomplete and have a
BulkUpdate.lastUpdatedbefore the givencutoff
-
readIncompleteLastUpdatedBeforeAndTenantId
Description copied from interface:BulkUpdateServiceReads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTEDorBulkUpdateStatus.PROCESSING) whoseBulkUpdate.lastUpdatedis before the givencutoff.- Specified by:
readIncompleteLastUpdatedBeforeAndTenantIdin interfaceBulkUpdateService<P extends BulkUpdate>- Parameters:
cutoff- the results will be filtered to only include those updates whoseBulkUpdate.lastUpdatedis before this valuetenantId- the tenant id that this bulk update operation was initiated from- Returns:
- the bulk updates which are incomplete and have a
BulkUpdate.lastUpdatedbefore the givencutoffandtenantId
-
getRepository
@NonNull protected BulkUpdateRepository<com.broadleafcommerce.data.tracking.core.Identifiable> getRepository()- Overrides:
getRepositoryin classcom.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P extends BulkUpdate>
-
getResourceLockRepository
@NonNull protected com.broadleafcommerce.common.messaging.repository.ResourceLockRepository<?,?> getResourceLockRepository() -
getNotificationManager
@NonNull protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()
-