use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class BasicTest method test07CascadeDeleteConditional.
/**
* DELETE_IF_CONSTRAINT_WOULD_BE_VIOLATED should
* trigger delete cascade from start to end node only
* if the remote node would not be valid afterwards
*/
@Test
public void test07CascadeDeleteConditional() {
try {
AbstractRelationship rel = cascadeRel(TestOne.class, TestTwo.class, Relation.CONSTRAINT_BASED);
NodeInterface sourceNode;
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 be deleted
assertNodeNotFound(startNodeId);
// End node should be deleted
assertNodeNotFound(endNodeId);
}
rel = cascadeRel(TestOne.class, TestThree.class, Relation.CONSTRAINT_BASED);
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 be deleted
assertNodeNotFound(startNodeId);
// End node should still be there
assertNodeExists(endNodeId);
}
rel = cascadeRel(TestOne.class, TestFour.class, Relation.CONSTRAINT_BASED);
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 be deleted
assertNodeNotFound(startNodeId);
// End node should still be there
assertNodeExists(endNodeId);
}
} catch (FrameworkException ex) {
logger.warn("", ex);
logger.error(ex.toString());
fail("Unexpected exception");
}
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class StructrConfigHtmlWriter method value.
@Override
public RestWriter value(String value) throws IOException {
if (!hasName) {
currentElement = currentElement.block("li");
}
if ("id".equals(lastName)) {
if (currentObject == null) {
currentElement.inline("a").css("id").attr(new Href(restPath + "/" + value + propertyView)).text("\"", value, "\"");
} else if (currentObject instanceof AbstractRelationship) {
currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getProperty(AbstractRelationship.type) + "/" + value + propertyView)).text("\"", value, "\"");
} else {
currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getType() + "/" + value + propertyView)).text("\"", value, "\"");
}
} else {
// escape backslashes in strings
value = value.replaceAll("\\\\", "\\\\\\\\");
// escape quotation marks inside strings
value = value.replaceAll("\"", "\\\\\\\"");
// Escape for HTML output
value = StringUtils.replaceEach(value, new String[] { "&", "<", ">" }, new String[] { "&", "<", ">" });
currentElement.inline("span").css("string").text("\"", value, "\"");
}
// end LI
currentElement = currentElement.parent();
hasName = false;
return this;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class StructrJsonHtmlWriter method value.
@Override
public RestWriter value(String value) throws IOException {
if (!hasName) {
currentElement = currentElement.block("li");
}
if ("id".equals(lastName)) {
if (currentObject == null) {
currentElement.inline("a").css("id").attr(new Href(restPath + "/" + value + propertyView)).text("\"", value, "\"");
} else if (currentObject instanceof AbstractRelationship) {
currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getProperty(AbstractRelationship.type) + "/" + value + propertyView)).text("\"", value, "\"");
} else {
currentElement.inline("a").css("id").attr(new Href(restPath + "/" + currentObject.getType() + "/" + value + propertyView)).text("\"", value, "\"");
}
} else {
// escape backslashes in strings
value = value.replaceAll("\\\\", "\\\\\\\\");
// escape quotation marks inside strings
value = value.replaceAll("\"", "\\\\\\\"");
// Escape for HTML output
value = StringUtils.replaceEach(value, new String[] { "&", "<", ">" }, new String[] { "&", "<", ">" });
currentElement.inline("span").css("string").text("\"", value, "\"");
}
// end LI
currentElement = currentElement.parent();
hasName = false;
return this;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class RelationshipEndNodeTypeConverter method revert.
@Override
public Object revert(String source) {
if (currentObject instanceof AbstractRelationship) {
final AbstractRelationship rel = (AbstractRelationship) currentObject;
final NodeInterface endNode = rel.getTargetNode();
if (endNode != null) {
return endNode.getType();
}
}
return null;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class RelationshipStartNodeTypeConverter method revert.
@Override
public Object revert(Object source) {
if (currentObject instanceof AbstractRelationship) {
final AbstractRelationship rel = (AbstractRelationship) currentObject;
final NodeInterface startNode = rel.getSourceNode();
if (startNode != null) {
return startNode.getType();
}
}
return null;
}
Aggregations