use of org.structr.core.property.PropertyMap 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.core.property.PropertyMap 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);
}
}
use of org.structr.core.property.PropertyMap 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.core.property.PropertyMap 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.core.property.PropertyMap in project structr by structr.
the class RemoveFromCollectionCommand method processMessage.
// ~--- methods --------------------------------------------------------
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final String keyString = (String) webSocketData.getNodeData().get("key");
if (keyString == null) {
logger.error("Unable to remove given object from collection: key is null");
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
final String idToRemove = (String) webSocketData.getNodeData().get("idToRemove");
if (idToRemove == null) {
logger.error("Unable to remove given object from collection: idToRemove is null");
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
GraphObject obj = getNode(webSocketData.getId());
if (obj != null) {
if (!((AbstractNode) obj).isGranted(Permission.write, getWebSocket().getSecurityContext())) {
getWebSocket().send(MessageBuilder.status().message("No write permission").code(400).build(), true);
logger.warn("No write permission for {} on {}", new Object[] { getWebSocket().getCurrentUser().toString(), obj.toString() });
return;
}
}
if (obj == null) {
// No node? Try to find relationship
obj = getRelationship(webSocketData.getId());
}
GraphObject objToRemove = getNode(idToRemove);
if (obj != null && objToRemove != null) {
try {
PropertyKey key = StructrApp.key(obj.getClass(), keyString);
if (key != null) {
List collection = (List) obj.getProperty(key);
collection.remove(objToRemove);
obj.setProperties(obj.getSecurityContext(), new PropertyMap(key, collection));
if (obj instanceof NodeInterface) {
TransactionCommand.registerNodeCallback((NodeInterface) obj, callback);
} else if (obj instanceof RelationshipInterface) {
TransactionCommand.registerRelCallback((RelationshipInterface) obj, callback);
}
}
} catch (FrameworkException ex) {
logger.error("Unable to set properties: {}", ((FrameworkException) ex).toString());
getWebSocket().send(MessageBuilder.status().code(400).build(), true);
}
} else {
logger.warn("Graph object with uuid {} not found.", webSocketData.getId());
getWebSocket().send(MessageBuilder.status().code(404).build(), true);
}
}
Aggregations