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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTenantVendorNotificationHandler(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 voidarchiveAll(String vendorRef, String tenant) Archives allMarketplaceApplicationCatalogentities corresponding to the givenvendorRef.protected voidbuildApplicationCatalogs(@NonNull Catalog parent, @NonNull List<String> applicationIds) Builds the connections between the Vendor'sCatalogand the Vendor's marketplaceApplications.protected com.broadleafcommerce.data.tracking.core.context.ContextInfobuildContextInfo(@NonNull String tenantId, @NonNull com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Builds aContextInfofor CRUD operations.protected CatalogcreateCatalog(@NonNull com.fasterxml.jackson.databind.JsonNode entityJson) Creates aCatalogfor the Vendor and associates it with the relevant MarketplaceApplication.protected com.broadleafcommerce.data.tracking.core.TrackablefetchExistingSystemCreatedCatalogMatchingVendorRef(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 MarketplaceDiscovererprotected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManagercom.fasterxml.jackson.databind.ObjectMapperString[]protected StringgetSystemGeneratedVendorCatalogId(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.TransactionTemplateprotected com.broadleafcommerce.common.extension.TypeFactoryvoidvoidprocessStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) voidsetHandlerProperties(TenantVendorNotificationHandlerProperties handlerProperties) protected voidupdateIfApplicable(@NonNull Catalog catalog, String vendorName) Updates thecatalogif it needs to be.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
hookin interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
processStateChange
public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson) - Specified by:
processStateChangein 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,
nullotherwise - 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:
getSupportedSimpleTypeNamesin interfacecom.broadleafcommerce.common.messaging.PersistenceHandler
-
updateIfApplicable
Updates thecatalogif 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 aCatalogfor the Vendor and associates it with the relevant MarketplaceApplication.- Parameters:
entityJson- The Vendor notification payload- Returns:
- The new
Catalog
-
archiveAll
Archives allMarketplaceApplicationCatalogentities 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'sCatalogand 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 aContextInfofor 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:
getObjectMapperin 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)
-