Class ExplorerResourcesDAO

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.explorer.resources.actions.ExplorerResourcesDAO
All Implemented Interfaces:
LogEnabled, Component, Contextualizable, Serviceable
Direct Known Subclasses:
ExplorerResourcesDAO, WorkspaceExplorerResourceDAO

Explorer resources DAO
  • Field Details

  • Constructor Details

  • Method Details

    • service

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

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      Throws:
      ContextException
    • getResourcesRootNodes

      Get the root nodes for resources
      Returns:
      the root nodes
    • getRootNodesInfo

      Retrieves the set of standard data for the explorer root node
      Returns:
      The data structured in a map
    • getDefaultInfoAsRootNode

      Get the necessary default info for a root node. Can be used to construct a root node for a tree (client side).
      Parameters:
      id - The root node id
      Returns:
      A map which contains a set of default info (such as id, applicationId, path, type etc...)
    • getDefaultInfoAsRootNode

      Get the necessary default info for a root node. Can be used to construct a root node for a tree (client side).
      Parameters:
      rootNode - The root node
      Returns:
      A map which contains a set of default info (such as id, applicationId, path, type etc...)
    • getRootNodeLabel

      Get the root node label
      Parameters:
      rootNode - the node
      Returns:
      the readable label
    • getNodesInfo

      Get the informations on given nodes (resources or collections)
      Parameters:
      ids - The ids of node
      Returns:
      the nodes information
    • getExplorerNodeProperties

      Get the explorer node properties
      Parameters:
      node - The explorer node
      Returns:
      The properties
    • getResourceProperties

      Get the resource properties
      Parameters:
      resource - The resources
      Returns:
      The properties
    • getExplorerNodePathPatterns

      Get the pattern that match an explorer node path
      Returns:
      the patterns
    • filterResourcesByRegExp

      public List<String> filterResourcesByRegExp(String id, String value, List<String> allowedExtensions)
      Get the path of pages which match filter regexp
      Parameters:
      id - The id of explorer node to start search
      value - the value to match
      allowedExtensions - The allowed file extensions (lower-case). Can be null or empty to not filter on file extensions
      Returns:
      the matching paths
    • getUserRights

      protected Set<String> getUserRights(ExplorerNode node)
      Get the user rights on the resource collection
      Parameters:
      node - The explorer node
      Returns:
      The user's rights
    • hasRight

      public boolean hasRight(String id, String rightId)
      Check current user right on given explorer node
      Parameters:
      id - The id of the explorer node
      rightId - The if of right to check
      Returns:
      true if user has right
    • checkLock

      public boolean checkLock(AmetysObject ao)
      Check lock on a Ametys object
      Parameters:
      ao - the Ametys object
      Returns:
      false if the Ametys object is locked and can not be edited or deleted
    • checkUserRight

      public void checkUserRight(AmetysObject object, String rightId) throws IllegalAccessException
      Check the user privilege on object
      Parameters:
      object - the object
      rightId - the right id
      Throws:
      IllegalAccessException - if the user has no sufficient rights
    • getUserRight

      public boolean getUserRight(UserIdentity user, String right, AmetysObject object)
      Retrieve the rights for the user
      Parameters:
      user - The user
      right - The right
      object - The object
      Returns:
      True if the user has the right
    • addResourceCollection

      public Map<String,Object> addResourceCollection(String parentId, String desiredName, Boolean renameIfExists)
      Add a resource collection
      Parameters:
      parentId - The identifier of the parent in which the resource collection will be added
      desiredName - The desired name for the resource collection
      renameIfExists - If false, in case of existing name the resource collection will not be created, if true it will be created and renamed
      Returns:
      The result map with id, parentId, name and message keys
    • addResourceCollection

      public ResourceCollection addResourceCollection(ModifiableResourceCollection parent, String desiredName, Boolean renameIfExists, List<String> errors)
      Add a resource collection
      Parameters:
      parent - The parent collection in which the resource collection will be added
      desiredName - The desired name for the resource collection
      renameIfExists - If false, in case of existing name the resource collection will not be created, if true it will be created and renamed
      errors - An optional list of possible error messages in case the creation failed. Possible values are: locked, already-exist.
      Returns:
      The created resource collection or null if creation failed
    • getResourceCollectionType

      Get the type of child resource collection
      Returns:
      the type of child resource collection
    • renameObject

      public Map<String,Object> renameObject(String id, String name) throws javax.jcr.RepositoryException
      Rename a resource, or resource collection
      Parameters:
      id - The id of the object to rename
      name - The desired name to set to the object.
      Returns:
      The result map with id, name and message keys
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • renameObject

      public JCRAmetysObject renameObject(JCRAmetysObject object, String name, List<String> errors) throws javax.jcr.RepositoryException
      Rename a resource, or resource collection
      Parameters:
      object - The object to rename
      name - The desired name to set to the object.
      errors - An optional list of possible error messages in case the operation failed. Possible values are: locked, already-exist.
      Returns:
      The new object
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • deleteObject

      Delete an object
      Parameters:
      ids - The list of identifiers for the objects to delete
      Returns:
      The result map with a message key in case of an error
    • deleteObject

      Delete an object
      Parameters:
      object - The object to delete
      errors - An optional list of possible error messages in case the creation failed. Possible values are: locked.
      Returns:
      the parent id of the removed object
    • renameResource

      public Map<String,Object> renameResource(String id, String name) throws javax.jcr.RepositoryException
      Rename a resource
      Parameters:
      id - The id of the resource to rename
      name - The desired name to set to the resource.
      Returns:
      The result map with id, name and message keys
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • renameResource

      public JCRResource renameResource(JCRResource resource, String name, List<String> errors) throws javax.jcr.RepositoryException
      Rename a resource
      Parameters:
      resource - The resource to rename
      name - The desired name to set to the resource.
      errors - An optional list of possible error messages in case the operation failed. Possible values are: locked, already-exist.
      Returns:
      The new resource
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • copyResource

      public Map<String,Object> copyResource(List<String> ids, String target) throws javax.jcr.RepositoryException
      Copy file resources
      Parameters:
      ids - The list of identifiers for the resources to copy
      target - The id of target to copy into
      Returns:
      The result map with a message key in case of an error or with the list of uncopied/copied resources
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • copyResource

      public Map<String,Object> copyResource(List<String> ids, ModifiableResourceCollection target) throws javax.jcr.RepositoryException
      Copy file resources
      Parameters:
      ids - The list of identifiers for the resources to copy
      target - The target to copy into
      Returns:
      The result map with a message key in case of an error or with the list of uncopied/copied resources
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • moveObject

      public Map<String,Object> moveObject(List<String> ids, String targetId) throws javax.jcr.RepositoryException
      Move objects
      Parameters:
      ids - The list of identifiers for the objects to move
      targetId - The id of target to move into
      Returns:
      The result map with a message key in case of an error or with the list of unmoved/moved objects
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • moveObject

      public Map<String,Object> moveObject(List<String> ids, JCRTraversableAmetysObject targetNode) throws javax.jcr.RepositoryException
      Move objects
      Parameters:
      ids - The list of identifiers for the objects to move
      targetNode - The target to move into
      Returns:
      The result map with a message key in case of an error or with the list of unmoved/moved objects
      Throws:
      javax.jcr.RepositoryException - If there is a repository error
    • resourceHistory

      public List<Map<String,Object>> resourceHistory(String id) throws javax.jcr.RepositoryException
      Get the history versions of a resource
      Parameters:
      id - the id of resource
      Returns:
      The versions
      Throws:
      javax.jcr.RepositoryException - if an error occurred
    • _version2json

      protected Map<String,Object> _version2json(JCRResource resource, ExplorerResourcesDAO.VersionInformation versionInformation) throws javax.jcr.RepositoryException
      Get the JSON representation of a version of a resource
      Parameters:
      resource - the resource
      versionInformation - the version information
      Returns:
      the version as JSON object
      Throws:
      javax.jcr.RepositoryException - if failed to get revision
    • restoreResource

      public void restoreResource(String id, String versionName)
      This action restores an old version of a Resource.
      Parameters:
      id - the id of resource
      versionName - the name of version to restore
    • resourcesExists

      public boolean resourcesExists(String parentId, List<String> names)
      Determines if at least one resource with given names already exists
      Parameters:
      parentId - the id of parent collection
      names - the names of the resources
      Returns:
      true if a resource with same name exists
    • resourceExists

      public boolean resourceExists(String parentId, String name)
      Determines if a resource with given name already exists
      Parameters:
      parentId - the id of parent collection
      name - the name of resource
      Returns:
      true if a resource with same name exists
    • resourceExists

      public boolean resourceExists(TraversableAmetysObject parent, String name)
      Determines if a resource with given name already exists
      Parameters:
      parent - the parent collection
      name - the name of resource
      Returns:
      true if a resource with same name exists
    • setDCMetadata

      public void setDCMetadata(String resourceId, Map<String,Object> values) throws ProcessingException
      Set the Dublin Core metadata of a Resource.
      Parameters:
      resourceId - the id of resource
      values - the DC values
      Throws:
      ProcessingException - if an error occurred
    • setDCMetadata

      public void setDCMetadata(ModifiableResource resource, Map<String,Object> values)
      Set the Dublin Core metadata of a Resource.
      Parameters:
      resource - the resource
      values - the DC values
    • getDCMetadata

      Get the DublinCore metadata of a DublinCoreAwareAmetysObject
      Parameters:
      id - the id of resource
      Returns:
      the DC metadata
    • addCMISCollection

      public Map<String,Object> addCMISCollection(String parentId, String originalName, String url, String login, String password, String repoId, String mountPoint, boolean renameIfExists)
      Creates a new CMIS folder (see CMISRootResourcesCollection)
      Parameters:
      parentId - the id of parent folder
      originalName - the original name if CMIS folder
      url - The url of CMIS repository
      login - The user's login to access CMIS repository
      password - The user's password to access CMIS repository
      repoId - The id of CMIS repository
      mountPoint - The mount point in the server
      renameIfExists - true to automatically renamed CMIS folder if requested name already exists
      Returns:
      the result map with id of created node
    • editCMISCollection

      public Map<String,Object> editCMISCollection(String id, String url, String login, String password, String repoId, String mountPoint)
      Edits a CMIS folder (see CMISRootResourcesCollection)
      Parameters:
      id - the id of CMIS folder
      url - The url of CMIS repository
      login - The user's login to access CMIS repository
      password - The user's password to access CMIS repository
      repoId - The id of CMIS repository
      mountPoint - The mount point to use for the repository
      Returns:
      the result map with id of edited node
    • isCMISCollection

      public boolean isCMISCollection(String id)
      Determines if a object is a CMISRootResourcesCollection
      Parameters:
      id - The id of object
      Returns:
      true if it is a CMIS root folder
    • getCMISProperties

      Get the CMIS properties of collection
      Parameters:
      id - The id of CMIS collection
      Returns:
      the CMIS properties to access CMIS repository
    • updateResource

      public void updateResource(ModifiableResource resource, InputStream is, String fileName)
      Updates resource input stream and metadata
      Parameters:
      resource - The resource
      is - The resource input stream
      fileName - The file name
    • extractResourceMetadata

      public void extractResourceMetadata(ModifiableResource resource, String mimeType)
      Extract the resource's metadata and populate the object accordingly.
      Parameters:
      resource - the resource to populate.
      mimeType - the resource MIME type.
    • checkpoint

      public void checkpoint(ModifiableResource resource)
      Creates a new version
      Parameters:
      resource - the resource
    • createResource

      Parameters:
      collection - the parent ModifiableResourceCollection
      name - the name of the child resource
      Returns:
      the new resource created.
      Throws:
      AmetysRepositoryException - if an error occurs.
      RepositoryIntegrityViolationException - if an object with the same name already exists and same name siblings is not allowed.
    • addComment

      public Map<String,Object> addComment(String resourceId, String comment)
      Add a comment to a resource
      Parameters:
      resourceId - The id of the resource
      comment - The comment
      Returns:
      the result
    • _canAddComment

      protected boolean _canAddComment(UserIdentity user, CommentableResource resource)
      Indicates if an user can add a comment of a given resource
      Parameters:
      user - An user identity
      resource - The resource to comment
      Returns:
      True if the user can add a comment
    • editComment

      public Map<String,Object> editComment(String resourceId, String commentId, String comment)
      Edit the comment of a resource
      Parameters:
      resourceId - The id of the resource
      commentId - The id of comment to edit
      comment - The comment
      Returns:
      the result
    • _canEditComment

      protected boolean _canEditComment(UserIdentity user, CommentableResource resource, JCRPost comment)
      Indicates if an user can edit a comment of a given resource
      Parameters:
      user - An user identity
      resource - The resource
      comment - The comment to edit
      Returns:
      True if the user can edit the comment
    • _setComment

      protected void _setComment(JCRPost comment, String content)
      Update the content of a comment
      Parameters:
      comment - The comment to update
      content - The content as string
    • _getComment

      Get the content of a comment as a String
      Parameters:
      post - the post
      Returns:
      The content as String
      Throws:
      AmetysRepositoryException - if failed to parse comment
    • _getCommentForEditing

      Get the content of a comment to edit as a String
      Parameters:
      post - the post
      Returns:
      The content as String
      Throws:
      AmetysRepositoryException - if failed to parse comment
    • deleteComment

      public Map<String,Object> deleteComment(String resourceId, String commentId)
      Delete the comment of a resource
      Parameters:
      resourceId - The id of the resource
      commentId - The id of comment to delete
      Returns:
      the result
    • _canDeleteComment

      protected boolean _canDeleteComment(UserIdentity user, CommentableResource resource, JCRPost comment)
      Indicates if an user can delete a comment of a given resource
      Parameters:
      user - An user identity
      resource - The resource
      comment - The comment to edit
      Returns:
      True if the user can edit the comment
    • getComments

      public List<Map<String,Object>> getComments(String resourceId, boolean isEdition)
      Get the comments of a resource
      Parameters:
      resourceId - The id of the resource
      isEdition - true to get the comments in edit mode
      Returns:
      The comments
    • getComment

      public Map<String,Object> getComment(String commentId, boolean isEdition)
      Get a comment of a resource
      Parameters:
      commentId - The id of the comment
      isEdition - true to get the comment in edit mode
      Returns:
      The comments
    • _comment2json

      protected Map<String,Object> _comment2json(JCRPost comment, boolean isEdition)
      Get JSOn representation of a comment
      Parameters:
      comment - The comment
      isEdition - true to get the comment in edit mode
      Returns:
      the comment as JSON