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 Details

  • 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

      @StreamListener("vendorNotificationInputTenant") public void hook(String entityJson)
      Specified by:
      hook in interface com.broadleafcommerce.common.messaging.PersistenceHandler
    • processStateChange

      public void processStateChange(com.fasterxml.jackson.databind.JsonNode entityJson)
      Specified by:
      processStateChange in interface com.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 for
      tenantId - the tenant to search for the catalog in
      Returns:
      the existing system-created catalog for the vendor if found, null otherwise
      See Also:
    • getSystemGeneratedVendorCatalogId

      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. This is the mechanism used since version 1.7.6.
      Parameters:
      vendorRef - the vendor ref for which to get the system generated vendor catalog ID
      tenantId - 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

      public String[] getSupportedSimpleTypeNames()
      Specified by:
      getSupportedSimpleTypeNames in interface com.broadleafcommerce.common.messaging.PersistenceHandler
    • updateIfApplicable

      protected void updateIfApplicable(@NonNull @NonNull Catalog catalog, String vendorName)
      Updates the catalog if it needs to be.
      Parameters:
      catalog - The Vendor's Catalog
      vendorName - The name of the Vendor
    • createCatalog

      protected Catalog createCatalog(@NonNull @NonNull com.fasterxml.jackson.databind.JsonNode entityJson)
      Creates a Catalog for the Vendor and associates it with the relevant Marketplace Application.
      Parameters:
      entityJson - The Vendor notification payload
      Returns:
      The new Catalog
    • archiveAll

      protected void archiveAll(String vendorRef, String tenant)
      Archives all MarketplaceApplicationCatalog entities corresponding to the given vendorRef.
      Parameters:
      vendorRef - the vendor ref of the vendor that was archived
      tenant - 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's Catalog and the Vendor's marketplace Applications.
      Parameters:
      parent - The Vendor's main catalog
      applicationIds - The Marketplace Application'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 a ContextInfo for CRUD operations.
      Parameters:
      tenantId - The tenant's ID
      operationType - The type of operation
      Returns:
      The context info to use for CRUD operations.
    • getCatalogService

      protected CatalogService<Catalog> 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 interface com.broadleafcommerce.common.messaging.PersistenceHandler
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getMapperManager

      protected com.broadleafcommerce.data.tracking.core.mapping.DomainMapperManager getMapperManager()
    • getDiscoverer

      protected MarketplaceDiscoverer getDiscoverer()
    • getHandlerProperties

      protected TenantVendorNotificationHandlerProperties getHandlerProperties()
    • setHandlerProperties

      @Autowired public void setHandlerProperties(TenantVendorNotificationHandlerProperties handlerProperties)