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