Search in sources :

Example 31 with Folder

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

the class StructrFilePath method setParentFolder.

// ----- private methods -----
private void setParentFolder(final AbstractFile file) throws FrameworkException {
    final Path parentPath = getParent();
    if (parentPath != null && parentPath instanceof StructrFilePath) {
        final StructrFilePath parentFilePath = (StructrFilePath) parentPath;
        final Folder parentFolder = (Folder) parentFilePath.getActualFile();
        if (parentFolder != null) {
            file.setParent(parentFolder);
        }
    }
}
Also used : StructrPath(org.structr.files.ssh.filesystem.StructrPath) Path(java.nio.file.Path) Folder(org.structr.web.entity.Folder)

Example 32 with Folder

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

the class StructrFilePath method createDirectory.

@Override
public void createDirectory(FileAttribute<?>... attrs) throws IOException {
    final App app = StructrApp.getInstance(fs.getSecurityContext());
    try (final Tx tx = app.tx()) {
        final String name = getFileName().toString();
        final Folder newFolder = app.create(Folder.class, new NodeAttribute<>(AbstractNode.name, name));
        // set parent folder
        setParentFolder(newFolder);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("Unable to delete file {}: {}", new Object[] { getActualFile().getPath(), fex.getMessage() });
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

Example 33 with Folder

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

the class CatCommand method execute.

@Override
public void execute(final StructrShellCommand parent) throws IOException {
    final App app = StructrApp.getInstance();
    try (final Tx tx = app.tx()) {
        final Folder currentFolder = parent.getCurrentFolder();
        if (currentFolder != null) {
            listFolder(parent, currentFolder.getChildren());
        } else {
            listFolder(parent, app.nodeQuery(AbstractFile.class).and(StructrApp.key(AbstractFile.class, "parent"), null).getAsList());
        }
        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)

Example 34 with Folder

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

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

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