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)
  • 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, String> & com.broadleafcommerce.common.extension.DomainTypeAware> P create(P businessInstance)
      Overriding to add notification behavior.

      Will create the BulkUpdate and emit an ProcessBulkUpdateRequest message.

      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P extends BulkUpdate>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P extends BulkUpdate>
    • setProcessingStatus

      @Nullable public P setProcessingStatus(String bulkUpdateId)
      Description copied from interface: BulkUpdateService
      Acquires a lock on the given bulkUpdateId, and if it is found to have a BulkUpdate.status of BulkUpdateStatus.REQUESTED, atomically updates the BulkUpdate.status to BulkUpdateStatus.PROCESSING and renews BulkUpdate.lastUpdated.
      Specified by:
      setProcessingStatus in interface BulkUpdateService<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

      public boolean setContainedErrors(P bulkUpdate)
      Description copied from interface: BulkUpdateService
      Atomically finds and updates the given bulk update: finds the bulk update with the ID matching the given bulkUpdate, sets the bulk update's BulkUpdate.errors to the errors contained within the given bulkUpdate, sets BulkUpdate.status to BulkUpdateStatus.ERROR, and renews BulkUpdate.lastUpdated. No other values from bulkUpdate are applied.

      The change is applied only if the bulk update is found to have a BulkUpdate.status of BulkUpdateStatus.REQUESTED or BulkUpdateStatus.PROCESSING.

      Specified by:
      setContainedErrors in interface BulkUpdateService<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

      public boolean setNumberOfRecordsProcessed(String bulkUpdateId, long numberOfRecordsProcessed)
      Description copied from interface: BulkUpdateService
      Acquires a lock on the given bulkUpdateId, and if the bulk update is found and has a BulkUpdate.status of BulkUpdateStatus.PROCESSING, atomically sets BulkUpdate.numberOfRecordsProcessed to the given value and renews BulkUpdate.lastUpdated.
      Specified by:
      setNumberOfRecordsProcessed in interface BulkUpdateService<P extends BulkUpdate>
      Parameters:
      bulkUpdateId - the ID of the bulk update to modify
      numberOfRecordsProcessed - the new value to set for BulkUpdate.numberOfRecordsProcessed
      Returns:
      true if the update was successfully performed, false otherwise
    • setFinishedStatus

      public boolean setFinishedStatus(String bulkUpdateId)
      Description copied from interface: BulkUpdateService
      Acquires a lock on the given bulkUpdateId, and if the bulk update is found and has a BulkUpdate.status of BulkUpdateStatus.PROCESSING, atomically sets the BulkUpdate.status to BulkUpdateStatus.FINISHED and renews BulkUpdate.lastUpdated
      Specified by:
      setFinishedStatus in interface BulkUpdateService<P extends BulkUpdate>
      Parameters:
      bulkUpdateId - the ID of the bulk update to modify
      Returns:
      true if the update was successfully performed, false otherwise
    • notifyOfCreateSandboxRequest

      @Nullable public P notifyOfCreateSandboxRequest(String bulkUpdateId)
      Description copied from interface: BulkUpdateService
      Acquires a lock on the given bulkUpdateId, and if the bulkUpdate is found and has a BulkUpdate.status of BulkUpdateStatus.PROCESSING, atomically initializes its NotificationState for CreateSandboxRequestProducer.TYPE and renews BulkUpdate.lastUpdated.

      If the update is successful, calls NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String) for the CreateSandboxRequestProducer.TYPE.

      Specified by:
      notifyOfCreateSandboxRequest in interface BulkUpdateService<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

      @Nullable public P notifyOfDeleteSandboxRequest(String bulkUpdateId)
      Description copied from interface: BulkUpdateService
      Acquires a lock on the given bulkUpdateId, and if the bulkUpdate is found and has a BulkUpdate.status of BulkUpdateStatus.ERROR, atomically initializes its NotificationState for DeleteSandboxRequestProducer.TYPE and renews BulkUpdate.lastUpdated.

      If the update is successful, calls NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String) for the DeleteSandboxRequestProducer.TYPE.

      Specified by:
      notifyOfDeleteSandboxRequest in interface BulkUpdateService<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 given BulkUpdate.target and BulkUpdate.applicationId.
      Specified by:
      readByTargetAndApplicationId in interface BulkUpdateService<P extends BulkUpdate>
      Parameters:
      target - the BulkUpdate.target to filter by
      applicationId - the BulkUpdate.applicationId to filter results by. Note that if this is null, only bulk updates with null 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

      public List<P> readIncompleteLastUpdatedBefore(Instant cutoff)
      Description copied from interface: BulkUpdateService
      Reads the bulk updates which are incomplete (those with status BulkUpdateStatus.REQUESTED or BulkUpdateStatus.PROCESSING) whose BulkUpdate.lastUpdated is before the given cutoff.
      Specified by:
      readIncompleteLastUpdatedBefore in interface BulkUpdateService<P extends BulkUpdate>
      Parameters:
      cutoff - the results will be filtered to only include those updates whose BulkUpdate.lastUpdated is before this value
      Returns:
      the bulk updates which are incomplete and have a BulkUpdate.lastUpdated before the given cutoff
    • readIncompleteLastUpdatedBeforeAndTenantId

      public List<P> readIncompleteLastUpdatedBeforeAndTenantId(Instant cutoff, String tenantId)
      Description copied from interface: BulkUpdateService
      Reads the bulk updates which are incomplete (those with status BulkUpdateStatus.REQUESTED or BulkUpdateStatus.PROCESSING) whose BulkUpdate.lastUpdated is before the given cutoff.
      Specified by:
      readIncompleteLastUpdatedBeforeAndTenantId in interface BulkUpdateService<P extends BulkUpdate>
      Parameters:
      cutoff - the results will be filtered to only include those updates whose BulkUpdate.lastUpdated is before this value
      tenantId - 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 given cutoff and tenantId
    • getRepository

      @NonNull protected BulkUpdateRepository<com.broadleafcommerce.data.tracking.core.Identifiable> getRepository()
      Overrides:
      getRepository in class com.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()