use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class StartNodeGroup method getGroupedProperties.
@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
if (source instanceof AbstractRelationship) {
RelationshipInterface rel = (RelationshipInterface) source;
NodeInterface startNode = rel.getSourceNode();
return super.getGroupedProperties(securityContext, startNode);
}
return null;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class GetIncomingRelationshipsFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
final List<AbstractRelationship> list = new ArrayList<>();
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && s.equals(targetNode) && t.equals(sourceNode)) {
list.add(rel);
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null && t != null && rel.getRelType().name().equals(relType) && s.equals(targetNode) && t.equals(sourceNode)) {
list.add(rel);
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return list;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class HasIncomingRelationshipFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && s.equals(targetNode) && t.equals(sourceNode)) {
return true;
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getIncomingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && rel.getRelType().name().equals(relType) && s.equals(targetNode) && t.equals(sourceNode)) {
return true;
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return false;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class HasOutgoingRelationshipFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndMaxLengthAndAllElementsNotNull(sources, 2, 3)) {
final Object source = sources[0];
final Object target = sources[1];
AbstractNode sourceNode = null;
AbstractNode targetNode = null;
if (source instanceof AbstractNode && target instanceof AbstractNode) {
sourceNode = (AbstractNode) source;
targetNode = (AbstractNode) target;
} else {
logger.warn("Error: entities are not nodes. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
if (sources.length == 2) {
for (final AbstractRelationship rel : sourceNode.getOutgoingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && s.equals(sourceNode) && t.equals(targetNode)) {
return true;
}
}
} else if (sources.length == 3) {
// dont try to create the relClass because we would need to do that both ways!!! otherwise it just fails if the nodes are in the "wrong" order (see tests:890f)
final String relType = (String) sources[2];
for (final AbstractRelationship rel : sourceNode.getOutgoingRelationships()) {
final NodeInterface s = rel.getSourceNode();
final NodeInterface t = rel.getTargetNode();
// We need to check if current user can see source and target node which is often not the case for OWNS or SECURITY rels
if (s != null & t != null && rel.getRelType().name().equals(relType) && s.equals(sourceNode) && t.equals(targetNode)) {
return true;
}
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
}
return false;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class BasicTest method test06CascadeDeleteBidirectional.
/**
* DELETE_INCOMING + DELETE_OUTGOING should trigger delete cascade from start to end node
* and from end node to start node
*/
@Test
public void test06CascadeDeleteBidirectional() {
try {
// Create a relationship with DELETE_INCOMING
AbstractRelationship rel = cascadeRel(TestOne.class, TestTwo.class, Relation.TARGET_TO_SOURCE | Relation.SOURCE_TO_TARGET);
NodeInterface sourceNode;
NodeInterface targetNode;
String startNodeId;
String endNodeId;
try (final Tx tx = app.tx()) {
startNodeId = rel.getSourceNode().getUuid();
endNodeId = rel.getTargetNode().getUuid();
sourceNode = rel.getSourceNode();
}
deleteCascade(sourceNode);
try (final Tx tx = app.tx()) {
// Start node should not be found after deletion
assertNodeNotFound(startNodeId);
// End node should not be found after deletion of start node
assertNodeNotFound(endNodeId);
}
// Create a relationship with DELETE_INCOMING
rel = cascadeRel(TestOne.class, TestTwo.class, Relation.TARGET_TO_SOURCE | Relation.SOURCE_TO_TARGET);
try (final Tx tx = app.tx()) {
startNodeId = rel.getSourceNode().getUuid();
endNodeId = rel.getTargetNode().getUuid();
targetNode = rel.getTargetNode();
}
deleteCascade(targetNode);
try (final Tx tx = app.tx()) {
// End node should not be found after deletion
assertNodeNotFound(endNodeId);
// Start node should not be found after deletion of end node
assertNodeNotFound(startNodeId);
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations