Main Content

Magnolia Community Forums: Get help with Magnolia: AssetQuery does not return assets in "natural" order


  • tomwespi
    tomwespi
    Full name: Tom Wespi
    Posts: 41
    Last post: Oct 10, 2017 12:10:00 PM
    AssetQuery does not return assets in "natural" order
    #1 by tomwespi on Oct 10, 2017 11:31:09 AM

    Hi

    I try to achieve a list with all assets and folders/subfolders as shown in the DAM app.

    I noticed when using AssetQuery the result is not in "natural" order. My exceptions is that when no "Ordering" clause is given, the result should be the same as in the workspace.

    I'm using the following AssetQuery:

    Builder builder = new AssetQuery.Builder();
    AssetQuery assetQuery = builder.fromPath(folderPath).includeFolders().build();

    respectDocumentOrder is set in the workspace.xml

    After deleting the index the "natural" order is returned, but after moving a asset, the asset shows up at the end of the resultlist. Is there an "order by lastModified" automatically added to the query?

    Any help highly welcome.

    Best

  • tomwespi
    tomwespi
    Full name: Tom Wespi
    Posts: 41
    Last post: Oct 10, 2017 12:10:00 PM
    Re: AssetQuery does not return assets in "natural" order
    #2 by tomwespi on Oct 10, 2017 12:10:00 PM

    After a bit google search I think there is no solution yet, to achieve this you need the good 'ol deprecated sql language:

    public LinkedList<HashMap<String, String>> getAllAssets() throws LoginException, RepositoryException {
    LinkedList<HashMap<String, String>> ll = new LinkedList<HashMap<String, String>>();
    final String statement = "select * from nt:base where jcr:path like '/myFolder/%'";
    final String language = "sql";
    NodeIterator nit = QueryUtil.search("dam", statement, language);
    while (nit.hasNext()) {
    HashMap<String, String> hm = new HashMap<String, String>();
    Node node = nit.nextNode();
    String primaryNodeType = node.getPrimaryNodeType().getName();

    if (primaryNodeType.equals("mgnl:folder")) {
    hm.put("isFolder", "true");
    if (node.hasProperty("title")) {
    hm.put("folderName", node.getProperty("title").getString());
    } else {
    hm.put("folderName", node.getName());
    }
    }
    if (primaryNodeType.equals("mgnl:asset")) {
    hm.put("isFolder", "false");
    Asset asset = damTemplatingFunctions. getAsset("jcr", node.getPath());
    hm.put("link", asset.getLink());
    hm.put("fileName", asset.getFileName());
    }

    if (!hm.isEmpty()) {
    ll.add(hm);
    }

    }
    return ll;
    }

You don't have the permission to post on this thread

Sign in

To login on this forum, you can use your Magnolia Forge, Support or Partner account, or, below, your Google, Yahoo! or OpenID account. If you have trouble logging in, or any other sort of issue, please let us know in the Meta forum, on the user-list, or simply by email at forum-admin at magnolia-cms dot com.

* Required

... or sign in with:

  • icon http://{your-openid-url}
  • icon
  • icon https://me.yahoo.com/