Class SearchComponentHelper
java.lang.Object
org.ametys.web.frontoffice.search.requesttime.impl.SearchComponentHelper
- All Implemented Interfaces:
Component,Serviceable
A helper for all search component
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ContextQueriesWrapper_createContextQueriesWrapper(SearchContext searchContext, Site currentSite, SitemapElement currentPage, String currentLang) Creates aContextQueriesWrappergiven oneSearchContextand the current site, page and lang.buildQuery(AbstractTreeNode<SearchServiceCriterion<?>> criterionTree, Map<String, Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Predicate<SearchServiceCriterion> filterCriterionPredicate, Map<String, Object> contextualParameters) Builds the query of the criterion treecheckValidInputs(AbstractTreeNode<SearchServiceCriterion<?>> criterionTree, Map<String, Object> userCriteria, boolean isFromUserPref, Map<String, Object> contextualParameters, org.slf4j.Logger logger) Checks the user inputs are valid.protected voidcheckValidInputSingleValue(Object userCriterionSingleValue, String criterionId, SearchServiceCriterionMode mode, Optional<RestrictedEnumerator.RestrictedValues> optionalRestrictedValues, Validator validator) Checks a single value of one user input for one criterion is validprotected voidcheckValidInputValues(Object userCriterionValues, String criterionId, SearchServiceCriterionDefinition criterionDefinition, SearchServiceCriterionMode mode, Optional<RestrictedEnumerator.RestrictedValues> optionalRestrictedValues, Validator validator, Map<String, Object> contextualParameters) Checks the user inputs for one criterion (can be multiple) are validprotected ObjectconvertUserCriterionValue(Object userCriterionValue, SearchServiceCriterionDefinition criterionDefinition, Map<String, Object> contextualParameters) Converts the given user criterion valuegetCriterionTreeQuery(SearchServiceInstance serviceInstance, Map<String, Object> userCriteria, Site site, String lang) Get the criterion tree querygetCriterionTreeQuery(SearchComponentArguments args, boolean checkValidInputs, boolean logTree) Get the criterion tree query from argumentsgetFilterQuery(SearchServiceInstance serviceInstance, Site site, SitemapElement page, String lang) Get the filter queryGet the filter query from argumentsRetrieves aMapof contextual parametersvoidservice(ServiceManager manager) <T> QuerysingleCriterionToQuery(SearchServiceCriterion<T> criterion, Map<String, Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Predicate<SearchServiceCriterion> filterCriterionPredicate, Map<String, Object> contextualParameters) Builds the query of the single criterion
-
Field Details
-
ROLE
The avalon role. -
EMPTY_QUERY
TheQuerybuilding to the empty string -
_advancedQueryBuilder
The builder of advanced queries -
_treeMaker
The Advanced tree maker -
_i18nUtils
The utils for i18nizable texts
-
-
Constructor Details
-
SearchComponentHelper
public SearchComponentHelper()
-
-
Method Details
-
service
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getCriterionTreeQuery
public Query getCriterionTreeQuery(SearchComponentArguments args, boolean checkValidInputs, boolean logTree) throws org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputException Get the criterion tree query from arguments- Parameters:
args- the search argumentscheckValidInputs- true if inputs needs to be checkedlogTree- true if the criterion tree need to be logged- Returns:
- the criterion tree query
- Throws:
org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputException- if an invalid user input occurred
-
getCriterionTreeQuery
public Query getCriterionTreeQuery(SearchServiceInstance serviceInstance, Map<String, Object> userCriteria, Site site, String lang) Get the criterion tree query- Parameters:
serviceInstance- the service instanceuserCriteria- the user criteriasite- the sitelang- the lang- Returns:
- the criterion tree query
-
checkValidInputs
protected Map<String,Object> checkValidInputs(AbstractTreeNode<SearchServiceCriterion<?>> criterionTree, Map<String, Object> userCriteria, boolean isFromUserPref, Map<String, throws org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputExceptionObject> contextualParameters, org.slf4j.Logger logger) Checks the user inputs are valid.- Parameters:
criterionTree- The criterion tree of the service instanceuserCriteria- The user input criteriaisFromUserPref-trueif the criteria are from user pref. Then return only the valid input, otherwise throw an exceptioncontextualParameters- the contextual parameterslogger- The logger- Returns:
- the filtered user criteria
- Throws:
org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputException- if at least one user input is invalid
-
checkValidInputValues
protected void checkValidInputValues(Object userCriterionValues, String criterionId, SearchServiceCriterionDefinition criterionDefinition, SearchServiceCriterionMode mode, Optional<RestrictedEnumerator.RestrictedValues> optionalRestrictedValues, Validator validator, Map<String, Object> contextualParameters) throws org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputExceptionChecks the user inputs for one criterion (can be multiple) are valid- Parameters:
userCriterionValues- The multiple user values (then it is a List) or the single user valuecriterionId- The criterion idcriterionDefinition- the criterion definitionmode- The criterion modeoptionalRestrictedValues- TheRestrictedEnumerator.RestrictedValuesif mode isSearchServiceCriterionMode.RESTRICTED_USER_INPUTvalidator- The criterion validatorcontextualParameters- The contextual parameters- Throws:
org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputException- if at least one user input is invalid
-
convertUserCriterionValue
protected Object convertUserCriterionValue(Object userCriterionValue, SearchServiceCriterionDefinition criterionDefinition, Map<String, Object> contextualParameters) Converts the given user criterion value- Parameters:
userCriterionValue- The single user valuecriterionDefinition- the criterion definitioncontextualParameters- The contextual parameters- Returns:
- the converted user value
-
checkValidInputSingleValue
protected void checkValidInputSingleValue(Object userCriterionSingleValue, String criterionId, SearchServiceCriterionMode mode, Optional<RestrictedEnumerator.RestrictedValues> optionalRestrictedValues, Validator validator) throws org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputException Checks a single value of one user input for one criterion is valid- Parameters:
userCriterionSingleValue- The single user valuecriterionId- The criterion idmode- The criterion modeoptionalRestrictedValues- TheRestrictedEnumerator.RestrictedValuesif mode isSearchServiceCriterionMode.RESTRICTED_USER_INPUTvalidator- The criterion validator- Throws:
org.ametys.web.frontoffice.search.requesttime.impl.InvalidUserInputException- if the user input is invalid
-
buildQuery
public Query buildQuery(AbstractTreeNode<SearchServiceCriterion<?>> criterionTree, Map<String, Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Predicate<SearchServiceCriterion> filterCriterionPredicate, Map<String, Object> contextualParameters) Builds the query of the criterion tree- Parameters:
criterionTree- The criterion tree of the service instanceuserCriteria- The user input criteriareturnables- The returnables of the service instancesearchables- The searchables of the service instanceadditionalParameters- The values of additional parameters of the service instancecurrentLang- The current langfilterCriterionPredicate- A function to filter criterion. Can be null for TruePredicatecontextualParameters- the search contextual parameters.- Returns:
- The query of the criterion tree
-
singleCriterionToQuery
public <T> Query singleCriterionToQuery(SearchServiceCriterion<T> criterion, Map<String, Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Predicate<SearchServiceCriterion> filterCriterionPredicate, Map<String, Object> contextualParameters) Builds the query of the single criterion- Type Parameters:
T- Type of the criterion value- Parameters:
criterion- The criterionuserCriteria- The user input criteriareturnables- The returnables of the service instancesearchables- The searchables of the service instanceadditionalParameters- The values of additional parameters of the service instancecurrentLang- The current langfilterCriterionPredicate- A function to filter criterioncontextualParameters- the search contextual parameters.- Returns:
- The query of the single criterion
-
getFilterQuery
Get the filter query from arguments- Parameters:
args- the search arguments- Returns:
- the filter query
-
getFilterQuery
public Query getFilterQuery(SearchServiceInstance serviceInstance, Site site, SitemapElement page, String lang) Get the filter query- Parameters:
serviceInstance- the service instancesite- the sitepage- the pagelang- the lang- Returns:
- the filter query
-
_createContextQueriesWrapper
protected ContextQueriesWrapper _createContextQueriesWrapper(SearchContext searchContext, Site currentSite, SitemapElement currentPage, String currentLang) Creates aContextQueriesWrappergiven oneSearchContextand the current site, page and lang.- Parameters:
searchContext- The search contextcurrentSite- The current sitecurrentPage- The current pagecurrentLang- The current lang- Returns:
- The created wrapper of queries of a
SearchContext
-
getSearchComponentContextualParameters
public static Map<String,Object> getSearchComponentContextualParameters(SearchComponentArguments args) Retrieves aMapof contextual parameters- Parameters:
args- the search component arguments- Returns:
- the
Mapof contextual parameters
-