Search in sources :

Example 21 with Relationship

use of org.structr.api.graph.Relationship 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 22 with Relationship

use of org.structr.api.graph.Relationship 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 23 with Relationship

use of org.structr.api.graph.Relationship in project structr by structr.

the class AbstractNode method getIncomingRelationshipAsSuperUser.

protected <A extends NodeInterface, B extends NodeInterface, T extends Target, R extends Relation<A, B, OneStartpoint<A>, T>> R getIncomingRelationshipAsSuperUser(final Class<R> type) {
    final RelationshipFactory<R> factory = new RelationshipFactory<>(SecurityContext.getSuperUserInstance());
    final R template = getRelationshipForType(type);
    final Relationship relationship = template.getSource().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 24 with Relationship

use of org.structr.api.graph.Relationship 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 25 with Relationship

use of org.structr.api.graph.Relationship 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

Relationship (org.structr.api.graph.Relationship)26 Node (org.structr.api.graph.Node)13 LinkedList (java.util.LinkedList)7 LinkedHashMap (java.util.LinkedHashMap)6 DatabaseService (org.structr.api.DatabaseService)6 GraphObject (org.structr.core.GraphObject)6 AbstractNode (org.structr.core.entity.AbstractNode)6 AbstractRelationship (org.structr.core.entity.AbstractRelationship)6 RelationshipFactory (org.structr.core.graph.RelationshipFactory)5 HashMap (java.util.HashMap)4 FrameworkException (org.structr.common.error.FrameworkException)4 List (java.util.List)3 Test (org.junit.Test)3 SessionTransaction (org.structr.bolt.SessionTransaction)3 RelationshipRelationshipMapper (org.structr.bolt.mapper.RelationshipRelationshipMapper)3 App (org.structr.core.app.App)3 StructrApp (org.structr.core.app.StructrApp)3 AbstractSchemaNode (org.structr.core.entity.AbstractSchemaNode)3 NodeFactory (org.structr.core.graph.NodeFactory)3 Tx (org.structr.core.graph.Tx)3