Search in sources :

Example 6 with ObjectInFolderContainer

use of org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer in project structr by structr.

the class CMISNavigationService method getFolderTree.

@Override
public List<ObjectInFolderContainer> getFolderTree(final String repositoryId, final String folderId, final BigInteger depth, final String filter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePathSegment, final ExtensionsData extension) {
    final PropertyKey<Folder> parentKey = StructrApp.key(AbstractFile.class, "parent");
    final List<ObjectInFolderContainer> result = new LinkedList<>();
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        int maxDepth = Integer.MAX_VALUE;
        if (depth != null && depth.intValue() >= 0) {
            maxDepth = depth.intValue();
        }
        if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
            for (final Folder folder : app.nodeQuery(Folder.class).and(parentKey, null).sort(AbstractNode.name).getAsList()) {
                recursivelyCollectFolderTree(result, folder, maxDepth, 1, includeAllowableActions);
            }
        } else {
            final Folder folder = app.get(Folder.class, folderId);
            if (folder != null) {
                final List<Folder> children = Iterables.toList(folder.getFolders());
                Collections.sort(children, new GraphObjectComparator(AbstractNode.name, false));
                for (final Folder child : children) {
                    recursivelyCollectFolderTree(result, child, maxDepth, 1, includeAllowableActions);
                }
            } else {
                throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
            }
        }
        tx.success();
    } catch (final FrameworkException fex) {
        logger.warn("", fex);
    }
    return result;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) FrameworkException(org.structr.common.error.FrameworkException) GraphObjectComparator(org.structr.common.GraphObjectComparator) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) LinkedList(java.util.LinkedList)

Aggregations

ObjectInFolderContainer (org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer)6 LinkedList (java.util.LinkedList)4 App (org.structr.core.app.App)3 StructrApp (org.structr.core.app.StructrApp)3 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)3 Folder (org.structr.web.entity.Folder)3 BigInteger (java.math.BigInteger)2 DateTimeFormat (org.apache.chemistry.opencmis.commons.enums.DateTimeFormat)2 IncludeRelationships (org.apache.chemistry.opencmis.commons.enums.IncludeRelationships)2 CmisRuntimeException (org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException)2 ObjectInFolderContainerImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderContainerImpl)2 JSONArray (org.apache.chemistry.opencmis.commons.impl.json.JSONArray)2 GraphObjectComparator (org.structr.common.GraphObjectComparator)2 FrameworkException (org.structr.common.error.FrameworkException)2 Tx (org.structr.core.graph.Tx)2 CMISObjectInFolderWrapper (org.structr.files.cmis.wrapper.CMISObjectInFolderWrapper)2 AbstractFile (org.structr.web.entity.AbstractFile)2 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1