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);
}
}
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());
}
}
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());
}
}
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;
}
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;
}
Aggregations