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 class
Concept 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.NotificationManager
protected 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.status
ofBulkUpdateStatus.PROCESSING
, atomically initializes itsNotificationState
forCreateSandboxRequestProducer.TYPE
and renewsBulkUpdate.lastUpdated
.notifyOfDeleteSandboxRequest
(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId
, and if the bulkUpdate is found and has aBulkUpdate.status
ofBulkUpdateStatus.ERROR
, atomically initializes itsNotificationState
forDeleteSandboxRequestProducer.TYPE
and 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.target
andBulkUpdate.applicationId
.Reads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTED
orBulkUpdateStatus.PROCESSING
) whoseBulkUpdate.lastUpdated
is before the givencutoff
.readIncompleteLastUpdatedBeforeAndTenantId
(Instant cutoff, String tenantId) Reads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTED
orBulkUpdateStatus.PROCESSING
) whoseBulkUpdate.lastUpdated
is before the givencutoff
.boolean
setContainedErrors
(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.errors
to the errors contained within the givenbulkUpdate
, setsBulkUpdate.status
toBulkUpdateStatus.ERROR
, and renewsBulkUpdate.lastUpdated
.boolean
setFinishedStatus
(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId
, and if the bulk update is found and has aBulkUpdate.status
ofBulkUpdateStatus.PROCESSING
, atomically sets theBulkUpdate.status
toBulkUpdateStatus.FINISHED
and renewsBulkUpdate.lastUpdated
boolean
setNumberOfRecordsProcessed
(String bulkUpdateId, long numberOfRecordsProcessed) Acquires a lock on the givenbulkUpdateId
, and if the bulk update is found and has aBulkUpdate.status
ofBulkUpdateStatus.PROCESSING
, atomically setsBulkUpdate.numberOfRecordsProcessed
to the given value and renewsBulkUpdate.lastUpdated
.setProcessingStatus
(String bulkUpdateId) Acquires a lock on the givenbulkUpdateId
, and if it is found to have aBulkUpdate.status
ofBulkUpdateStatus.REQUESTED
, atomically updates theBulkUpdate.status
toBulkUpdateStatus.PROCESSING
and 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, updateAllAllowingPartialSuccess
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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
BulkUpdate
and emit anProcessBulkUpdateRequest
message.- Specified by:
create
in interfacecom.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P extends BulkUpdate>
- Overrides:
create
in classcom.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P extends BulkUpdate>
-
setProcessingStatus
Description copied from interface:BulkUpdateService
Acquires a lock on the givenbulkUpdateId
, and if it is found to have aBulkUpdate.status
ofBulkUpdateStatus.REQUESTED
, atomically updates theBulkUpdate.status
toBulkUpdateStatus.PROCESSING
and renewsBulkUpdate.lastUpdated
.- Specified by:
setProcessingStatus
in interfaceBulkUpdateService<P extends BulkUpdate>
- Parameters:
bulkUpdateId
- the ID of the bulk update to find and update- Returns:
- the updated
BulkUpdate
if successfully found and updated,null
otherwise
-
setContainedErrors
Description copied from interface:BulkUpdateService
Atomically finds and updates the given bulk update: finds the bulk update with the ID matching the givenbulkUpdate
, sets the bulk update'sBulkUpdate.errors
to the errors contained within the givenbulkUpdate
, setsBulkUpdate.status
toBulkUpdateStatus.ERROR
, and renewsBulkUpdate.lastUpdated
. No other values frombulkUpdate
are applied.The change is applied only if the bulk update is found to have a
BulkUpdate.status
ofBulkUpdateStatus.REQUESTED
orBulkUpdateStatus.PROCESSING
.- Specified by:
setContainedErrors
in 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:BulkUpdateService
Acquires a lock on the givenbulkUpdateId
, and if the bulk update is found and has aBulkUpdate.status
ofBulkUpdateStatus.PROCESSING
, atomically setsBulkUpdate.numberOfRecordsProcessed
to the given value and renewsBulkUpdate.lastUpdated
.- Specified by:
setNumberOfRecordsProcessed
in 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:BulkUpdateService
Acquires a lock on the givenbulkUpdateId
, and if the bulk update is found and has aBulkUpdate.status
ofBulkUpdateStatus.PROCESSING
, atomically sets theBulkUpdate.status
toBulkUpdateStatus.FINISHED
and renewsBulkUpdate.lastUpdated
- Specified by:
setFinishedStatus
in 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:BulkUpdateService
Acquires a lock on the givenbulkUpdateId
, and if the bulkUpdate is found and has aBulkUpdate.status
ofBulkUpdateStatus.PROCESSING
, atomically initializes itsNotificationState
forCreateSandboxRequestProducer.TYPE
and renewsBulkUpdate.lastUpdated
.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)
for theCreateSandboxRequestProducer.TYPE
.- Specified by:
notifyOfCreateSandboxRequest
in interfaceBulkUpdateService<P extends BulkUpdate>
- Parameters:
bulkUpdateId
- the ID of the bulk update to modify- Returns:
- the updated
BulkUpdate
if successfully found and updated,null
otherwise
-
notifyOfDeleteSandboxRequest
Description copied from interface:BulkUpdateService
Acquires a lock on the givenbulkUpdateId
, and if the bulkUpdate is found and has aBulkUpdate.status
ofBulkUpdateStatus.ERROR
, atomically initializes itsNotificationState
forDeleteSandboxRequestProducer.TYPE
and renewsBulkUpdate.lastUpdated
.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)
for theDeleteSandboxRequestProducer.TYPE
.- Specified by:
notifyOfDeleteSandboxRequest
in interfaceBulkUpdateService<P extends BulkUpdate>
- Parameters:
bulkUpdateId
- the ID of the bulk update to modify- Returns:
- the updated
BulkUpdate
if successfully found and updated,null
otherwise
-
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:BulkUpdateService
Reads the bulk updates with the givenBulkUpdate.target
andBulkUpdate.applicationId
.- Specified by:
readByTargetAndApplicationId
in interfaceBulkUpdateService<P extends BulkUpdate>
- Parameters:
target
- theBulkUpdate.target
to filter byapplicationId
- theBulkUpdate.applicationId
to filter results by. Note that if this isnull
, only bulk updates withnull
application 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:BulkUpdateService
Reads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTED
orBulkUpdateStatus.PROCESSING
) whoseBulkUpdate.lastUpdated
is before the givencutoff
.- Specified by:
readIncompleteLastUpdatedBefore
in interfaceBulkUpdateService<P extends BulkUpdate>
- Parameters:
cutoff
- the results will be filtered to only include those updates whoseBulkUpdate.lastUpdated
is before this value- Returns:
- the bulk updates which are incomplete and have a
BulkUpdate.lastUpdated
before the givencutoff
-
readIncompleteLastUpdatedBeforeAndTenantId
Description copied from interface:BulkUpdateService
Reads the bulk updates which are incomplete (those with statusBulkUpdateStatus.REQUESTED
orBulkUpdateStatus.PROCESSING
) whoseBulkUpdate.lastUpdated
is before the givencutoff
.- Specified by:
readIncompleteLastUpdatedBeforeAndTenantId
in interfaceBulkUpdateService<P extends BulkUpdate>
- Parameters:
cutoff
- the results will be filtered to only include those updates whoseBulkUpdate.lastUpdated
is 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.lastUpdated
before the givencutoff
andtenantId
-
getRepository
@NonNull protected BulkUpdateRepository<com.broadleafcommerce.data.tracking.core.Identifiable> getRepository()- Overrides:
getRepository
in 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()
-