Search in sources :

Example 36 with AbstractFile

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

the class ListFilesCommand method processMessage.

@Override
public void processMessage(final WebSocketMessage webSocketData) {
    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final String rawType = (String) webSocketData.getNodeData().get("type");
    final Class type = SchemaHelper.getEntityClassForRawType(rawType);
    final String sortOrder = webSocketData.getSortOrder();
    final String sortKey = webSocketData.getSortKey();
    final int pageSize = webSocketData.getPageSize();
    final int page = webSocketData.getPage();
    final PropertyKey sortProperty = StructrApp.key(type, sortKey);
    final Query query = StructrApp.getInstance(securityContext).nodeQuery(type).includeDeletedAndHidden().sort(sortProperty).order("desc".equals(sortOrder));
    // for image lists, suppress thumbnails
    if (type.equals(Image.class)) {
        query.and(StructrApp.key(Image.class, "isThumbnail"), false);
    }
    try {
        // do search
        List<NodeInterface> filteredResults = new LinkedList();
        List<? extends GraphObject> resultList = query.getAsList();
        // add only root folders to the list
        for (GraphObject obj : resultList) {
            if (obj instanceof AbstractFile) {
                AbstractFile node = (AbstractFile) obj;
                if (node.getParent() == null) {
                    filteredResults.add(node);
                }
            }
        }
        // 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("", fex);
    }
}
Also used : AbstractFile(org.structr.web.entity.AbstractFile) Query(org.structr.core.app.Query) FrameworkException(org.structr.common.error.FrameworkException) Image(org.structr.web.entity.Image) GraphObject(org.structr.core.GraphObject) SecurityContext(org.structr.common.SecurityContext) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

AbstractFile (org.structr.web.entity.AbstractFile)36 Folder (org.structr.web.entity.Folder)24 Tx (org.structr.core.graph.Tx)17 FrameworkException (org.structr.common.error.FrameworkException)16 App (org.structr.core.app.App)14 StructrApp (org.structr.core.app.StructrApp)14 File (org.structr.web.entity.File)10 PropertyMap (org.structr.core.property.PropertyMap)8 LinkedList (java.util.LinkedList)6 CMISRootFolder (org.structr.files.cmis.repository.CMISRootFolder)4 Path (java.nio.file.Path)3 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 PropertyKey (org.structr.core.property.PropertyKey)3 Image (org.structr.web.entity.Image)3 Map (java.util.Map)2 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)2 GraphObject (org.structr.core.GraphObject)2 AbstractNode (org.structr.core.entity.AbstractNode)2 NodeAttribute (org.structr.core.graph.NodeAttribute)2 FileNotFoundException (java.io.FileNotFoundException)1