public class TenantPersistenceHandler extends Object implements com.broadleafcommerce.common.messaging.PersistenceHandler
Specialized PersistenceHandler
that 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, an ApplicationEvent
is published representing what changed.
As a result of updating this tenant domain, there might also be tenant-discriminated entities
(entities that have TrackableBehavior.CATALOG
or TrackableBehavior.APPLICATION
modifiers on them) that care about this hierarchy. If this is the case, you can listen to the
ApplicationEvent
s 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; }@EventListener
protected void updateItems(CatalogChangedEvent changed) { catalogChangeHelper.sync(changed.getCatalog(), itemRepository.getEntityInformation().getJavaType(), changed.getOperationType()); } }
CatalogChangeHelper.sync(Trackable, Class, boolean)
synchronizes the entity-specific
store for any TrackableBehavior.CATALOG
enabled entities.ConditionalOnTenantSynchronization
,
CatalogChangeHelper
Modifier and Type | Field and Description |
---|---|
static String |
JPA_TENANT_APPLICATION_TYPE |
static String |
JPA_TENANT_CATALOG_TYPE |
static String |
JPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE |
Constructor and 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) |
Modifier and Type | Method and Description |
---|---|
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
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.
|
void |
hook(String entityJson) |
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.
|
protected List<String> |
ignoreRoutes() |
void |
init() |
protected boolean |
isApplicationProcessingValid() |
protected boolean |
isCatalogProcessingValid() |
boolean |
isValidType(String reportedType,
String projectionType) |
void |
processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) |
void |
setApplicationCatalogRepository(CommonMarketplaceApplicationCatalogRepository<Trackable> applicationCatalogRepository) |
void |
setCacheManager(org.springframework.cache.CacheManager cacheManager) |
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.
|
void |
setSupportedTenantApplicationTypes(String[] supportedTenantApplicationTypes)
The fully qualified class names of application domain type from the tenant service that this
tenant listener should look for.
|
void |
setSupportedTenantCatalogTypes(String[] supportedTenantCatalogTypes)
The fully qualified class names of catalog domain type from the tenant service that this
tenant listener should look for.
|
protected void |
updateCache(Trackable existingInstance)
Update Spring CacheManager to groom caches related to this entity persistence
|
public static final String JPA_TENANT_APPLICATION_TYPE
public static final String JPA_TENANT_CATALOG_TYPE
public static final String JPA_TENANT_MARKETPLACE_APPLICATION_CATALOG_TYPE
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)
@PostConstruct public void init()
@StreamListener(value="persistenceInputTenantSyncDataTracking") public void hook(String entityJson)
hook
in interface com.broadleafcommerce.common.messaging.PersistenceHandler
@Autowired public void setCacheManager(@Nullable org.springframework.cache.CacheManager cacheManager)
public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)
processStateChange
in interface com.broadleafcommerce.common.messaging.PersistenceHandler
protected boolean isApplicationProcessingValid()
protected boolean isCatalogProcessingValid()
public boolean isValidType(String reportedType, @Nullable String projectionType)
isValidType
in interface com.broadleafcommerce.common.messaging.PersistenceHandler
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
getObjectMapper
in interface com.broadleafcommerce.common.messaging.PersistenceHandler
public String[] getSupportedSimpleTypeNames()
getSupportedSimpleTypeNames
in interface com.broadleafcommerce.common.messaging.PersistenceHandler
public String[] getSupportedTenantApplicationTypes()
JPA_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.public void setSupportedTenantApplicationTypes(String[] supportedTenantApplicationTypes)
JPA_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.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.public String[] getSupportedTenantApplicationCatalogTypes()
JPA_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.public void setSupportedTenantApplicationCatalogTypes(String[] supportedTenantApplicationCatalogTypes)
JPA_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.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.public String[] getSupportedTenantCatalogTypes()
JPA_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.public void setSupportedTenantCatalogTypes(String[] supportedTenantCatalogTypes)
JPA_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.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.protected void updateCache(Trackable existingInstance)
existingInstance
- The tenant related entity being persistedprotected Trackable hydrateFromJson(com.fasterxml.jackson.databind.JsonNode entityJson, Class<?> domainType, com.fasterxml.jackson.databind.ObjectMapper mapper)
entityJson
- The JSON representation of the entitydomainType
- The repository specific domain class typemapper
- The Jackson mapper instance that can facilitate conversion@Autowired public void setApplicationCatalogRepository(@Nullable CommonMarketplaceApplicationCatalogRepository<Trackable> applicationCatalogRepository)
Copyright © 2021. All rights reserved.