Search in sources :

Example 6 with AbstractFile

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

the class StructrFileSystemView method getWorkingDirectory.

@Override
public FtpFile getWorkingDirectory() throws FtpException {
    try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
        AbstractFile structrWorkingDir = FileHelper.getFileByAbsolutePath(securityContext, workingDir);
        tx.success();
        if (structrWorkingDir == null || structrWorkingDir instanceof File) {
            return new StructrFtpFolder(securityContext, null);
        }
        return new StructrFtpFolder(securityContext, (Folder) structrWorkingDir);
    } catch (FrameworkException fex) {
        logger.error("Error in changeWorkingDirectory()", fex);
    }
    return null;
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) FtpFile(org.apache.ftpserver.ftplet.FtpFile)

Example 7 with AbstractFile

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

the class CdCommand method handleTabCompletion.

@Override
public void handleTabCompletion(final StructrShellCommand parent, final String line, final int tabCount) throws IOException {
    if (line.contains(" ") && line.length() >= 3) {
        final PropertyKey<AbstractFile> parentKey = StructrApp.key(AbstractFile.class, "parent");
        String incompletePath = line.substring(line.indexOf(" ") + 1);
        Folder baseFolder = null;
        String lastPathPart = null;
        if (incompletePath.startsWith("\"")) {
            incompletePath = incompletePath.substring(1);
        }
        final App app = StructrApp.getInstance();
        if ("..".equals(incompletePath)) {
            term.handleCharacter('/');
            return;
        }
        if (incompletePath.startsWith("/")) {
            incompletePath = incompletePath.substring(1);
        } else {
            baseFolder = parent.getCurrentFolder();
        }
        // identify full path parts and find folders
        final String[] parts = incompletePath.split("[/]+");
        final int partCount = parts.length;
        try (final Tx tx = app.tx()) {
            // only a single path part
            if (partCount == 1) {
                lastPathPart = parts[0];
            } else {
                lastPathPart = parts[partCount - 1];
                // more than a single path part, find preceding folders
                for (int i = 0; i < partCount - 1; i++) {
                    // skip empty path parts
                    if (StringUtils.isNotBlank(parts[i])) {
                        baseFolder = app.nodeQuery(Folder.class).and(parentKey, baseFolder).and(Folder.name, parts[i]).getFirst();
                        if (baseFolder == null) {
                            return;
                        }
                    }
                }
            }
            final List<Folder> allFolders = app.nodeQuery(Folder.class).and(parentKey, baseFolder).getAsList();
            final List<Folder> folders = new LinkedList<>();
            for (final Folder folder : allFolders) {
                if (folder.getName().startsWith(lastPathPart)) {
                    folders.add(folder);
                }
            }
            if (folders.size() > 1) {
                // only display autocomplete suggestions after second tab
                if (tabCount > 1) {
                    displayAutocompleteSuggestions(parent, folders, line);
                }
            } else if (!folders.isEmpty()) {
                final Folder folder = folders.get(0);
                if (parent.isAllowed(folder, Permission.read, false)) {
                    if (lastPathPart.equals(folder.getName())) {
                        // only display autocomplete suggestions after second tab
                        if (tabCount > 1) {
                            displayAutocompleteSuggestions(parent, folder.getFolders(), line);
                        } else {
                            if (!line.endsWith("/")) {
                                term.handleCharacter('/');
                            }
                        }
                    } else {
                        displayAutocompleteFolder(folder, lastPathPart);
                    }
                }
            }
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
}
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) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder) LinkedList(java.util.LinkedList)

Example 8 with AbstractFile

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

the class CMISNavigationService method getDescendants.

@Override
public List<ObjectInFolderContainer> getDescendants(String repositoryId, String folderId, BigInteger depth, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, ExtensionsData extension) {
    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();
        }
        for (final AbstractFile child : getChildrenQuery(app, folderId).getAsList()) {
            recursivelyCollectDescendants(result, child, maxDepth, 1, includeAllowableActions);
        }
        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) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) ObjectInFolderContainer(org.apache.chemistry.opencmis.commons.data.ObjectInFolderContainer) LinkedList(java.util.LinkedList)

Example 9 with AbstractFile

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

the class CMISNavigationService method getObjectParents.

@Override
public List<ObjectParentData> getObjectParents(String repositoryId, String objectId, String propertyFilter, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includeRelativePathSegment, ExtensionsData extension) {
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        final List<ObjectParentData> data = new LinkedList<>();
        final AbstractFile graphObject = app.get(AbstractFile.class, objectId);
        final Folder parent = graphObject.getParent();
        final ObjectData element = parent != null ? CMISObjectWrapper.wrap(parent, propertyFilter, includeAllowableActions) : new CMISRootFolder(propertyFilter, includeAllowableActions);
        final ObjectParentDataImpl impl = new ObjectParentDataImpl(element);
        impl.setRelativePathSegment(graphObject.getProperty(AbstractNode.name));
        data.add(impl);
        tx.success();
        return data;
    } catch (Throwable t) {
        logger.warn("", t);
    }
    return null;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) ObjectParentData(org.apache.chemistry.opencmis.commons.data.ObjectParentData) 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) CMISRootFolder(org.structr.files.cmis.repository.CMISRootFolder) Folder(org.structr.web.entity.Folder) ObjectParentDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectParentDataImpl) LinkedList(java.util.LinkedList)

Example 10 with AbstractFile

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

the class CMISObjectService method getObjectByPath.

@Override
public ObjectData getObjectByPath(final String repositoryId, final String path, final String propertyFilter, final Boolean includeAllowableActions, final IncludeRelationships includeRelationships, final String renditionFilter, final Boolean includePolicyIds, final Boolean includeAcl, final ExtensionsData extension) {
    final PropertyKey<String> pathKey = StructrApp.key(AbstractFile.class, "path");
    final App app = StructrApp.getInstance();
    ObjectData result = null;
    try (final Tx tx = app.tx()) {
        final AbstractFile file = app.nodeQuery(AbstractFile.class).and(pathKey, path).getFirst();
        if (file != null) {
            result = CMISObjectWrapper.wrap(file, propertyFilter, includeAllowableActions);
        }
        tx.success();
    } catch (Throwable t) {
        logger.warn("", t);
    }
    if (result != null) {
        return result;
    }
    throw new CmisObjectNotFoundException("Object with path " + path + " does not exist");
}
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) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData)

Aggregations

AbstractFile (org.structr.web.entity.AbstractFile)36 Folder (org.structr.web.entity.Folder)24 Tx (org.structr.core.graph.Tx)17 FrameworkException (org.structr.common.error.FrameworkException)16 App (org.structr.core.app.App)14 StructrApp (org.structr.core.app.StructrApp)14 File (org.structr.web.entity.File)10 PropertyMap (org.structr.core.property.PropertyMap)8 LinkedList (java.util.LinkedList)6 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)4 Path (java.nio.file.Path)3 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 PropertyKey (org.structr.core.property.PropertyKey)3 Image (org.structr.web.entity.Image)3 Map (java.util.Map)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 GraphObject (org.structr.core.GraphObject)2 AbstractNode (org.structr.core.entity.AbstractNode)2 NodeAttribute (org.structr.core.graph.NodeAttribute)2 FileNotFoundException (java.io.FileNotFoundException)1