use of org.structr.core.entity.AbstractNode 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.AbstractNode 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.AbstractNode in project structr by structr.
the class BasicTest method test01CreateNode.
@Test
public void test01CreateNode() {
try {
try {
// Create node out of transaction => should give a NotInTransactionException
app.create(TestOne.class);
fail("Should have raised a NotInTransactionException");
} catch (NotInTransactionException e) {
}
try {
// Try to create node without parameters => should fail
app.create(TestOne.class);
fail("Should have raised a NotInTransactionException");
} catch (NotInTransactionException e) {
}
AbstractNode node = null;
try (final Tx tx = app.tx()) {
node = app.create(TestOne.class);
tx.success();
}
assertTrue(node != null);
assertTrue(node instanceof TestOne);
} catch (FrameworkException ex) {
logger.error("", ex);
fail("Unexpected exception");
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class SearchAndSortingTest method test12SearchByEmptyLongField.
@Test
public void test12SearchByEmptyLongField() {
try {
PropertyMap props = new PropertyMap();
AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).and(TestOne.aLong, null).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class SearchAndSortingTest method test07SearchByStaticMethod01.
@Test
public void test07SearchByStaticMethod01() {
try {
PropertyMap props = new PropertyMap();
final PropertyKey key = AbstractNode.name;
final String name = "89w3hkl sdfghsdkljth";
props.put(key, name);
final AbstractNode node = createTestNode(TestOne.class, props);
try (final Tx tx = app.tx()) {
Result result = app.nodeQuery(TestOne.class).andName(name).includeDeletedAndHidden().getResult();
assertTrue(result.size() == 1);
assertTrue(result.get(0).equals(node));
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
Aggregations