Class CatalogDiscriminatedEntityVendorVisibilityHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.extension.data.DataRoutePartitionAware
,VendorVisibilityHandler
,org.springframework.core.Ordered
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.
-
Field Summary
Fields inherited from interface com.broadleafcommerce.common.extension.data.DataRoutePartitionAware
ALL_MATCH
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionCatalogDiscriminatedEntityVendorVisibilityHandler
(TrackableBehaviorUtil trackableBehaviorUtil, CommonCatalogService<Catalog> catalogService, int order, String dataRoutePartitiion) -
Method Summary
Modifier and TypeMethodDescriptionprotected String
buildCatalogIdFilter
(@NonNull Set<String> catalogIds) boolean
If thepersistedDomainEntityType
is catalog discriminated, this handler supports it.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.getAssociatedVendorRef
(Object persistedDomainEntity, ContextInfo contextInfo) Given apersistedDomainEntity
, determine what vendor it is associated to (if any).protected CommonCatalogService<Catalog>
int
getOrder()
protected TrackableBehaviorUtil
boolean
isEntityMutableByVendorRestrictions
(@NonNull Object persistedDomainEntity, @NonNull Set<String> restrictedVendorRefs, ContextInfo contextInfo) This method always returns true.
-
Constructor Details
-
CatalogDiscriminatedEntityVendorVisibilityHandler
public CatalogDiscriminatedEntityVendorVisibilityHandler(TrackableBehaviorUtil trackableBehaviorUtil, CommonCatalogService<Catalog> catalogService, int order, String dataRoutePartitiion)
-
-
Method Details
-
canHandle
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
- 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:
-
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:
-
buildCatalogIdFilter
-
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:
-
getTrackableBehaviorUtil
-
getCatalogService
-