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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJpaCustomizedCatalogRepository(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 Summary
Modifier and TypeMethodDescriptionvoidvoidbulkUpdateApplicationCatalogRefByCatalog(Catalog updatedCatalog) Bulk updatesApplicationCatalogRef.namefor entries whose context id matches the given updated catalog idfindAllByContextIdInAndHiddenNot(List<String> catalogIds, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) org.springframework.data.domain.Page<D>findAllByOwningApplicationIsNullAndHiddenNot(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) findByTypeAndTenantIdAndOwningApplicationIsNull(String catalogType, String tenantId) Finds all catalogs by type and tenant ID that do not belong to an application.findDirectChildren(String parentCatalogContextId) Find direct, unarchived, children for the given catalog ID.protected com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtilprotected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilderprotected jakarta.persistence.EntityManagerprotected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelperprotected JpaCatalogRepository<D>protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManagerprotected cz.jirutka.rsql.parser.ast.RSQLVisitor<jakarta.persistence.criteria.Predicate,Class<?>> protected com.broadleafcommerce.data.tracking.jpa.persistence.NativeSqlStrategyManagerprotected voidInitialize or reset theNotificationStateforPersistenceProducer.TYPEon the givencatalog'sTrackable.getNotificationStates().protected booleanisDefaultCurrencyChanged(D catalog) Determine if the default currency has changed for the passed catalog by evaluating itstrackinginformation.protected voidSend a message covering the changed catalog state via thePersistenceProducerchannel.protected voidprocessChild(Map<String, Long> levels, D deepChild) Update and persist theJpaTenantCatalog.getLevel()value for the passedJpaTenantCatalogby evaluating theJpaTenantCatalog.getParents()and their levels.readCatalogRelationships(@NonNull String catalogId) Given a catalog ID, read itself and all catalogs that are descendants (direct or indirect) of it.com.broadleafcommerce.data.tracking.core.Trackablesave(com.broadleafcommerce.data.tracking.core.Trackable catalog, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Iterable<com.broadleafcommerce.data.tracking.core.Trackable>saveAll(Iterable<com.broadleafcommerce.data.tracking.core.Trackable> trackable, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected DsaveInternal(D catalog, boolean isCreate) voidsetNotificationManager(com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager) voidsetRepository(JpaCatalogRepository<D> repository) voidsetRepositoryEntityTypeManager(com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager) protected voidsetTimestampToNow(D catalog) Sets the value ofJpaTenantCatalog.getTimestamp()toInstant.now()on the given catalog.protected booleanshouldUpdateImplicitCatalogs(D catalog) Whether this catalog's implicit catalogs should be updated based on changes to this catalog.protected DupdateBasedOnParents(D catalog, boolean isCreate) Update and persist theJpaTenantCatalog.getLevel()value for the passedJpaTenantCatalogby evaluating theJpaTenantCatalog.getParents()and their levels.protected voidupdateChildLevels(D catalog) Increment theJpaTenantCatalog.getLevel()values for all children of the passedJpaTenantCatalog.protected voidupdateImplicitCatalog(D implicitCatalog, D parentCatalog, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Updates the implicit catalog based on the parent catalog.protected voidupdateImplicitCatalogsIfNeeded(D catalog, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Cascade changes to implicit catalogs from a catalog
-
Field Details
-
CHILD_CATALOGS_SQL
- See Also:
-
CATALOG_RELATIONSHIPS_SQL
- See Also:
-
APPLICATION_CATALOG_REF_BULK_UPDATE_SQL
- See Also:
-
IMPLICIT_CATALOGS_FOR_CATALOG_SQL
- See Also:
-
-
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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
setNotificationManager
@Autowired public void setNotificationManager(@Nullable com.broadleafcommerce.common.messaging.notification.NotificationManager notificationManager) -
readCatalogRelationships
Description copied from interface:CustomizedCatalogRepositoryGiven 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:
readCatalogRelationshipsin interfaceCustomizedCatalogRepository<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
-
findByTypeAndTenantIdAndOwningApplicationIsNull
@NonNull public List<D> findByTypeAndTenantIdAndOwningApplicationIsNull(@NonNull String catalogType, @Nullable String tenantId) Description copied from interface:CustomizedCatalogRepositoryFinds all catalogs by type and tenant ID that do not belong to an application.- Specified by:
findByTypeAndTenantIdAndOwningApplicationIsNullin interfaceCustomizedCatalogRepository<D extends JpaTenantCatalog>- Parameters:
catalogType- the catalog type to filter ontenantId- 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:CustomizedCatalogRepositoryFind 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:
findDirectChildrenin interfaceCustomizedCatalogRepository<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 fromcontextInfo- 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 updateparentCatalog- the parent catalog to update fromcontextInfo- the contextInfo for the request
-
shouldUpdateImplicitCatalogs
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
Determine if the default currency has changed for the passed catalog by evaluating itstrackinginformation.- Parameters:
catalog- The catalog to evaluate- Returns:
- true if the default currency has changed, false otherwise
-
saveAll
-
bulkUpdateApplicationCatalogRefByCatalog
@Transactional public void bulkUpdateApplicationCatalogRefByCatalog(@NonNull Catalog updatedCatalog) Description copied from interface:CustomizedCatalogRepositoryBulk updatesApplicationCatalogRef.namefor entries whose context id matches the given updated catalog id- Specified by:
bulkUpdateApplicationCatalogRefByCatalogin interfaceCustomizedCatalogRepository<D extends JpaTenantCatalog>- Parameters:
updatedCatalog- the updated catalog
-
updateChildLevels
Increment theJpaTenantCatalog.getLevel()values for all children of the passedJpaTenantCatalog.- 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
Update and persist theJpaTenantCatalog.getLevel()value for the passedJpaTenantCatalogby evaluating theJpaTenantCatalog.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 updatedisCreate- Whether or not the passed catalog is new
-
notify
Send a message covering the changed catalog state via thePersistenceProducerchannel.- Parameters:
catalog- The changed catalog instance
-
processChild
Update and persist theJpaTenantCatalog.getLevel()value for the passedJpaTenantCatalogby evaluating theJpaTenantCatalog.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
Initialize or reset theNotificationStateforPersistenceProducer.TYPEon the givencatalog'sTrackable.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
Sets the value ofJpaTenantCatalog.getTimestamp()toInstant.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
-
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
-
setRepository
-
setRepositoryEntityTypeManager
@Autowired @Lazy public void setRepositoryEntityTypeManager(com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager) -
getRepositoryEntityTypeManager
protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager getRepositoryEntityTypeManager()
-