Search in sources :

Example 1 with RelationshipFactory

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

the class IncomingFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 1, 2)) {
        final RelationshipFactory factory = new RelationshipFactory(ctx.getSecurityContext());
        final Object source = sources[0];
        if (source instanceof NodeInterface) {
            final NodeInterface node = (NodeInterface) source;
            if (sources.length > 1) {
                final Object relType = sources[1];
                if (relType != null && relType instanceof String) {
                    final String relTypeName = (String) relType;
                    return factory.bulkInstantiate(node.getNode().getRelationships(Direction.INCOMING, RelationshipType.forName(relTypeName)));
                }
            } else {
                return factory.bulkInstantiate(node.getNode().getRelationships(Direction.INCOMING));
            }
        } else {
            logger.warn("Error: entity is not a node. Parameters: {}", getParametersAsString(sources));
            return "Error: entity is not a node.";
        }
    } else {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
    }
    return "";
}
Also used : RelationshipFactory(org.structr.core.graph.RelationshipFactory) NodeInterface(org.structr.core.graph.NodeInterface)

Example 2 with RelationshipFactory

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

the class CypherQueryHandler method setSecurityContext.

public void setSecurityContext(SecurityContext securityContext) {
    this.securityContext = securityContext;
    this.nodeFactory = new NodeFactory(securityContext);
    this.relFactory = new RelationshipFactory(securityContext);
}
Also used : NodeFactory(org.structr.core.graph.NodeFactory) RelationshipFactory(org.structr.core.graph.RelationshipFactory)

Example 3 with RelationshipFactory

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

the class AbstractNode method getIncomingRelationship.

@Override
public final <A extends NodeInterface, B extends NodeInterface, T extends Target, R extends Relation<A, B, OneStartpoint<A>, T>> R getIncomingRelationship(final Class<R> type) {
    final RelationshipFactory<R> factory = new RelationshipFactory<>(securityContext);
    final R template = getRelationshipForType(type);
    final Relationship relationship = template.getSource().getRawSource(securityContext, 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 4 with RelationshipFactory

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

the class AbstractNode method getOutgoingRelationship.

@Override
public final <A extends NodeInterface, B extends NodeInterface, S extends Source, R extends Relation<A, B, S, OneEndpoint<B>>> R getOutgoingRelationship(final Class<R> type) {
    final RelationshipFactory<R> factory = new RelationshipFactory<>(securityContext);
    final R template = getRelationshipForType(type);
    final Relationship relationship = template.getTarget().getRawSource(securityContext, 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 5 with RelationshipFactory

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

the class OutgoingFunction method apply.

@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
    if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 1, 2)) {
        final RelationshipFactory factory = new RelationshipFactory(ctx.getSecurityContext());
        final Object source = sources[0];
        if (source instanceof NodeInterface) {
            final NodeInterface node = (NodeInterface) source;
            if (sources.length > 1) {
                final Object relType = sources[1];
                if (relType != null && relType instanceof String) {
                    final String relTypeName = (String) relType;
                    return factory.bulkInstantiate(node.getNode().getRelationships(Direction.OUTGOING, RelationshipType.forName(relTypeName)));
                }
            } else {
                return factory.bulkInstantiate(node.getNode().getRelationships(Direction.OUTGOING));
            }
        } else {
            logger.warn("Error: entity is not a node. Parameters: {}", getParametersAsString(sources));
            return "Error: entity is not a node.";
        }
    } else {
        logParameterError(caller, sources, ctx.isJavaScriptContext());
    }
    return "";
}
Also used : RelationshipFactory(org.structr.core.graph.RelationshipFactory) 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