Search in sources :

Example 36 with App

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;
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) 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 37 with App

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);
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaMethod(org.structr.core.entity.SchemaMethod) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode)

Example 38 with App

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;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) SchemaMethod(org.structr.core.entity.SchemaMethod) FrameworkException(org.structr.common.error.FrameworkException) StructrPath(org.structr.files.ssh.filesystem.StructrPath) DirectoryStream(java.nio.file.DirectoryStream) LinkedList(java.util.LinkedList)

Example 39 with App

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());
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode) StructrToplevelAttributes(org.structr.files.ssh.filesystem.StructrToplevelAttributes) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 40 with App

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;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode)

Aggregations

App (org.structr.core.app.App)296 StructrApp (org.structr.core.app.StructrApp)294 Tx (org.structr.core.graph.Tx)201 FrameworkException (org.structr.common.error.FrameworkException)176 LinkedList (java.util.LinkedList)60 SecurityContext (org.structr.common.SecurityContext)56 PropertyMap (org.structr.core.property.PropertyMap)41 Folder (org.structr.web.entity.Folder)38 GraphObject (org.structr.core.GraphObject)35 Principal (org.structr.core.entity.Principal)31 IOException (java.io.IOException)30 AbstractFile (org.structr.web.entity.AbstractFile)27 AbstractNode (org.structr.core.entity.AbstractNode)26 Test (org.junit.Test)24 NodeAttribute (org.structr.core.graph.NodeAttribute)24 File (org.structr.web.entity.File)23 NodeInterface (org.structr.core.graph.NodeInterface)22 SchemaNode (org.structr.core.entity.SchemaNode)19 PropertyKey (org.structr.core.property.PropertyKey)17 Map (java.util.Map)16