Search in sources :

Example 1 with ContentContainer

use of org.structr.web.entity.ContentContainer in project structr by structr.

the class ContentPathProperty method getProperty.

@Override
public String getProperty(SecurityContext securityContext, GraphObject obj, boolean applyConverter, final Predicate<GraphObject> predicate) {
    ContentContainer parentContainer = ((ContentContainer) obj).getParent();
    String containerPath = obj.getProperty(AbstractFile.name);
    if (containerPath == null) {
        containerPath = obj.getProperty(GraphObject.id);
    }
    while (parentContainer != null) {
        containerPath = parentContainer.getName().concat("/").concat(containerPath);
        parentContainer = parentContainer.getParent();
    }
    return "/".concat(containerPath);
}
Also used : ContentContainer(org.structr.web.entity.ContentContainer)

Example 2 with ContentContainer

use of org.structr.web.entity.ContentContainer in project structr by structr.

the class AppendContentItemCommand 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 append node without parentId").build(), true);
        return;
    }
    // never append to self
    if (parentId.equals(id)) {
        getWebSocket().send(MessageBuilder.status().code(422).message("Cannot append node as its own child.").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 ContentContainer) {
        ContentContainer container = (ContentContainer) parentNode;
        ContentItem item = (ContentItem) getNode(id);
        if (item != null) {
            try {
                final List<ContentItem> items = container.getItems();
                items.add(item);
                container.setProperty(StructrApp.key(ContentContainer.class, "items"), items);
                TransactionCommand.registerNodeCallback(item, callback);
            } catch (FrameworkException ex) {
                logger.error("", ex);
                getWebSocket().send(MessageBuilder.status().code(422).message("Cannot append content item").build(), true);
            }
        }
    } else {
        // send exception
        getWebSocket().send(MessageBuilder.status().code(422).message("Parent node is not instance of ContentContainer").build(), true);
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) AbstractNode(org.structr.core.entity.AbstractNode) ContentContainer(org.structr.web.entity.ContentContainer) ContentItem(org.structr.web.entity.ContentItem)

Aggregations

ContentContainer (org.structr.web.entity.ContentContainer)2 FrameworkException (org.structr.common.error.FrameworkException)1 AbstractNode (org.structr.core.entity.AbstractNode)1 ContentItem (org.structr.web.entity.ContentItem)1