Interface ImportService<P extends Import>

All Superinterfaces:
com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P>
All Known Implementing Classes:
DefaultImportService

public interface ImportService<P extends Import> extends com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P>
Author:
Phillip Verheyden (phillipuniverse)
  • Method Details

    • markProcessing

      @Nullable P markProcessing(String importId)
      Sets the given import to ImportStatus.PROCESSING if and only if the given import was already ImportStatus.REQUESTED.
      Parameters:
      importId - the Import to update
      Returns:
      the updated Import with a status of ImportStatus.PROCESSING, or null if there was no import found with the given id whose status is ImportStatus.REQUESTED
    • markErrored

      @Nullable P markErrored(String importId, @Nullable String errorMessage)
      Atomically finds and updates the import's Import.status to ImportStatus.FAILED, sets Import.errorMessage to errorMessage, and renews Import.lastUpdated.
      Parameters:
      importId - the ID of the import to update
      errorMessage - error message to set as Import.errorMessage
      Returns:
      the updated import if found and updated, null otherwise
    • markHanging

      boolean markHanging(String importId, Instant cutoff, @Nullable String errorMessage)
      Atomically updates the import only if its Import.status is ImportStatus.REQUESTED and its Import.lastUpdated is before the given cutoff.

      The update will set the Import.status to ImportStatus.FAILED, set the error message, and renew Import.lastUpdated.

      Parameters:
      importId - the ID of the import to update
      cutoff - the value that the import's Import.lastUpdated must be before
      errorMessage - error message to set as Import.errorMessage
      Returns:
      true if the import was found and updated, false otherwise
    • createSandbox

      @Nullable P createSandbox(String importId, String importingSandboxId)
      If the import is found and has a Import.status of ImportStatus.PROCESSING, atomically sets its Import.importingSandboxId to the given value, initializes its NotificationState for CreateSandboxRequestProducer.TYPE, and renews Import.lastUpdated.

      If the update is successful, calls NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String) for the CreateSandboxRequestProducer.TYPE, which will emit a request to create the sandbox with the given ID.

      Note: before calling this method, ensure that the Import.importingSandboxNameToCreate has been set, as CreateSandboxRequestMessageFactory.createMessage(Object) will use its value for CreateSandboxRequest.sandboxName.

      Parameters:
      importId - the ID of the import to modify
      importingSandboxId - the ID of the sandbox which should be created
      Returns:
      the updated Import if successfully found and updated, null otherwise
    • readRequestedLastUpdatedBefore

      List<P> readRequestedLastUpdatedBefore(Instant cutoff)
      Reads the imports whose status is ImportStatus.REQUESTED and whose Import.lastUpdated is before the given cutoff.
      Parameters:
      cutoff - the results will be filtered to only include those imports whose Import.lastUpdated is before this value
      Returns:
      the imports with status ImportStatus.REQUESTED which have a Import.lastUpdated before the given cutoff
    • readRequestedLastUpdatedBeforeAndTenantId

      List<P> readRequestedLastUpdatedBeforeAndTenantId(Instant cutoff, String tenantId)
      Reads the imports whose status is ImportStatus.REQUESTED and whose Import.lastUpdated is before the given cutoff, within the specified tenant.
      Parameters:
      cutoff - the results will be filtered to only include those imports whose Import.lastUpdated is before this value
      tenantId - the tenant id that this import was initiated from
      Returns:
      the imports with status ImportStatus.REQUESTED which have a Import.lastUpdated before the given cutoff
    • setTotalItems

      @Nullable P setTotalItems(String importId, long totalItems)
      Atomically sets the Import.totalItems of the given import to the specified value and renews Import.lastUpdated.
      Parameters:
      importId - the ID of the import to update
      totalItems - the value to set for the total item count
      Returns:
      the updated import if found and updated, null otherwise
    • adjustCountsFromCompletedBatch

      @Nullable P adjustCountsFromCompletedBatch(Batch completedBatch)
      Updates an Import (specified in Batch.importId) based upon the information received in a Batch. Batch must be a completed batch with a BatchStatus.COMPLETED status.

      This will atomically update the following fields: increment Import.successCount, increment Import.errorCount, and renew Import.lastUpdated.

      Parameters:
      completedBatch - must be a batch with a BatchStatus.COMPLETED status.
      Returns:
      the updated import if found and updated, null otherwise
      See Also:
    • incrementSuccessAndErrorCounts

      @Nullable P incrementSuccessAndErrorCounts(String importId, long successCount, long errorCount)
      Atomically updates the following fields in the given Import (specified in importId): increment Import.successCount, increment Import.errorCount, and renew Import.lastUpdated.
      Parameters:
      importId - the ID of the import to update
      successCount - the amount to add to the Import.successCount
      errorCount - the amount to add to the Import.errorCount
      Returns:
      the updated import if found and updated, null otherwise
    • markCompleted

      @Nullable P markCompleted(String importId)
      Atomically marks the given import as completed. The update will only be performed if the import currently does not currently have a status of ImportStatus.CANCELLED, ImportStatus.FAILED, or ImportStatus.COMPLETED.
      Parameters:
      importId - the ID of the import to update
      Returns:
      the updated import if found and updated, null otherwise
      See Also:
    • markCancelled

      @Nullable P markCancelled(String importId)
      Atomically marks the given import as cancelled. The update will only be performed if the import currently does not currently have a status of ImportStatus.CANCELLED, ImportStatus.FAILED, or ImportStatus.COMPLETED.
      Parameters:
      importId - the ID of the import to update
      Returns:
      the updated import if found and updated, null otherwise
      See Also:
    • readById

      P readById(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Reads the specified import by Import.getId().
      Parameters:
      id - the ID of the import to find
      contextInfo - context information surrounding multitenant state. Results will be filtered such that only results exactly matching the ContextRequest.getApplication() and ContextRequest.getTenantId() will be returned (unless ContextInfo.isIgnoreNarrowing()).
      Returns:
      the requested import matching the given ID
      Throws:
      com.broadleafcommerce.data.tracking.core.exception.EntityMissingException - if not found
    • readByActiveStatus

      org.springframework.data.domain.Page<P> readByActiveStatus(boolean isActive, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finds and returns all imports whose Import.getStatus() satisfies the requirement of isActive. If isActive is true, only imports with ImportStatus.PROCESSING returned. If isActive is false, only imports who do not have ImportStatus.PROCESSING will be returned.
      Parameters:
      isActive - true if only active imports should be returned, false if only inactive imports should be returned
      pageable - information about which page of results should be returned from the database
      contextInfo - context information surrounding multitenant state. Results will be filtered such that only results exactly matching the ContextRequest.getApplication() and ContextRequest.getTenantId() will be returned (unless ContextInfo.isIgnoreNarrowing()).
      Returns:
      all imports whose status satisfies the given isActive requirement
    • readAll

      org.springframework.data.domain.Page<P> readAll(org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Finds and returns all imports.
      Parameters:
      pageable - information about which page of results should be returned from the database
      contextInfo - context information surrounding multitenant state. Results will be filtered such that only results exactly matching the ContextRequest.getApplication() and ContextRequest.getTenantId() will be returned (unless ContextInfo.isIgnoreNarrowing()).
      Returns:
      all imports in the datastore
    • readByAuthorAndApplicationIdAndTenantId

      @Deprecated org.springframework.data.domain.Page<P> readByAuthorAndApplicationIdAndTenantId(String author, @Nullable String applicationId, String tenantId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable)
      Deprecated.
      Reads the imports with the given Import.author and Import.applicationId.
      Parameters:
      author - the author to filter results by
      applicationId - the Import.applicationId to filter by. Note that if this is null, only imports with null application IDs will be returned.
      tenantId - the Import.tenantId to filter by
      filters - additional filters to apply, must not be null
      pageable - information about which page of results to return from the database
      Returns:
      the imports matching the given criteria
    • readByAuthor

      org.springframework.data.domain.Page<P> readByAuthor(String author, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Reads the imports with the given Import.getAuthor().
      Parameters:
      author - the author to filter results by
      filters - additional filters to apply, must not be null
      pageable - information about which page of results to return from the database
      contextInfo - context information surrounding multitenant state. Results will be filtered such that only results exactly matching the ContextRequest.getApplication() and ContextRequest.getTenantId() will be returned (unless ContextInfo.isIgnoreNarrowing()).
      Returns:
      the imports matching the given criteria
    • notifyOfDeleteSandboxRequest

      @Nullable P notifyOfDeleteSandboxRequest(String importId)
      Tries to find Import by Import.id if found and it has a Import.status of ImportStatus.FAILED, atomically initializes its NotificationState for ImportDeleteSandboxRequestProducer.TYPE and renews Import.lastUpdated.

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

      Parameters:
      importId - the ID of the Import to modify
      Returns:
      the updated Import if successfully found and updated, null otherwise
      Throws:
      com.broadleafcommerce.common.messaging.exception.ResourceLockException - if the lock could not be acquired
    • readImportsBeforeDate

      List<P> readImportsBeforeDate(Instant before)
      Read all imports whose Import.getLastUpdated() occurs before the provided time
      Parameters:
      before - the time for which to get all imports older than
      Returns:
      all imports whose Import.getLastUpdated() occurs before the provided time
    • deleteImportsById

      @Transactional("importTransactionManager") Long deleteImportsById(List<String> importIds)
      Delete the imports that match the corresponding ids
      Parameters:
      importIds - the list of import ids to delete against
      Returns:
      the number of imports deleted