Class TenantVendorNotificationHandler
java.lang.Object
com.broadleafcommerce.tenant.service.messaging.vendor.TenantVendorNotificationHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.messaging.PersistenceHandler
@DataRouteByKey("tenant")
public class TenantVendorNotificationHandler
extends Object
implements com.broadleafcommerce.common.messaging.PersistenceHandler
Event listener that listens for a VendorCreationEvent and is responsible for setting up a new
catalog for the vendor.
- Author:
- Jon Fleschler (jfleschler), Jeff Fischer
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTenantVendorNotificationHandler
(CatalogService<Catalog> catalogService, CatalogRepository<com.broadleafcommerce.data.tracking.core.Trackable> catalogRepository, MarketplaceApplicationCatalogService<MarketplaceApplicationCatalog> marketplaceApplicationCatalogService, org.springframework.transaction.support.TransactionTemplate template, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager mapperManager, MarketplaceDiscoverer discoverer) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
archiveAll
(String vendorRef, String tenant) Archives allMarketplaceApplicationCatalog
entities corresponding to the givenvendorRef
.protected void
buildApplicationCatalogs
(@NonNull Catalog parent, @NonNull List<String> applicationIds) Builds the connections between the Vendor'sCatalog
and the Vendor's marketplaceApplications
.protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildContextInfo
(@NonNull String tenantId, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Builds aContextInfo
for CRUD operations.protected Catalog
createCatalog
(@NonNull com.fasterxml.jackson.databind.JsonNode entityJson) Creates aCatalog
for the Vendor and associates it with the relevant MarketplaceApplication
.protected com.broadleafcommerce.data.tracking.core.Trackable
fetchExistingSystemCreatedCatalogMatchingVendorRef
(String vendorRef, String tenantId) When a vendor is persisted, the system automatically creates a vendor catalog for it.protected CatalogRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected CatalogService<Catalog>
protected MarketplaceDiscoverer
protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager
com.fasterxml.jackson.databind.ObjectMapper
String[]
protected String
getSystemGeneratedVendorCatalogId
(String vendorRef, String tenantId) Get the consistent, unique string that can be used to identify the system-generated vendor catalog for a particular vendor.protected org.springframework.transaction.support.TransactionTemplate
protected com.broadleafcommerce.common.extension.TypeFactory
void
void
processStateChange
(com.fasterxml.jackson.databind.JsonNode entityJson) void
setHandlerProperties
(TenantVendorNotificationHandlerProperties handlerProperties) protected void
updateIfApplicable
(@NonNull Catalog catalog, String vendorName) Updates thecatalog
if it needs to be.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.common.messaging.PersistenceHandler
handle, isValidType, validate
-
Field Details
-
JPA_VENDOR_TYPE
- See Also:
-
-
Constructor Details
-
TenantVendorNotificationHandler
public TenantVendorNotificationHandler(CatalogService<Catalog> catalogService, CatalogRepository<com.broadleafcommerce.data.tracking.core.Trackable> catalogRepository, MarketplaceApplicationCatalogService<MarketplaceApplicationCatalog> marketplaceApplicationCatalogService, org.springframework.transaction.support.TransactionTemplate template, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager mapperManager, MarketplaceDiscoverer discoverer)
-
-
Method Details
-
hook
- Specified by:
hook
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
processStateChange
public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) - Specified by:
processStateChange
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
fetchExistingSystemCreatedCatalogMatchingVendorRef
@Nullable protected com.broadleafcommerce.data.tracking.core.Trackable fetchExistingSystemCreatedCatalogMatchingVendorRef(String vendorRef, String tenantId) When a vendor is persisted, the system automatically creates a vendor catalog for it. This method attempts to fetch the existing system-created vendor catalog (if present). However, there are some additional considerations involved:- There may be additional catalogs for the same vendor created manually by users. Thus, we need a mechanism to consistently identify the system-generated catalog for idempotency, ignoring the user-created vendor catalogs.
- Prior to TenantServices 1.7.6, the logic in this component directly used 'vendorRef' as the ID for the system-generated catalog. Thus, backwards compatibility needs to be preserved for catalogs that have already been created with that mechanism.
- Starting with VendorServices 1.7.0, vendorRef can be up to 255 characters in length, which exceeds the length constraints for the catalog ID column.
- Parameters:
vendorRef
- the vendor ref to find the existing system created catalog fortenantId
- the tenant to search for the catalog in- Returns:
- the existing system-created catalog for the vendor if found,
null
otherwise - See Also:
-
getSystemGeneratedVendorCatalogId
Get the consistent, unique string that can be used to identify the system-generated vendor catalog for a particular vendor. This is the mechanism used since version 1.7.6.- Parameters:
vendorRef
- the vendor ref for which to get the system generated vendor catalog IDtenantId
- the tenant ID for which to get the system generated vendor catalog ID- Returns:
- a consistent ID that can be used to identify the system-generated vendor catalog for the vendor
- See Also:
-
getSupportedSimpleTypeNames
- Specified by:
getSupportedSimpleTypeNames
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
updateIfApplicable
Updates thecatalog
if it needs to be.- Parameters:
catalog
- The Vendor's CatalogvendorName
- The name of the Vendor
-
createCatalog
protected Catalog createCatalog(@NonNull @NonNull com.fasterxml.jackson.databind.JsonNode entityJson) Creates aCatalog
for the Vendor and associates it with the relevant MarketplaceApplication
.- Parameters:
entityJson
- The Vendor notification payload- Returns:
- The new
Catalog
-
archiveAll
Archives allMarketplaceApplicationCatalog
entities corresponding to the givenvendorRef
.- Parameters:
vendorRef
- the vendor ref of the vendor that was archivedtenant
- the tenant ID in which the vendor existed
-
buildApplicationCatalogs
protected void buildApplicationCatalogs(@NonNull @NonNull Catalog parent, @NonNull @NonNull List<String> applicationIds) Builds the connections between the Vendor'sCatalog
and the Vendor's marketplaceApplications
.- Parameters:
parent
- The Vendor's main catalogapplicationIds
- The MarketplaceApplication's IDs
.
-
buildContextInfo
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfo(@NonNull @NonNull String tenantId, @NonNull @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Builds aContextInfo
for CRUD operations.- Parameters:
tenantId
- The tenant's IDoperationType
- The type of operation- Returns:
- The context info to use for CRUD operations.
-
getCatalogService
-
getCatalogRepository
protected CatalogRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCatalogRepository() -
getMarketplaceApplicationCatalogService
protected MarketplaceApplicationCatalogService<MarketplaceApplicationCatalog> getMarketplaceApplicationCatalogService() -
getTemplate
protected org.springframework.transaction.support.TransactionTemplate getTemplate() -
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()- Specified by:
getObjectMapper
in interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getMapperManager
protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager getMapperManager() -
getDiscoverer
-
getHandlerProperties
-
setHandlerProperties
@Autowired public void setHandlerProperties(TenantVendorNotificationHandlerProperties handlerProperties)
-