Search in sources :

Example 46 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrFilePath method getDirectoryStream.

@Override
public DirectoryStream<Path> getDirectoryStream(DirectoryStream.Filter<? super Path> filter) {
    final Folder folder = (Folder) getActualFile();
    if (folder != null) {
        return new DirectoryStream() {

            boolean closed = false;

            @Override
            public Iterator iterator() {
                if (!closed) {
                    final App app = StructrApp.getInstance(fs.getSecurityContext());
                    final List<StructrPath> files = new LinkedList<>();
                    try (final Tx tx = app.tx()) {
                        for (final Folder folder : folder.getFolders()) {
                            files.add(new StructrFilePath(fs, StructrFilePath.this, folder.getName()));
                        }
                        for (final File file : folder.getFiles()) {
                            files.add(new StructrFilePath(fs, StructrFilePath.this, file.getName()));
                        }
                        tx.success();
                    } catch (FrameworkException fex) {
                        logger.warn("", fex);
                    }
                    return files.iterator();
                }
                return Collections.emptyIterator();
            }

            @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) FrameworkException(org.structr.common.error.FrameworkException) StructrPath(org.structr.files.ssh.filesystem.StructrPath) DirectoryStream(java.nio.file.DirectoryStream) Folder(org.structr.web.entity.Folder) AbstractFile(org.structr.web.entity.AbstractFile) File(org.structr.web.entity.File) LinkedList(java.util.LinkedList)

Example 47 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrFilePath method createDirectory.

@Override
public void createDirectory(FileAttribute<?>... attrs) throws IOException {
    final App app = StructrApp.getInstance(fs.getSecurityContext());
    try (final Tx tx = app.tx()) {
        final String name = getFileName().toString();
        final Folder newFolder = app.create(Folder.class, new NodeAttribute<>(AbstractNode.name, name));
        // set parent folder
        setParentFolder(newFolder);
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("Unable to delete file {}: {}", new Object[] { getActualFile().getPath(), fex.getMessage() });
    }
}
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) Folder(org.structr.web.entity.Folder)

Example 48 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrSchemaPropertiesPath method getDirectoryStream.

@Override
public DirectoryStream<Path> getDirectoryStream(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 SchemaProperty schemaProperty : schemaNode.getProperty(SchemaNode.schemaProperties)) {
                        nodes.add(new StructrSchemaPropertyPath(fs, StructrSchemaPropertiesPath.this, schemaNode, schemaProperty));
                    }
                    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) SchemaProperty(org.structr.core.entity.SchemaProperty) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrPath(org.structr.files.ssh.filesystem.StructrPath) DirectoryStream(java.nio.file.DirectoryStream) LinkedList(java.util.LinkedList)

Example 49 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrSchemaPropertiesPath method resolveStructrPath.

@Override
public StructrPath resolveStructrPath(final String pathComponent) {
    final App app = StructrApp.getInstance(fs.getSecurityContext());
    StructrPath path = null;
    try (final Tx tx = app.tx()) {
        for (final SchemaProperty schemaProperty : schemaNode.getProperty(SchemaNode.schemaProperties)) {
            if (pathComponent.equals(schemaProperty.getName())) {
                path = new StructrSchemaPropertyPath(fs, StructrSchemaPropertiesPath.this, schemaNode, schemaProperty);
            }
        }
        tx.success();
    } catch (FrameworkException fex) {
        logger.warn("", fex);
    }
    return path;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) SchemaProperty(org.structr.core.entity.SchemaProperty) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) StructrPath(org.structr.files.ssh.filesystem.StructrPath)

Example 50 with App

use of org.structr.core.app.App in project structr by structr.

the class StructrSchemaPropertyPath method getDirectoryStream.

@Override
public DirectoryStream<Path> getDirectoryStream(DirectoryStream.Filter<? super Path> filter) {
    if (schemaProperty != 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()) {
                    // add configuration "files" for this schema property
                    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) FrameworkException(org.structr.common.error.FrameworkException) StructrPath(org.structr.files.ssh.filesystem.StructrPath) DirectoryStream(java.nio.file.DirectoryStream) LinkedList(java.util.LinkedList)

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