use of org.structr.core.app.App in project structr by structr.
the class FileOrFolder method mkdir.
@Override
public boolean mkdir() {
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
logger.info("mkdir() Folder");
AbstractFile existing = FileHelper.getFileByAbsolutePath(SecurityContext.getSuperUserInstance(), newPath);
if (existing != null) {
logger.warn("File {} already exists.", newPath);
return false;
}
final Folder parentFolder = (Folder) FileHelper.getFileByAbsolutePath(securityContext, StringUtils.substringBeforeLast(newPath, "/"));
try {
Folder newFolder = (Folder) app.command(CreateNodeCommand.class).execute(new NodeAttribute(AbstractNode.type, Folder.class.getSimpleName()), new NodeAttribute(AbstractNode.owner, owner.getStructrUser()), new NodeAttribute(AbstractNode.name, getName()));
if (parentFolder != null) {
newFolder.setParent(parentFolder);
}
} catch (FrameworkException ex) {
logger.error("", ex);
return false;
}
tx.success();
return true;
} catch (FrameworkException ex) {
logger.error("", ex);
return false;
}
}
use of org.structr.core.app.App in project structr by structr.
the class StructrSchemaMethodPath method move.
@Override
public void move(final Path target, final CopyOption... options) throws IOException {
if (target instanceof StructrSchemaMethodPath) {
final App app = StructrApp.getInstance(fs.getSecurityContext());
final StructrSchemaMethodPath other = (StructrSchemaMethodPath) target;
final AbstractSchemaNode otherNode = other.getSchemaNode();
final SchemaMethod method = getSchemaMethodNode();
final String targetName = target.getFileName().toString();
try (final Tx tx = app.tx()) {
if (otherNode.getUuid().equals(schemaNode.getUuid())) {
// move from node to same node
method.setProperty(SchemaMethod.name, normalizeFileNameForJavaIdentifier(targetName));
method.setProperty(SchemaMethod.virtualFileName, targetName);
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
}
use of org.structr.core.app.App in project structr by structr.
the class StructrSchemaMethodsPath method getDirectoryStream.
@Override
public DirectoryStream<Path> getDirectoryStream(final DirectoryStream.Filter<? super Path> filter) {
if (schemaNode != null) {
return new DirectoryStream() {
boolean closed = false;
@Override
public Iterator iterator() {
final App app = StructrApp.getInstance(fs.getSecurityContext());
final List<StructrPath> nodes = new LinkedList<>();
try (final Tx tx = app.tx()) {
for (final SchemaMethod schemaMethod : schemaNode.getProperty(SchemaNode.schemaMethods)) {
// schema methods have a virtual file name so that external editors don't get confused
String name = schemaMethod.getProperty(SchemaMethod.virtualFileName);
if (name == null) {
// no virtual file name set, use real name
name = schemaMethod.getName();
}
nodes.add(new StructrSchemaMethodPath(fs, StructrSchemaMethodsPath.this, schemaNode, name));
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return nodes.iterator();
}
@Override
public void close() throws IOException {
closed = true;
}
};
}
return null;
}
use of org.structr.core.app.App in project structr by structr.
the class StructrSchemaNodePath method getAttributes.
@Override
public <T extends BasicFileAttributes> T getAttributes(Class<T> type, LinkOption... options) throws IOException {
final AbstractSchemaNode schemaNode = getSchemaNode();
if (schemaNode != null) {
final App app = StructrApp.getInstance(fs.getSecurityContext());
String name = null;
try (final Tx tx = app.tx()) {
name = schemaNode.getName();
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
return (T) new StructrToplevelAttributes(name);
}
throw new NoSuchFileException(toString());
}
use of org.structr.core.app.App in project structr by structr.
the class StructrSchemaNodePath method getSchemaNode.
public AbstractSchemaNode getSchemaNode() {
if (cachedSchemaNode == null) {
final App app = StructrApp.getInstance(fs.getSecurityContext());
try (final Tx tx = app.tx()) {
// remove /files from path since it is a virtual directory
cachedSchemaNode = app.nodeQuery(AbstractSchemaNode.class).and(AbstractNode.name, name).getFirst();
tx.success();
} catch (FrameworkException fex) {
logger.warn("Unable to load actual file for path {}: {}", new Object[] { toString(), fex.getMessage() });
}
}
return cachedSchemaNode;
}
Aggregations