Class DefaultImportService<P extends Import>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.MappableCrudEntityService<P>,com.broadleafcommerce.data.tracking.core.service.RsqlMappableCrudEntityService<P>,ImportService<P>
- Author:
- Phillip Verheyden (phillipuniverse)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultImportService(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 TypeMethodDescriptionadjustCountsFromCompletedBatch(Batch completedBatch) <D,R extends org.springframework.data.repository.CrudRepository<D, String> & com.broadleafcommerce.common.extension.DomainTypeAware>
PcreateSandbox(String importId, String importingSandboxId) If the import is found and has aImport.statusofImportStatus.PROCESSING, atomically sets itsImport.importingSandboxIdto the given value, initializes itsNotificationStateforCreateSandboxRequestProducer.TYPE, and renewsImport.lastUpdated.deleteAllByIdInBatch(List<String> ids) Delete the imports that match the corresponding ids using a single query.protected com.broadleafcommerce.common.messaging.notification.NotificationManagerprotected ImportRepository<com.broadleafcommerce.data.tracking.core.Identifiable>protected Map<BatchItemStatus,Long> getStatusCounts(Batch batch) incrementSuccessAndErrorCounts(String importId, long successCount, long errorCount) Atomically updates the following fields in the givenImport(specified inimportId): incrementImport.successCount, incrementImport.errorCount, and renewImport.lastUpdated.markCancelled(String importId) Atomically marks the given import as cancelled.markCompleted(String importId) Atomically marks the given import as completed.markErrored(String importId, String errorMessage) Atomically finds and updates the import'sImport.statustoImportStatus.FAILED, setsImport.errorMessagetoerrorMessage, and renewsImport.lastUpdated.booleanmarkHanging(String importId, Instant cutoff, String errorMessage) Atomically updates the import only if itsImport.statusisImportStatus.REQUESTEDand itsImport.lastUpdatedis before the givencutoff.markProcessing(String importId) Sets the given import toImportStatus.PROCESSINGif and only if the given import was alreadyImportStatus.REQUESTED.notifyOfDeleteSandboxRequest(String importId) Tries to findImportbyImport.idif found and it has aImport.statusofImportStatus.FAILED, atomically initializes itsNotificationStateforImportDeleteSandboxRequestProducer.TYPEand renewsImport.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 whoseImport.getStatus()satisfies the requirement ofisActive.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 givenImport.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 givenImport.authorandImport.applicationId.readById(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads the specified import byImport.getId().readImportsBeforeDate(Instant before) Read all imports whoseImport.getLastUpdated()occurs before the provided timeReads the imports whose status isImportStatus.REQUESTEDand whoseImport.lastUpdatedis before the givencutoff.readRequestedLastUpdatedBeforeAndTenantId(Instant cutoff, String tenantId) Reads the imports whose status isImportStatus.REQUESTEDand whoseImport.lastUpdatedis before the givencutoff, within the specified tenant.setTotalItems(String importId, long totalItems) Atomically sets theImport.totalItemsof the given import to the specified value and renewsImport.lastUpdated.Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlMappableCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAllMethods 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.dataimport.service.ImportService
deleteImportsByIdMethods 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() -
create
-
markProcessing
Description copied from interface:ImportServiceSets the given import toImportStatus.PROCESSINGif and only if the given import was alreadyImportStatus.REQUESTED.- Specified by:
markProcessingin interfaceImportService<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 isImportStatus.REQUESTED
-
createSandbox
Description copied from interface:ImportServiceIf the import is found and has aImport.statusofImportStatus.PROCESSING, atomically sets itsImport.importingSandboxIdto the given value, initializes itsNotificationStateforCreateSandboxRequestProducer.TYPE, and renewsImport.lastUpdated.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)for theCreateSandboxRequestProducer.TYPE, which will emit a request to create the sandbox with the given ID.Note: before calling this method, ensure that the
Import.importingSandboxNameToCreatehas been set, asCreateSandboxRequestMessageFactory.createMessage(Object)will use its value forCreateSandboxRequest.sandboxName.- Specified by:
createSandboxin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to modifyimportingSandboxId- the ID of the sandbox which should be created- Returns:
- the updated
Importif successfully found and updated,nullotherwise
-
setTotalItems
Description copied from interface:ImportServiceAtomically sets theImport.totalItemsof the given import to the specified value and renewsImport.lastUpdated.- Specified by:
setTotalItemsin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to updatetotalItems- the value to set for the total item count- Returns:
- the updated import if found and updated,
nullotherwise
-
adjustCountsFromCompletedBatch
Description copied from interface:ImportServiceUpdates anImport(specified inBatch.importId) based upon the information received in aBatch. Batch must be a completed batch with aBatchStatus.COMPLETEDstatus.This will atomically update the following fields: increment
Import.successCount, incrementImport.errorCount, and renewImport.lastUpdated.- Specified by:
adjustCountsFromCompletedBatchin interfaceImportService<P extends Import>- Parameters:
completedBatch- must be a batch with aBatchStatus.COMPLETEDstatus.- Returns:
- the updated import if found and updated,
nullotherwise - See Also:
-
getStatusCounts
-
incrementSuccessAndErrorCounts
@Nullable public P incrementSuccessAndErrorCounts(String importId, long successCount, long errorCount) Description copied from interface:ImportServiceAtomically updates the following fields in the givenImport(specified inimportId): incrementImport.successCount, incrementImport.errorCount, and renewImport.lastUpdated.- Specified by:
incrementSuccessAndErrorCountsin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to updatesuccessCount- the amount to add to theImport.successCounterrorCount- the amount to add to theImport.errorCount- Returns:
- the updated import if found and updated,
nullotherwise
-
markErrored
Description copied from interface:ImportServiceAtomically finds and updates the import'sImport.statustoImportStatus.FAILED, setsImport.errorMessagetoerrorMessage, and renewsImport.lastUpdated.- Specified by:
markErroredin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to updateerrorMessage- error message to set asImport.errorMessage- Returns:
- the updated import if found and updated,
nullotherwise
-
markHanging
Description copied from interface:ImportServiceAtomically updates the import only if itsImport.statusisImportStatus.REQUESTEDand itsImport.lastUpdatedis before the givencutoff.The update will set the
Import.statustoImportStatus.FAILED, set the error message, and renewImport.lastUpdated.- Specified by:
markHangingin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to updatecutoff- the value that the import'sImport.lastUpdatedmust be beforeerrorMessage- error message to set asImport.errorMessage- Returns:
- true if the import was found and updated, false otherwise
-
readRequestedLastUpdatedBefore
Description copied from interface:ImportServiceReads the imports whose status isImportStatus.REQUESTEDand whoseImport.lastUpdatedis before the givencutoff.- Specified by:
readRequestedLastUpdatedBeforein interfaceImportService<P extends Import>- Parameters:
cutoff- the results will be filtered to only include those imports whoseImport.lastUpdatedis before this value- Returns:
- the imports with status
ImportStatus.REQUESTEDwhich have aImport.lastUpdatedbefore the givencutoff
-
readRequestedLastUpdatedBeforeAndTenantId
Description copied from interface:ImportServiceReads the imports whose status isImportStatus.REQUESTEDand whoseImport.lastUpdatedis before the givencutoff, within the specified tenant.- Specified by:
readRequestedLastUpdatedBeforeAndTenantIdin interfaceImportService<P extends Import>- Parameters:
cutoff- the results will be filtered to only include those imports whoseImport.lastUpdatedis before this valuetenantId- the tenant id that this import was initiated from- Returns:
- the imports with status
ImportStatus.REQUESTEDwhich have aImport.lastUpdatedbefore the givencutoff
-
markCompleted
Description copied from interface:ImportServiceAtomically marks the given import as completed. The update will only be performed if the import currently does not currently have a status ofImportStatus.CANCELLED,ImportStatus.FAILED, orImportStatus.COMPLETED.- Specified by:
markCompletedin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to update- Returns:
- the updated import if found and updated,
nullotherwise - See Also:
-
markCancelled
Description copied from interface:ImportServiceAtomically marks the given import as cancelled. The update will only be performed if the import currently does not currently have a status ofImportStatus.CANCELLED,ImportStatus.FAILED, orImportStatus.COMPLETED.- Specified by:
markCancelledin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the import to update- Returns:
- the updated import if found and updated,
nullotherwise - See Also:
-
readById
public P readById(@NonNull @NonNull String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ImportServiceReads the specified import byImport.getId().- Specified by:
readByIdin interfaceImportService<P extends Import>- Parameters:
id- the ID of the import to findcontextInfo- context information surrounding multitenant state. Results will be filtered such that only results exactly matching theContextRequest.getApplication()andContextRequest.getTenantId()will be returned (unlessContextInfo.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:ImportServiceFinds and returns all imports whoseImport.getStatus()satisfies the requirement ofisActive. IfisActiveis true, only imports withImportStatus.PROCESSINGreturned. IfisActiveis false, only imports who do not haveImportStatus.PROCESSINGwill be returned.- Specified by:
readByActiveStatusin interfaceImportService<P extends Import>- Parameters:
isActive- true if only active imports should be returned, false if only inactive imports should be returnedpageable- information about which page of results should be returned from the databasecontextInfo- context information surrounding multitenant state. Results will be filtered such that only results exactly matching theContextRequest.getApplication()andContextRequest.getTenantId()will be returned (unlessContextInfo.isIgnoreNarrowing()).- Returns:
- all imports whose status satisfies the given
isActiverequirement
-
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:ImportServiceFinds and returns all imports.- Specified by:
readAllin interfaceImportService<P extends Import>- Parameters:
pageable- information about which page of results should be returned from the databasecontextInfo- context information surrounding multitenant state. Results will be filtered such that only results exactly matching theContextRequest.getApplication()andContextRequest.getTenantId()will be returned (unlessContextInfo.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:ImportServiceReads the imports with the givenImport.authorandImport.applicationId.- Specified by:
readByAuthorAndApplicationIdAndTenantIdin interfaceImportService<P extends Import>- Parameters:
author- the author to filter results byapplicationId- theImport.applicationIdto filter by. Note that if this isnull, only imports with null application IDs will be returned.tenantId- theImport.tenantIdto filter byfilters- additional filters to apply, must not be nullpageable- 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:ImportServiceReads the imports with the givenImport.getAuthor().- Specified by:
readByAuthorin interfaceImportService<P extends Import>- Parameters:
author- the author to filter results byfilters- additional filters to apply, must not be nullpageable- information about which page of results to return from the databasecontextInfo- context information surrounding multitenant state. Results will be filtered such that only results exactly matching theContextRequest.getApplication()andContextRequest.getTenantId()will be returned (unlessContextInfo.isIgnoreNarrowing()).- Returns:
- the imports matching the given criteria
-
notifyOfDeleteSandboxRequest
Description copied from interface:ImportServiceTries to findImportbyImport.idif found and it has aImport.statusofImportStatus.FAILED, atomically initializes itsNotificationStateforImportDeleteSandboxRequestProducer.TYPEand renewsImport.lastUpdated.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)for theImportDeleteSandboxRequestProducer.TYPE.- Specified by:
notifyOfDeleteSandboxRequestin interfaceImportService<P extends Import>- Parameters:
importId- the ID of the Import to modify- Returns:
- the updated
Importif successfully found and updated,nullotherwise
-
readImportsBeforeDate
Description copied from interface:ImportServiceRead all imports whoseImport.getLastUpdated()occurs before the provided time- Specified by:
readImportsBeforeDatein interfaceImportService<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
-
deleteAllByIdInBatch
Description copied from interface:ImportServiceDelete the imports that match the corresponding ids using a single query.- Specified by:
deleteAllByIdInBatchin interfaceImportService<P extends Import>- Parameters:
ids- the list of import ids to delete against- Returns:
- the number of imports deleted
-
getNotificationManager
@NonNull protected com.broadleafcommerce.common.messaging.notification.NotificationManager getNotificationManager()
-