Class SearchComponentHelper
- java.lang.Object
-
- org.ametys.web.frontoffice.search.requesttime.impl.SearchComponentHelper
-
- All Implemented Interfaces:
Component,Serviceable
public class SearchComponentHelper extends Object implements Serviceable, Component
A helper for all search component
-
-
Field Summary
Fields Modifier and Type Field Description protected AdvancedQueryBuilder_advancedQueryBuilderThe builder of advanced queriesprotected I18nUtils_i18nUtilsThe utils for i18nizable textsprotected TreeMaker_treeMakerThe Advanced tree makerstatic QueryEMPTY_QUERYTheQuerybuilding to the empty stringstatic StringROLEThe avalon role.
-
Constructor Summary
Constructors Constructor Description SearchComponentHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private Map<String,Object>_contextualParameters(Site currentSite)protected ContextQueriesWrapper_createContextQueriesWrapper(SearchContext searchContext, Site currentSite, Page currentPage, String currentLang)Creates aContextQueriesWrappergiven oneSearchContextand the current site, page and lang.private void_logTree(org.slf4j.Logger logger, AbstractTreeNode<FOSearchCriterion> tree, Map<String,Object> userCriteria)private Query_queryFromTransformedValAndRealOperator(SearchCriterionDefinition criterionDefinition, FOSearchCriterionMode.FoWrappedValue transformedVal, Query.Operator realOperator, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Map<String,Object> contextualParameters)private Query_queryOnCriterion(SearchCriterionDefinition criterionDefinition, FOSearchCriterionMode.FoWrappedValue transformedVal, Query.Operator realOperator, String currentLang, Map<String,Object> contextualParameters)QuerybuildQuery(AbstractTreeNode<FOSearchCriterion> criterionTree, Map<String,Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Map<String,Object> contextualParameters)Builds the query of the criterion treeprotected voidcheckValidInputs(AbstractTreeNode<FOSearchCriterion> criterionTree, Map<String,Object> userCriteria)Checks the user inputs are validprotected voidcheckValidInputSingleValue(Object userCriterionSingleValue, String criterionId, FOSearchCriterionMode mode, Optional<EnumeratedValues.RestrictedValues> optionalRestrictedValues, Validator validator, boolean isMandatory)Checks a single value of one user input for one criterion is validprotected voidcheckValidInputValues(Object userCriterionValues, String criterionId, FOSearchCriterionMode mode, Optional<EnumeratedValues.RestrictedValues> optionalRestrictedValues, Validator validator, boolean isMandatory)Checks the user inputs for one criterion (can be multiple) are validQuerygetCriterionTreeQuery(SearchComponentArguments args, boolean checkValidInputs, boolean logTree)Get the criterion tree query from argumentsQuerygetFilterQuery(SearchComponentArguments args)Get the filter query from argumentsvoidservice(ServiceManager manager)QuerysingleCriterionToQuery(FOSearchCriterion searchCriterion, Map<String,Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Map<String,Object> contextualParameters)Builds the query of the single criterion
-
-
-
Field Detail
-
EMPTY_QUERY
public static final Query EMPTY_QUERY
TheQuerybuilding to the empty string
-
_advancedQueryBuilder
protected AdvancedQueryBuilder _advancedQueryBuilder
The builder of advanced queries
-
_treeMaker
protected TreeMaker _treeMaker
The Advanced tree maker
-
_i18nUtils
protected I18nUtils _i18nUtils
The utils for i18nizable texts
-
-
Constructor Detail
-
SearchComponentHelper
public SearchComponentHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getCriterionTreeQuery
public Query getCriterionTreeQuery(SearchComponentArguments args, boolean checkValidInputs, boolean logTree) throws 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:
InvalidUserInputException- if an invalid user input occurred
-
checkValidInputs
protected void checkValidInputs(AbstractTreeNode<FOSearchCriterion> criterionTree, Map<String,Object> userCriteria) throws InvalidUserInputException
Checks the user inputs are valid- Parameters:
criterionTree- The criterion tree of the service instanceuserCriteria- The user input criteria- Throws:
InvalidUserInputException- if at least one user input is invalid
-
checkValidInputValues
protected void checkValidInputValues(Object userCriterionValues, String criterionId, FOSearchCriterionMode mode, Optional<EnumeratedValues.RestrictedValues> optionalRestrictedValues, Validator validator, boolean isMandatory) throws InvalidUserInputException
Checks 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 idmode- The criterion modeoptionalRestrictedValues- TheEnumeratedValues.RestrictedValuesif mode isFOSearchCriterionMode.RESTRICTED_USER_INPUTvalidator- The criterion validatorisMandatory- true if the criterion is linked to a mandatory data- Throws:
InvalidUserInputException- if at least one user input is invalid
-
checkValidInputSingleValue
protected void checkValidInputSingleValue(Object userCriterionSingleValue, String criterionId, FOSearchCriterionMode mode, Optional<EnumeratedValues.RestrictedValues> optionalRestrictedValues, Validator validator, boolean isMandatory) throws 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- TheEnumeratedValues.RestrictedValuesif mode isFOSearchCriterionMode.RESTRICTED_USER_INPUTvalidator- The criterion validatorisMandatory- true if the criterion is linked to a mandatory data- Throws:
InvalidUserInputException- if the user input is invalid
-
_contextualParameters
private Map<String,Object> _contextualParameters(Site currentSite)
-
buildQuery
public Query buildQuery(AbstractTreeNode<FOSearchCriterion> criterionTree, Map<String,Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, 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 langcontextualParameters- the search contextual parameters.- Returns:
- The query of the criterion tree
-
singleCriterionToQuery
public Query singleCriterionToQuery(FOSearchCriterion searchCriterion, Map<String,Object> userCriteria, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Map<String,Object> contextualParameters)
Builds the query of the single criterion- Parameters:
searchCriterion- 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 langcontextualParameters- the search contextual parameters.- Returns:
- The query of the single criterion
-
_queryFromTransformedValAndRealOperator
private Query _queryFromTransformedValAndRealOperator(SearchCriterionDefinition criterionDefinition, FOSearchCriterionMode.FoWrappedValue transformedVal, Query.Operator realOperator, Collection<Returnable> returnables, Collection<Searchable> searchables, AdditionalParameterValueMap additionalParameters, String currentLang, Map<String,Object> contextualParameters)
-
_queryOnCriterion
private Query _queryOnCriterion(SearchCriterionDefinition criterionDefinition, FOSearchCriterionMode.FoWrappedValue transformedVal, Query.Operator realOperator, String currentLang, Map<String,Object> contextualParameters)
-
_logTree
private void _logTree(org.slf4j.Logger logger, AbstractTreeNode<FOSearchCriterion> tree, Map<String,Object> userCriteria)
-
getFilterQuery
public Query getFilterQuery(SearchComponentArguments args)
Get the filter query from arguments- Parameters:
args- the search arguments- Returns:
- the filter query
-
_createContextQueriesWrapper
protected ContextQueriesWrapper _createContextQueriesWrapper(SearchContext searchContext, Site currentSite, Page 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
-
-