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_NAME
protected GroupManager
_groupManager
The group managerprivate AmetysObjectResolver
_resolver
The Ametys object resolverprivate RightManager
_rightManager
private UserHelper
_userHelper
protected CurrentUserProvider
_userProvider
The current user providerstatic String
ROLE
The Avalon rolestatic String
ROOT_QUERY_CONTAINER_ID
The 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 boolean
canDeleteAllQueryContainers(List<String> ids)
Can the current user delete all theQueryContainer
s from the list ?Map<String,Boolean>
canDeleteQueryContainers(List<String> ids)
Determines if the current user can delete the givenQueryContainer
sMap<String,Object>
changeVisibility(String queryId, String visibilityStr)
Changes the visibility of aQuery
Map<String,Object>
createQuery(String title, String desc, String type, String content, String parentId)
Creates a newQuery
Map<String,Object>
createQueryContainer(String parentId, String name)
Creates a newQueryContainer
Map<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' propertiesQueryContainer
getQueriesRootNode()
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 propertiesboolean
hasRightOnContainers()
Determines if the current user has right to handleQueryContainer
sboolean
isAdministrator()
Determines if the current user is administrator of queriesMap<String,Object>
moveQuery(String id, String newParentId)
Moves aQuery
Map<String,Object>
moveQueryContainer(String id, String newParentId)
Moves aQueryContainer
boolean
mustWarnBeforeDeletion(List<String> ids)
Determines if application must warn before deleting the givenQueryContainer
sMap<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 aQueryContainer
Map<String,Object>
saveQuery(String id, String type, String content)
Saves aQuery
void
service(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:
service
in 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 handleQueryContainer
s- Returns:
true
if the current user has right to handleQueryContainer
s
-
getQueryContainerProperties
public Map<String,Object> getQueryContainerProperties(String id)
Get the query container properties- Parameters:
id
- The query container id. Can beROOT_QUERY_CONTAINER_ID
for 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_ID
for 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_ID
for 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_ID
for 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_ID
for 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 theQueryContainer
s from the list ?- Parameters:
ids
- TheQueryContainer
ids- Returns:
true
if he can
-
canDeleteQueryContainers
public Map<String,Boolean> canDeleteQueryContainers(List<String> ids)
Determines if the current user can delete the givenQueryContainer
s- Parameters:
ids
- TheQueryContainer
ids- Returns:
- A map with
true
for 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 givenQueryContainer
s- Parameters:
ids
- TheQueryContainer
ids- Returns:
true
if 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:
true
if 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
-true
in order to have only direct child queries from parent path,false
otherwise 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
-true
in order to have only direct child queries from parent path,false
otherwise 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
-true
in order to have only direct child queries from parent path,false
otherwise 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
-
-