Search in sources :

Example 6 with RelationshipFactory

use of org.structr.core.graph.RelationshipFactory 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 7 with RelationshipFactory

use of org.structr.core.graph.RelationshipFactory 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 8 with RelationshipFactory

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

the class AbstractNode method getOutgoingRelationshipAsSuperUser.

@Override
public <A extends NodeInterface, B extends NodeInterface, S extends Source, R extends Relation<A, B, S, OneEndpoint<B>>> R getOutgoingRelationshipAsSuperUser(final Class<R> type) {
    final RelationshipFactory<R> factory = new RelationshipFactory<>(SecurityContext.getSuperUserInstance());
    final R template = getRelationshipForType(type);
    final Relationship relationship = template.getTarget().getRawSource(SecurityContext.getSuperUserInstance(), dbNode, null);
    if (relationship != null) {
        return factory.adapt(relationship);
    }
    return null;
}
Also used : RelationshipFactory(org.structr.core.graph.RelationshipFactory) Relationship(org.structr.api.graph.Relationship)

Example 9 with RelationshipFactory

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

the class AbstractNode method getRelationships.

@Override
public final <A extends NodeInterface, B extends NodeInterface, S extends Source, T extends Target, R extends Relation<A, B, S, T>> Iterable<R> getRelationships(final Class<R> type) {
    final RelationshipFactory<R> factory = new RelationshipFactory<>(securityContext);
    final R template = getRelationshipForType(type);
    final Direction direction = template.getDirectionForType(entityType);
    final RelationshipType relType = template;
    return new IterableAdapter<>(dbNode.getRelationships(direction, relType), factory);
}
Also used : IterableAdapter(org.structr.core.IterableAdapter) RelationshipFactory(org.structr.core.graph.RelationshipFactory) RelationshipType(org.structr.api.graph.RelationshipType) Direction(org.structr.api.graph.Direction)

Example 10 with RelationshipFactory

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

the class AbstractNode method getRelationshipsAsSuperUser.

protected final <A extends NodeInterface, B extends NodeInterface, S extends Source, T extends Target, R extends Relation<A, B, S, T>> Iterable<R> getRelationshipsAsSuperUser(final Class<R> type) {
    final RelationshipFactory<R> factory = new RelationshipFactory<>(SecurityContext.getSuperUserInstance());
    final R template = getRelationshipForType(type);
    final Direction direction = template.getDirectionForType(entityType);
    final RelationshipType relType = template;
    return new IterableAdapter<>(dbNode.getRelationships(direction, relType), factory);
}
Also used : IterableAdapter(org.structr.core.IterableAdapter) RelationshipFactory(org.structr.core.graph.RelationshipFactory) RelationshipType(org.structr.api.graph.RelationshipType) Direction(org.structr.api.graph.Direction)

Aggregations

RelationshipFactory (org.structr.core.graph.RelationshipFactory)12 Relationship (org.structr.api.graph.Relationship)5 NodeInterface (org.structr.core.graph.NodeInterface)4 IterableAdapter (org.structr.core.IterableAdapter)3 NodeFactory (org.structr.core.graph.NodeFactory)3 Direction (org.structr.api.graph.Direction)2 RelationshipType (org.structr.api.graph.RelationshipType)2 RelationshipInterface (org.structr.core.graph.RelationshipInterface)2 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 FrameworkException (org.structr.common.error.FrameworkException)1 GraphObject (org.structr.core.GraphObject)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 AbstractNode (org.structr.core.entity.AbstractNode)1 Tx (org.structr.core.graph.Tx)1 PropertyMap (org.structr.core.property.PropertyMap)1 File (org.structr.dynamic.File)1