Class JpaCustomizedCatalogRepository<D extends JpaTenantCatalog>

java.lang.Object
com.broadleafcommerce.tenant.provider.jpa.repository.JpaCustomizedCatalogRepository<D>
All Implemented Interfaces:
CustomizedCatalogRepository<D>, org.springframework.beans.factory.InitializingBean

public class JpaCustomizedCatalogRepository<D extends JpaTenantCatalog> extends Object implements org.springframework.beans.factory.InitializingBean, CustomizedCatalogRepository<D>
Fragment repository override to handle specialized persistence behavior for JpaTenantCatalog instances.
Author:
Jeff Fischer
  • Field Details

  • Constructor Details

    • JpaCustomizedCatalogRepository

      public JpaCustomizedCatalogRepository(com.broadleafcommerce.data.tracking.jpa.persistence.NativeSqlStrategyManager sqlStrategyManager, cz.jirutka.rsql.parser.ast.RSQLVisitor<jakarta.persistence.criteria.Predicate,Class<?>> rsqlVisitor, com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder builder)
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • setNotificationManager

      @Autowired public void setNotificationManager(@Nullable com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager)
    • readCatalogRelationships

      @NonNull public List<String> readCatalogRelationships(@NonNull @NonNull @NonNull String catalogId)
      Description copied from interface: CustomizedCatalogRepository
      Given a catalog ID, read itself and all catalogs that are descendants (direct or indirect) of it. Order is not guaranteed.

      For example, given catalog IDs A, B, and C, and a catalog graph of A <- B <- C (with A being the parent of B and B the parent of C):

      • a query of 'A' will return A, B, and C
      • a query of 'B' will return B and C
      • a query of 'C' will return C
      Specified by:
      readCatalogRelationships in interface CustomizedCatalogRepository<D extends JpaTenantCatalog>
      Parameters:
      catalogId - The ID of the catalog for which to read descendants.
      Returns:
      A list of catalog IDs for which to read descendants
    • findAllByOwningApplicationIsNullAndHiddenNot

      @NonNull public org.springframework.data.domain.Page<D> findAllByOwningApplicationIsNullAndHiddenNot(@Nullable cz.jirutka.rsql.parser.ast.Node filters, @NonNull org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • findAllByContextIdInAndHiddenNot

      @NonNull public List<D> findAllByContextIdInAndHiddenNot(@NonNull List<String> catalogIds, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • findByTypeAndTenantIdAndOwningApplicationIsNull

      @NonNull public List<D> findByTypeAndTenantIdAndOwningApplicationIsNull(@NonNull String catalogType, @Nullable String tenantId)
      Description copied from interface: CustomizedCatalogRepository
      Finds all catalogs by type and tenant ID that do not belong to an application.
      Specified by:
      findByTypeAndTenantIdAndOwningApplicationIsNull in interface CustomizedCatalogRepository<D extends JpaTenantCatalog>
      Parameters:
      catalogType - the catalog type to filter on
      tenantId - the tenant ID to filter on
      Returns:
      all catalogs by type and tenant ID that do not belong to an application
    • findDirectChildren

      @NonNull public List<org.apache.commons.lang3.tuple.Pair<String,String>> findDirectChildren(@NonNull String parentCatalogContextId)
      Description copied from interface: CustomizedCatalogRepository
      Find direct, unarchived, children for the given catalog ID. For all direct children, a list of child catalog ID/name pairs will be returned.
      Specified by:
      findDirectChildren in interface CustomizedCatalogRepository<D extends JpaTenantCatalog>
      Parameters:
      parentCatalogContextId - the catalog id
      Returns:
      a list of child catalog IDs if any exist, otherwise an empty list
    • save

      public com.broadleafcommerce.data.tracking.core.Trackable save(com.broadleafcommerce.data.tracking.core.Trackable catalog, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • updateImplicitCatalogsIfNeeded

      protected void updateImplicitCatalogsIfNeeded(D catalog, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Cascade changes to implicit catalogs from a catalog
      Parameters:
      catalog - the catalog to cascade changes from
      contextInfo - the contextInfo for the request
    • updateImplicitCatalog

      protected void updateImplicitCatalog(D implicitCatalog, D parentCatalog, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the implicit catalog based on the parent catalog.

      By default, only the default currency is updated.

      Parameters:
      implicitCatalog - the implicit catalog to update
      parentCatalog - the parent catalog to update from
      contextInfo - the contextInfo for the request
    • shouldUpdateImplicitCatalogs

      protected boolean shouldUpdateImplicitCatalogs(D catalog)
      Whether this catalog's implicit catalogs should be updated based on changes to this catalog.

      By default, only changes to the default currency trigger an update.

      Parameters:
      catalog - the catalog to evaluate
      Returns:
      true if implicit catalogs should be updated, false otherwise
    • isDefaultCurrencyChanged

      protected boolean isDefaultCurrencyChanged(D catalog)
      Determine if the default currency has changed for the passed catalog by evaluating its tracking information.
      Parameters:
      catalog - The catalog to evaluate
      Returns:
      true if the default currency has changed, false otherwise
    • saveAll

      public Iterable<com.broadleafcommerce.data.tracking.core.Trackable> saveAll(@NonNull Iterable<com.broadleafcommerce.data.tracking.core.Trackable> trackable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • bulkUpdateApplicationCatalogRefByCatalog

      @Transactional public void bulkUpdateApplicationCatalogRefByCatalog(@NonNull Catalog updatedCatalog)
      Description copied from interface: CustomizedCatalogRepository
      Bulk updates ApplicationCatalogRef.name for entries whose context id matches the given updated catalog id
      Specified by:
      bulkUpdateApplicationCatalogRefByCatalog in interface CustomizedCatalogRepository<D extends JpaTenantCatalog>
      Parameters:
      updatedCatalog - the updated catalog
    • updateChildLevels

      protected void updateChildLevels(D catalog)
      Increment the JpaTenantCatalog.getLevel() values for all children of the passed JpaTenantCatalog.
      Parameters:
      catalog - The parent catalog for whom all children should be update for level values. This includes deep children (i.e. children that are greater than immediate descendants).
    • updateBasedOnParents

      protected D updateBasedOnParents(D catalog, boolean isCreate)
      Update and persist the JpaTenantCatalog.getLevel() value for the passed JpaTenantCatalog by evaluating the JpaTenantCatalog.getParents() and their levels. Generally, this catalog's level should be incremented greater than the max level displayed in the parents.
      Parameters:
      catalog - The catalog whose level value should be updated
      isCreate - Whether or not the passed catalog is new
    • notify

      protected void notify(D catalog)
      Send a message covering the changed catalog state via the PersistenceProducer channel.
      Parameters:
      catalog - The changed catalog instance
    • processChild

      protected void processChild(Map<String,Long> levels, D deepChild)
      Update and persist the JpaTenantCatalog.getLevel() value for the passed JpaTenantCatalog by evaluating the JpaTenantCatalog.getParents() and their levels. Generally, this catalog's level should be incremented greater than the max level displayed in the parents. The passed catalog is considered a deep child of the originally changed catalog.
      Parameters:
      levels - Library of contextIds to levels. Generally used during review of the passed catalog's parents.
      deepChild - A child catalog of the originally changed catalog. This is possibly a deep child (i.e. not an immediate child of the original).
    • initializeOrResetPersistenceNotificationState

      protected void initializeOrResetPersistenceNotificationState(D catalog)
      Initialize or reset the NotificationState for PersistenceProducer.TYPE on the given catalog's Trackable.getNotificationStates(). This ensures that the notification state will be considered fresh and a message will be emitted.

      This can be important if the catalog has not gone through the standard mapping flow which would otherwise be responsible for doing this.

      Parameters:
      catalog - the catalog for which the persistence notification state should be initialized or reset
    • setTimestampToNow

      protected void setTimestampToNow(D catalog)
      Sets the value of JpaTenantCatalog.getTimestamp() to Instant.now() on the given catalog.

      This can be important if the catalog has not gone through the standard mapping flow which would otherwise be responsible for doing this.

      Parameters:
      catalog - the catalog for which the timestamp should be set
    • saveInternal

      protected D saveInternal(D catalog, boolean isCreate)
    • getManagedType

      protected Class<D> getManagedType()
    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()
    • getSqlStrategyManager

      protected com.broadleafcommerce.data.tracking.jpa.persistence.NativeSqlStrategyManager getSqlStrategyManager()
    • getRsqlVisitor

      protected cz.jirutka.rsql.parser.ast.RSQLVisitor<jakarta.persistence.criteria.Predicate,Class<?>> getRsqlVisitor()
    • getBehaviorUtil

      protected com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil getBehaviorUtil()
    • getBuilder

      protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder getBuilder()
    • getHelper

      protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper getHelper()
    • getRepository

      protected JpaCatalogRepository<D> getRepository()
    • setRepository

      @Autowired @Lazy public void setRepository(JpaCatalogRepository<D> repository)
    • setRepositoryEntityTypeManager

      @Autowired @Lazy public void setRepositoryEntityTypeManager(com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager)
    • getRepositoryEntityTypeManager

      protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager getRepositoryEntityTypeManager()