use of org.structr.common.SecurityContext in project structr by structr.
the class ListActiveElementsCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
final String id = webSocketData.getId();
try (final Tx tx = app.tx()) {
final Page page = app.get(Page.class, id);
final List<GraphObject> result = new LinkedList<>();
if (page != null) {
collectActiveElements(result, page, Collections.EMPTY_SET, null, 0);
// set full result list
webSocketData.setResult(result);
webSocketData.setRawResultCount(result.size());
// send only over local connection
getWebSocket().send(webSocketData, true);
} else {
getWebSocket().send(MessageBuilder.status().code(404).message("Page with ID " + id + " not found.").build(), true);
}
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class ListCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final Map<String, Object> nodeData = webSocketData.getNodeData();
final String rawType = (String) nodeData.get("type");
final String properties = (String) webSocketData.getNodeData().get("properties");
final boolean rootOnly = Boolean.TRUE.equals((Boolean) nodeData.get("rootOnly"));
Class type = SchemaHelper.getEntityClassForRawType(rawType);
if (type == null) {
getWebSocket().send(MessageBuilder.status().code(404).message("Type " + rawType + " not found").build(), true);
return;
}
if (properties != null) {
securityContext.setCustomView(StringUtils.split(properties, ","));
}
final String sortOrder = webSocketData.getSortOrder();
final String sortKey = webSocketData.getSortKey();
final int pageSize = webSocketData.getPageSize();
final int page = webSocketData.getPage();
final PropertyKey sortProperty = StructrApp.key(type, sortKey);
final Query query = StructrApp.getInstance(securityContext).nodeQuery(type).sort(sortProperty).order("desc".equals(sortOrder)).page(page).pageSize(pageSize);
if (File.class.isAssignableFrom(type)) {
if (rootOnly) {
query.and(StructrApp.key(File.class, "hasParent"), false);
}
// inverted as isThumbnail is not necessarily present in all objects inheriting from FileBase
query.not().and(StructrApp.key(Image.class, "isThumbnail"), true);
}
// important
if (Folder.class.isAssignableFrom(type) && rootOnly) {
query.and(StructrApp.key(Folder.class, "hasParent"), false);
}
try {
// do search
final Result result = query.getResult();
// save raw result count
// filteredResults.size();
int resultCountBeforePaging = result.getRawResultCount();
// set full result list
webSocketData.setResult(result.getResults());
webSocketData.setRawResultCount(resultCountBeforePaging);
// 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);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class ListUnattachedNodesCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final int pageSize = webSocketData.getPageSize();
final int page = webSocketData.getPage();
final App app = StructrApp.getInstance(securityContext);
try (final Tx tx = app.tx()) {
// do search
List<NodeInterface> filteredResults = getUnattachedNodes(app, securityContext, webSocketData);
// save raw result count
int resultCountBeforePaging = filteredResults.size();
// set full result list
webSocketData.setResult(PagingHelper.subList(filteredResults, pageSize, page));
webSocketData.setRawResultCount(resultCountBeforePaging);
// send only over local connection
getWebSocket().send(webSocketData, true);
tx.success();
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class ClonePageCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final String nodeId = webSocketData.getId();
final AbstractNode nodeToClone = getNode(nodeId);
if (nodeToClone != null) {
try {
final Page pageToClone = nodeToClone instanceof Page ? (Page) nodeToClone : null;
if (pageToClone != null) {
final Page newPage = (Page) pageToClone.cloneNode(false);
newPage.setProperties(securityContext, new PropertyMap(Page.name, pageToClone.getProperty(Page.name) + "-" + newPage.getIdString()));
DOMNode firstChild = (DOMNode) pageToClone.getFirstChild().getNextSibling();
if (firstChild == null) {
firstChild = (DOMNode) pageToClone.getFirstChild();
}
if (firstChild != null) {
final DOMNode newHtmlNode = DOMNode.cloneAndAppendChildren(securityContext, firstChild);
newPage.appendChild(newHtmlNode);
}
}
} catch (FrameworkException fex) {
logger.warn("Could not create node.", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
} catch (DOMException dex) {
logger.warn("Could not create node.", dex);
getWebSocket().send(MessageBuilder.status().code(422).message(dex.getMessage()).build(), true);
}
} else {
logger.warn("Node with uuid {} not found.", webSocketData.getId());
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class CreateCommand method processMessage.
// ~--- methods --------------------------------------------------------
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final App app = StructrApp.getInstance(securityContext);
Map<String, Object> nodeData = webSocketData.getNodeData();
try {
final PropertyMap properties = PropertyMap.inputTypeToJavaType(securityContext, nodeData);
Class type = SchemaHelper.getEntityClassForRawType(properties.get(AbstractNode.type));
final NodeInterface newNode = app.create(type, properties);
TransactionCommand.registerNodeCallback(newNode, callback);
// check for File node and store in WebSocket to receive chunks
if (newNode instanceof File) {
getWebSocket().createFileUploadHandler((File) newNode);
}
} catch (FrameworkException fex) {
logger.warn("Could not create node.", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
}
}
Aggregations