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 Details

    • JpaCustomizedImportRepository

      public JpaCustomizedImportRepository(com.broadleafcommerce.common.messaging.notification.NotificationStateRepositoryFragment notificationStateRepository)
  • Method Details

    • save

      @Transactional("importTransactionManager") public Object save(Object entity)
    • saveAll

      @Transactional("importTransactionManager") public List<Object> saveAll(Iterable<?> entities)
    • getDomainType

      public Class<D> getDomainType()
      Specified by:
      getDomainType in interface com.broadleafcommerce.common.extension.DomainTypeAware
    • markProcessing

      @Nullable @Transactional("importTransactionManager") public D markProcessing(String importId)
      Description copied from interface: CustomizedImportRepository
      Sets an import with the given importId to ImportStatus.PROCESSING, if and only if it was originally ImportStatus.REQUESTED. Also atomically renews Import.lastUpdated.
      Specified by:
      markProcessing in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      importId - the persisted import to set to processing
      Returns:
      the updated import or null if nothing found with a status of ImportStatus.PROCESSING or by the given importId
    • initializeForSandboxCreation

      @Nullable @Transactional("importTransactionManager") public D initializeForSandboxCreation(String importId, String importingSandboxId)
      Description copied from interface: CustomizedImportRepository
      If the import is found and has a Import.status of ImportStatus.PROCESSING, atomically sets the Import.importingSandboxId to the given value, initializes the NotificationState for CreateSandboxRequestProducer.TYPE, and renews Import.lastUpdated.
      Specified by:
      initializeForSandboxCreation in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      importId - the ID of the import to modify
      importingSandboxId - the ID of the sandbox to create
      Returns:
      the updated Import if found and updated, null otherwise
    • buildIdFilter

      protected javax.persistence.criteria.Predicate buildIdFilter(String importId, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    • buildStatusFilter

      protected javax.persistence.criteria.Predicate buildStatusFilter(String status, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    • initializeNotificationState

      protected com.broadleafcommerce.common.messaging.notification.domain.NotificationState initializeNotificationState(D entity, String notificationStateName, Instant changeTimestamp)
    • markErrored

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

      @Nullable @Transactional("importTransactionManager") public D markHanging(String importId, Instant cutoff, @Nullable String errorMessage)
      Description copied from interface: CustomizedImportRepository
      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 and set the error message.

      Specified by:
      markHanging in interface CustomizedImportRepository<D extends JpaImport>
      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:
      the updated import if found and updated, null otherwise
    • buildLastUpdatedBeforeFilter

      protected javax.persistence.criteria.Predicate buildLastUpdatedBeforeFilter(Instant cutoff, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    • setNotificationAcknowledged

      public boolean setNotificationAcknowledged(Object nativeId, String messageType, int attemptCount, Class<?> entityType)
      Specified by:
      setNotificationAcknowledged in interface com.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 interface com.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 interface com.broadleafcommerce.common.messaging.notification.NotificationStateRepository
    • setTotalItems

      @Nullable @Transactional("importTransactionManager") public D setTotalItems(String importId, long totalItems)
      Description copied from interface: CustomizedImportRepository
      Atomically sets the Import.totalItems of the given import to the specified value and renews Import.lastUpdated.
      Specified by:
      setTotalItems in interface CustomizedImportRepository<D extends JpaImport>
      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
    • 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: increment Import.successCount, increment Import.errorCount, and renew Import.lastUpdated.
      Specified by:
      incrementSuccessAndErrorCounts in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      importId - the ID of the import to update
      successCount - the value to add to the existing value of Import.successCount
      errorCount - the value to add to the existing value of Import.errorCount
      Returns:
      the updated import if found and updated, null otherwise
    • markCompleted

      @Nullable @Transactional("importTransactionManager") public D markCompleted(String importId)
      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 of ImportStatus.CANCELLED, ImportStatus.FAILED, or ImportStatus.COMPLETED.
      Specified by:
      markCompleted in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      importId - the ID of the import to update
      Returns:
      the updated import if found and updated, null otherwise
    • buildStatusNotInFilter

      protected javax.persistence.criteria.Predicate buildStatusNotInFilter(List<String> statuses, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    • markCancelled

      @Nullable @Transactional("importTransactionManager") public D markCancelled(String importId)
      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 of ImportStatus.CANCELLED, ImportStatus.FAILED, or ImportStatus.COMPLETED.
      Specified by:
      markCancelled in interface CustomizedImportRepository<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 by Import.getId().
      Specified by:
      findById in interface CustomizedImportRepository<D extends JpaImport>
      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:
      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 whose Import.getStatus() equals the given value.
      Specified by:
      readByStatus in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      importStatus - the status which imports should have in order to be included in the results
      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 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 in contextInfo (even if null).
      Parameters:
      contextInfo - context information surrounding multitenant state
      importEntity - the import entity root
      criteriaBuilder - standard criteria builder
      parameterValues - 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 as readByStatus(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 results
      contextInfo - 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 whose Import.getStatus() is not equal to the given value.
      Specified by:
      readByStatusNot in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      importStatus - the status which imports should not have in order to be included in the results
      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 equals importStatus
    • countByStatusNot

      protected Long countByStatusNot(String importStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Has the same criteria filters as readByStatusNot(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 results
      contextInfo - 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

      protected javax.persistence.criteria.Predicate buildStatusNotFilter(String status, javax.persistence.criteria.Root<D> importEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    • 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 interface CustomizedImportRepository<D extends JpaImport>
      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
    • 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 given Import.getAuthor().
      Specified by:
      findByAuthor in interface CustomizedImportRepository<D extends JpaImport>
      Parameters:
      author - the Import.getAuthor() 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
    • 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 as findByAuthor(String, Node, Pageable, ContextInfo) and is used for its paging implementation.
      Parameters:
      author - the Import.getAuthor() to filter results by
      filters - additional filters to apply, must not be null
      contextInfo - 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 the NotificationState for ImportDeleteSandboxRequestProducer.TYPE on the given import if it is found to have a Import.status of ImportStatus.FAILED.
      Specified by:
      initializeDeleteSandboxNotificationState in interface CustomizedImportRepository<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 as readAll(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)