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
ConstructorDescriptionDefaultImportService
(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.status
ofImportStatus.PROCESSING
, atomically sets itsImport.importingSandboxId
to the given value, initializes itsNotificationState
forCreateSandboxRequestProducer.TYPE
, and renewsImport.lastUpdated
.deleteImportsById
(List<String> importIds) Delete the imports that match the corresponding idsprotected com.broadleafcommerce.common.messaging.notification.NotificationManager
protected 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.status
toImportStatus.FAILED
, setsImport.errorMessage
toerrorMessage
, and renewsImport.lastUpdated
.boolean
markHanging
(String importId, Instant cutoff, String errorMessage) Atomically updates the import only if itsImport.status
isImportStatus.REQUESTED
and itsImport.lastUpdated
is before the givencutoff
.markProcessing
(String importId) Sets the given import toImportStatus.PROCESSING
if and only if the given import was alreadyImportStatus.REQUESTED
.notifyOfDeleteSandboxRequest
(String importId) Tries to findImport
byImport.id
if found and it has aImport.status
ofImportStatus.FAILED
, atomically initializes itsNotificationState
forImportDeleteSandboxRequestProducer.TYPE
and 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.author
andImport.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.REQUESTED
and whoseImport.lastUpdated
is before the givencutoff
.readRequestedLastUpdatedBeforeAndTenantId
(Instant cutoff, String tenantId) Reads the imports whose status isImportStatus.REQUESTED
and whoseImport.lastUpdated
is before the givencutoff
, within the specified tenant.setTotalItems
(String importId, long totalItems) Atomically sets theImport.totalItems
of 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, 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() -
create
-
markProcessing
Description copied from interface:ImportService
Sets the given import toImportStatus.PROCESSING
if and only if the given import was alreadyImportStatus.REQUESTED
.- Specified by:
markProcessing
in 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:ImportService
If the import is found and has aImport.status
ofImportStatus.PROCESSING
, atomically sets itsImport.importingSandboxId
to the given value, initializes itsNotificationState
forCreateSandboxRequestProducer.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.importingSandboxNameToCreate
has been set, asCreateSandboxRequestMessageFactory.createMessage(Object)
will use its value forCreateSandboxRequest.sandboxName
.- Specified by:
createSandbox
in 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
Import
if successfully found and updated,null
otherwise
-
setTotalItems
Description copied from interface:ImportService
Atomically sets theImport.totalItems
of the given import to the specified value and renewsImport.lastUpdated
.- Specified by:
setTotalItems
in 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,
null
otherwise
-
adjustCountsFromCompletedBatch
Description copied from interface:ImportService
Updates anImport
(specified inBatch.importId
) based upon the information received in aBatch
. Batch must be a completed batch with aBatchStatus.COMPLETED
status.This will atomically update the following fields: increment
Import.successCount
, incrementImport.errorCount
, and renewImport.lastUpdated
.- Specified by:
adjustCountsFromCompletedBatch
in interfaceImportService<P extends Import>
- Parameters:
completedBatch
- must be a batch with aBatchStatus.COMPLETED
status.- Returns:
- the updated import if found and updated,
null
otherwise - See Also:
-
getStatusCounts
-
incrementSuccessAndErrorCounts
@Nullable public P incrementSuccessAndErrorCounts(String importId, long successCount, long errorCount) Description copied from interface:ImportService
Atomically updates the following fields in the givenImport
(specified inimportId
): incrementImport.successCount
, incrementImport.errorCount
, and renewImport.lastUpdated
.- Specified by:
incrementSuccessAndErrorCounts
in interfaceImportService<P extends Import>
- Parameters:
importId
- the ID of the import to updatesuccessCount
- the amount to add to theImport.successCount
errorCount
- the amount to add to theImport.errorCount
- Returns:
- the updated import if found and updated,
null
otherwise
-
markErrored
Description copied from interface:ImportService
Atomically finds and updates the import'sImport.status
toImportStatus.FAILED
, setsImport.errorMessage
toerrorMessage
, and renewsImport.lastUpdated
.- Specified by:
markErrored
in 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,
null
otherwise
-
markHanging
Description copied from interface:ImportService
Atomically updates the import only if itsImport.status
isImportStatus.REQUESTED
and itsImport.lastUpdated
is before the givencutoff
.The update will set the
Import.status
toImportStatus.FAILED
, set the error message, and renewImport.lastUpdated
.- Specified by:
markHanging
in interfaceImportService<P extends Import>
- Parameters:
importId
- the ID of the import to updatecutoff
- the value that the import'sImport.lastUpdated
must be beforeerrorMessage
- error message to set asImport.errorMessage
- Returns:
- true if the import was found and updated, false otherwise
-
readRequestedLastUpdatedBefore
Description copied from interface:ImportService
Reads the imports whose status isImportStatus.REQUESTED
and whoseImport.lastUpdated
is before the givencutoff
.- Specified by:
readRequestedLastUpdatedBefore
in interfaceImportService<P extends Import>
- Parameters:
cutoff
- the results will be filtered to only include those imports whoseImport.lastUpdated
is before this value- Returns:
- the imports with status
ImportStatus.REQUESTED
which have aImport.lastUpdated
before the givencutoff
-
readRequestedLastUpdatedBeforeAndTenantId
Description copied from interface:ImportService
Reads the imports whose status isImportStatus.REQUESTED
and whoseImport.lastUpdated
is before the givencutoff
, within the specified tenant.- Specified by:
readRequestedLastUpdatedBeforeAndTenantId
in interfaceImportService<P extends Import>
- Parameters:
cutoff
- the results will be filtered to only include those imports whoseImport.lastUpdated
is before this valuetenantId
- the tenant id that this import was initiated from- Returns:
- the imports with status
ImportStatus.REQUESTED
which have aImport.lastUpdated
before the givencutoff
-
markCompleted
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 ofImportStatus.CANCELLED
,ImportStatus.FAILED
, orImportStatus.COMPLETED
.- Specified by:
markCompleted
in interfaceImportService<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
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 ofImportStatus.CANCELLED
,ImportStatus.FAILED
, orImportStatus.COMPLETED
.- Specified by:
markCancelled
in interfaceImportService<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 byImport.getId()
.- Specified by:
readById
in 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:ImportService
Finds and returns all imports whoseImport.getStatus()
satisfies the requirement ofisActive
. IfisActive
is true, only imports withImportStatus.PROCESSING
returned. IfisActive
is false, only imports who do not haveImportStatus.PROCESSING
will be returned.- Specified by:
readByActiveStatus
in 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
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 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:ImportService
Reads the imports with the givenImport.author
andImport.applicationId
.- Specified by:
readByAuthorAndApplicationIdAndTenantId
in interfaceImportService<P extends Import>
- Parameters:
author
- the author to filter results byapplicationId
- theImport.applicationId
to filter by. Note that if this isnull
, only imports with null application IDs will be returned.tenantId
- theImport.tenantId
to 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:ImportService
Reads the imports with the givenImport.getAuthor()
.- Specified by:
readByAuthor
in 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:ImportService
Tries to findImport
byImport.id
if found and it has aImport.status
ofImportStatus.FAILED
, atomically initializes itsNotificationState
forImportDeleteSandboxRequestProducer.TYPE
and renewsImport.lastUpdated
.If the update is successful, calls
NotificationManager.handle(NotificationStateRepository, NotificationStateAware, String)
for theImportDeleteSandboxRequestProducer.TYPE
.- Specified by:
notifyOfDeleteSandboxRequest
in interfaceImportService<P extends Import>
- Parameters:
importId
- the ID of the Import to modify- Returns:
- the updated
Import
if successfully found and updated,null
otherwise
-
readImportsBeforeDate
Description copied from interface:ImportService
Read all imports whoseImport.getLastUpdated()
occurs before the provided time- Specified by:
readImportsBeforeDate
in 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
-
deleteImportsById
Description copied from interface:ImportService
Delete the imports that match the corresponding ids- Specified by:
deleteImportsById
in interfaceImportService<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()
-