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 "";
}
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);
}
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;
}
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;
}
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 "";
}
Aggregations