Class QueryHelper
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.queriesdirectory.QueryHelper
-
- All Implemented Interfaces:
LogEnabled,Component,Serviceable
public class QueryHelper extends AbstractLogEnabled implements Serviceable, Component
Helper for manipulatingQuery
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classQueryHelper.ObjectToReturnstatic classQueryHelper.VisibilityThe user and its groups for checking visibility
-
Field Summary
Fields Modifier and Type Field Description protected ContentSearcherFactory_contentSearcherFactoryContent Searcher Factoryprotected JSONUtils_jsonUtilsJSON Utilsprotected ServiceManager_managerThe service managerprotected AmetysObjectResolver_resolverThe Ametys object resolverprotected SearchUIModelExtensionPoint_searchUiEPSearchUI Model Extension Pointstatic StringROLEAvalon Role
-
Constructor Summary
Constructors Constructor Description QueryHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void_appendGroupAccessCondition(StringBuilder query, String groupId, String groupDirectory, String accessNodeName)private static void_appendGroupsCondition(StringBuilder query, Set<GroupIdentity> groups, boolean readAccess)private static void_appendPrivatePredicate(StringBuilder query, String login, String populationId)private static void_appendPublicPredicate(StringBuilder query)private static void_appendSharedPredicate(StringBuilder query, String login, String populationId, Set<GroupIdentity> groups, boolean readAccess)private static void_appendUserAccessCondition(StringBuilder query, String login, String populationId, String accessNodeName)private static void_appendUserCondition(StringBuilder query, String login, String populationId)private static StringBuilder_getParentPath(QueryContainer queryContainer)private static String_getXPathQuery(QueryContainer queryContainer, boolean onlyDirectChildren, QueryHelper.ObjectToReturn objectToReturn, Optional<QueryHelper.Visibility> visibility, Optional<String> type, Boolean readAccess)AmetysObjectIterable<Content>executeQuery(String queryId)Execute a queryAmetysObjectIterable<Content>executeQuery(Query query)Execute a queryList<String>getContentTypesForQuery(Map<String,Object> exportParams)Get the Content Types of the query based on exportParamsMap<String,Object>getContextualParametersForQuery(Map<String,Object> exportParams)Get the contextual parameters of the query based on exportParamsMap<String,Object>getExportParams(Query query)Get the export params of the queryintgetLimitForQuery(Map<String,Object> exportParams)Get the limit of results stored in a query, or -1 if none is foundStringgetModelForQuery(Map<String,Object> exportParams)Get the model of the query based on exportParamsStringgetQueryStringForQuery(Map<String,Object> exportParams)Get the solr query string of the query based on exportParamsStringgetSearchModeForQuery(Map<String,Object> exportParams)Get the search model of the query based on exportParamsList<Sort>getSortForQuery(Map<String,Object> exportParams)Get the sort of the query based on exportParamsMap<String,Object>getValuesForQuery(Map<String,Object> exportParams)Get the values of the query based on exportParams(package private) static StringgetXPathForQueriesForAdministrator(QueryContainer queryContainer, boolean onlyDirectChildren, Optional<String> type)Creates the XPath query to get all queries for administrator(package private) static StringgetXPathForQueriesInReadAccess(QueryContainer queryContainer, boolean onlyDirectChildren, QueryHelper.Visibility visibility, Optional<String> type)Creates the XPath query to get all queries in READ access(package private) static StringgetXPathForQueriesInWriteAccess(QueryContainer queryContainer, boolean onlyDirectChildren, QueryHelper.Visibility visibility, Optional<String> type)Creates the XPath query to get all queries in WRITE access(package private) static StringgetXPathForQueryContainers(QueryContainer queryContainer)Creates the XPath query to get all query containersvoidservice(ServiceManager manager)-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_resolver
protected AmetysObjectResolver _resolver
The Ametys object resolver
-
_jsonUtils
protected JSONUtils _jsonUtils
JSON Utils
-
_searchUiEP
protected SearchUIModelExtensionPoint _searchUiEP
SearchUI Model Extension Point
-
_contentSearcherFactory
protected ContentSearcherFactory _contentSearcherFactory
Content Searcher Factory
-
_manager
protected ServiceManager _manager
The service manager
-
-
Constructor Detail
-
QueryHelper
public QueryHelper()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getXPathForQueryContainers
static String getXPathForQueryContainers(QueryContainer queryContainer)
Creates the XPath query to get all query containers- Parameters:
queryContainer- TheQueryContainer, defining the context from which getting children- Returns:
- The XPath query
-
getXPathForQueriesForAdministrator
static String getXPathForQueriesForAdministrator(QueryContainer queryContainer, boolean onlyDirectChildren, Optional<String> type)
Creates the XPath query to get all queries for administrator- Parameters:
queryContainer- TheQueryContainer, defining the context from which getting childrenonlyDirectChildren-truein order to have only direct child queries from parent path,falseotherwise to have all queries at any level underneath the parent pathtype- The query type- Returns:
- The XPath query
-
getXPathForQueriesInReadAccess
static String getXPathForQueriesInReadAccess(QueryContainer queryContainer, boolean onlyDirectChildren, QueryHelper.Visibility visibility, Optional<String> type)
Creates the XPath query to get all queries in READ access- Parameters:
queryContainer- TheQueryContainer, defining the context from which getting childrenonlyDirectChildren-truein order to have only direct child queries from parent path,falseotherwise to have all queries at any level underneath the parent pathvisibility- The user and its groups for checking visibilitytype- The query type- Returns:
- The XPath query
-
getXPathForQueriesInWriteAccess
static String getXPathForQueriesInWriteAccess(QueryContainer queryContainer, boolean onlyDirectChildren, QueryHelper.Visibility visibility, Optional<String> type)
Creates the XPath query to get all queries in WRITE access- Parameters:
queryContainer- TheQueryContainer, defining the context from which getting childrenonlyDirectChildren-truein order to have only direct child queries from parent path,falseotherwise to have all queries at any level underneath the parent pathvisibility- The user and its groups for checking visibilitytype- The query type- Returns:
- The XPath query
-
_getParentPath
private static StringBuilder _getParentPath(QueryContainer queryContainer)
-
_getXPathQuery
private static String _getXPathQuery(QueryContainer queryContainer, boolean onlyDirectChildren, QueryHelper.ObjectToReturn objectToReturn, Optional<QueryHelper.Visibility> visibility, Optional<String> type, Boolean readAccess)
-
_appendPublicPredicate
private static void _appendPublicPredicate(StringBuilder query)
-
_appendPrivatePredicate
private static void _appendPrivatePredicate(StringBuilder query, String login, String populationId)
-
_appendSharedPredicate
private static void _appendSharedPredicate(StringBuilder query, String login, String populationId, Set<GroupIdentity> groups, boolean readAccess)
-
_appendUserCondition
private static void _appendUserCondition(StringBuilder query, String login, String populationId)
-
_appendGroupsCondition
private static void _appendGroupsCondition(StringBuilder query, Set<GroupIdentity> groups, boolean readAccess)
-
_appendUserAccessCondition
private static void _appendUserAccessCondition(StringBuilder query, String login, String populationId, String accessNodeName)
-
_appendGroupAccessCondition
private static void _appendGroupAccessCondition(StringBuilder query, String groupId, String groupDirectory, String accessNodeName)
-
executeQuery
public AmetysObjectIterable<Content> executeQuery(String queryId) throws Exception
Execute a query- Parameters:
queryId- id of the query to execute- Returns:
- the results of the query
- Throws:
Exception- something went wrong
-
executeQuery
public AmetysObjectIterable<Content> executeQuery(Query query) throws Exception
Execute a query- Parameters:
query- the query to execute- Returns:
- the results of the query, can be null
- Throws:
Exception- something went wrong
-
getLimitForQuery
public int getLimitForQuery(Map<String,Object> exportParams)
Get the limit of results stored in a query, or -1 if none is found- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the maximum number of results that this query should return, -1 if no limit
-
getModelForQuery
public String getModelForQuery(Map<String,Object> exportParams)
Get the model of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the model of the query
-
getValuesForQuery
public Map<String,Object> getValuesForQuery(Map<String,Object> exportParams)
Get the values of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the values of the query
-
getContextualParametersForQuery
public Map<String,Object> getContextualParametersForQuery(Map<String,Object> exportParams)
Get the contextual parameters of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the contextual parameters of the query
-
getSortForQuery
public List<Sort> getSortForQuery(Map<String,Object> exportParams)
Get the sort of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the sort of the query
-
getContentTypesForQuery
public List<String> getContentTypesForQuery(Map<String,Object> exportParams)
Get the Content Types of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the Content Types of the query
-
getQueryStringForQuery
public String getQueryStringForQuery(Map<String,Object> exportParams)
Get the solr query string of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the solr query string of the query
-
getSearchModeForQuery
public String getSearchModeForQuery(Map<String,Object> exportParams)
Get the search model of the query based on exportParams- Parameters:
exportParams- export params of the query, available viagetExportParams(Query)- Returns:
- the search model of the query
-
getExportParams
public Map<String,Object> getExportParams(Query query)
Get the export params of the query- Parameters:
query- the query- Returns:
- the export params of the query
-
-