Search in sources :

Example 61 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class AppendUserCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    String id = webSocketData.getId();
    Map<String, Object> nodeData = webSocketData.getNodeData();
    String parentId = (String) nodeData.get("parentId");
    // check node to append
    if (id == null) {
        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot append node, no id is given").build(), true);
        return;
    }
    // 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 Group) {
        Group group = (Group) parentNode;
        Principal user = (Principal) getNode(id);
        if (user != null) {
            group.addMember(user);
        }
    } else {
        // send exception
        getWebSocket().send(MessageBuilder.status().code(422).message("Parent node is not instance of Folder").build(), true);
    }
}
Also used : Group(org.structr.core.entity.Group) AbstractNode(org.structr.core.entity.AbstractNode) Principal(org.structr.core.entity.Principal)

Example 62 with AbstractNode

use of org.structr.core.entity.AbstractNode in project structr by structr.

the class ChildrenCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final RelationshipFactory factory = new RelationshipFactory(this.getWebSocket().getSecurityContext());
    final AbstractNode node = getNode(webSocketData.getId());
    if (node == null) {
        return;
    }
    final Iterable<RelationshipInterface> rels = new IterableAdapter<>(node.getNode().getRelationships(Direction.OUTGOING, RelType.CONTAINS), factory);
    final List<GraphObject> result = new LinkedList();
    for (RelationshipInterface rel : rels) {
        NodeInterface endNode = rel.getTargetNode();
        if (endNode == null) {
            continue;
        }
        result.add(endNode);
    }
    webSocketData.setView(PropertyView.Ui);
    webSocketData.setResult(result);
    // send only over local connection
    getWebSocket().send(webSocketData, true);
}
Also used : IterableAdapter(org.structr.core.IterableAdapter) AbstractNode(org.structr.core.entity.AbstractNode) RelationshipFactory(org.structr.core.graph.RelationshipFactory) RelationshipInterface(org.structr.core.graph.RelationshipInterface) GraphObject(org.structr.core.GraphObject) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

AbstractNode (org.structr.core.entity.AbstractNode)62 FrameworkException (org.structr.common.error.FrameworkException)31 Tx (org.structr.core.graph.Tx)20 App (org.structr.core.app.App)18 StructrApp (org.structr.core.app.StructrApp)18 GraphObject (org.structr.core.GraphObject)17 SecurityContext (org.structr.common.SecurityContext)16 PropertyMap (org.structr.core.property.PropertyMap)12 Result (org.structr.core.Result)10 Test (org.junit.Test)9 AbstractRelationship (org.structr.core.entity.AbstractRelationship)9 LinkedList (java.util.LinkedList)8 TestOne (org.structr.core.entity.TestOne)8 DatabaseService (org.structr.api.DatabaseService)7 NodeInterface (org.structr.core.graph.NodeInterface)7 PropertyKey (org.structr.core.property.PropertyKey)7 Principal (org.structr.core.entity.Principal)6 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)5 DOMNode (org.structr.web.entity.dom.DOMNode)5 LinkedHashSet (java.util.LinkedHashSet)4