Search in sources :

Example 11 with AbstractSchemaNode

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

the class SyncCommand method exportDatabase.

private static void exportDatabase(final ZipOutputStream zos, final OutputStream outputStream, final Iterable<? extends NodeInterface> nodes, final Iterable<? extends RelationshipInterface> relationships) throws IOException, FrameworkException {
    // start database zip entry
    final ZipEntry dbEntry = new ZipEntry(STRUCTR_ZIP_DB_NAME);
    final DataOutputStream dos = new DataOutputStream(outputStream);
    final String uuidPropertyName = GraphObject.id.dbName();
    int nodeCount = 0;
    int relCount = 0;
    zos.putNextEntry(dbEntry);
    for (NodeInterface nodeObject : nodes) {
        // skip schema
        if (nodeObject instanceof AbstractSchemaNode) {
            continue;
        }
        final Node node = nodeObject.getNode();
        // ignore non-structr nodes
        if (node.hasProperty(GraphObject.id.dbName())) {
            outputStream.write('N');
            for (String key : node.getPropertyKeys()) {
                serialize(dos, key);
                serialize(dos, node.getProperty(key));
            }
            // do not use platform-specific line ending here!
            dos.write('\n');
            nodeCount++;
        }
    }
    dos.flush();
    for (RelationshipInterface relObject : relationships) {
        final Relationship rel = relObject.getRelationship();
        // ignore non-structr nodes
        if (rel.hasProperty(GraphObject.id.dbName())) {
            final Node startNode = rel.getStartNode();
            final Node endNode = rel.getEndNode();
            if (startNode.hasProperty(uuidPropertyName) && endNode.hasProperty(uuidPropertyName)) {
                String startId = (String) startNode.getProperty(uuidPropertyName);
                String endId = (String) endNode.getProperty(uuidPropertyName);
                outputStream.write('R');
                serialize(dos, startId);
                serialize(dos, endId);
                serialize(dos, rel.getType().name());
                for (String key : rel.getPropertyKeys()) {
                    serialize(dos, key);
                    serialize(dos, rel.getProperty(key));
                }
                // do not use platform-specific line ending here!
                dos.write('\n');
                relCount++;
            }
        }
    }
    dos.flush();
    // finish db entry
    zos.closeEntry();
    logger.info("Exported {} nodes and {} rels", new Object[] { nodeCount, relCount });
}
Also used : DataOutputStream(java.io.DataOutputStream) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode) ZipEntry(java.util.zip.ZipEntry) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractSchemaNode(org.structr.core.entity.AbstractSchemaNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship)

Example 12 with AbstractSchemaNode

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

the class StructrSchemaPropertyPath 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