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 TypeMethodDescriptionvoidprotected LinkedRSQLQueryDetailsapplyRsqlCriteria(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 givenfiltersto build and apply the necessaryPredicatefor 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.JpaNarrowingHelperprotected AssetRepository<D>protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer>protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitororg.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) IfsearchStringis provided, then this method will search for assets whoseAsset.url,Asset.title,Asset.altText, orAsset.tagscontain it.voidsetRepository(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:
afterPropertiesSetin 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:CustomizedAssetRepositoryIfsearchStringis provided, then this method will search for assets whoseAsset.url,Asset.title,Asset.altText, orAsset.tagscontain it.If no
searchStringis provided, then this method will simply return all assets.This method also supports RSQL filtration via
filters.- Specified by:
searchAllin interfaceCustomizedAssetRepository<D extends JpaAsset>- Parameters:
searchString- (optional) a string which should be found inAsset.url,Asset.title,Asset.altText, orAsset.tagsfilters- additional filters to apply in the query. Should beEmptyNodeif 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 givenfiltersto build and apply the necessaryPredicatefor RSQL.- Parameters:
filters- RSQL filters to apply in the query. Should beEmptyNodeif no additional filters should be applied.criteriaBuilder- the criteria builder used to generate parameters/predicates. Only used as an argument to populate theCriteriaContextinCriteriaContext.withBuilder(CriteriaBuilder).nativeQuery- the native query for the original request. Only used as an argument to populate theCriteriaContextinCriteriaContext.withCriteriaQuery(AbstractQuery).nativeQueryParams- the parameter values for thenativeQuery. Only used as an argument to populate theCriteriaContextinCriteriaContext.withNarrowingParams(Map).nativePredicates- the list of predicates that will be applied onnativeQuery. If thefiltersare not for linked fields, then thePredicatewill 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:CustomizedAssetRepositoryFinds 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:
findByUrlAndStorageTypein interfaceCustomizedAssetRepository<D extends JpaAsset>- Parameters:
url- the url which should match withAsset.urlstorageType- (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()
-