// ----- private methods ----- private void listFolder(final StructrShellCommand parent, final List<AbstractFile> folder) throws FrameworkException, IOException { for (final AbstractFile child : folder) { if (parent.isAllowed(child, Permission.read, false)) { if (child instanceof Folder) { term.setBold(true); term.setTextColor(4); term.print(child.getName() + " "); term.setTextColor(7); term.setBold(false); } else { term.print(child.getName() + " "); } } } if (!folder.isEmpty()) { term.println(); } }
@Override public void processMessage(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 Folder) { Folder folder = (Folder) parentNode; AbstractFile file = (AbstractFile) getNode(id); if (file != null) { try { // Remove from existing parent LinkedTreeNode currentParent = file.treeGetParent(RelType.CONTAINS); if (currentParent != null) { currentParent.treeRemoveChild(RelType.CONTAINS, file); } folder.treeAppendChild(RelType.CONTAINS, file); } catch (FrameworkException ex) { logger.log(Level.SEVERE, null, ex); getWebSocket() .send(MessageBuilder.status().code(422).message("Cannot append file").build(), true); } } } else { // send exception getWebSocket() .send( MessageBuilder.status() .code(422) .message("Parent node is not instance of Folder") .build(), true); } }