Search in sources :

Example 86 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CMISNavigationService method getFolderParent.

@Override
public ObjectData getFolderParent(final String repositoryId, final String folderId, final String propertyFilter, final ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile graphObject = app.get(AbstractFile.class, folderId);
        if (graphObject != null) {
            final Folder parent = graphObject.getParent();
            if (parent != null) {
                result = CMISObjectWrapper.wrap(parent, propertyFilter, false);
            }
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    return null;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder)

Example 87 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CMISNavigationService method getChildrenQuery.

public Query<AbstractFile> getChildrenQuery(final App app, final String folderId) throws FrameworkException {
    final Query<AbstractFile> query = app.nodeQuery(AbstractFile.class).sort(AbstractNode.name);
    final PropertyKey<Folder> parent = StructrApp.key(AbstractFile.class, "parent");
    final PropertyKey<Boolean> hasParent = StructrApp.key(AbstractFile.class, "hasParent");
    final PropertyKey<Boolean> isThumbnail = StructrApp.key(Image.class, "isThumbnail");
    if (CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
        query.and(hasParent, false).and(isThumbnail, false);
    } else {
        final Folder folder = app.get(Folder.class, folderId);
        if (folder != null) {
            query.and(parent, folder).and(isThumbnail, false);
        } else {
            throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
        }
    }
    return query;
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder)

Example 88 with Folder

use of org.structr.web.entity.Folder 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)

Example 89 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class CMISObjectService method createFolder.

@Override
public String createFolder(final String repositoryId, final Properties properties, final String folderId, final List<String> policies, final Acl addAces, final Acl removeAces, final ExtensionsData extension) {
    final App app = StructrApp.getInstance(securityContext);
    String uuid = null;
    try (final Tx tx = app.tx()) {
        final String objectTypeId = getStringValue(properties, PropertyIds.OBJECT_TYPE_ID);
        final Class type = typeFromObjectTypeId(objectTypeId, BaseTypeId.CMIS_FOLDER, Folder.class);
        // check if type exists
        if (type != null) {
            // check that base type is cmis:folder
            final BaseTypeId baseTypeId = getBaseTypeId(type);
            if (baseTypeId != null && BaseTypeId.CMIS_FOLDER.equals(baseTypeId)) {
                // create folder
                final AbstractFile newFolder = (AbstractFile) app.create(type, PropertyMap.cmisTypeToJavaType(securityContext, type, properties));
                // find and set parent if it exists
                if (!CMISInfo.ROOT_FOLDER_ID.equals(folderId)) {
                    final Folder parent = app.get(Folder.class, folderId);
                    if (parent != null) {
                        newFolder.setParent(parent);
                    } else {
                        throw new CmisObjectNotFoundException("Folder with ID " + folderId + " does not exist");
                    }
                }
                uuid = newFolder.getUuid();
            } else {
                throw new CmisConstraintException("Cannot create cmis:folder of type " + objectTypeId);
            }
        } else {
            throw new CmisObjectNotFoundException("Type with ID " + objectTypeId + " does not exist");
        }
        tx.success();
    } catch (Throwable t) {
        throw new CmisRuntimeException("New folder could not be created: " + t.getMessage());
    }
    return uuid;
}
Also used : App(org.structr.core.app.App) StructrApp(org.structr.core.app.StructrApp) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisRuntimeException(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException) CmisConstraintException(org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) Folder(org.structr.web.entity.Folder)

Example 90 with Folder

use of org.structr.web.entity.Folder in project structr by structr.

the class FileSyncWatchEventListener method handle.

// ----- private methods -----
private FolderAndFile handle(final Path root, final Path relativePath, final Path path, final boolean create) throws FrameworkException {
    // identify mounted folder object
    final PropertyKey<String> mountTargetKey = StructrApp.key(Folder.class, "mountTarget");
    final Folder folder = StructrApp.getInstance().nodeQuery(Folder.class).and(mountTargetKey, root.toString()).getFirst();
    if (folder != null) {
        final String mountFolderPath = folder.getProperty(StructrApp.key(Folder.class, "path"));
        if (mountFolderPath != null) {
            final Path relativePathParent = relativePath.getParent();
            if (relativePathParent == null) {
                return new FolderAndFile(folder, getOrCreate(folder, path, relativePath, create));
            } else {
                final String pathRelativeToRoot = folder.getPath() + "/" + relativePathParent.toString();
                final Folder parentFolder = FileHelper.createFolderPath(SecurityContext.getSuperUserInstance(), pathRelativeToRoot);
                final AbstractFile file = getOrCreate(parentFolder, path, relativePath, create);
                return new FolderAndFile(folder, file);
            }
        } else {
            logger.warn("Cannot handle watch event, folder {} has no path", folder.getUuid());
        }
    }
    return null;
}
Also used : Path(java.nio.file.Path) AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder)

Aggregations

Folder (org.structr.web.entity.Folder)95 Tx (org.structr.core.graph.Tx)64 FrameworkException (org.structr.common.error.FrameworkException)60 AbstractFile (org.structr.web.entity.AbstractFile)42 App (org.structr.core.app.App)35 StructrApp (org.structr.core.app.StructrApp)35 File (org.structr.web.entity.File)34 Test (org.junit.Test)23 StructrUiTest (org.structr.web.StructrUiTest)21 IOException (java.io.IOException)20 PropertyMap (org.structr.core.property.PropertyMap)16 Path (java.nio.file.Path)14 LinkedList (java.util.LinkedList)10 NodeAttribute (org.structr.core.graph.NodeAttribute)9 InputStream (java.io.InputStream)5 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)5 User (org.structr.web.entity.User)5 Page (org.structr.web.entity.dom.Page)5 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4