use of org.structr.core.entity.LinkedTreeNode in project structr by structr.
the class DeleteNodeCommand method deleteNode.
protected static void deleteNode(final StructrWebSocket ws, final NodeInterface obj, final Boolean recursive) {
final SecurityContext securityContext = ws.getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
if (!(obj.isGranted(Permission.delete, securityContext))) {
logger.warn("No delete permission for {} on {}", new Object[] { ws.getCurrentUser().toString(), obj.toString() });
ws.send(MessageBuilder.status().message("No delete permission").code(400).build(), true);
tx.success();
return;
}
} catch (FrameworkException ex) {
logger.warn("", ex);
}
if (Boolean.TRUE.equals(recursive)) {
// Remove all child nodes first
try {
final List<NodeInterface> filteredResults = new LinkedList<>();
if (obj instanceof DOMNode) {
DOMNode node = (DOMNode) obj;
filteredResults.addAll(DOMNode.getAllChildNodes(node));
} else if (obj instanceof LinkedTreeNode) {
LinkedTreeNode node = (LinkedTreeNode) obj;
filteredResults.addAll(node.getAllChildNodes());
}
for (NodeInterface node : filteredResults) {
app.delete(node);
}
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
ws.send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
} catch (DOMException dex) {
logger.warn("DOMException occured.", dex);
ws.send(MessageBuilder.status().code(422).message(dex.getMessage()).build(), true);
}
}
try {
app.delete(obj);
} catch (FrameworkException fex) {
logger.warn("Unable to delete node(s)", fex);
}
}
use of org.structr.core.entity.LinkedTreeNode in project structr by structr.
the class SetPermissionCommand method setPermission.
private void setPermission(final Value<Tx> transaction, final App app, final AbstractNode obj, final Principal principal, final String action, final Permission permission, final boolean rec) throws FrameworkException {
// create new transaction if not already present
Tx tx = transaction.get(null);
if (tx == null) {
tx = app.tx();
transaction.set(null, tx);
}
switch(action) {
case "grant":
obj.grant(permission, principal);
break;
case "revoke":
obj.revoke(permission, principal);
break;
}
sum++;
// commit transaction after 100 nodes
if (++count == 100) {
logger.info("Committing transaction after {} objects..", sum);
count = 0;
// commit and close old transaction
tx.success();
tx.close();
// create new transaction, do not notify Ui
tx = app.tx(true, true, false);
}
if (rec && obj instanceof LinkedTreeNode) {
for (final Object t : ((LinkedTreeNode) obj).treeGetChildren()) {
setPermission(transaction, app, (AbstractNode) t, principal, action, permission, rec);
}
}
}
Aggregations