use of org.structr.common.SecurityContext in project structr by structr.
the class GetByTypeCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final String rawType = (String) webSocketData.getNodeData().get("type");
final String properties = (String) webSocketData.getNodeData().get("properties");
final boolean includeDeletedAndHidden = (Boolean) webSocketData.getNodeData().get("includeDeletedAndHidden");
final 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 Query query = StructrApp.getInstance(securityContext).nodeQuery(type).includeDeletedAndHidden(includeDeletedAndHidden);
if (sortKey != null) {
final PropertyKey sortProperty = StructrApp.key(type, sortKey);
if (sortProperty != null) {
query.sort(sortProperty).order("desc".equals(sortOrder));
}
}
// for image lists, suppress thumbnails
if (type.equals(Image.class)) {
query.and(StructrApp.key(Image.class, "isThumbnail"), false);
}
try {
// do search
Result result = query.getResult();
// save raw result count
int resultCountBeforePaging = result.size();
// set full result list
webSocketData.setResult(PagingHelper.subList(result.getResults(), pageSize, page));
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 QueryCommand 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) nodeData.get("properties");
final Boolean exact = (Boolean) nodeData.get("exact");
final Class type = SchemaHelper.getEntityClassForRawType(rawType);
if (type == null) {
getWebSocket().send(MessageBuilder.status().code(404).message("Type " + rawType + " not found").build(), true);
return;
}
final String sortKey = webSocketData.getSortKey();
final int pageSize = webSocketData.getPageSize();
final int page = webSocketData.getPage();
final Query query = StructrApp.getInstance(securityContext).nodeQuery(type).page(page).pageSize(pageSize);
if (sortKey != null) {
final PropertyKey sortProperty = StructrApp.key(type, sortKey);
final String sortOrder = webSocketData.getSortOrder();
query.sort(sortProperty).order("desc".equals(sortOrder));
}
if (properties != null) {
try {
final Gson gson = new GsonBuilder().create();
final Map<String, Object> querySource = gson.fromJson(properties, new TypeToken<Map<String, Object>>() {
}.getType());
final PropertyMap queryMap = PropertyMap.inputTypeToJavaType(securityContext, type, querySource);
final boolean inexactQuery = exact != null && exact == false;
// add properties to query
for (final Entry<PropertyKey, Object> entry : queryMap.entrySet()) {
query.and(entry.getKey(), entry.getValue(), !inexactQuery);
}
} catch (FrameworkException fex) {
logger.warn("Exception occured", fex);
getWebSocket().send(MessageBuilder.status().code(fex.getStatus()).message(fex.getMessage()).build(), true);
return;
}
}
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 SaveLocalStorageCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final Map<String, Object> nodeData = webSocketData.getNodeData();
final String localStorageString = (String) nodeData.get("localStorageString");
final SecurityContext securityContext = getWebSocket().getSecurityContext();
if (StringUtils.isNotBlank(localStorageString)) {
try {
final User me = (User) securityContext.getUser(false);
me.setLocalStorage(localStorageString);
TransactionCommand.registerNodeCallback(me, callback);
} catch (Throwable t) {
logger.warn("Error saving localstorage", t);
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message(t.toString()).build(), true);
}
} else {
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message("Cannot save localStorage").build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class GetCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
final String nodeId = (String) webSocketData.getNodeData().get("nodeId");
final String properties = (String) webSocketData.getNodeData().get("properties");
if (properties != null) {
securityContext.setCustomView(StringUtils.split(properties, ","));
}
final GraphObject graphObject = getGraphObject(webSocketData.getId(), nodeId);
if (graphObject != null) {
webSocketData.setResult(Arrays.asList(graphObject));
// send only over local connection (no broadcast)
getWebSocket().send(webSocketData, true);
} else {
// logger.warn("Node not found for id {}!", webSocketData.getId());
// Not necessary to send a 404 here
// getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
}
use of org.structr.common.SecurityContext in project structr by structr.
the class GetLocalStorageCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final SecurityContext securityContext = getWebSocket().getSecurityContext();
try {
webSocketData.setNodeData("localStorageString", ((User) securityContext.getUser(false)).getLocalStorage());
// send only over local connection (no broadcast)
getWebSocket().send(webSocketData, true);
} catch (Throwable t) {
logger.warn("Error retrieving localstorage", t);
// send exception
getWebSocket().send(MessageBuilder.status().code(422).message(t.toString()).build(), true);
}
}
Aggregations