use of org.structr.web.entity.dom.DOMNode in project structr by structr.
the class DeleteUnattachedNodesCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) throws FrameworkException {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
final List<NodeInterface> filteredResults = new LinkedList<>();
try (final Tx tx = app.tx(true, false, false)) {
// Get all top nodes, use method from list command
final List<NodeInterface> topNodes = ListUnattachedNodesCommand.getUnattachedNodes(app, securityContext, webSocketData);
// Loop through all top nodes and collect all their child nodes
for (final NodeInterface topNode : topNodes) {
filteredResults.add(topNode);
filteredResults.addAll(DOMNode.getAllChildNodes((DOMNode) topNode));
}
for (final NodeInterface node : filteredResults) {
app.delete(node);
}
tx.success();
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
Aggregations