Search in sources :

Example 51 with Folder

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

the class StructrFileAttributes method permissions.

@Override
public Set<PosixFilePermission> permissions() {
    final Set<PosixFilePermission> permissions = new HashSet<>();
    permissions.add(PosixFilePermission.OWNER_READ);
    permissions.add(PosixFilePermission.OWNER_WRITE);
    if (file != null) {
        if (file instanceof Folder) {
            permissions.add(PosixFilePermission.OWNER_EXECUTE);
        }
        try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
            if (file.isVisibleToPublicUsers()) {
                permissions.add(PosixFilePermission.OTHERS_READ);
                permissions.add(PosixFilePermission.OTHERS_WRITE);
                if (file instanceof Folder) {
                    permissions.add(PosixFilePermission.OTHERS_EXECUTE);
                }
            }
            if (file.isVisibleToAuthenticatedUsers()) {
                permissions.add(PosixFilePermission.GROUP_READ);
                permissions.add(PosixFilePermission.GROUP_WRITE);
                if (file instanceof Folder) {
                    permissions.add(PosixFilePermission.GROUP_EXECUTE);
                }
            }
            tx.success();
        } catch (FrameworkException fex) {
            logger.error("", fex);
        }
    }
    return permissions;
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) Folder(org.structr.web.entity.Folder) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 52 with Folder

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

the class StructrFileAttributes method isDirectory.

@Override
public boolean isDirectory() {
    if (file == null) {
        return false;
    }
    boolean isDirectory = false;
    try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
        isDirectory = file instanceof Folder;
        tx.success();
    } catch (FrameworkException fex) {
        logger.error("", fex);
    }
    return isDirectory;
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) Folder(org.structr.web.entity.Folder)

Example 53 with Folder

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

the class StructrFilePath method move.

@Override
public void move(final Path target, final CopyOption... options) throws IOException {
    if (target instanceof StructrFilePath) {
        final App app = StructrApp.getInstance(fs.getSecurityContext());
        final StructrFilePath other = (StructrFilePath) target;
        final AbstractFile otherFile = other.getActualFile();
        final AbstractFile thisFile = getActualFile();
        final String targetName = target.getFileName().toString();
        try (final Tx tx = app.tx()) {
            final Path otherParent = other.getParent();
            if (otherParent instanceof StructrFilesPath) {
                // rename & move (parent is null: root path)
                thisFile.setParent(null);
                thisFile.setProperty(AbstractNode.name, targetName);
                // this is a move operation, delete existing file
                if (otherFile != null) {
                    app.delete(otherFile);
                }
            } else {
                final StructrFilePath parent = (StructrFilePath) other.getParent();
                final Folder newParentFolder = (Folder) parent.getActualFile();
                // rename & move
                thisFile.setParent(newParentFolder);
                thisFile.setProperty(AbstractNode.name, targetName);
                // this is a move operation, delete existing file
                if (otherFile != null) {
                    app.delete(otherFile);
                }
            }
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) StructrPath(org.structr.files.ssh.filesystem.StructrPath) Path(java.nio.file.Path) 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 54 with Folder

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

the class StructrFilePath method delete.

@Override
public void delete() throws IOException {
    final App app = StructrApp.getInstance(fs.getSecurityContext());
    final AbstractFile actualFile = getActualFile();
    try (final Tx tx = app.tx()) {
        // if a folder is to be deleted, check contents
        if (actualFile instanceof Folder && ((Folder) actualFile).getChildren().iterator().hasNext()) {
            throw new DirectoryNotEmptyException(getActualFile().getPath());
        } else {
            app.delete(actualFile);
            // remove cached version
            this.cachedActualFile = null;
        }
        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) AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) Folder(org.structr.web.entity.Folder)

Example 55 with Folder

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

the class AbstractStructrFtpFile method move.

@Override
public boolean move(final FtpFile target) {
    try (Tx tx = StructrApp.getInstance(securityContext).tx()) {
        logger.info("move()");
        final AbstractStructrFtpFile targetFile = (AbstractStructrFtpFile) target;
        final String path = targetFile instanceof StructrFtpFile ? "/" : targetFile.getAbsolutePath();
        try {
            if (path.contains("/")) {
                String newParentPath = StringUtils.substringBeforeLast(path, "/");
                AbstractFile newParent = FileHelper.getFileByAbsolutePath(securityContext, newParentPath);
                if (newParent != null && newParent instanceof Folder) {
                    Folder newParentFolder = (Folder) newParent;
                    structrFile.setParent(newParentFolder);
                } else {
                    // Move to /
                    structrFile.setParent(null);
                }
            }
            if (!("/".equals(path))) {
                final String newName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path;
                structrFile.setProperty(AbstractNode.name, newName);
            }
        } catch (FrameworkException ex) {
            logger.error("Could not move ftp file", ex);
            return false;
        }
        tx.success();
        return true;
    } catch (FrameworkException ex) {
        logger.error("", ex);
    }
    return false;
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) 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