Search in sources :

Example 11 with RelationshipFactory

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

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

the class ChildrenCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final RelationshipFactory factory = new RelationshipFactory(this.getWebSocket().getSecurityContext());
    final AbstractNode node = getNode(webSocketData.getId());
    if (node == null) {
        return;
    }
    final Iterable<RelationshipInterface> rels = new IterableAdapter<>(node.getNode().getRelationships(Direction.OUTGOING, RelType.CONTAINS), factory);
    final List<GraphObject> result = new LinkedList();
    for (RelationshipInterface rel : rels) {
        NodeInterface endNode = rel.getTargetNode();
        if (endNode == null) {
            continue;
        }
        result.add(endNode);
    }
    webSocketData.setView(PropertyView.Ui);
    webSocketData.setResult(result);
    // send only over local connection
    getWebSocket().send(webSocketData, true);
}
Also used : IterableAdapter(org.structr.core.IterableAdapter) AbstractNode(org.structr.core.entity.AbstractNode) RelationshipFactory(org.structr.core.graph.RelationshipFactory) RelationshipInterface(org.structr.core.graph.RelationshipInterface) GraphObject(org.structr.core.GraphObject) NodeInterface(org.structr.core.graph.NodeInterface)

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