Expand my Community achievements bar.

AEM 6.5 p.nodedepth working on Query Builder Debugger but not java servlet

Avatar

Level 1

I am attempting to use query builder to get all of the values of all instances of a specific component, including the file path for the image within the child component. 

 

I am successfully able to get all values of the component including the child image component using:

 

path= /content/site
1_property=sling:resourceType
1_property.value=site/components/structure/article/articleHead
2_property=articleTags
2_property.operation=like
2_property.value=forum:topic
p.nodedepth=2
p.hits=full

 

output from Json Query Builder Link:

 

{
  "success": true,
  "results": 1,
  "total": 1,
  "more": false,
  "offset": 0,
  "hits": [
    {
      "jcr:path": "/content/site/template-test/jcr:content/root/responsivegrid_534909131/responsivegrid/articlehead",
      "jcr:primaryType": "nt:unstructured",
      "facebookSocialShare": "true",
      "jcr:createdBy": "admin",
      "articlePublishDate": "Wed May 15 2024 00:00:00 GMT-0400",
      "jcr:lastModifiedBy": "admin",
      "articleTitle": "Test Article",
      "jcr:created": "Wed May 01 2024 14:12:13 GMT-0400",
      "articleTags": [
        "forum:topic"
      ],
      "jcr:lastModified": "Wed May 15 2024 13:39:48 GMT-0400",
      "sling:resourceType": "site/components/structure/article/articleHead",
      "mediaDescription": "Pictured: Maecenas venenatis diam sit amet massa commodo, non pulvinar tortor bibendum. Morbi ut efficitur metus, at scelerisque massa.",
      "mediaType": "image",
      "articleImage": {
        "jcr:primaryType": "nt:unstructured",
        "jcr:lastModifiedBy": "admin",
        "newtab": "false",
        "fileName": "default-image.png",
        "alt": "Default Image",
        "jcr:lastModified": "Thu May 02 2024 14:29:07 GMT-0400",
        "linkType": "anchorLink",
        "sling:resourceType": "site/components/content/image",
        "isDecorative": "false",
        "file": {
          "jcr:primaryType": "nt:file",
          "jcr:createdBy": "admin",
          "jcr:created": "Wed May 15 2024 13:39:03 GMT-0400",
          "jcr:content": {
            "jcr:primaryType": "nt:resource",
            "jcr:lastModifiedBy": "admin",
            "jcr:mimeType": "image/png",
            "jcr:lastModified": "Thu May 02 2024 14:29:01 GMT-0400",
            ":jcr:data": 985648,
            "jcr:uuid": "4a9c0f95-4f01-4d3f-ade1-9892e5ce5446"
          }
        }
      }
    }
  ]
}

 However in my servlet, I am not getting back the "article image" object as shown above but I am still getting all other data.

 

Here is the code for the predicate in the servlet:

predicate.put("path", "/content/site");
predicate.put("1_property", "sling:resourceType");
predicate.put("1_property.value", "site/components/structure/article/articleHead");
predicate.put("2_property", "articleTags");
predicate.put("2_property.operation", "like");
//TODO: value from url
predicate.put("2_property.value", "forum:topic");
predicate.put("p.nodedepth", "2");
predicate.put("p.hits", "full");
 
Any ideas on why this is not working?
 
Note: previously I was also trying to only get certain values from the servlet and was trying and was still receiving the full list of values from hit, despite it also working in the Query Builder Debugger so I am wondering if that could be related.
 
Call I was using to try to get specific values:
predicate.put("p.hits", "selective");
predicate.put("p.properties", "articleTitle articleTags);
 
 
4 Replies

Avatar

Community Advisor

Hi, 

Did you check this is not ACL's related issue? I guess you are using queryBuilder UI with the admin user 

 



Esteban Bustamante

Avatar

Level 1

How would I check that, I am using my local instance for the servlet call which is also the admin

Avatar

Community Advisor

@cvieira1599 

The issue you're facing is likely due to the way the p.nodedepth parameter is handled in the Query Builder Debugger and in the Java servlet code

when using the QueryBuilder API in Java code, the p.nodedepth parameter is interpreted differently.
It specifies the depth of the properties to be included in the search results, not the depth of the node hierarchy to be searched.
To achieve the same behavior as the Query Builder Debugger in your Java servlet, you need to adjust the path predicate instead of using p.nodedepth. Here's how you can modify your code:

predicate.put("path", "/content/site//*");
predicate.put("1_property", "sling:resourceType");
predicate.put("1_property.value", "site/components/structure/article/articleHead");
predicate.put("2_property", "articleTags");
predicate.put("2_property.operation", "like");
predicate.put("2_property.value", "forum:topic");
predicate.put("p.hits", "full");

By changing the path predicate to /content/site//*, you're instructing the query to search for nodes under /content/site and all its descendants.
This should give you the same results as the Query Builder Debugger when using p.nodedepth=2.
As for retrieving specific properties, you can use the p.properties predicate in your Java servlet code. For example:

predicate.put("p.properties", "articleTitle articleTags articleImage/fileReference");

Avatar

Administrator

@cvieira1599 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni