Search in sources :

Example 26 with RelationshipInterface

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

the class AbstractNode method hasEffectivePermissions.

private boolean hasEffectivePermissions(final BFSInfo parent, final Principal principal, final Permission permission, final PermissionResolutionMask mask, final int level, final AlreadyTraversed alreadyTraversed, final Queue<BFSInfo> bfsNodes, final boolean doLog) {
    // check nodes here to avoid circles in permission-propagating relationships
    if (alreadyTraversed.contains("Node", dbNode.getId())) {
        return false;
    }
    for (final Class<Relation> propagatingType : SchemaRelationshipNode.getPropagatingRelationshipTypes()) {
        final Relation template = getRelationshipForType(propagatingType);
        final Direction direction = template.getDirectionForType(entityType);
        // skip relationship type if it is not applicable for the current node type
        if (Direction.BOTH.equals(direction)) {
            continue;
        }
        // iterate over list of relationships
        final Iterable<Relation> iterable = getRelationshipsAsSuperUser(propagatingType);
        for (final Relation source : iterable) {
            if (source instanceof PermissionPropagation) {
                final PermissionPropagation perm = (PermissionPropagation) source;
                final RelationshipInterface rel = (RelationshipInterface) source;
                // check propagation direction vs. evaluation direction
                if (propagationAllowed(this, rel, perm.getPropagationDirection(), doLog)) {
                    applyCurrentStep(perm, mask);
                    if (mask.allowsPermission(permission)) {
                        final AbstractNode otherNode = (AbstractNode) rel.getOtherNode(this);
                        if (otherNode.isGranted(permission, principal, mask, level + 1, alreadyTraversed, false, doLog)) {
                            otherNode.storePermissionResolutionResult(principal.getId(), permission, true);
                            // break early
                            return true;
                        } else {
                            // add node to BFS queue
                            bfsNodes.add(new BFSInfo(parent, otherNode));
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : PermissionPropagation(org.structr.common.PermissionPropagation) RelationshipInterface(org.structr.core.graph.RelationshipInterface) Direction(org.structr.api.graph.Direction)

Example 27 with RelationshipInterface

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

the class StructrApp method getRelationshipById.

@Override
public RelationshipInterface getRelationshipById(final Class type, final String uuid) throws FrameworkException {
    if (uuid == null) {
        return null;
    }
    final Long id = getRelFromCache(uuid);
    if (id == null) {
        final Query query = relationshipQuery().uuid(uuid);
        // set type for faster query
        if (type != null) {
            query.andType(type);
        } else {
            logger.warn("Relationship access by UUID is deprecated and not supported by Neo4j, this can take a very long time. Please examine the following stack trace and amend.");
            Thread.dumpStack();
        }
        final GraphObject entity = query.getFirst();
        if (entity != null) {
            relUuidMap.put(uuid, entity.getId());
            return (RelationshipInterface) entity;
        }
    } else {
        try {
            return relFactory.instantiate(getDatabaseService().getRelationshipById(id));
        } catch (NotFoundException ignore) {
            relUuidMap.remove(uuid);
        }
    }
    return null;
}
Also used : RelationshipInterface(org.structr.core.graph.RelationshipInterface) NotFoundException(org.structr.api.NotFoundException) GraphObject(org.structr.core.GraphObject)

Example 28 with RelationshipInterface

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

RelationshipInterface (org.structr.core.graph.RelationshipInterface)28 NodeInterface (org.structr.core.graph.NodeInterface)15 GraphObject (org.structr.core.GraphObject)8 LinkedList (java.util.LinkedList)6 FrameworkException (org.structr.common.error.FrameworkException)6 PropertyMap (org.structr.core.property.PropertyMap)6 App (org.structr.core.app.App)5 StructrApp (org.structr.core.app.StructrApp)5 List (java.util.List)4 SecurityContext (org.structr.common.SecurityContext)4 AbstractNode (org.structr.core.entity.AbstractNode)4 GenericNode (org.structr.core.entity.GenericNode)4 Tx (org.structr.core.graph.Tx)4 RelationshipDataContainer (org.structr.cloud.message.RelationshipDataContainer)3 Result (org.structr.core.Result)3 PropertyKey (org.structr.core.property.PropertyKey)3 LinkedHashSet (java.util.LinkedHashSet)2 Test (org.junit.Test)2 NotFoundException (org.structr.api.NotFoundException)2 RelationshipType (org.structr.api.graph.RelationshipType)2