Class CatalogDiscriminatedEntityVendorVisibilityHandler

java.lang.Object
com.broadleafcommerce.data.tracking.core.marketplace.vendor.visibility.catalog.CatalogDiscriminatedEntityVendorVisibilityHandler
All Implemented Interfaces:
com.broadleafcommerce.common.extension.data.DataRoutePartitionAware, VendorVisibilityHandler, org.springframework.core.Ordered

public class CatalogDiscriminatedEntityVendorVisibilityHandler extends Object implements VendorVisibilityHandler
Responsible for performing vendor-visibility operations on catalog-discriminated entities.

Catalog-discriminated entities are implicitly associated to vendors through their catalog's Catalog.getVendorRef(). This handler is capable of taking a set of vendors and determining the catalog IDs associated to those vendors. Whether or not an entity is within a vendor can then be determined by comparing its catalog ID.

Since many services may not want to participate in this behavior, this component is not registered as a bean by default. Consumers must manually define this bean in their configurations.

  • Constructor Details

  • Method Details

    • canHandle

      public boolean canHandle(@NonNull @NonNull Class<?> persistedDomainEntityType)
      If the persistedDomainEntityType is catalog discriminated, this handler supports it.
      Specified by:
      canHandle in interface VendorVisibilityHandler
      Parameters:
      persistedDomainEntityType - the type to check support for
      Returns:
      true if the trackable behavior is catalog-discriminated, false otherwise
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface org.springframework.core.Ordered
      Specified by:
      getOrder in interface VendorVisibilityHandler
    • getDataRoutePartition

      public String getDataRoutePartition()
      Specified by:
      getDataRoutePartition in interface com.broadleafcommerce.common.extension.data.DataRoutePartitionAware
    • isEntityMutableByVendorRestrictions

      public boolean isEntityMutableByVendorRestrictions(@NonNull @NonNull Object persistedDomainEntity, @NonNull @NonNull Set<String> restrictedVendorRefs, @Nullable ContextInfo contextInfo)
      This method always returns true.

      Catalog is a special case for vendor discrimination since it's a first-class citizen of ContextRequest and VendorAwareTrackablePolicyUtils is directly knowledgeable about it. The mutability of a catalog-discriminated entity is determined via InheritanceLines.mutabilityType(String) of the ContextRequest.getCatalog() in comparison to the entity's Tracking.getCatalog(). This is already checked by VendorAwareTrackablePolicyUtils, and thus rather than re-defining all of that validation here, we simply return true to allow policy to drive the response.

      This is safe since the visibility of ContextRequest.getCatalog() itself is also validated by VendorAwareTrackablePolicyUtils with consideration for vendor restrictions.

      Specified by:
      isEntityMutableByVendorRestrictions in interface VendorVisibilityHandler
      Parameters:
      persistedDomainEntity - the persisted-domain entity to validate visibility for. This is guaranteed to only be an entity for which canHandle(Class) returns true.
      restrictedVendorRefs - the "vendorRef" (typically a vendor ID or code) of all vendors that visibility should be restricted to. Will never be empty.
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      true
      See Also:
    • createVendorNarrowingFilter

      public String createVendorNarrowingFilter(@NonNull @NonNull Set<String> restrictedVendorRefs, @Nullable ContextInfo contextInfo)
      Builds a filter on tracking.catalog.contextId that serves as an "upper bound" to possible catalogs the results can come from.

      The narrowing filter cannot just only allow the directly assigned vendor catalog IDs. A vendor catalog may inherit from a non-vendor catalog, and thus for the purpose of reading data, it should be possible for results to contain records from the non-vendor parent catalogs. Thus we fetch those ancestor catalog IDs and include them as possible valid values for our narrowing filter.

      Specified by:
      createVendorNarrowingFilter in interface VendorVisibilityHandler
      Parameters:
      restrictedVendorRefs - the "vendorRef" (typically a vendor ID or code) of all vendors that the results need to be restricted to. Will never be empty.
      contextInfo - context information surrounding sandboxing/multitenant state. Some implementations may inform their filtration decisions with this.
      Returns:
      a Node filter string that can be used to restrict results on supported entity type(s) to only include data from the restrictedVendorRefs. Cannot return null.
      See Also:
    • buildCatalogIdFilter

      protected String buildCatalogIdFilter(@NonNull @NonNull Set<String> catalogIds)
    • getAssociatedVendorRef

      @Nullable public String getAssociatedVendorRef(Object persistedDomainEntity, @Nullable ContextInfo contextInfo)
      Description copied from interface: VendorVisibilityHandler
      Given a persistedDomainEntity, determine what vendor it is associated to (if any).
      Specified by:
      getAssociatedVendorRef in interface VendorVisibilityHandler
      Parameters:
      persistedDomainEntity - the persisted-domain entity to determine the vendor association for
      contextInfo - context information surrounding multitenant state
      Returns:
      the vendorRef that the given entity is associated to, or null if not associated to a vendor
      See Also:
    • getTrackableBehaviorUtil

      protected TrackableBehaviorUtil getTrackableBehaviorUtil()
    • getCatalogService

      protected CommonCatalogService<Catalog> getCatalogService()