use of org.structr.common.SecurityContext in project structr by structr.
the class CreateRelationshipCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final Map<String, Object> properties = webSocketData.getRelData();
final String sourceId = (String) properties.get("sourceId");
final String targetId = (String) properties.get("targetId");
final String relType = (String) properties.get("relType");
final AbstractNode sourceNode = getNode(sourceId);
final AbstractNode targetNode = getNode(targetId);
if ((sourceNode != null) && (targetNode != null)) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
try {
final Class relationClass = StructrApp.getConfiguration().getRelationClassForCombinedType(sourceNode.getType(), relType, targetNode.getType());
final RelationshipInterface rel = app.create(sourceNode, targetNode, relationClass);
TransactionCommand.registerRelCallback(rel, callback);
if (rel != null) {
webSocketData.setResult(Arrays.asList(rel));
getWebSocket().send(webSocketData, true);
}
} catch (FrameworkException t) {
getWebSocket().send(MessageBuilder.status().code(400).message(t.getMessage()).build(), true);
}
} else {
getWebSocket().send(MessageBuilder.status().code(400).message("The CREATE_RELATIONSHIP command needs source and target!").build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class CreateSimplePage method processMessage.
// ~--- methods --------------------------------------------------------
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final String pageName = (String) webSocketData.getNodeData().get(Page.name.dbName());
final SecurityContext securityContext = getWebSocket().getSecurityContext();
try {
final Page page = Page.createSimplePage(securityContext, pageName);
TransactionCommand.registerNodeCallback(page, callback);
} catch (FrameworkException fex) {
logger.warn("Could not create node.", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.toString()).build(), true);
}
}
use of org.structr.common.SecurityContext 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.common.SecurityContext in project structr by structr.
the class DeleteRelationshipCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final AbstractRelationship obj = getRelationship(webSocketData.getId());
if (obj != null) {
StructrApp.getInstance(securityContext).delete(obj);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class FindDuplicateFilesCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final PropertyKey<String> path = StructrApp.key(AbstractFile.class, "path");
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final Query query = StructrApp.getInstance(securityContext).nodeQuery(AbstractFile.class).sort(path);
try {
AbstractFile lastFile = null;
String lastFilepath = null;
boolean lastWasDupe = false;
final ArrayList<GraphObject> filesWithSamePath = new ArrayList<>();
final Iterator it = query.getAsList().iterator();
while (it.hasNext()) {
final AbstractNode node = (AbstractNode) it.next();
try {
final AbstractFile file = (AbstractFile) node;
final String currentFilepath = file.getProperty(path);
// skip the first file as we can not compare it to the previous one
if (lastFile != null) {
if (currentFilepath.equals(lastFilepath)) {
if (!lastWasDupe) {
// if this is the first duplicate found we need to add both files
filesWithSamePath.add(lastFile);
}
filesWithSamePath.add(file);
lastWasDupe = true;
} else {
lastWasDupe = false;
}
}
lastFilepath = currentFilepath;
lastFile = file;
} catch (ClassCastException cce) {
logger.warn("Tried casting node '{}' of type '{}' to AbstractFile. Most likely a node type inheriting from File was deleted and an instance remains. Please delete this node or change its type.", node.getUuid(), node.getType());
}
}
// set full result list
webSocketData.setResult(filesWithSamePath);
webSocketData.setRawResultCount(filesWithSamePath.size());
// send only over local connection
getWebSocket().send(webSocketData, true);
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
Aggregations