use of org.structr.web.entity.dom.DOMNode in project structr by structr.
the class CreateComponentCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
String id = webSocketData.getId();
if (id != null) {
final DOMNode node = (DOMNode) getDOMNode(id);
try {
final DOMNode clonedNode = create(node);
TransactionCommand.registerNodeCallback(clonedNode, callback);
} catch (DOMException | FrameworkException ex) {
// send DOM exception
getWebSocket().send(MessageBuilder.status().code(422).message(ex.getMessage()).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(422).message("Cannot append node without id").build(), true);
}
}
use of org.structr.web.entity.dom.DOMNode in project structr by structr.
the class CreateLocalWidgetCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final App app = StructrApp.getInstance(getWebSocket().getSecurityContext());
final String id = webSocketData.getId();
final Map<String, Object> nodeData = webSocketData.getNodeData();
final String source = (String) nodeData.get("source");
final String name = (String) nodeData.get("name");
// check for ID
if (id == null) {
getWebSocket().send(MessageBuilder.status().code(422).message("Cannot create widget without id").build(), true);
return;
}
// check if parent node with given ID exists
DOMNode node = getDOMNode(id);
if (node == null) {
getWebSocket().send(MessageBuilder.status().code(404).message("Node not found").build(), true);
return;
}
try {
// convertFromInput
PropertyMap properties = new PropertyMap();
properties.put(AbstractNode.type, Widget.class.getSimpleName());
properties.put(AbstractNode.name, name);
properties.put(StructrApp.key(Widget.class, "source"), source);
final Widget widget = app.create(Widget.class, properties);
TransactionCommand.registerNodeCallback(widget, callback);
} catch (Throwable t) {
logger.warn(t.toString());
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message(t.toString()).build(), true);
}
}
use of org.structr.web.entity.dom.DOMNode 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.web.entity.dom.DOMNode in project structr by structr.
the class InsertCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
// new node properties
final Map<String, Object> properties = webSocketData.getNodeData();
String parentId = (String) properties.get("id");
final Map<String, Object> relData = webSocketData.getRelData();
if (parentId != null) {
DOMNode parentNode = (DOMNode) getNode(parentId);
DOMNode nodeToInsert = null;
try {
PropertyMap nodeProperties = PropertyMap.inputTypeToJavaType(securityContext, properties);
nodeToInsert = app.create(DOMNode.class, nodeProperties);
} catch (FrameworkException fex) {
logger.warn("Could not create node.", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
if ((nodeToInsert != null) && (parentNode != null)) {
try {
PropertyMap relProperties = PropertyMap.inputTypeToJavaType(securityContext, relData);
app.create(parentNode, nodeToInsert, parentNode.getChildLinkType(), relProperties);
} catch (FrameworkException t) {
getWebSocket().send(MessageBuilder.status().code(400).message(t.getMessage()).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(400).message("Insertion of new node failed.").build(), true);
}
}
use of org.structr.web.entity.dom.DOMNode in project structr by structr.
the class AppendWidgetCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final String pageId = webSocketData.getPageId();
final Map<String, Object> nodeData = webSocketData.getNodeData();
final String parentId = (String) nodeData.get("parentId");
final String baseUrl = (String) nodeData.get("widgetHostBaseUrl");
final boolean processDeploymentInfo = (Boolean) nodeData.get("processDeploymentInfo");
// 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 DOMNode) {
DOMNode parentDOMNode = getDOMNode(parentId);
if (parentDOMNode == null) {
getWebSocket().send(MessageBuilder.status().code(422).message("Parent node is no DOM node").build(), true);
return;
}
Page page = getPage(pageId);
if (page != null) {
try {
Widget.expandWidget(getWebSocket().getSecurityContext(), page, parentDOMNode, baseUrl, nodeData, processDeploymentInfo);
} catch (FrameworkException fex) {
logger.warn(fex.toString());
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message(fex.toString()).build(), true);
}
}
} else {
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message("Cannot use given node, not instance of DOMNode").build(), true);
}
}
Aggregations