Search in sources :

Example 11 with ShadowDocument

use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.

the class AbstractCommand method getOrCreateHiddenDocument.

/**
 * Search for a hidden page named __ShadowDocument__ of type.
 *
 * If found, return it, if not, create it.
 * The shadow page is the DOM document all reusable components are connected to.
 * It is necessary to comply with DOM standards.
 *
 * @return shadow document
 * @throws FrameworkException
 */
public static ShadowDocument getOrCreateHiddenDocument() throws FrameworkException {
    final App app = StructrApp.getInstance();
    ShadowDocument doc = app.nodeQuery(ShadowDocument.class).includeDeletedAndHidden().getFirst();
    if (doc == null) {
        final PropertyMap properties = new PropertyMap();
        properties.put(AbstractNode.type, ShadowDocument.class.getSimpleName());
        properties.put(AbstractNode.name, "__ShadowDocument__");
        properties.put(AbstractNode.hidden, true);
        properties.put(AbstractNode.visibleToAuthenticatedUsers, true);
        doc = app.create(ShadowDocument.class, properties);
    }
    return doc;
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) PropertyMap(org.structr.core.property.PropertyMap) ShadowDocument(org.structr.web.entity.dom.ShadowDocument)

Example 12 with ShadowDocument

use of org.structr.web.entity.dom.ShadowDocument in project structr by structr.

the class ListComponentsCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final int pageSize = webSocketData.getPageSize();
    final int page = webSocketData.getPage();
    try {
        final ShadowDocument hiddenDoc = CreateComponentCommand.getOrCreateHiddenDocument();
        List<DOMNode> filteredResults = new LinkedList();
        List<DOMNode> resultList = hiddenDoc.getElements();
        // Filter list and return only top level nodes
        for (DOMNode node : resultList) {
            if (Boolean.FALSE.equals(node.hasIncomingRelationships(node.getChildLinkType()))) {
                filteredResults.add(node);
            }
        }
        // Sort the components by name
        Collections.sort(filteredResults, new Comparator<DOMNode>() {

            @Override
            public int compare(DOMNode node1, DOMNode node2) {
                final String nameNode1 = node1.getProperty(DOMNode.name);
                final String nameNode2 = node2.getProperty(DOMNode.name);
                if (nameNode1 != null && nameNode2 != null) {
                    return nameNode1.compareTo(nameNode2);
                } else if (nameNode1 == null && nameNode2 == null) {
                    return 0;
                } else if (nameNode1 == null) {
                    return -1;
                } else {
                    return 1;
                }
            }
        });
        // save raw result count
        int resultCountBeforePaging = filteredResults.size();
        // set full result list
        webSocketData.setResult(PagingHelper.subList(filteredResults, pageSize, page));
        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);
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) ShadowDocument(org.structr.web.entity.dom.ShadowDocument) DOMNode(org.structr.web.entity.dom.DOMNode)

Aggregations

ShadowDocument (org.structr.web.entity.dom.ShadowDocument)12 DOMNode (org.structr.web.entity.dom.DOMNode)8 Tx (org.structr.core.graph.Tx)7 FrameworkException (org.structr.common.error.FrameworkException)4 App (org.structr.core.app.App)4 StructrApp (org.structr.core.app.StructrApp)4 PropertyMap (org.structr.core.property.PropertyMap)4 LinkedList (java.util.LinkedList)3 Page (org.structr.web.entity.dom.Page)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 Path (java.nio.file.Path)2 TreeMap (java.util.TreeMap)2 Test (org.junit.Test)2 GraphObject (org.structr.core.GraphObject)2 NodeInterface (org.structr.core.graph.NodeInterface)2 StructrUiTest (org.structr.web.StructrUiTest)2