Search in sources :

Example 66 with Folder

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

the class MkdirCommand method createFolder.

// ----- private methods -----
private void createFolder(final StructrShellCommand parent, final Folder currentFolder, final String target) throws FrameworkException, IOException {
    final App app = StructrApp.getInstance();
    if (target.contains("/")) {
        final int lastSlashIndex = target.lastIndexOf("/");
        final String targetFolderPath = target.substring(0, lastSlashIndex);
        final String targetFolderName = target.substring(lastSlashIndex + 1);
        final Folder parentFolder = parent.findRelativeFolder(currentFolder, targetFolderPath);
        if (parentFolder != null) {
            checkAndCreateFolder(app, parent, parentFolder, targetFolderName);
        } else {
            term.println("Folder " + targetFolderPath + " does not exist");
        }
    } else {
        checkAndCreateFolder(app, parent, currentFolder, target);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Folder(org.structr.web.entity.Folder)

Example 67 with Folder

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

the class FtpAccessTest method test04UserAccessToSubdirectory.

@Test
public void test04UserAccessToSubdirectory() {
    FTPClient client1 = setupFTPClient("ftpuser1");
    final String name1 = "FTPdir1";
    final String name2 = "FTPdir2";
    FTPFile[] dirs = null;
    Folder dir1 = null;
    Folder dir2 = null;
    try (final Tx tx = app.tx()) {
        dirs = client1.listDirectories();
        assertNotNull(dirs);
        assertEquals(0, dirs.length);
        // Create folders by API methods
        dir1 = createFTPDirectory(null, name1);
        dir2 = createFTPDirectory(dir1.getPath(), name2);
        // Make dir1 visible to authenticated users
        dir1.setProperty(Folder.visibleToAuthenticatedUsers, true);
        tx.success();
    } catch (IOException | FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
    try (final Tx tx = app.tx()) {
        dirs = client1.listDirectories();
        assertNotNull(dirs);
        assertEquals(1, dirs.length);
        assertEquals(name1, dirs[0].getName());
        client1.changeWorkingDirectory(dir1.getPath());
        FTPFile[] subdirs = client1.listDirectories();
        assertNotNull(subdirs);
        assertEquals(1, subdirs.length);
        assertEquals(name2, subdirs[0].getName());
        tx.success();
    } catch (IOException | FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
    // Try to access the directories as another user.
    // client2 should see dir1
    FTPClient client2 = setupFTPClient("ftpuser2");
    try (final Tx tx = app.tx()) {
        dirs = client2.listDirectories();
        assertNotNull(dirs);
        assertEquals(1, dirs.length);
        assertEquals(name1, dirs[0].getName());
        client2.changeWorkingDirectory(dir1.getPath());
        FTPFile[] subdirs = client2.listDirectories();
        assertNotNull(subdirs);
        assertEquals(0, subdirs.length);
        tx.success();
    } catch (IOException | FrameworkException ex) {
        logger.warn("", ex);
        fail("Unexpected exception: " + ex.getMessage());
    }
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) FTPFile(org.apache.commons.net.ftp.FTPFile) IOException(java.io.IOException) Folder(org.structr.web.entity.Folder) FTPClient(org.apache.commons.net.ftp.FTPClient) FtpTest(org.structr.web.files.FtpTest) Test(org.junit.Test)

Example 68 with Folder

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

the class SSHFilesTest method test06DeleteDirectory.

@Test
public void test06DeleteDirectory() {
    final ChannelSftp sftp = setupSftpClient("ftpuser1", "ftpuserpw1");
    try {
        // create some dirs
        sftp.mkdir("/files/test1");
        sftp.mkdir("/files/test2");
        sftp.mkdir("/files/test2/nested1");
        sftp.mkdir("/files/test2/nested1/nested2");
        // delete one dir
        sftp.rmdir("/files/test2/nested1/nested2");
        // byebye
        sftp.disconnect();
    } catch (SftpException ex) {
        fail("Unexpected exception: " + ex.getMessage());
    }
    try (final Tx tx = app.tx()) {
        assertEquals("Folder test1 should exist", "test1", app.nodeQuery(Folder.class).andName("test1").getFirst().getName());
        assertEquals("Folder test2 should exist", "test2", app.nodeQuery(Folder.class).andName("test2").getFirst().getName());
        assertEquals("Folder nested1 should exist", "nested1", app.nodeQuery(Folder.class).andName("nested1").getFirst().getName());
        assertNull("Folder nested2 should have been deleted", app.nodeQuery(Folder.class).andName("nested2").getFirst());
        tx.success();
    } catch (FrameworkException fex) {
        fail("Unexpected exception: " + fex.getMessage());
    }
}
Also used : ChannelSftp(com.jcraft.jsch.ChannelSftp) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) SftpException(com.jcraft.jsch.SftpException) Folder(org.structr.web.entity.Folder) SSHTest(org.structr.web.files.SSHTest) Test(org.junit.Test)

Example 69 with Folder

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

the class FtpTest method createFTPFile.

protected File createFTPFile(final String path, final String name) throws FrameworkException {
    PropertyMap props = new PropertyMap();
    props.put(StructrApp.key(File.class, "name"), name);
    props.put(StructrApp.key(File.class, "size"), 0L);
    props.put(StructrApp.key(File.class, "owner"), ftpUser);
    File file = (File) createTestNodes(File.class, 1, props).get(0);
    if (StringUtils.isNotBlank(path)) {
        AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
        if (parent != null && parent instanceof Folder) {
            Folder parentFolder = (Folder) parent;
            file.setParent(parentFolder);
        }
    }
    logger.info("FTP file {} created successfully.", file);
    return file;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) AbstractFile(org.structr.web.entity.AbstractFile) Folder(org.structr.web.entity.Folder) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) FTPFile(org.apache.commons.net.ftp.FTPFile)

Example 70 with Folder

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

the class FtpTest method createFTPDirectory.

protected Folder createFTPDirectory(final String path, final String name) throws FrameworkException {
    PropertyMap props = new PropertyMap();
    props.put(Folder.name, name);
    props.put(Folder.owner, ftpUser);
    Folder dir = (Folder) createTestNodes(Folder.class, 1, props).get(0);
    if (StringUtils.isNotBlank(path)) {
        AbstractFile parent = FileHelper.getFileByAbsolutePath(securityContext, path);
        if (parent != null && parent instanceof Folder) {
            Folder parentFolder = (Folder) parent;
            dir.setParent(parentFolder);
        }
    }
    logger.info("FTP directory {} created successfully.", dir);
    return dir;
}
Also used : PropertyMap(org.structr.core.property.PropertyMap) 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