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 protected ObservationManager_observationManagerThe observation managerprotected 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 Instance Methods Concrete Methods Modifier and Type Method Description protected 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>createQuery(String title, String desc, String documentation, 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 parentStream<Query>getChildQueriesInReadAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, Optional<String> type)Gets all queries in READ access for given parentStream<Query>getChildQueriesInRightAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, Optional<String> type)Gets all queries in WRITE access for given parentStream<Query>getChildQueriesInWriteAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, 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 propertiesMap<String,Object>getRootProperties()Get the root container propertiesBooleanhasAnyAssignableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)Check if a folder have descendant in right assignment access for a given userBooleanhasAnyReadableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)Check if a folder have a descendant in read access for a given userBooleanhasAnyWritableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)Check if a folder have descendant in write access for a given userbooleanhasCreationRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)Check if a user have creation rights on a query containerbooleanhasReadRightOnQuery(UserIdentity userIdentity, Query query)Check if a user have read rights on a querybooleanhasReadRightOnQueryContainer(UserIdentity userIdentity, QueryContainer query)Check if a user have read rights on a query containerbooleanhasRightAffectationRightOnQuery(UserIdentity userIdentity, Query query)Check if a user have write rights on a querybooleanhasRightAffectationRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)Check if a user have write rights on a query containerbooleanhasWriteRightOnQuery(UserIdentity userIdentity, Query query)Check if a user have write rights on a querybooleanhasWriteRightOnQueryAndParent(UserIdentity userIdentity, Query query, QueryContainer queryContainer)Check if a user have write rights on a querybooleanhasWriteRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)Check if a user have write rights on a query containerMap<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>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, String documentation)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
-
_userProvider
protected CurrentUserProvider _userProvider
The current user provider
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
-
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.
-
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
-
getRootProperties
public Map<String,Object> getRootProperties()
Get the root container properties- Returns:
- The root container properties
-
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 documentation, String type, String content, String parentId)
Creates a newQuery- Parameters:
title- The title of the querydesc- The description of the querydocumentation- The documentation 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, String documentation)
Edits aQuery- Parameters:
id- The id of the querytitle- The title of the querydesc- The description of the querydocumentation- The documentation 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
-
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
-
mustWarnBeforeDeletion
public boolean mustWarnBeforeDeletion(List<String> ids)
Determines if application must warn before deleting the givenQueryContainers- Parameters:
ids- TheQueryContainerids- Returns:
trueif application must warn
-
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
-
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 Stream<Query> getChildQueriesInReadAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, 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 pathuser- The usertype- The query type- Returns:
- all queries in READ access for given parent
-
hasReadRightOnQuery
public boolean hasReadRightOnQuery(UserIdentity userIdentity, Query query)
Check if a user have read rights on a query- Parameters:
userIdentity- the userquery- the query- Returns:
- true if the user have read rights on a query
-
hasReadRightOnQueryContainer
public boolean hasReadRightOnQueryContainer(UserIdentity userIdentity, QueryContainer query)
Check if a user have read rights on a query container- Parameters:
userIdentity- the userquery- the query container- Returns:
- true if the user have read rights on a query container
-
getChildQueriesInWriteAccess
public Stream<Query> getChildQueriesInWriteAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, 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 pathuser- The usertype- The query type- Returns:
- all queries in WRITE access for given parent
-
hasWriteRightOnQuery
public boolean hasWriteRightOnQuery(UserIdentity userIdentity, Query query)
Check if a user have write rights on a query- Parameters:
userIdentity- the userquery- the query- Returns:
- true if the user have write rights on a query
-
getChildQueriesInRightAccess
public Stream<Query> getChildQueriesInRightAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, 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 pathuser- The usertype- The query type- Returns:
- all queries in WRITE access for given parent
-
hasRightAffectationRightOnQuery
public boolean hasRightAffectationRightOnQuery(UserIdentity userIdentity, Query query)
Check if a user have write rights on a query- Parameters:
userIdentity- the userquery- the query- Returns:
- true if the user have write rights on a query
-
hasCreationRightOnQueryContainer
public boolean hasCreationRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a user have creation rights on a query container- Parameters:
userIdentity- the userqueryContainer- the query container- Returns:
- true if the user have creation rights on a query container
-
hasWriteRightOnQueryContainer
public boolean hasWriteRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a user have write rights on a query container- Parameters:
userIdentity- the userqueryContainer- the query container- Returns:
- true if the user have write rights on a query container
-
hasRightAffectationRightOnQueryContainer
public boolean hasRightAffectationRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a user have write rights on a query container- Parameters:
userIdentity- the userqueryContainer- the query container- Returns:
- true if the user have write rights on a query
-
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
-
hasAnyReadableDescendant
public Boolean hasAnyReadableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a folder have a descendant in read access for a given user- Parameters:
userIdentity- the userqueryContainer- the query container- Returns:
- true if the user have read right for at least one child of this container
-
hasAnyWritableDescendant
public Boolean hasAnyWritableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a folder have descendant in write access for a given user- Parameters:
userIdentity- the userqueryContainer- the query container- Returns:
- true if the user have write right for at least one child of this container
-
hasAnyAssignableDescendant
public Boolean hasAnyAssignableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a folder have descendant in right assignment access for a given user- Parameters:
userIdentity- the userqueryContainer- the query container- Returns:
- true if the user have right assignment right for at least one child of this container
-
hasWriteRightOnQueryAndParent
public boolean hasWriteRightOnQueryAndParent(UserIdentity userIdentity, Query query, QueryContainer queryContainer)
Check if a user have write rights on a query- Parameters:
userIdentity- the userquery- the source for the queryqueryContainer- the query container- Returns:
- true if the user have write rights on an query
-
-