Class RsqlCrudEntityHelper
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper
Helper class responsible for providing additional support for RSQL filtering for business domain
services. This service is intended to be used in support of
RsqlCrudEntityServices
and most methods require passing in those services'
TrackableRepository
dependency.
Typically, it is sufficient to extend BaseRsqlCrudEntityService
in order to gain access
to this helper; however, if a service implementation spans several repository types, it is
recommend to inject this class instead. In such a case, this helper also provides access to a
CrudEntityHelper
bean.
@Service
public class DefaultMyService<P extends MyPayload> implements MyService<P>
{private final RsqlCrudEntityService<MyPayload> helper;
private final MyTrackableRepository repository;
public DefaultMyService(MyTrackableRepository repository, DomainMapperManager mapper) { this.helper = new RsqlCrudEntityService(repository, mapper); this repository = repository; } }
- Author:
- Phillip Verheyden (phillipuniverse), Nathan Moore (nathandmoore)
-
Constructor Summary
ConstructorDescriptionRsqlCrudEntityHelper
(CrudEntityHelper crudEntityHelper, List<RsqlQueryTransformer> rsqlQueryTransformers) -
Method Summary
Modifier and TypeMethodDescription<R extends TrackableRepository<Trackable> & TrackableRsqlFilterExecutor<Trackable>>
RcastToRsqlRepository
(TrackableRepository<Trackable> repository) Since most of the methods in the service require a repository that implements bothTrackableRepository
andTrackableRsqlFilterExecutor
, this method provides a convenient way to handle that casting.Provides access to the internalCrudEntityHelper
so as to avoid having to inject it again.protected List<RsqlQueryTransformer>
<P,
R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>>
List<P>readAll
(cz.jirutka.rsql.parser.ast.Node filters, ContextInfo context, R repository) Retrieve all domain instances using a structured query string to drive the query criteria.<P,
R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>>
org.springframework.data.domain.Page<P>readAll
(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageable, ContextInfo context, R repository) Retrieve all domain instances using a structured query string to drive the query criteria.<P,
R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>>
List<P>readAll
(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Sort sort, ContextInfo context, R repository) Retrieve all domain instances using a structured query string to drive the query criteria.<P,
R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>>
org.springframework.data.domain.Page<P>readAll
(cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Sort sort, org.springframework.data.domain.Pageable pageable, ContextInfo context, R repository) Retrieve all domain instances using a structured query string to drive the query criteria.cz.jirutka.rsql.parser.ast.Node
transform
(cz.jirutka.rsql.parser.ast.Node filters, TrackableRepository<Trackable> repository) Transformsfilters
from properties that target a projection into ones that apply to a backing repository provider domain object
-
Constructor Details
-
RsqlCrudEntityHelper
public RsqlCrudEntityHelper(CrudEntityHelper crudEntityHelper, List<RsqlQueryTransformer> rsqlQueryTransformers)
-
-
Method Details
-
readAll
public <P,R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>> List<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Sort sort, @Nullable ContextInfo context, @NonNull R repository) Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParser
for more information.This version also accepts a formatted sort string that declares the sorting characteristics for the query. See
SortTransformer
for more information.- Parameters:
filters
- the RSQLNode
used to restrict result, must not be nullsort
- The string containing the structured list of sorts to applycontext
- Request context information around sandbox and multitenant staterepository
- A repository that implementsTrackableRepository
andTrackableRsqlFilterExecutor
to perform the persistence operation- Returns:
- The list of narrowed, sorted entities
-
readAll
public <P,R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>> List<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable ContextInfo context, @NonNull R repository) Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParser
for more information.- Parameters:
filters
- the RSQLNode
used to restrict result, must not be nullcontext
- Request context information around sandbox and multitenant staterepository
- A repository that implementsTrackableRepository
andTrackableRsqlFilterExecutor
to perform the persistence operation- Returns:
- The list of narrowed, sorted entities
-
readAll
public <P,R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>> org.springframework.data.domain.Page<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Sort sort, @NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo context, @NonNull R repository) Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParser
for more information.This version also accepts a Sort to apply to the result set
- Parameters:
filters
- the RSQLNode
used to restrict result, must not be nullsort
- sort to apply to the querypageable
- may bePageable.unpaged()
, must not be null.context
- Request context information around sandbox and multitenant staterepository
- A repository that implementsTrackableRepository
andTrackableRsqlFilterExecutor
to perform the persistence operation- Returns:
- The subset (page) of narrowed entities
-
readAll
public <P,R extends TrackableRsqlFilterExecutor<Trackable> & TrackableRepository<Trackable>> org.springframework.data.domain.Page<P> readAll(@NonNull cz.jirutka.rsql.parser.ast.Node filters, @NonNull org.springframework.data.domain.Pageable pageable, @Nullable ContextInfo context, @NonNull R repository) Retrieve all domain instances using a structured query string to drive the query criteria. The filters string is parsed by an internal implementation and the result is added to the query before executing the fetch against the persistence store. SeeFilterParser
for more information.- Parameters:
filters
- the RSQLNode
used to restrict result, must not be nullpageable
- may bePageable.unpaged()
, must not be null.context
- Request context information around sandbox and multitenant staterepository
- A repository that implementsTrackableRepository
andTrackableRsqlFilterExecutor
to perform the persistence operation- Returns:
- The subset (page) of narrowed entities
-
transform
@NonNull public cz.jirutka.rsql.parser.ast.Node transform(@Nullable cz.jirutka.rsql.parser.ast.Node filters, @NonNull TrackableRepository<Trackable> repository) Transformsfilters
from properties that target a projection into ones that apply to a backing repository provider domain object- Parameters:
filters
- RSQL filters targeting a projection domainrepository
- ATrackableRepository
form which to glean entity information for the transformation- Returns:
- null if
filters
is null, otherwise an RSQL query suitable for targeting a repository domain object. - See Also:
-
castToRsqlRepository
public <R extends TrackableRepository<Trackable> & TrackableRsqlFilterExecutor<Trackable>> R castToRsqlRepository(TrackableRepository<Trackable> repository) Since most of the methods in the service require a repository that implements bothTrackableRepository
andTrackableRsqlFilterExecutor
, this method provides a convenient way to handle that casting.- Type Parameters:
R
- used to do the multi-interface check.- Parameters:
repository
- Since most services that use this helper will useTrackableRepositories
, this method expects that as the argument.- Returns:
- A
TrackableRepository
that also implementsTrackableRsqlFilterExecutor
cast in such a way as to allow type checking for both interfaces for use with this service's methods.
-
getCrudEntityHelper
Provides access to the internalCrudEntityHelper
so as to avoid having to inject it again.- Returns:
- the internal
CrudEntityHelper
- See Also:
-
getRsqlQueryTransformers
-