Class DocumentNodeDescriber

java.lang.Object
org.exoplatform.documents.storage.jcr.util.DocumentNodeDescriber

public final class DocumentNodeDescriber extends Object
Reads, in a session the caller opened and closes, what nodes are, where they are and what a user may do with files, for several nodes at once. Every lookup goes to ExtendedSession.getNodeByIdentifier(String) directly: only ItemNotFoundException means that no node carries an id, and any other repository failure reaches the caller.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of a space group's library folder.
    static final String
    The statement reading a page of the files under a folder: the folder's path, the jcr:uuid condition, then the ordering property.
    static final int
    The bound on the unreadable search index hits after a file listing's cursor: once a full page leaves more than this many unreadable hits after the cursor and no readable one, the listing reports the index as broken rather than end the walk.
    static final String
    The path under which every space's group folder lies.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String,org.exoplatform.documents.model.DocumentNodeInfo>
    describe(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids, org.exoplatform.social.core.space.spi.SpaceService spaceService)
    Describes some nodes, whoever may see them.
    static Map<String,org.exoplatform.documents.model.DocumentIndexInfo>
    describeForIndex(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids, org.exoplatform.social.core.space.spi.SpaceService spaceService)
    Describes some files for a search index built outside Documents, whoever may see them.
    getAccess(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids)
    Tells which of some nodes are files the session's user may read, and which of them he may edit.
    getFolderAccess(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids)
    Tells which of some nodes are folders the session's user may open, and which of them he may edit.
    static List<String>
    listFileIds(org.exoplatform.services.jcr.core.ExtendedSession session, String folderId, String afterId, int limit)
    Lists a page of the files under a folder, its sub-folders included, whoever may see them, ordered by jcr:uuid.
    static String
    listFileIdsStatement(String folderPath, String afterId)
    Builds the statement reading a page of the files under a folder.
    static org.exoplatform.documents.constant.DocumentNodeType
    typeOf(javax.jcr.Node node)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SPACES_PATH_PREFIX

      public static final String SPACES_PATH_PREFIX
      The path under which every space's group folder lies.
      See Also:
    • LIBRARY_FOLDER_NAME

      public static final String LIBRARY_FOLDER_NAME
      The name of a space group's library folder.
      See Also:
    • LIST_FILE_IDS_QUERY

      public static final String LIST_FILE_IDS_QUERY
      The statement reading a page of the files under a folder: the folder's path, the jcr:uuid condition, then the ordering property.
      See Also:
    • MAX_UNREADABLE_HITS

      public static final int MAX_UNREADABLE_HITS
      The bound on the unreadable search index hits after a file listing's cursor: once a full page leaves more than this many unreadable hits after the cursor and no readable one, the listing reports the index as broken rather than end the walk. Pages double while they hold no readable hit, so a last page may step over up to about twice as many before the folder ends.
      See Also:
  • Method Details

    • getAccess

      public static Map<String,Boolean> getAccess(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids) throws javax.jcr.RepositoryException
      Tells which of some nodes are files the session's user may read, and which of them he may edit.
      Parameters:
      session - a session of the user
      ids - node identifiers
      Returns:
      for each id naming a file the user may read, whether he may edit it; ids naming no node, a node he may not read or another kind of node are absent
      Throws:
      javax.jcr.RepositoryException - when the repository fails otherwise reading a node; a failure of the edit check reads as read only
    • getFolderAccess

      public static Map<String,Boolean> getFolderAccess(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids) throws javax.jcr.RepositoryException
      Tells which of some nodes are folders the session's user may open, and which of them he may edit. A folder is typed as typeOf(Node) types it, so a library root is one, and a shortcut is not: a caller resolves a shortcut to its target first.
      Parameters:
      session - a session of the user
      ids - node identifiers
      Returns:
      for each id naming a folder the user may open, whether he may edit it; ids naming no node, a node he may not read or another kind of node are absent
      Throws:
      javax.jcr.RepositoryException - when the repository fails otherwise reading a node; a failure of the edit check reads as read only
    • describe

      public static Map<String,org.exoplatform.documents.model.DocumentNodeInfo> describe(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids, org.exoplatform.social.core.space.spi.SpaceService spaceService) throws javax.jcr.RepositoryException
      Describes some nodes, whoever may see them.
      Parameters:
      session - a session that may read every node, a system session
      ids - node identifiers
      spaceService - the service resolving a library's space
      Returns:
      each id's description, plus, for a shortcut whose chain ends on a node that is not a shortcut, that node's description under its id; an id no node carries is absent
      Throws:
      javax.jcr.RepositoryException - when the repository fails otherwise than by finding no node
    • describeForIndex

      public static Map<String,org.exoplatform.documents.model.DocumentIndexInfo> describeForIndex(org.exoplatform.services.jcr.core.ExtendedSession session, Collection<String> ids, org.exoplatform.social.core.space.spi.SpaceService spaceService) throws javax.jcr.RepositoryException
      Describes some files for a search index built outside Documents, whoever may see them.
      Parameters:
      session - a session that may read every node, a system session
      ids - node identifiers
      spaceService - the service resolving a library's space
      Returns:
      each id naming a file and its description, in the order of the ids, every url null; an id no node carries, naming a folder, a shortcut or another kind of node, or naming a file in the trash (itself trashed, or under a trashed folder) is absent
      Throws:
      javax.jcr.RepositoryException - when the repository fails otherwise than by finding no node
    • listFileIds

      public static List<String> listFileIds(org.exoplatform.services.jcr.core.ExtendedSession session, String folderId, String afterId, int limit) throws javax.jcr.RepositoryException
      Lists a page of the files under a folder, its sub-folders included, whoever may see them, ordered by jcr:uuid. Documents makes every file it stores referenceable, so its identifier is its jcr:uuid; a file that is not referenceable carries no jcr:uuid and is not listed.

      The end of the folder is decided from the rows the query returns, never from the nodes loaded: the search index can hold a hit whose node no longer exists (a file deleted since it was indexed), which the node iterator would skip silently and so shorten the page. Each row's path is read from the repository's item data, without loading the node; a hit with no item is counted and skipped. It cannot move the cursor, since its jcr:uuid is not readable, so the next query asks for as many more rows as there are unreadable hits after the cursor, and for twice the last page when that page held no readable hit, so that a run of unreadable hits reaches the bound in a few queries; the page still ends at limit files. A row whose node now lies outside the folder (a file moved since it was indexed) moves the cursor but is not listed.

      Parameters:
      session - a session that may read every node, a system session
      folderId - the folder's identifier
      afterId - the identifier the page starts after, null for the first page
      limit - the most identifiers returned
      Returns:
      up to limit file identifiers following afterId, fewer only when the query has no row left; empty when no folder carries folderId
      Throws:
      javax.jcr.RepositoryException - when the repository fails otherwise than by finding no node, or when a full page leaves more than MAX_UNREADABLE_HITS unreadable hits after the cursor and no readable one
    • listFileIdsStatement

      public static String listFileIdsStatement(String folderPath, String afterId)
      Builds the statement reading a page of the files under a folder.
      Parameters:
      folderPath - the folder's path
      afterId - the identifier the page starts after, null for the first page
      Returns:
      a JCR SQL statement, its string literals escaped
    • typeOf

      public static org.exoplatform.documents.constant.DocumentNodeType typeOf(javax.jcr.Node node) throws javax.jcr.RepositoryException
      Parameters:
      node - a node
      Returns:
      what the node is, read from its own primary type: a version's frozen node is DocumentNodeType.OTHER, whatever it froze
      Throws:
      javax.jcr.RepositoryException - when the type cannot be read