Search in sources :

Example 1 with AbstractSchemaNode

use of org.structr.core.entity.AbstractSchemaNode 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 2 with AbstractSchemaNode

use of org.structr.core.entity.AbstractSchemaNode 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 3 with AbstractSchemaNode

use of org.structr.core.entity.AbstractSchemaNode 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)

Example 4 with AbstractSchemaNode

use of org.structr.core.entity.AbstractSchemaNode in project structr by structr.

the class StructrSchemaNodePath method getDirectoryStream.

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

            boolean closed = false;

            @Override
            public Iterator iterator() {
                if (!closed) {
                    final List<StructrPath> children = new LinkedList<>();
                    // children.add(new StructrSchemaPropertiesPath(fs, StructrSchemaNodePath.this, schemaNode));
                    // children.add(new StructrSchemaViewsPath(fs, StructrSchemaNodePath.this, schemaNode));
                    children.add(new StructrSchemaMethodsPath(fs, StructrSchemaNodePath.this, schemaNode));
                    children.add(resolveStructrPath("extendsClass"));
                    return children.iterator();
                }
                return Collections.emptyIterator();
            }

            @Override
            public void close() throws IOException {
                closed = true;
            }
        };
    }
    return null;
}
Also used : StructrPath(org.structr.files.ssh.filesystem.StructrPath) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode) DirectoryStream(java.nio.file.DirectoryStream) LinkedList(java.util.LinkedList)

Example 5 with AbstractSchemaNode

use of org.structr.core.entity.AbstractSchemaNode in project structr by structr.

the class StructrSchemaViewPath method getSchemaNode.

public AbstractSchemaNode getSchemaNode() {
    if (schemaNode == null) {
        final App app = StructrApp.getInstance(fs.getSecurityContext());
        try (final Tx tx = app.tx()) {
            // remove /files from path since it is a virtual directory
            schemaNode = 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 schemaNode;
}
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

AbstractSchemaNode (org.structr.core.entity.AbstractSchemaNode)12 App (org.structr.core.app.App)8 StructrApp (org.structr.core.app.StructrApp)8 FrameworkException (org.structr.common.error.FrameworkException)6 Tx (org.structr.core.graph.Tx)5 PropertyContainer (org.structr.api.graph.PropertyContainer)3 SchemaMethod (org.structr.core.entity.SchemaMethod)3 LinkedList (java.util.LinkedList)2 SchemaProperty (org.structr.core.entity.SchemaProperty)2 StringProperty (org.structr.core.property.StringProperty)2 DataOutputStream (java.io.DataOutputStream)1 DirectoryStream (java.nio.file.DirectoryStream)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 ZipEntry (java.util.zip.ZipEntry)1 Node (org.structr.api.graph.Node)1 Relationship (org.structr.api.graph.Relationship)1 AbstractNode (org.structr.core.entity.AbstractNode)1 AbstractRelationship (org.structr.core.entity.AbstractRelationship)1 SchemaNode (org.structr.core.entity.SchemaNode)1 SchemaView (org.structr.core.entity.SchemaView)1