Search in sources :

Example 1 with Direction

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

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

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

Direction (org.structr.api.graph.Direction)3 RelationshipType (org.structr.api.graph.RelationshipType)2 IterableAdapter (org.structr.core.IterableAdapter)2 RelationshipFactory (org.structr.core.graph.RelationshipFactory)2 PermissionPropagation (org.structr.common.PermissionPropagation)1 RelationshipInterface (org.structr.core.graph.RelationshipInterface)1