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 Details

  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager serviceManager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • getQueriesRootNode

      Get the root plugin storage object.
      Returns:
      the root plugin storage object.
      Throws:
      AmetysRepositoryException - if a repository error occurs.
    • getQueriesProperties

      Get queries' properties
      Parameters:
      queryIds - The ids of queries to retrieve
      Returns:
      The queries' properties
    • getQueryProperties

      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

      Get the root container properties
      Returns:
      The root container properties
    • getQueryContainerProperties

      Get the query container properties
      Parameters:
      id - The query container id. Can be ROOT_QUERY_CONTAINER_ID for the root container.
      Returns:
      The query container properties
    • getQueryContainerProperties

      Get the query container properties
      Parameters:
      queryContainer - The query container
      Returns:
      The query container properties
    • filterQueries

      public List<String> filterQueries(String rootNode, String search, boolean ownerOnly, boolean requestType, boolean solrType, boolean scriptType, boolean formattingType)
      Filter queries on the server side
      Parameters:
      rootNode - The root node where to seek (to refresh subtrees)
      search - Textual search
      ownerOnly - Only queries of the owner will be returned
      requestType - Only simple/advanced requests will be returned
      solrType - Only Solr requests will be returned
      scriptType - Only script requests will be returned
      formattingType - Only formatting will be returned
      Returns:
      The list of query path
    • createQuery

      public Map<String,Object> createQuery(String title, String desc, String documentation, String type, String content, String parentId)
      Creates a new Query
      Parameters:
      title - The title of the query
      desc - The description of the query
      documentation - The documentation of the query
      type - The type of the query
      content - The content of the query
      parentId - The id of the parent of the query. Use ROOT_QUERY_CONTAINER_ID for the root container.
      Returns:
      A result map
    • createQueryContainer

      public Map<String,Object> createQueryContainer(String parentId, String name)
      Creates a new QueryContainer
      Parameters:
      parentId - The id of the parent. Use ROOT_QUERY_CONTAINER_ID for the root container.
      name - The desired name for the new QueryContainer
      Returns:
      A result map
    • updateQuery

      public Map<String,Object> updateQuery(String id, String title, String desc, String documentation)
      Edits a Query
      Parameters:
      id - The id of the query
      title - The title of the query
      desc - The description of the query
      documentation - The documentation of the query
      Returns:
      A result map
    • renameQueryContainer

      Renames a QueryContainer
      Parameters:
      id - The id of the query container
      newName - The new name of the container
      Returns:
      A result map
    • moveQuery

      public Map<String,Object> moveQuery(String id, String newParentId)
      Moves a Query
      Parameters:
      id - The id of the query
      newParentId - The id of the new parent container of the query. Use ROOT_QUERY_CONTAINER_ID for the root container.
      Returns:
      A result map
    • moveQueryContainer

      public Map<String,Object> moveQueryContainer(String id, String newParentId)
      Parameters:
      id - The id of the query container
      newParentId - The id of the new parent container of the query container. Use ROOT_QUERY_CONTAINER_ID for the root container.
      Returns:
      A result map
    • saveQuery

      public Map<String,Object> saveQuery(String id, String type, String content)
      Saves a Query
      Parameters:
      id - The id of the query
      type - The type of the query
      content - The content of the query
      Returns:
      A result map
    • deleteQuery

      Deletes Query(ies)
      Parameters:
      ids - The ids of the queries to delete
      Returns:
      A result map
    • mustWarnBeforeDeletion

      public boolean mustWarnBeforeDeletion(List<String> ids)
      Determines if application must warn before deleting the given QueryContainers
      Parameters:
      ids - The QueryContainer ids
      Returns:
      true if application must warn
    • deleteQueryContainer

      Deletes QueryContainer(s)
      Parameters:
      ids - The ids of the query containers to delete
      Returns:
      A result map
    • getChildQueriesForAdministrator

      public AmetysObjectIterable<Query> getChildQueriesForAdministrator(QueryContainer parent, boolean onlyDirect, List<String> acceptedTypes)
      Gets all queries for administrator for given parent
      Parameters:
      parent - The QueryContainer, defining the context from which getting children
      onlyDirect - true in order to have only direct child queries from parent path, false otherwise to have all queries at any level underneath the parent path
      acceptedTypes - The type of queries. Can be null or empty to accept all types.
      Returns:
      all queries for administrator for given parent
    • getChildQueriesInReadAccess

      public Stream<Query> getChildQueriesInReadAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, List<String> acceptedTypes)
      Gets all queries in READ access for given parent
      Parameters:
      parent - The QueryContainer, defining the context from which getting children
      onlyDirect - true in order to have only direct child queries from parent path, false otherwise to have all queries at any level underneath the parent path
      user - The user
      acceptedTypes - The type of queries. Can be null or empty to accept all types.
      Returns:
      all queries in READ access for given parent
    • canRead

      public boolean canRead(UserIdentity userIdentity, Query query)
      Determine if user has read access on a query
      Parameters:
      userIdentity - the user
      query - the query
      Returns:
      true if the user have read rights on a query
    • canRead

      public boolean canRead(UserIdentity userIdentity, QueryContainer queryContainer)
      Determines if the user has read access on a query container
      Parameters:
      userIdentity - the user
      queryContainer - the query container
      Returns:
      true if the user has read access on the query container
    • getChildQueriesInWriteAccess

      public Stream<Query> getChildQueriesInWriteAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, List<String> acceptedTypes)
      Gets all queries in WRITE access for given parent
      Parameters:
      parent - The QueryContainer, defining the context from which getting children
      onlyDirect - true in order to have only direct child queries from parent path, false otherwise to have all queries at any level underneath the parent path
      user - The user
      acceptedTypes - The type of queries. Can be null or empty to accept all types.
      Returns:
      all queries in WRITE access for given parent
    • canWrite

      public boolean canWrite(UserIdentity userIdentity, Query query)
      Determines if the user has write access on a query
      Parameters:
      userIdentity - the user
      query - the query
      Returns:
      true if the user has write access on query
    • canDelete

      public boolean canDelete(UserIdentity userIdentity, Query query)
      Determines if the user can delete a query
      Parameters:
      userIdentity - the user
      query - the query
      Returns:
      true if the user can delete the query
    • canRename

      public boolean canRename(UserIdentity userIdentity, QueryContainer queryContainer)
      Determines if the user can rename a query container
      Parameters:
      userIdentity - the user
      queryContainer - the query container
      Returns:
      true if the user can delete the query
    • canDelete

      public boolean canDelete(UserIdentity userIdentity, QueryContainer queryContainer)
      Determines if the user can delete a query container
      Parameters:
      userIdentity - the user
      queryContainer - the query container
      Returns:
      true if the user can delete the query container
    • _isRoot

      protected boolean _isRoot(QueryContainer queryContainer)
      Determines if the query container is the root node
      Parameters:
      queryContainer - the query container
      Returns:
      true if is root
    • getChildQueriesInRightAccess

      public Stream<Query> getChildQueriesInRightAccess(QueryContainer parent, boolean onlyDirect, UserIdentity user, List<String> acceptedTypes)
      Gets all queries in WRITE access for given parent
      Parameters:
      parent - The QueryContainer, defining the context from which getting children
      onlyDirect - true in order to have only direct child queries from parent path, false otherwise to have all queries at any level underneath the parent path
      user - The user
      acceptedTypes - The type of queries. Can be null or empty to accept all types.
      Returns:
      all queries in WRITE access for given parent
    • canAssignRights

      public boolean canAssignRights(UserIdentity userIdentity, Query query)
      Check if a user can edit rights on a query
      Parameters:
      userIdentity - the user
      query - the query
      Returns:
      true if the user can edit rights on a query
    • canCreate

      public boolean canCreate(UserIdentity userIdentity, QueryContainer queryContainer)
      Check if a user has creation rights on a query container
      Parameters:
      userIdentity - the user identity
      queryContainer - the query container
      Returns:
      true if the user has creation rights on a query container
    • canWrite

      public boolean canWrite(UserIdentity userIdentity, QueryContainer queryContainer)
      Check if a user has write access on a query container
      Parameters:
      userIdentity - the user identity
      queryContainer - the query container
      Returns:
      true if the user has write access on the a query container
    • canWrite

      public boolean canWrite(UserIdentity userIdentity, QueryContainer queryContainer, boolean recursively)
      Check if a user has write access on a query container
      Parameters:
      userIdentity - the user user identity
      queryContainer - the query container
      recursively - true to check write access on all descendants recursively
      Returns:
      true if the user has write access on the a query container
    • canAssignRights

      public boolean canAssignRights(UserIdentity userIdentity, QueryContainer queryContainer)
      Check if a user can edit rights on a query container
      Parameters:
      userIdentity - the user
      queryContainer - the query container
      Returns:
      true if the user can edit rights on a query
    • getChildQueryContainers

      Gets all query containers for given parent
      Parameters:
      parent - The QueryContainer, 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 user
      queryContainer - 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 query container have descendant in write access for a given user
      Parameters:
      userIdentity - the user identity
      queryContainer - 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 user identity
      queryContainer - the query container
      Returns:
      true if the user have right assignment right for at least one child of this container