use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class BasicTest method test05CascadeDeleteOutgoing.
/**
* DELETE_OUTGOING should trigger delete cascade from start to end node,
* but not from end to start node.
*/
@Test
public void test05CascadeDeleteOutgoing() {
try {
// Create a relationship with DELETE_OUTGOING
AbstractRelationship rel = cascadeRel(TestOne.class, TestTwo.class, 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
assertNodeNotFound(endNodeId);
}
// Create another relationship with DELETE_OUTGOING
rel = cascadeRel(TestOne.class, TestTwo.class, 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 still exist deletion of end node
assertNodeExists(startNodeId);
}
} 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 RemoveCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final String id = webSocketData.getId();
if (id != null) {
final NodeInterface node = getNode(id);
if (node != null) {
if (node instanceof DOMNode) {
// Use new DOM interface
DOMNode domNode = (DOMNode) node;
try {
domNode.getParentNode().removeChild(domNode);
// remove pageId from node and all children ("move to trash")
recursivelyRemoveNodesFromPage(domNode, securityContext);
} catch (DOMException | FrameworkException ex) {
logger.error("Could not remove node from page " + domNode, ex);
getWebSocket().send(MessageBuilder.status().code(422).message(ex.getMessage()).build(), true);
}
} else {
// is this even used any more?
logger.warn("Deprecated use of RemoveCommand, please report this error and the following stack trace to the Structr team on https://github.com/structr/structr. Thanks!");
Thread.dumpStack();
final App app = StructrApp.getInstance(securityContext);
try {
// Old style: Delete all incoming CONTAINS rels
for (AbstractRelationship rel : node.getIncomingRelationships()) {
if ("CONTAINS".equals(rel.getType())) {
app.delete(rel);
}
}
} catch (Throwable t) {
logger.error("Could not delete relationship", t);
getWebSocket().send(MessageBuilder.status().code(400).message("Error in RemoveCommand: " + t.getMessage()).build(), true);
}
}
} else {
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(400).message("RemoveCommand called with empty id").build(), true);
}
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class Property method index.
@Override
public void index(final GraphObject entity, final Object value) {
if (entity instanceof AbstractNode) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractNode node = (AbstractNode) entity;
final Node dbNode = node.getNode();
final Index<Node> index = nodeService.getNodeIndex();
if (index != null) {
try {
index.remove(dbNode, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbNode, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
logger.warn("", t);
}
}
} else if (entity instanceof AbstractRelationship) {
final NodeService nodeService = Services.getInstance().getService(NodeService.class);
final AbstractRelationship rel = (AbstractRelationship) entity;
final Relationship dbRel = rel.getRelationship();
final Index<Relationship> index = nodeService.getRelationshipIndex();
if (index != null) {
try {
index.remove(dbRel, dbName);
if (value != null || isIndexedWhenEmpty()) {
index.add(dbRel, dbName, value, valueType());
}
} catch (Throwable t) {
logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
}
}
}
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class ReferenceGroup method getGroupedProperties.
// ----- interface PropertyGroup -----
@Override
public PropertyMap getGroupedProperties(SecurityContext securityContext, GraphObject source) {
if (source instanceof AbstractRelationship) {
AbstractRelationship rel = (AbstractRelationship) source;
PropertyMap properties = new PropertyMap();
for (PropertyKey key : propertyKeys.values()) {
Reference reference = (Reference) key;
GraphObject referencedEntity = reference.getReferencedEntity(rel);
PropertyKey referenceKey = reference.getReferenceKey();
PropertyKey propertyKey = reference.getPropertyKey();
if (referencedEntity != null) {
properties.put(propertyKey, referencedEntity.getProperty(referenceKey));
}
}
return properties;
}
return null;
}
use of org.structr.core.entity.AbstractRelationship in project structr by structr.
the class ReferenceGroup method setGroupedProperties.
@Override
public void setGroupedProperties(SecurityContext securityContext, PropertyMap source, GraphObject destination) throws FrameworkException {
if (destination instanceof AbstractRelationship) {
AbstractRelationship rel = (AbstractRelationship) destination;
for (PropertyKey key : propertyKeys.values()) {
Reference reference = (Reference) key;
GraphObject referencedEntity = reference.getReferencedEntity(rel);
PropertyKey referenceKey = reference.getReferenceKey();
PropertyKey propertyKey = reference.getPropertyKey();
if (referencedEntity != null && !reference.isReadOnly()) {
Object value = source.get(propertyKey);
referencedEntity.setProperty(referenceKey, value);
}
}
}
}
Aggregations