Search in sources :

Example 16 with Group

use of org.structr.core.entity.Group 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)

Aggregations

Group (org.structr.core.entity.Group)16 Principal (org.structr.core.entity.Principal)13 FrameworkException (org.structr.common.error.FrameworkException)12 Tx (org.structr.core.graph.Tx)12 Test (org.junit.Test)11 LinkedList (java.util.LinkedList)4 TestOne (org.structr.core.entity.TestOne)4 List (java.util.List)3 StructrTest (org.structr.common.StructrTest)3 NodeAttribute (org.structr.core.graph.NodeAttribute)3 ActionContext (org.structr.schema.action.ActionContext)3 UnlicensedException (org.structr.common.error.UnlicensedException)2 App (org.structr.core.app.App)2 StructrApp (org.structr.core.app.StructrApp)2 StructrGraphQLTest (org.structr.rest.common.StructrGraphQLTest)2 StructrUiTest (org.structr.web.StructrUiTest)2 User (org.structr.web.entity.User)2 GroupPrincipal (java.nio.file.attribute.GroupPrincipal)1 UserPrincipal (java.nio.file.attribute.UserPrincipal)1 LinkedHashSet (java.util.LinkedHashSet)1