Class DefaultImportService<P extends Import>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService<P>
com.broadleafcommerce.dataimport.service.DefaultImportService<P>
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityService<P>, ImportService<P>

public class DefaultImportService<P extends Import> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService<P> implements ImportService<P>
Author:
Phillip Verheyden (phillipuniverse)
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultImportService(ImportRepository<com.broadleafcommerce.data.tracking.core.Identifiable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityHelper helper, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager, BatchService<?> batchService)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Updates an Import (specified in Batch.importId) based upon the information received in a Batch.
    <D, R extends org.springframework.data.repository.CrudRepository<D, String> & com.broadleafcommerce.common.extension.DomainTypeAware>
    P
    create(P businessInstance)
     
    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.
    Delete the imports that match the corresponding ids
    protected com.broadleafcommerce.common.messaging.notification.NotificationManager
     
    protected ImportRepository<com.broadleafcommerce.data.tracking.core.Identifiable>
     
     
    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.
    Atomically marks the given import as cancelled.
    Atomically marks the given import as completed.
    markErrored(String importId, String errorMessage)
    Atomically finds and updates the import's Import.status to ImportStatus.FAILED, sets Import.errorMessage to errorMessage, and renews Import.lastUpdated.
    boolean
    markHanging(String importId, Instant cutoff, String errorMessage)
    Atomically updates the import only if its Import.status is ImportStatus.REQUESTED and its Import.lastUpdated is before the given cutoff.
    Sets the given import to ImportStatus.PROCESSING if and only if the given import was already ImportStatus.REQUESTED.
    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.
    org.springframework.data.domain.Page<P>
    readAll(org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds and returns all imports.
    org.springframework.data.domain.Page<P>
    readByActiveStatus(boolean isActive, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds and returns all imports whose Import.getStatus() satisfies the requirement of isActive.
    org.springframework.data.domain.Page<P>
    readByAuthor(@NonNull String author, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads the imports with the given Import.getAuthor().
    org.springframework.data.domain.Page<P>
    readByAuthorAndApplicationIdAndTenantId(String author, String applicationId, String tenantId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable)
    Reads the imports with the given Import.author and Import.applicationId.
    readById(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads the specified import by Import.getId().
    Read all imports whose Import.getLastUpdated() occurs before the provided time
    Reads the imports whose status is ImportStatus.REQUESTED and whose Import.lastUpdated is before the given cutoff.
    Reads the imports whose status is ImportStatus.REQUESTED and whose Import.lastUpdated is before the given cutoff, within the specified tenant.
    setTotalItems(String importId, long totalItems)
    Atomically sets the Import.totalItems of the given import to the specified value and renews Import.lastUpdated.

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService

    getRsqlHelper, readAll, readAll, readAll, readAll

    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

    • DefaultImportService

      public DefaultImportService(ImportRepository<com.broadleafcommerce.data.tracking.core.Identifiable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityHelper helper, com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager, BatchService<?> batchService)
  • Method Details

    • getRepository

      @NonNull protected ImportRepository<com.broadleafcommerce.data.tracking.core.Identifiable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P extends Import>
    • create

      public <D, R extends org.springframework.data.repository.CrudRepository<D, String> & com.broadleafcommerce.common.extension.DomainTypeAware> P create(P businessInstance)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P extends Import>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseMappableCrudEntityService<P extends Import>
    • markProcessing

      @Nullable public P markProcessing(String importId)
      Description copied from interface: ImportService
      Sets the given import to ImportStatus.PROCESSING if and only if the given import was already ImportStatus.REQUESTED.
      Specified by:
      markProcessing in interface ImportService<P extends Import>
      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
    • createSandbox

      @Nullable public P createSandbox(String importId, String importingSandboxId)
      Description copied from interface: ImportService
      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.

      Specified by:
      createSandbox in interface ImportService<P extends Import>
      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
    • setTotalItems

      @Nullable public P setTotalItems(String importId, long totalItems)
      Description copied from interface: ImportService
      Atomically sets the Import.totalItems of the given import to the specified value and renews Import.lastUpdated.
      Specified by:
      setTotalItems in interface ImportService<P extends Import>
      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 public P adjustCountsFromCompletedBatch(Batch completedBatch)
      Description copied from interface: ImportService
      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.

      Specified by:
      adjustCountsFromCompletedBatch in interface ImportService<P extends Import>
      Parameters:
      completedBatch - must be a batch with a BatchStatus.COMPLETED status.
      Returns:
      the updated import if found and updated, null otherwise
      See Also:
    • getStatusCounts

      protected Map<BatchItemStatus,Long> getStatusCounts(Batch batch)
    • incrementSuccessAndErrorCounts

      @Nullable public P incrementSuccessAndErrorCounts(String importId, long successCount, long errorCount)
      Description copied from interface: ImportService
      Atomically updates the following fields in the given Import (specified in importId): increment Import.successCount, increment Import.errorCount, and renew Import.lastUpdated.
      Specified by:
      incrementSuccessAndErrorCounts in interface ImportService<P extends Import>
      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
    • markErrored

      @Nullable public P markErrored(String importId, @Nullable String errorMessage)
      Description copied from interface: ImportService
      Atomically finds and updates the import's Import.status to ImportStatus.FAILED, sets Import.errorMessage to errorMessage, and renews Import.lastUpdated.
      Specified by:
      markErrored in interface ImportService<P extends Import>
      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

      public boolean markHanging(String importId, Instant cutoff, @Nullable String errorMessage)
      Description copied from interface: ImportService
      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.

      Specified by:
      markHanging in interface ImportService<P extends Import>
      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
    • readRequestedLastUpdatedBefore

      public List<P> readRequestedLastUpdatedBefore(Instant cutoff)
      Description copied from interface: ImportService
      Reads the imports whose status is ImportStatus.REQUESTED and whose Import.lastUpdated is before the given cutoff.
      Specified by:
      readRequestedLastUpdatedBefore in interface ImportService<P extends Import>
      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

      public List<P> readRequestedLastUpdatedBeforeAndTenantId(Instant cutoff, String tenantId)
      Description copied from interface: ImportService
      Reads the imports whose status is ImportStatus.REQUESTED and whose Import.lastUpdated is before the given cutoff, within the specified tenant.
      Specified by:
      readRequestedLastUpdatedBeforeAndTenantId in interface ImportService<P extends Import>
      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
    • markCompleted

      @Nullable public P markCompleted(String importId)
      Description copied from interface: ImportService
      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.
      Specified by:
      markCompleted in interface ImportService<P extends Import>
      Parameters:
      importId - the ID of the import to update
      Returns:
      the updated import if found and updated, null otherwise
      See Also:
    • markCancelled

      @Nullable public P markCancelled(String importId)
      Description copied from interface: ImportService
      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.
      Specified by:
      markCancelled in interface ImportService<P extends Import>
      Parameters:
      importId - the ID of the import to update
      Returns:
      the updated import if found and updated, null otherwise
      See Also:
    • readById

      public P readById(@NonNull @NonNull String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ImportService
      Reads the specified import by Import.getId().
      Specified by:
      readById in interface ImportService<P extends Import>
      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
    • readByActiveStatus

      public org.springframework.data.domain.Page<P> readByActiveStatus(boolean isActive, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ImportService
      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.
      Specified by:
      readByActiveStatus in interface ImportService<P extends Import>
      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

      public org.springframework.data.domain.Page<P> readAll(org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ImportService
      Finds and returns all imports.
      Specified by:
      readAll in interface ImportService<P extends Import>
      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

      public 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)
      Description copied from interface: ImportService
      Reads the imports with the given Import.author and Import.applicationId.
      Specified by:
      readByAuthorAndApplicationIdAndTenantId in interface ImportService<P extends Import>
      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

      public org.springframework.data.domain.Page<P> readByAuthor(@NonNull @NonNull String author, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ImportService
      Reads the imports with the given Import.getAuthor().
      Specified by:
      readByAuthor in interface ImportService<P extends Import>
      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 public P notifyOfDeleteSandboxRequest(String importId)
      Description copied from interface: ImportService
      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.

      Specified by:
      notifyOfDeleteSandboxRequest in interface ImportService<P extends Import>
      Parameters:
      importId - the ID of the Import to modify
      Returns:
      the updated Import if successfully found and updated, null otherwise
    • readImportsBeforeDate

      public List<P> readImportsBeforeDate(Instant before)
      Description copied from interface: ImportService
      Read all imports whose Import.getLastUpdated() occurs before the provided time
      Specified by:
      readImportsBeforeDate in interface ImportService<P extends Import>
      Parameters:
      before - the time for which to get all imports older than
      Returns:
      all imports whose Import.getLastUpdated() occurs before the provided time
    • deleteImportsById

      public Long deleteImportsById(List<String> importIds)
      Description copied from interface: ImportService
      Delete the imports that match the corresponding ids
      Specified by:
      deleteImportsById in interface ImportService<P extends Import>
      Parameters:
      importIds - the list of import ids to delete against
      Returns:
      the number of imports deleted
    • getNotificationManager

      @NonNull protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()