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
'sCatalog.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 Summary
Constructors Constructor Description CatalogDiscriminatedEntityVendorVisibilityHandler(TrackableBehaviorUtil trackableBehaviorUtil, CommonCatalogService<Catalog> catalogService, int order, String dataRoutePartitiion)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
buildCatalogIdFilter(@NonNull Set<String> catalogIds)
boolean
canHandle(@NonNull Class<?> persistedDomainEntityType)
If thepersistedDomainEntityType
is catalog discriminated, this handler supports it.String
createVendorNarrowingFilter(@NonNull Set<String> restrictedVendorRefs, ContextInfo contextInfo)
Builds a filter ontracking.catalog.contextId
that serves as an "upper bound" to possible catalogs the results can come from.String
getAssociatedVendorRef(Object persistedDomainEntity, ContextInfo contextInfo)
Given apersistedDomainEntity
, determine what vendor it is associated to (if any).protected CommonCatalogService<Catalog>
getCatalogService()
String
getDataRoutePartition()
int
getOrder()
protected TrackableBehaviorUtil
getTrackableBehaviorUtil()
boolean
isEntityMutableByVendorRestrictions(@NonNull Object persistedDomainEntity, @NonNull Set<String> restrictedVendorRefs, ContextInfo contextInfo)
This method always returns true.
-
-
-
Constructor Detail
-
CatalogDiscriminatedEntityVendorVisibilityHandler
public CatalogDiscriminatedEntityVendorVisibilityHandler(TrackableBehaviorUtil trackableBehaviorUtil, CommonCatalogService<Catalog> catalogService, int order, String dataRoutePartitiion)
-
-
Method Detail
-
canHandle
public boolean canHandle(@NonNull @NonNull Class<?> persistedDomainEntityType)
If thepersistedDomainEntityType
is catalog discriminated, this handler supports it.- Specified by:
canHandle
in interfaceVendorVisibilityHandler
- 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 interfaceorg.springframework.core.Ordered
- Specified by:
getOrder
in interfaceVendorVisibilityHandler
-
getDataRoutePartition
public String getDataRoutePartition()
- Specified by:
getDataRoutePartition
in interfacecom.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
andVendorAwareTrackablePolicyUtils
is directly knowledgeable about it. The mutability of a catalog-discriminated entity is determined viaInheritanceLines.mutabilityType(String)
of theContextRequest.getCatalog()
in comparison to the entity'sTracking.getCatalog()
. This is already checked byVendorAwareTrackablePolicyUtils
, 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 byVendorAwareTrackablePolicyUtils
with consideration for vendor restrictions.- Specified by:
isEntityMutableByVendorRestrictions
in interfaceVendorVisibilityHandler
- Parameters:
persistedDomainEntity
- the persisted-domain entity to validate visibility for. This is guaranteed to only be an entity for whichcanHandle(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:
VendorVisibilityManager.isEntityMutableByVendorRestrictions(Object, Set, ContextInfo)
-
createVendorNarrowingFilter
public String createVendorNarrowingFilter(@NonNull @NonNull Set<String> restrictedVendorRefs, @Nullable ContextInfo contextInfo)
Builds a filter ontracking.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 interfaceVendorVisibilityHandler
- 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 therestrictedVendorRefs
. Cannot return null. - See Also:
VendorVisibilityManager.createVendorNarrowingFilter(Class, Set, ContextInfo)
-
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 apersistedDomainEntity
, determine what vendor it is associated to (if any).- Specified by:
getAssociatedVendorRef
in interfaceVendorVisibilityHandler
- Parameters:
persistedDomainEntity
- the persisted-domain entity to determine the vendor association forcontextInfo
- 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:
VendorVisibilityManager.getAssociatedVendorRef(Object, ContextInfo)
-
getTrackableBehaviorUtil
protected TrackableBehaviorUtil getTrackableBehaviorUtil()
-
getCatalogService
protected CommonCatalogService<Catalog> getCatalogService()
-
-