Search in sources :

Example 1 with NodeFactory

use of org.structr.core.graph.NodeFactory in project structr by structr.

the class CypherQueryHandler method setSecurityContext.

public void setSecurityContext(SecurityContext securityContext) {
    this.securityContext = securityContext;
    this.nodeFactory = new NodeFactory(securityContext);
    this.relFactory = new RelationshipFactory(securityContext);
}
Also used : NodeFactory(org.structr.core.graph.NodeFactory) RelationshipFactory(org.structr.core.graph.RelationshipFactory)

Example 2 with NodeFactory

use of org.structr.core.graph.NodeFactory in project structr by structr.

the class UpdateTransmission method doRemote.

@Override
public Boolean doRemote(final CloudConnection client) throws IOException, FrameworkException {
    // send synchronization request first
    client.send(new Synchronize());
    // send all node and relationship data
    final DatabaseService graphDb = StructrApp.getInstance().getDatabaseService();
    final NodeFactory nodeFactory = new NodeFactory(SecurityContext.getSuperUserInstance());
    final RelationshipFactory relFactory = new RelationshipFactory(SecurityContext.getSuperUserInstance());
    for (final Node neo4jNode : graphDb.getAllNodes()) {
        final NodeInterface node = nodeFactory.instantiate(neo4jNode);
        if (node instanceof File) {
            PushTransmission.sendFile(client, (File) node, CloudService.CHUNK_SIZE);
        } else {
            client.send(new NodeDataContainer(node, 0));
        }
    }
    for (final Relationship relationship : graphDb.getAllRelationships()) {
        final RelationshipInterface relationshipInterface = relFactory.instantiate(relationship);
        client.send(new RelationshipDataContainer(relationshipInterface, 0));
    }
    // wait for end of transmission
    client.waitForTransmission();
    return true;
}
Also used : NodeFactory(org.structr.core.graph.NodeFactory) RelationshipDataContainer(org.structr.cloud.message.RelationshipDataContainer) RelationshipFactory(org.structr.core.graph.RelationshipFactory) Node(org.structr.api.graph.Node) Relationship(org.structr.api.graph.Relationship) RelationshipInterface(org.structr.core.graph.RelationshipInterface) NodeDataContainer(org.structr.cloud.message.NodeDataContainer) DatabaseService(org.structr.api.DatabaseService) File(org.structr.dynamic.File) NodeInterface(org.structr.core.graph.NodeInterface)

Example 3 with NodeFactory

use of org.structr.core.graph.NodeFactory in project structr by structr.

the class DumpDatabaseCommand method execute.

@Override
public void execute(Map<String, Object> attributes) throws FrameworkException {
    try {
        final NodeFactory nodeFactory = new NodeFactory(SecurityContext.getSuperUserInstance());
        final RelationshipFactory relFactory = new RelationshipFactory(SecurityContext.getSuperUserInstance());
        final App app = StructrApp.getInstance();
        final String fileName = (String) attributes.get("name");
        if (fileName == null || fileName.isEmpty()) {
            throw new FrameworkException(400, "Please specify name.");
        }
        try (final Tx tx = app.tx()) {
            final File file = FileHelper.createFile(securityContext, new byte[0], "application/zip", File.class, fileName);
            // make file visible for auth. users
            file.setProperties(securityContext, new PropertyMap(File.visibleToAuthenticatedUsers, true));
            // Don't include files
            SyncCommand.exportToStream(file.getOutputStream(), nodeFactory.bulkInstantiate(app.getDatabaseService().getAllNodes()), relFactory.bulkInstantiate(app.getDatabaseService().getAllRelationships()), null, false);
            tx.success();
        }
    } catch (Throwable t) {
        throw new FrameworkException(500, t.getMessage());
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) PropertyMap(org.structr.core.property.PropertyMap) NodeFactory(org.structr.core.graph.NodeFactory) FrameworkException(org.structr.common.error.FrameworkException) Tx(org.structr.core.graph.Tx) RelationshipFactory(org.structr.core.graph.RelationshipFactory) File(org.structr.web.entity.File)

Example 4 with NodeFactory

use of org.structr.core.graph.NodeFactory in project structr by structr.

the class OneEndpoint method get.

@Override
public T get(final SecurityContext securityContext, final NodeInterface node, final Predicate<GraphObject> predicate) {
    final NodeFactory<T> nodeFactory = new NodeFactory<>(securityContext);
    final Relationship rel = getRawSource(securityContext, node.getNode(), predicate);
    if (rel != null) {
        return nodeFactory.instantiate(rel.getEndNode(), rel);
    }
    return null;
}
Also used : NodeFactory(org.structr.core.graph.NodeFactory) Relationship(org.structr.api.graph.Relationship)

Example 5 with NodeFactory

use of org.structr.core.graph.NodeFactory in project structr by structr.

the class OneStartpoint method get.

@Override
public S get(final SecurityContext securityContext, final NodeInterface node, final Predicate<GraphObject> predicate) {
    final NodeFactory<S> nodeFactory = new NodeFactory<>(securityContext);
    final Relationship rel = getRawSource(securityContext, node.getNode(), predicate);
    if (rel != null) {
        return nodeFactory.instantiate(rel.getStartNode(), rel);
    }
    return null;
}
Also used : NodeFactory(org.structr.core.graph.NodeFactory) Relationship(org.structr.api.graph.Relationship)

Aggregations

NodeFactory (org.structr.core.graph.NodeFactory)6 Relationship (org.structr.api.graph.Relationship)3 RelationshipFactory (org.structr.core.graph.RelationshipFactory)3 FrameworkException (org.structr.common.error.FrameworkException)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 PropertyMap (org.structr.core.property.PropertyMap)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 DatabaseService (org.structr.api.DatabaseService)1 Node (org.structr.api.graph.Node)1 NodeDataContainer (org.structr.cloud.message.NodeDataContainer)1 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)1 Principal (org.structr.core.entity.Principal)1 NodeInterface (org.structr.core.graph.NodeInterface)1 RelationshipInterface (org.structr.core.graph.RelationshipInterface)1 Tx (org.structr.core.graph.Tx)1 PropertyKey (org.structr.core.property.PropertyKey)1 File (org.structr.dynamic.File)1