Search in sources :

Example 16 with Query

use of org.structr.core.app.Query in project structr by structr.

the class HtmlServlet method findPossibleEntryPointsByUuid.

private List<Linkable> findPossibleEntryPointsByUuid(final SecurityContext securityContext, final HttpServletRequest request, final String uuid) throws FrameworkException {
    final List<Linkable> possibleEntryPoints = (List<Linkable>) request.getAttribute(POSSIBLE_ENTRY_POINTS_KEY);
    if (CollectionUtils.isNotEmpty(possibleEntryPoints)) {
        return possibleEntryPoints;
    }
    if (uuid.length() > 0) {
        logger.debug("Requested id: {}", uuid);
        final Query query = StructrApp.getInstance(securityContext).nodeQuery();
        query.and(GraphObject.id, uuid);
        query.and().orType(Page.class).orTypes(File.class);
        // Searching for pages needs super user context anyway
        Result results = query.getResult();
        logger.debug("{} results", results.size());
        request.setAttribute(POSSIBLE_ENTRY_POINTS_KEY, results.getResults());
        return (List<Linkable>) results.getResults();
    }
    return Collections.EMPTY_LIST;
}
Also used : Query(org.structr.core.app.Query) Linkable(org.structr.web.entity.Linkable) List(java.util.List) LinkedList(java.util.LinkedList) Page(org.structr.web.entity.dom.Page) Result(org.structr.core.Result)

Example 17 with Query

use of org.structr.core.app.Query 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

Query (org.structr.core.app.Query)17 FrameworkException (org.structr.common.error.FrameworkException)11 PropertyKey (org.structr.core.property.PropertyKey)11 SecurityContext (org.structr.common.SecurityContext)10 Result (org.structr.core.Result)9 GraphObject (org.structr.core.GraphObject)8 Map (java.util.Map)5 PropertyMap (org.structr.core.property.PropertyMap)5 ConfigurationProvider (org.structr.schema.ConfigurationProvider)5 LinkedList (java.util.LinkedList)4 PropertyConverter (org.structr.core.converter.PropertyConverter)4 AbstractNode (org.structr.core.entity.AbstractNode)3 NodeInterface (org.structr.core.graph.NodeInterface)3 Gson (com.google.gson.Gson)2 List (java.util.List)2 AbstractFile (org.structr.web.entity.AbstractFile)2 Image (org.structr.web.entity.Image)2 Linkable (org.structr.web.entity.Linkable)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1