Class TenantPersistenceHandler
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.tenant.service.TenantPersistenceHandler
-
- All Implemented Interfaces:
com.broadleafcommerce.common.messaging.PersistenceHandler
public class TenantPersistenceHandler extends Object implements com.broadleafcommerce.common.messaging.PersistenceHandler
Specialized
PersistenceHandlerthat listens specifically for repository changes to tenant domain. This allows other microservices to synchronize changes to tenant hierarchies and assignments within their local persistent stores. Once the local tenant persistent store is updated, anApplicationEventis published representing what changed.As a result of updating this tenant domain, there might also be tenant-discriminated entities (entities that have
TrackableBehavior.CATALOGorTrackableBehavior.APPLICATIONmodifiers on them) that care about this hierarchy. If this is the case, you can listen to theApplicationEvents that this class publishes:An example is to synchronize repository domain when a catalog hierarchy is updated:
public class ItemCatalogChangeListener { private final CatalogChangeHelper catalogChangeHelper;Theprivate final ItemRepository<Trackable> itemRepository;public TestTenantPersistenceHandler(ItemRepository<Trackable> itemRepository,CatalogChangeHelper catalogChangeHelper) { this.catalogChangeHelper = catalogChangeHelper; this.itemRepository = itemRepository; }@EventListenerprotected void updateItems(CatalogChangedEvent changed) { catalogChangeHelper.sync(changed.getCatalog(), itemRepository.getEntityInformation().getJavaType(), changed.getOperationType()); } }CatalogChangeHelper.sync(Trackable, Class, boolean)synchronizes the entity-specific store for anyTrackableBehavior.CATALOGenabled entities.- Author:
- Jeff Fischer, Phillip Verheyden (phillipuniverse)
- See Also:
ConditionalOnTenantSynchronization,CatalogChangeHelper
-
-
Field Summary
Fields Modifier and Type Field Description static StringJPA_TENANT_APPLICATION_TYPEstatic StringJPA_TENANT_CATALOG_TYPEstatic StringJPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE
-
Constructor Summary
Constructors Constructor Description TenantPersistenceHandler(CommonCatalogRepository<Trackable> catalogRepository, CommonApplicationRepository<Trackable> applicationRepository, DomainMapperManager trackingMapper, org.springframework.context.ApplicationEventPublisher eventPublisher, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<ApplicationDataRouteSupporting> applicationRoutes, List<CatalogDataRouteSupporting> catalogRoutes, org.springframework.core.env.Environment environment)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()String[]getSupportedSimpleTypeNames()String[]getSupportedTenantApplicationCatalogTypes()The fully qualified class names of application catalog domain type from the tenant service that this tenant listener should look for.String[]getSupportedTenantApplicationTypes()The fully qualified class names of application domain type from the tenant service that this tenant listener should look for.String[]getSupportedTenantCatalogTypes()The fully qualified class names of catalog domain type from the tenant service that this tenant listener should look for.voidhook(String entityJson)protected TrackablehydrateFromJson(com.fasterxml.jackson.databind.JsonNode entityJson, Class<?> domainType, com.fasterxml.jackson.databind.ObjectMapper mapper)Create a repository-specific entity instance given a JSON representation.protected List<String>ignoreRoutes()voidinit()protected booleanisApplicationProcessingValid()protected booleanisCatalogProcessingValid()booleanisValidType(String reportedType, String projectionType)voidprocessStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)voidsetApplicationCatalogRepository(CommonMarketplaceApplicationCatalogRepository<Trackable> applicationCatalogRepository)voidsetCacheManager(org.springframework.cache.CacheManager cacheManager)voidsetSupportedTenantApplicationCatalogTypes(String[] supportedTenantApplicationCatalogTypes)The fully qualified class names of application catalog domain type from the tenant service that this tenant listener should look for.voidsetSupportedTenantApplicationTypes(String[] supportedTenantApplicationTypes)The fully qualified class names of application domain type from the tenant service that this tenant listener should look for.voidsetSupportedTenantCatalogTypes(String[] supportedTenantCatalogTypes)The fully qualified class names of catalog domain type from the tenant service that this tenant listener should look for.protected voidupdateCache(Trackable existingInstance)Update Spring CacheManager to groom caches related to this entity persistence
-
-
-
Field Detail
-
JPA_TENANT_APPLICATION_TYPE
public static final String JPA_TENANT_APPLICATION_TYPE
- See Also:
- Constant Field Values
-
JPA_TENANT_CATALOG_TYPE
public static final String JPA_TENANT_CATALOG_TYPE
- See Also:
- Constant Field Values
-
JPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE
public static final String JPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TenantPersistenceHandler
public TenantPersistenceHandler(CommonCatalogRepository<Trackable> catalogRepository, CommonApplicationRepository<Trackable> applicationRepository, DomainMapperManager trackingMapper, org.springframework.context.ApplicationEventPublisher eventPublisher, com.fasterxml.jackson.databind.ObjectMapper objectMapper, List<ApplicationDataRouteSupporting> applicationRoutes, List<CatalogDataRouteSupporting> catalogRoutes, org.springframework.core.env.Environment environment)
-
-
Method Detail
-
init
@PostConstruct public void init()
-
hook
@StreamListener("persistenceInputTenantSyncDataTracking") public void hook(String entityJson)- Specified by:
hookin interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
setCacheManager
@Autowired public void setCacheManager(@Nullable org.springframework.cache.CacheManager cacheManager)
-
processStateChange
public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)
- Specified by:
processStateChangein interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
isApplicationProcessingValid
protected boolean isApplicationProcessingValid()
-
isCatalogProcessingValid
protected boolean isCatalogProcessingValid()
-
isValidType
public boolean isValidType(String reportedType, @Nullable String projectionType)
- Specified by:
isValidTypein interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
- Specified by:
getObjectMapperin interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
getSupportedSimpleTypeNames
public String[] getSupportedSimpleTypeNames()
- Specified by:
getSupportedSimpleTypeNamesin interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
getSupportedTenantApplicationTypes
public String[] getSupportedTenantApplicationTypes()
The fully qualified class names of application domain type from the tenant service that this tenant listener should look for. By default, this will beJPA_TENANT_APPLICATION_TYPEIf an extension of the application domain has been created for the tenant service, then that fully qualified classname should be set on a bean override or this handler.- Returns:
- The one or more application domain types from the tenant service for which sync is supported. Normally, end implementations need only declare the single type they've overridden.
-
setSupportedTenantApplicationTypes
public void setSupportedTenantApplicationTypes(String[] supportedTenantApplicationTypes)
The fully qualified class names of application domain type from the tenant service that this tenant listener should look for. By default, this will beJPA_TENANT_APPLICATION_TYPE. If an extension of the application domain has been created for the tenant service, then that fully qualified classname should be set on a bean override or this handler.- Parameters:
supportedTenantApplicationTypes- The one or more application domain types from the tenant service for which sync is supported. Normally, end implementations need only declare the single type they've overridden.
-
getSupportedTenantApplicationCatalogTypes
public String[] getSupportedTenantApplicationCatalogTypes()
The fully qualified class names of application catalog domain type from the tenant service that this tenant listener should look for. By default, this will beJPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE. If an extension of the application domain has been created for the tenant service, then that fully qualified classname should be set on a bean override or this handler.- Returns:
- The one or more application catalog domain types from the tenant service for which sync is supported. Normally, end implementations need only declare the single type they've overridden.
-
setSupportedTenantApplicationCatalogTypes
public void setSupportedTenantApplicationCatalogTypes(String[] supportedTenantApplicationCatalogTypes)
The fully qualified class names of application catalog domain type from the tenant service that this tenant listener should look for. By default, this will beJPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE. If an extension of the application domain has been created for the tenant service, then that fully qualified classname should be set on a bean override or this handler.- Parameters:
supportedTenantApplicationCatalogTypes- The one or more application catalog domain types from the tenant service for which sync is supported. Normally, end implementations need only declare the single type they've overridden.
-
getSupportedTenantCatalogTypes
public String[] getSupportedTenantCatalogTypes()
The fully qualified class names of catalog domain type from the tenant service that this tenant listener should look for. By default, this will beJPA_TENANT_CATALOG_TYPE. If an extension of the catalog domain has been created for the tenant service, then that fully qualified classname should be set on a bean override or this handler.- Returns:
- The one or more catalog domain types from the tenant service for which sync is supported. Normally, end implementations need only declare the single type they've overridden.
-
setSupportedTenantCatalogTypes
public void setSupportedTenantCatalogTypes(String[] supportedTenantCatalogTypes)
The fully qualified class names of catalog domain type from the tenant service that this tenant listener should look for. By default, this will beJPA_TENANT_CATALOG_TYPE. If an extension of the catalog domain has been created for the tenant service, then that fully qualified classname should be set on a bean override or this handler.- Parameters:
supportedTenantCatalogTypes- The one or more catalog domain types from the tenant service for which sync is supported. Normally, end implementations need only declare the single type they've overridden.
-
updateCache
protected void updateCache(Trackable existingInstance)
Update Spring CacheManager to groom caches related to this entity persistence- Parameters:
existingInstance- The tenant related entity being persisted
-
hydrateFromJson
protected Trackable hydrateFromJson(com.fasterxml.jackson.databind.JsonNode entityJson, Class<?> domainType, com.fasterxml.jackson.databind.ObjectMapper mapper)
Create a repository-specific entity instance given a JSON representation.- Parameters:
entityJson- The JSON representation of the entitydomainType- The repository specific domain class typemapper- The Jackson mapper instance that can facilitate conversion- Returns:
- The instantiated and fully-populated entity instance
-
setApplicationCatalogRepository
@Autowired public void setApplicationCatalogRepository(@Nullable CommonMarketplaceApplicationCatalogRepository<Trackable> applicationCatalogRepository)
-
-