Class JpaCustomizedAssetRepository<D extends JpaAsset>
- All Implemented Interfaces:
CustomizedAssetRepository<D>
,org.springframework.beans.factory.InitializingBean
CustomizedAssetRepository
for JPA.- Author:
- Nathan Moore (nathanmoore).
-
Constructor Summary
ConstructorsConstructorDescriptionJpaCustomizedAssetRepository
(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser) -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected LinkedRSQLQueryDetails
applyRsqlCriteria
(cz.jirutka.rsql.parser.ast.Node filters, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, jakarta.persistence.criteria.CriteriaQuery<D> nativeQuery, Map<String, Object> nativeQueryParams, List<jakarta.persistence.criteria.Predicate> nativePredicates) Processes the givenfilters
to build and apply the necessaryPredicate
for RSQL.findByUrlAndStorageType
(String url, String storageType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds the asset whose url and storage type match the provided values.protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper
protected AssetRepository<D>
protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer>
protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor
org.springframework.data.domain.Page<D>
searchAll
(String searchString, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) IfsearchString
is provided, then this method will search for assets whoseAsset.url
,Asset.title
,Asset.altText
, orAsset.tags
contain it.void
setRepository
(AssetRepository<D> repository)
-
Constructor Details
-
JpaCustomizedAssetRepository
public JpaCustomizedAssetRepository(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
searchAll
@Policy(operationTypes=READ) public org.springframework.data.domain.Page<D> searchAll(@Nullable String searchString, @NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable pageInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedAssetRepository
IfsearchString
is provided, then this method will search for assets whoseAsset.url
,Asset.title
,Asset.altText
, orAsset.tags
contain it.If no
searchString
is provided, then this method will simply return all assets.This method also supports RSQL filtration via
filters
.- Specified by:
searchAll
in interfaceCustomizedAssetRepository<D extends JpaAsset>
- Parameters:
searchString
- (optional) a string which should be found inAsset.url
,Asset.title
,Asset.altText
, orAsset.tags
filters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.pageInfo
- information about which page of results to return from the databasecontextInfo
- context information surrounding sandboxing/multitenant state- Returns:
- the assets matching the given search/filter arguments if provided, otherwise all assets
-
applyRsqlCriteria
protected LinkedRSQLQueryDetails applyRsqlCriteria(cz.jirutka.rsql.parser.ast.Node filters, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, jakarta.persistence.criteria.CriteriaQuery<D> nativeQuery, Map<String, Object> nativeQueryParams, List<jakarta.persistence.criteria.Predicate> nativePredicates) Processes the givenfilters
to build and apply the necessaryPredicate
for RSQL.- Parameters:
filters
- RSQL filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.criteriaBuilder
- the criteria builder used to generate parameters/predicates. Only used as an argument to populate theCriteriaContext
inCriteriaContext.withBuilder(CriteriaBuilder)
.nativeQuery
- the native query for the original request. Only used as an argument to populate theCriteriaContext
inCriteriaContext.withCriteriaQuery(AbstractQuery)
.nativeQueryParams
- the parameter values for thenativeQuery
. Only used as an argument to populate theCriteriaContext
inCriteriaContext.withNarrowingParams(Map)
.nativePredicates
- the list of predicates that will be applied onnativeQuery
. If thefilters
are not for linked fields, then thePredicate
will be added to this list.- Returns:
- the
CriteriaContext.getLinkedQuery()
andCriteriaContext.getLinkedNarrowingParams()
that were produced during processing. While the wrapper object will not be null, any/all of its fields can be (for example, if the filters were not on linked fields). These values are useful for ultimately being supplied toJpaNarrowingHelper.JpaCriterias
.
-
findByUrlAndStorageType
@Policy(operationTypes=READ) @NonNull public Optional<D> findByUrlAndStorageType(@NonNull String url, @Nullable String storageType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CustomizedAssetRepository
Finds the asset whose url and storage type match the provided values.This is a custom repository method because there is a scenario where an asset in the tenant and an asset in a standard application can have the same URL. This scenario arises in the event that a standard-application asset is uploaded, and then on the tenant an asset with the same URL is uploaded. Due to the mechanism by which application discrimination works, the tenant asset upload will succeed because the standard-application asset will not be visible in the tenant context, and therefore will not be recognized as a duplicate.
This ultimately means that "findByUrlAndStorageType" can potentially return more than one result, which is undesirable. The target behavior should be that if an asset with the given URL is found in both the tenant and standard-application contexts, the standard-application asset should be returned.
- Specified by:
findByUrlAndStorageType
in interfaceCustomizedAssetRepository<D extends JpaAsset>
- Parameters:
url
- the url which should match withAsset.url
storageType
- (optional) the storage type which should match withAsset.storageType
. If left null, results will not be filtered by storage type.contextInfo
- context information around sandboxing and multitenant state- Returns:
- an optional containing the asset whose url and storage type (optional) match the provided values, empty otherwise
-
getManagedType
-
getRepository
-
setRepository
-
getRsqlQueryTransformers
@NonNull protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> getRsqlQueryTransformers() -
getRsqlVisitor
@NonNull protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor getRsqlVisitor() -
getNarrowingHelper
protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper getNarrowingHelper()
-