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
_observationManager
The observation managerprotected 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 Instance Methods Concrete Methods Modifier and Type Method Description protected 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>
createQuery(String title, String desc, String documentation, 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 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' 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 propertiesMap<String,Object>
getRootProperties()
Get the root container propertiesBoolean
hasAnyAssignableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a folder have descendant in right assignment access for a given userBoolean
hasAnyReadableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a folder have a descendant in read access for a given userBoolean
hasAnyWritableDescendant(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a folder have descendant in write access for a given userboolean
hasCreationRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a user have creation rights on a query containerboolean
hasReadRightOnQuery(UserIdentity userIdentity, Query query)
Check if a user have read rights on a queryboolean
hasReadRightOnQueryContainer(UserIdentity userIdentity, QueryContainer query)
Check if a user have read rights on a query containerboolean
hasRightAffectationRightOnQuery(UserIdentity userIdentity, Query query)
Check if a user have write rights on a queryboolean
hasRightAffectationRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a user have write rights on a query containerboolean
hasWriteRightOnQuery(UserIdentity userIdentity, Query query)
Check if a user have write rights on a queryboolean
hasWriteRightOnQueryAndParent(UserIdentity userIdentity, Query query, QueryContainer queryContainer)
Check if a user have write rights on a queryboolean
hasWriteRightOnQueryContainer(UserIdentity userIdentity, QueryContainer queryContainer)
Check if a user have write rights on a query containerMap<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>
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, 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:
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.
-
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_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 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_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, 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_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
-
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
-
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
-
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
-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 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
-true
in order to have only direct child queries from parent path,false
otherwise 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
-true
in order to have only direct child queries from parent path,false
otherwise 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
-true
in order to have only direct child queries from parent path,false
otherwise 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
-
-