Class QueryDAO
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.queriesdirectory.QueryDAO
-
- All Implemented Interfaces:
LogEnabled,Component,Serviceable
public class QueryDAO extends AbstractLogEnabled implements Serviceable, Component
DAO for manipulating queries
-
-
Field Summary
Fields Modifier and Type Field Description private static String__PLUGIN_NODE_NAMEprotected GroupManager_groupManagerThe group managerprivate AmetysObjectResolver_resolverThe Ametys object resolverprivate RightManager_rightManagerprivate UserHelper_userHelperprotected CurrentUserProvider_userProviderThe current user providerstatic StringROLEThe Avalon rolestatic StringROOT_QUERY_CONTAINER_IDThe alias id of the rootQueryContainer
-
Constructor Summary
Constructors Constructor Description QueryDAO()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Map<String,Object>_assignRights(String queryId, String profileId, String type, List<Map<String,String>> users, List<Map<String,String>> groups)private boolean_canDeleteQueryContainer(String id)private boolean_containsNotOwnQueries(AmetysObjectIterable<Query> allQueries)private boolean_containsSharedQueries(AmetysObjectIterable<Query> allQueries)private static AmetysObject_getOrCreateNode(ModifiableTraversableAmetysObject parentNode, String nodeName, String nodeType)private QueryContainer_getOrCreateRootNode()private QueryContainer_getQueryContainer(String id)protected boolean_hasRight(Query query)Test if the current user has the right required to access the queryprivate void_move(MovableAmetysObject obj, String newParentId, Map<String,Object> results)private boolean_mustWarnBeforeDeletion(String id)Map<String,Object>addGrantedGroups(String queryId, String profileId, List<Map<String,String>> groups)Assign rigths to the given groups on the given queryMap<String,Object>addGrantedUsers(String queryId, String profileId, List<Map<String,String>> users)Assign rights to the given users on the given queryprotected booleancanDeleteAllQueryContainers(List<String> ids)Can the current user delete all theQueryContainers from the list ?Map<String,Boolean>canDeleteQueryContainers(List<String> ids)Determines if the current user can delete the givenQueryContainersMap<String,Object>changeVisibility(String queryId, String visibilityStr)Changes the visibility of aQueryMap<String,Object>createQuery(String title, String desc, String type, String content, String parentId)Creates a newQueryMap<String,Object>createQueryContainer(String parentId, String name)Creates a newQueryContainerMap<String,Object>deleteQuery(List<String> ids)DeletesQuery(ies)Map<String,Object>deleteQueryContainer(List<String> ids)DeletesQueryContainer(s)AmetysObjectIterable<Query>getChildQueriesForAdministrator(QueryContainer parent, boolean onlyDirect, Optional<String> type)Gets all queries for administrator for given parentAmetysObjectIterable<Query>getChildQueriesInReadAccess(QueryContainer parent, boolean onlyDirect, QueryHelper.Visibility visibility, Optional<String> type)Gets all queries in READ access for given parentAmetysObjectIterable<Query>getChildQueriesInWriteAccess(QueryContainer parent, boolean onlyDirect, QueryHelper.Visibility visibility, Optional<String> type)Gets all queries in WRITE access for given parentAmetysObjectIterable<QueryContainer>getChildQueryContainers(QueryContainer parent)Gets all query containers for given parentList<String>getIdsOfPath(String queryId)Gets the ids of the path elements of a query or query container, i.e.Map<String,Object>getQueriesProperties(List<String> queryIds)Get queries' propertiesQueryContainergetQueriesRootNode()Get the root plugin storage object.Map<String,Object>getQueryContainerProperties(String id)Get the query container propertiesMap<String,Object>getQueryContainerProperties(QueryContainer queryContainer)Get the query container propertiesMap<String,Object>getQueryProperties(Query query)Get the query propertiesbooleanhasRightOnContainers()Determines if the current user has right to handleQueryContainersbooleanisAdministrator()Determines if the current user is administrator of queriesMap<String,Object>moveQuery(String id, String newParentId)Moves aQueryMap<String,Object>moveQueryContainer(String id, String newParentId)Moves aQueryContainerbooleanmustWarnBeforeDeletion(List<String> ids)Determines if application must warn before deleting the givenQueryContainersMap<String,Object>removeAssignment(String queryId, String profileId, List<Map<String,String>> users, List<Map<String,String>> groups)Remove rights to the given users on the given queryMap<String,Object>renameQueryContainer(String id, String newName)Renames aQueryContainerMap<String,Object>saveQuery(String id, String type, String content)Saves aQueryvoidservice(ServiceManager serviceManager)Map<String,Object>updateQuery(String id, String title, String desc)Edits aQuery-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
ROOT_QUERY_CONTAINER_ID
public static final String ROOT_QUERY_CONTAINER_ID
The alias id of the rootQueryContainer- See Also:
- Constant Field Values
-
__PLUGIN_NODE_NAME
private static final String __PLUGIN_NODE_NAME
- See Also:
- Constant Field Values
-
_userProvider
protected CurrentUserProvider _userProvider
The current user provider
-
_groupManager
protected GroupManager _groupManager
The group manager
-
_resolver
private AmetysObjectResolver _resolver
The Ametys object resolver
-
_userHelper
private UserHelper _userHelper
-
_rightManager
private RightManager _rightManager
-
-
Constructor Detail
-
QueryDAO
public QueryDAO()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
servicein interfaceServiceable- Throws:
ServiceException
-
getQueriesRootNode
public QueryContainer getQueriesRootNode() throws AmetysRepositoryException
Get the root plugin storage object.- Returns:
- the root plugin storage object.
- Throws:
AmetysRepositoryException- if a repository error occurs.
-
_getOrCreateRootNode
private QueryContainer _getOrCreateRootNode() throws AmetysRepositoryException
- Throws:
AmetysRepositoryException
-
_getOrCreateNode
private static AmetysObject _getOrCreateNode(ModifiableTraversableAmetysObject parentNode, String nodeName, String nodeType) throws AmetysRepositoryException
- Throws:
AmetysRepositoryException
-
getQueriesProperties
public Map<String,Object> getQueriesProperties(List<String> queryIds)
Get queries' properties- Parameters:
queryIds- The ids of queries to retrieve- Returns:
- The queries' properties
-
getQueryProperties
public Map<String,Object> getQueryProperties(Query query)
Get the query properties- Parameters:
query- The query- Returns:
- The query properties
-
getIdsOfPath
public List<String> getIdsOfPath(String queryId)
Gets the ids of the path elements of a query or query container, i.e. the parent ids.
For instance, if the query path is 'a/b/c', then the result list will be ["id-of-a", "id-of-b", "id-of-c"]- Parameters:
queryId- The id of the query- Returns:
- the ids of the path elements of a query
-
hasRightOnContainers
public boolean hasRightOnContainers()
Determines if the current user has right to handleQueryContainers- Returns:
trueif the current user has right to handleQueryContainers
-
getQueryContainerProperties
public Map<String,Object> getQueryContainerProperties(String id)
Get the query container properties- Parameters:
id- The query container id. Can beROOT_QUERY_CONTAINER_IDfor the root container.- Returns:
- The query container properties
-
getQueryContainerProperties
public Map<String,Object> getQueryContainerProperties(QueryContainer queryContainer)
Get the query container properties- Parameters:
queryContainer- The query container- Returns:
- The query container properties
-
createQuery
public Map<String,Object> createQuery(String title, String desc, String type, String content, String parentId)
Creates a newQuery- Parameters:
title- The title of the querydesc- The description of the querytype- The type of the querycontent- The content of the queryparentId- The id of the parent of the query. UseROOT_QUERY_CONTAINER_IDfor the root container.- Returns:
- A result map
-
createQueryContainer
public Map<String,Object> createQueryContainer(String parentId, String name)
Creates a newQueryContainer- Parameters:
parentId- The id of the parent. UseROOT_QUERY_CONTAINER_IDfor the root container.name- The desired name for the newQueryContainer- Returns:
- A result map
-
updateQuery
public Map<String,Object> updateQuery(String id, String title, String desc)
Edits aQuery- Parameters:
id- The id of the querytitle- The title of the querydesc- The description of the query- Returns:
- A result map
-
renameQueryContainer
public Map<String,Object> renameQueryContainer(String id, String newName)
Renames aQueryContainer- Parameters:
id- The id of the query containernewName- The new name of the container- Returns:
- A result map
-
moveQuery
public Map<String,Object> moveQuery(String id, String newParentId)
Moves aQuery- Parameters:
id- The id of the querynewParentId- The id of the new parent container of the query. UseROOT_QUERY_CONTAINER_IDfor the root container.- Returns:
- A result map
-
moveQueryContainer
public Map<String,Object> moveQueryContainer(String id, String newParentId)
Moves aQueryContainer- Parameters:
id- The id of the query containernewParentId- The id of the new parent container of the query container. UseROOT_QUERY_CONTAINER_IDfor the root container.- Returns:
- A result map
-
_getQueryContainer
private QueryContainer _getQueryContainer(String id)
-
saveQuery
public Map<String,Object> saveQuery(String id, String type, String content)
Saves aQuery- Parameters:
id- The id of the querytype- The type of the querycontent- The content of the query- Returns:
- A result map
-
deleteQuery
public Map<String,Object> deleteQuery(List<String> ids)
DeletesQuery(ies)- Parameters:
ids- The ids of the queries to delete- Returns:
- A result map
-
canDeleteAllQueryContainers
protected boolean canDeleteAllQueryContainers(List<String> ids)
Can the current user delete all theQueryContainers from the list ?- Parameters:
ids- TheQueryContainerids- Returns:
trueif he can
-
canDeleteQueryContainers
public Map<String,Boolean> canDeleteQueryContainers(List<String> ids)
Determines if the current user can delete the givenQueryContainers- Parameters:
ids- TheQueryContainerids- Returns:
- A map with
truefor each id if the current user can delete the associatedQueryContainer
-
_canDeleteQueryContainer
private boolean _canDeleteQueryContainer(String id)
-
mustWarnBeforeDeletion
public boolean mustWarnBeforeDeletion(List<String> ids)
Determines if application must warn before deleting the givenQueryContainers- Parameters:
ids- TheQueryContainerids- Returns:
trueif application must warn
-
_mustWarnBeforeDeletion
private boolean _mustWarnBeforeDeletion(String id)
-
_containsNotOwnQueries
private boolean _containsNotOwnQueries(AmetysObjectIterable<Query> allQueries)
-
_containsSharedQueries
private boolean _containsSharedQueries(AmetysObjectIterable<Query> allQueries)
-
deleteQueryContainer
public Map<String,Object> deleteQueryContainer(List<String> ids)
DeletesQueryContainer(s)- Parameters:
ids- The ids of the query containers to delete- Returns:
- A result map
-
changeVisibility
public Map<String,Object> changeVisibility(String queryId, String visibilityStr)
Changes the visibility of aQuery- Parameters:
queryId- The id of the queryvisibilityStr- The new visibility- Returns:
- A result map
-
addGrantedUsers
public Map<String,Object> addGrantedUsers(String queryId, String profileId, List<Map<String,String>> users)
Assign rights to the given users on the given query- Parameters:
queryId- The query idprofileId- The profile idusers- The users to grant- Returns:
- A result map
-
addGrantedGroups
public Map<String,Object> addGrantedGroups(String queryId, String profileId, List<Map<String,String>> groups)
Assign rigths to the given groups on the given query- Parameters:
queryId- The query idprofileId- The profile idgroups- The groups to grant- Returns:
- A result map
-
_assignRights
private Map<String,Object> _assignRights(String queryId, String profileId, String type, List<Map<String,String>> users, List<Map<String,String>> groups)
-
removeAssignment
public Map<String,Object> removeAssignment(String queryId, String profileId, List<Map<String,String>> users, List<Map<String,String>> groups)
Remove rights to the given users on the given query- Parameters:
queryId- The query idprofileId- The profile idusers- The users to removegroups- The groups to remove- Returns:
- A result map
-
isAdministrator
public boolean isAdministrator()
Determines if the current user is administrator of queries- Returns:
trueif current user is administrator
-
_hasRight
protected boolean _hasRight(Query query)
Test if the current user has the right required to access the query- Parameters:
query- The query- Returns:
- true if the user has the right needed, false otherwise.
-
getChildQueriesForAdministrator
public AmetysObjectIterable<Query> getChildQueriesForAdministrator(QueryContainer parent, boolean onlyDirect, Optional<String> type)
Gets all queries for administrator for given parent- Parameters:
parent- TheQueryContainer, defining the context from which getting childrenonlyDirect-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:
- all queries for administrator for given parent
-
getChildQueriesInReadAccess
public AmetysObjectIterable<Query> getChildQueriesInReadAccess(QueryContainer parent, boolean onlyDirect, QueryHelper.Visibility visibility, Optional<String> type)
Gets all queries in READ access for given parent- Parameters:
parent- TheQueryContainer, defining the context from which getting childrenonlyDirect-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:
- all queries in READ access for given parent
-
getChildQueriesInWriteAccess
public AmetysObjectIterable<Query> getChildQueriesInWriteAccess(QueryContainer parent, boolean onlyDirect, QueryHelper.Visibility visibility, Optional<String> type)
Gets all queries in WRITE access for given parent- Parameters:
parent- TheQueryContainer, defining the context from which getting childrenonlyDirect-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:
- all queries in WRITE access for given parent
-
getChildQueryContainers
public AmetysObjectIterable<QueryContainer> getChildQueryContainers(QueryContainer parent)
Gets all query containers for given parent- Parameters:
parent- TheQueryContainer, defining the context from which getting children- Returns:
- all query containers for given parent
-
-