Search in sources :

Example 1 with StructrPropertyValueChannel

use of org.structr.files.ssh.filesystem.path.graph.StructrPropertyValueChannel in project structr by structr.

the class StructrSchemaMethodPath method newFileChannel.

@Override
public FileChannel newFileChannel(final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) throws IOException {
    // Possible open options are: CREATE, READ, WRITE, TRUNCATE_EXISTING
    // The filesystem code will first try to fetch the attributes of a file, then call this
    // method with the CREATE and WRITE OPTIONS (and an optional TRUNCATE_EXISTING)
    SchemaMethod method = getSchemaMethodNode();
    final boolean read = options.contains(StandardOpenOption.READ);
    final boolean create = options.contains(StandardOpenOption.CREATE);
    final boolean createNew = options.contains(StandardOpenOption.CREATE_NEW);
    final boolean write = options.contains(StandardOpenOption.WRITE);
    final boolean truncate = options.contains(StandardOpenOption.TRUNCATE_EXISTING);
    final boolean append = options.contains(StandardOpenOption.APPEND);
    // creation of a new file requested (=> create a new schema method)
    if (create || createNew) {
        // if CREATE_NEW, file must not exist, otherwise an error should be thrown
        if (createNew && method != null) {
            throw new java.nio.file.FileAlreadyExistsException(toString());
        }
        final App app = StructrApp.getInstance(fs.getSecurityContext());
        try (final Tx tx = app.tx()) {
            // create a new schema method with an empty source string
            method = app.create(SchemaMethod.class, new NodeAttribute<>(SchemaMethod.schemaNode, schemaNode), new NodeAttribute<>(SchemaMethod.virtualFileName, name), new NodeAttribute<>(AbstractNode.name, normalizeFileNameForJavaIdentifier(name)), new NodeAttribute<>(SchemaMethod.source, ""));
            tx.success();
        } catch (FrameworkException fex) {
            logger.warn("", fex);
        }
    }
    return new StructrPropertyValueChannel(fs.getSecurityContext(), method, SchemaMethod.source, truncate, append);
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NodeAttribute(org.structr.core.graph.NodeAttribute) StructrPropertyValueChannel(org.structr.files.ssh.filesystem.path.graph.StructrPropertyValueChannel) SchemaMethod(org.structr.core.entity.SchemaMethod) Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 SchemaMethod (org.structr.core.entity.SchemaMethod)1 NodeAttribute (org.structr.core.graph.NodeAttribute)1 Tx (org.structr.core.graph.Tx)1 StructrPropertyValueChannel (org.structr.files.ssh.filesystem.path.graph.StructrPropertyValueChannel)1