use of org.structr.core.entity.AbstractNode in project structr by structr.
the class AppendUserCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
String id = webSocketData.getId();
Map<String, Object> nodeData = webSocketData.getNodeData();
String parentId = (String) nodeData.get("parentId");
// check node to append
if (id == null) {
getWebSocket().send(MessageBuilder.status().code(422).message("Cannot append node, no id is given").build(), true);
return;
}
// check for parent ID
if (parentId == null) {
getWebSocket().send(MessageBuilder.status().code(422).message("Cannot add node without parentId").build(), true);
return;
}
// check if parent node with given ID exists
AbstractNode parentNode = getNode(parentId);
if (parentNode == null) {
getWebSocket().send(MessageBuilder.status().code(404).message("Parent node not found").build(), true);
return;
}
if (parentNode instanceof Group) {
Group group = (Group) parentNode;
Principal user = (Principal) getNode(id);
if (user != null) {
group.addMember(user);
}
} else {
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message("Parent node is not instance of Folder").build(), true);
}
}
use of org.structr.core.entity.AbstractNode in project structr by structr.
the class ChildrenCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final RelationshipFactory factory = new RelationshipFactory(this.getWebSocket().getSecurityContext());
final AbstractNode node = getNode(webSocketData.getId());
if (node == null) {
return;
}
final Iterable<RelationshipInterface> rels = new IterableAdapter<>(node.getNode().getRelationships(Direction.OUTGOING, RelType.CONTAINS), factory);
final List<GraphObject> result = new LinkedList();
for (RelationshipInterface rel : rels) {
NodeInterface endNode = rel.getTargetNode();
if (endNode == null) {
continue;
}
result.add(endNode);
}
webSocketData.setView(PropertyView.Ui);
webSocketData.setResult(result);
// send only over local connection
getWebSocket().send(webSocketData, true);
}
Aggregations