Class JpaCustomizedImportRepository<D extends JpaImport>
java.lang.Object
com.broadleafcommerce.dataimport.provider.jpa.repository.JpaCustomizedImportRepository<D>
- All Implemented Interfaces:
com.broadleafcommerce.common.extension.DomainTypeAware
,com.broadleafcommerce.common.messaging.notification.NotificationStateRepository
,com.broadleafcommerce.common.messaging.notification.NotificationStateRepositoryFragment
,CustomizedImportRepository<D>
@Repository
public class JpaCustomizedImportRepository<D extends JpaImport>
extends Object
implements CustomizedImportRepository<D>, com.broadleafcommerce.common.messaging.notification.NotificationStateRepositoryFragment
- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorDescriptionJpaCustomizedImportRepository
(com.broadleafcommerce.common.messaging.notification.NotificationStateRepositoryFragment notificationStateRepository) -
Method Summary
Modifier and TypeMethodDescriptionprotected javax.persistence.criteria.Predicate
buildContextCriteria
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) This builds criteria such that the import's application and tenant ID values should match exactly what is incontextInfo
(even if null).protected void
buildContextPredicates
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.AbstractQuery<?> query, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, List<javax.persistence.criteria.Predicate> predicates, Map<String, Object> params) protected javax.persistence.criteria.Predicate
buildIdFilter
(String importId, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected javax.persistence.criteria.Predicate
buildLastUpdatedBeforeFilter
(Instant cutoff, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected List<javax.persistence.criteria.Predicate>
buildReadByStatusNotPredicates
(String importStatus, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected List<javax.persistence.criteria.Predicate>
buildReadByStatusPredicates
(String importStatus, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected javax.persistence.criteria.Predicate
buildStatusFilter
(String status, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected javax.persistence.criteria.Predicate
buildStatusNotFilter
(String status, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected javax.persistence.criteria.Predicate
buildStatusNotInFilter
(List<String> statuses, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) protected Long
countAll
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asreadAll(Pageable, ContextInfo)
and is used for its paging implementation.protected Long
countByAuthor
(String author, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asfindByAuthor(String, Node, Pageable, ContextInfo)
and is used for its paging implementation.protected Long
countByStatus
(String importStatus, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asreadByStatus(String, Pageable, ContextInfo)
and is used for its paging implementation.protected Long
countByStatusNot
(String importStatus, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asreadByStatusNot(String, Pageable, ContextInfo)
and is used for its paging implementation.org.springframework.data.domain.Page<D>
findByAuthor
(String author, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the imports with the givenImport.getAuthor()
.findById
(@NonNull String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the specified import byImport.getId()
.Stream<com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware>
findNotificationReadyMembers
(Object lastProcessedNativeId, int pageSize, String messageType, Duration faultThreshold, Class<?> entityType) protected String
getApplicationIdFromContext
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.RSQLVisitorHolder<cz.jirutka.rsql.parser.ast.RSQLVisitor<javax.persistence.criteria.Predicate,
Class<?>>> incrementSuccessAndErrorCounts
(String importId, long successCount, long errorCount) This will atomically update the following fields: incrementImport.successCount
, incrementImport.errorCount
, and renewImport.lastUpdated
.Atomically initializes theNotificationState
forImportDeleteSandboxRequestProducer.TYPE
on the given import if it is found to have aImport.status
ofImportStatus.FAILED
.initializeForSandboxCreation
(String importId, String importingSandboxId) If the import is found and has aImport.status
ofImportStatus.PROCESSING
, atomically sets theImport.importingSandboxId
to the given value, initializes theNotificationState
forCreateSandboxRequestProducer.TYPE
, and renewsImport.lastUpdated
.protected com.broadleafcommerce.common.messaging.notification.domain.NotificationState
initializeNotificationState
(D entity, String notificationStateName, Instant changeTimestamp) 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
and setsImport.errorMessage
toerrorMessage
.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 an import with the givenimportId
toImportStatus.PROCESSING
, if and only if it was originallyImportStatus.REQUESTED
.org.springframework.data.domain.Page<D>
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<D>
readByStatus
(String importStatus, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds and returns all imports whoseImport.getStatus()
equals the given value.org.springframework.data.domain.Page<D>
readByStatusNot
(String importStatus, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds and returns all imports whoseImport.getStatus()
is not equal to the given value.boolean
setFailedNotificationAttempt
(Object nativeId, String messageType, int attemptCount, Instant nextAttempt, Class<?> entityType, boolean stopped) void
setFilterRulesCriteriaBuilder
(com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder filterRulesCriteriaBuilder) boolean
setNotificationAcknowledged
(Object nativeId, String messageType, int attemptCount, Class<?> entityType) void
setRsqlVisitorHolder
(com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.RSQLVisitorHolder<cz.jirutka.rsql.parser.ast.RSQLVisitor<javax.persistence.criteria.Predicate, Class<?>>> rsqlVisitorHolder) setTotalItems
(String importId, long totalItems) Atomically sets theImport.totalItems
of the given import to the specified value and renewsImport.lastUpdated
.
-
Constructor Details
-
JpaCustomizedImportRepository
public JpaCustomizedImportRepository(com.broadleafcommerce.common.messaging.notification.NotificationStateRepositoryFragment notificationStateRepository)
-
-
Method Details
-
save
-
saveAll
-
getDomainType
- Specified by:
getDomainType
in interfacecom.broadleafcommerce.common.extension.DomainTypeAware
-
markProcessing
Description copied from interface:CustomizedImportRepository
Sets an import with the givenimportId
toImportStatus.PROCESSING
, if and only if it was originallyImportStatus.REQUESTED
. Also atomically renewsImport.lastUpdated
.- Specified by:
markProcessing
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importId
- the persisted import to set to processing- Returns:
- the updated import or
null
if nothing found with a status ofImportStatus.PROCESSING
or by the givenimportId
-
initializeForSandboxCreation
@Nullable @Transactional("importTransactionManager") public D initializeForSandboxCreation(String importId, String importingSandboxId) Description copied from interface:CustomizedImportRepository
If the import is found and has aImport.status
ofImportStatus.PROCESSING
, atomically sets theImport.importingSandboxId
to the given value, initializes theNotificationState
forCreateSandboxRequestProducer.TYPE
, and renewsImport.lastUpdated
.- Specified by:
initializeForSandboxCreation
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importId
- the ID of the import to modifyimportingSandboxId
- the ID of the sandbox to create- Returns:
- the updated
Import
if found and updated,null
otherwise
-
buildIdFilter
-
buildStatusFilter
-
initializeNotificationState
-
markErrored
@Nullable @Transactional("importTransactionManager") public D markErrored(String importId, @Nullable String errorMessage) Description copied from interface:CustomizedImportRepository
Atomically finds and updates the import'sImport.status
toImportStatus.FAILED
and setsImport.errorMessage
toerrorMessage
.- Specified by:
markErrored
in interfaceCustomizedImportRepository<D extends JpaImport>
- 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
@Nullable @Transactional("importTransactionManager") public D markHanging(String importId, Instant cutoff, @Nullable String errorMessage) Description copied from interface:CustomizedImportRepository
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
and set the error message.- Specified by:
markHanging
in interfaceCustomizedImportRepository<D extends JpaImport>
- 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:
- the updated import if found and updated,
null
otherwise
-
buildLastUpdatedBeforeFilter
-
setNotificationAcknowledged
public boolean setNotificationAcknowledged(Object nativeId, String messageType, int attemptCount, Class<?> entityType) - Specified by:
setNotificationAcknowledged
in interfacecom.broadleafcommerce.common.messaging.notification.NotificationStateRepository
-
setFailedNotificationAttempt
public boolean setFailedNotificationAttempt(Object nativeId, String messageType, int attemptCount, Instant nextAttempt, Class<?> entityType, boolean stopped) - Specified by:
setFailedNotificationAttempt
in interfacecom.broadleafcommerce.common.messaging.notification.NotificationStateRepository
-
findNotificationReadyMembers
public Stream<com.broadleafcommerce.common.messaging.notification.domain.NotificationStateAware> findNotificationReadyMembers(Object lastProcessedNativeId, int pageSize, String messageType, Duration faultThreshold, Class<?> entityType) - Specified by:
findNotificationReadyMembers
in interfacecom.broadleafcommerce.common.messaging.notification.NotificationStateRepository
-
setTotalItems
@Nullable @Transactional("importTransactionManager") public D setTotalItems(String importId, long totalItems) Description copied from interface:CustomizedImportRepository
Atomically sets theImport.totalItems
of the given import to the specified value and renewsImport.lastUpdated
.- Specified by:
setTotalItems
in interfaceCustomizedImportRepository<D extends JpaImport>
- 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
-
incrementSuccessAndErrorCounts
@Nullable @Transactional("importTransactionManager") public D incrementSuccessAndErrorCounts(String importId, long successCount, long errorCount) Description copied from interface:CustomizedImportRepository
This will atomically update the following fields: incrementImport.successCount
, incrementImport.errorCount
, and renewImport.lastUpdated
.- Specified by:
incrementSuccessAndErrorCounts
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importId
- the ID of the import to updatesuccessCount
- the value to add to the existing value ofImport.successCount
errorCount
- the value to add to the existing value ofImport.errorCount
- Returns:
- the updated import if found and updated,
null
otherwise
-
markCompleted
Description copied from interface:CustomizedImportRepository
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 interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importId
- the ID of the import to update- Returns:
- the updated import if found and updated,
null
otherwise
-
buildStatusNotInFilter
-
markCancelled
Description copied from interface:CustomizedImportRepository
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 interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importId
- the ID of the import to update- Returns:
- the updated import if found and updated,
null
otherwise
-
findById
public Optional<D> findById(@NonNull @NonNull String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedImportRepository
Finds the specified import byImport.getId()
.- Specified by:
findById
in interfaceCustomizedImportRepository<D extends JpaImport>
- 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:
- an optional containing the requested import matching the given ID if found,
Optional.empty()
otherwise
-
readByStatus
public org.springframework.data.domain.Page<D> readByStatus(String importStatus, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedImportRepository
Finds and returns all imports whoseImport.getStatus()
equals the given value.- Specified by:
readByStatus
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importStatus
- the status which imports should have in order to be included in the resultspageable
- 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 equals
importStatus
-
buildReadByStatusPredicates
protected List<javax.persistence.criteria.Predicate> buildReadByStatusPredicates(String importStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) -
buildContextPredicates
protected void buildContextPredicates(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.AbstractQuery<?> query, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, List<javax.persistence.criteria.Predicate> predicates, Map<String, Object> params) -
buildContextCriteria
protected javax.persistence.criteria.Predicate buildContextCriteria(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) This builds criteria such that the import's application and tenant ID values should match exactly what is incontextInfo
(even if null).- Parameters:
contextInfo
- context information surrounding multitenant stateimportEntity
- the import entity rootcriteriaBuilder
- standard criteria builderparameterValues
- map of query parameter values that will be applied- Returns:
- a predicate filtering to an exact match on application ID and tenant ID
-
getApplicationIdFromContext
@Nullable protected String getApplicationIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
countByStatus
protected Long countByStatus(String importStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asreadByStatus(String, Pageable, ContextInfo)
and is used for its paging implementation.- Parameters:
importStatus
- the status which imports should have in order to be included in the resultscontextInfo
- context information about multitenant state- Returns:
- the number of results expected to be returned by
readByStatus(String, Pageable, ContextInfo)
-
readByStatusNot
public org.springframework.data.domain.Page<D> readByStatusNot(String importStatus, org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedImportRepository
Finds and returns all imports whoseImport.getStatus()
is not equal to the given value.- Specified by:
readByStatusNot
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importStatus
- the status which imports should not have in order to be included in the resultspageable
- 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 equals
importStatus
-
countByStatusNot
protected Long countByStatusNot(String importStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asreadByStatusNot(String, Pageable, ContextInfo)
and is used for its paging implementation.- Parameters:
importStatus
- the status which imports should have in order to be included in the resultscontextInfo
- context information about multitenant state, used to filter results further by application- Returns:
- the number of results expected to be returned by
readByStatusNot(String, Pageable, ContextInfo)
-
buildReadByStatusNotPredicates
protected List<javax.persistence.criteria.Predicate> buildReadByStatusNotPredicates(String importStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, javax.persistence.criteria.CriteriaQuery<?> criteriaQuery, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String, Object> parameterValues) -
buildStatusNotFilter
-
readAll
public org.springframework.data.domain.Page<D> readAll(org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedImportRepository
Finds and returns all imports.- Specified by:
readAll
in interfaceCustomizedImportRepository<D extends JpaImport>
- 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
-
findByAuthor
public org.springframework.data.domain.Page<D> findByAuthor(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:CustomizedImportRepository
Finds the imports with the givenImport.getAuthor()
.- Specified by:
findByAuthor
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
author
- theImport.getAuthor()
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
-
countByAuthor
protected Long countByAuthor(String author, cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asfindByAuthor(String, Node, Pageable, ContextInfo)
and is used for its paging implementation.- Parameters:
author
- theImport.getAuthor()
to filter results byfilters
- additional filters to apply, must not be nullcontextInfo
- context information about multitenant state- Returns:
- the number of results expected to be returned by
findByAuthor(String, Node, Pageable, ContextInfo)
-
initializeDeleteSandboxNotificationState
@Nullable @Transactional("importTransactionManager") public D initializeDeleteSandboxNotificationState(String importId) Description copied from interface:CustomizedImportRepository
Atomically initializes theNotificationState
forImportDeleteSandboxRequestProducer.TYPE
on the given import if it is found to have aImport.status
ofImportStatus.FAILED
.- Specified by:
initializeDeleteSandboxNotificationState
in interfaceCustomizedImportRepository<D extends JpaImport>
- Parameters:
importId
- the ID of the import to modify- Returns:
- the updated
Import
if found and updated,null
otherwise
-
countAll
protected Long countAll(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Has the same criteria filters asreadAll(Pageable, ContextInfo)
and is used for its paging implementation.- Parameters:
contextInfo
- context information about multitenant state, used to filter results further by application- Returns:
- the number of results expected to be returned by
readAll(Pageable, ContextInfo)
-
getRsqlVisitorHolder
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.RSQLVisitorHolder<cz.jirutka.rsql.parser.ast.RSQLVisitor<javax.persistence.criteria.Predicate,Class<?>>> getRsqlVisitorHolder() -
setRsqlVisitorHolder
@Autowired public void setRsqlVisitorHolder(com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.RSQLVisitorHolder<cz.jirutka.rsql.parser.ast.RSQLVisitor<javax.persistence.criteria.Predicate, Class<?>>> rsqlVisitorHolder) -
getFilterRulesCriteriaBuilder
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder getFilterRulesCriteriaBuilder() -
setFilterRulesCriteriaBuilder
@Autowired public void setFilterRulesCriteriaBuilder(com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder filterRulesCriteriaBuilder)
-