Solved
AEM Query for retrieving tags value
Hi Team,
I have a requirement to fetch the value of tags, which is under the metadata of content fragment through json url . So can anyone please provide the query for it.
Hi Team,
I have a requirement to fetch the value of tags, which is under the metadata of content fragment through json url . So can anyone please provide the query for it.
@skumari ,
I think you need to write a servlet to run a xpath query to fetch the results. Assuming you need a servlet, this sample code should help you to return result in JSON format
Session session = resourceResolver.adaptTo(Session.class);
Map<String, String> predicateMap = new HashMap<>();
predicateMap.put("1_path", /content/dam/content-fragments/bookpedia);
predicateMap.put("2_type", "dam:Asset");
predicateMap.put("3_property", "jcr:content/contentFragment");
predicateMap.put("3_property.value", "true");
predicateMap.put("4_orderby", "@jcr:content/jcr:lastModified");
predicateMap.put("4_orderby.sort", "desc");
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap),session);
SearchResult result = query.getResult();
Iterator<Resource> resultIterator = result.getResources();
Resource resource = null;
ValueMap valueMap = null;
com.google.gson.JsonObject jsonObject = new JsonObject();
while (resultIterator.hasNext()){
resource = resultIterator.next();
valueMap = resource.getValueMap();
//TO DO
//Fetch your properties from the valueMap and add them to the JsonObject as per your needs
//jsonObject.addProperty("key", valueFromValueMap);
//jsonObject.add("key", anotherJSONObject);
}
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(jsonObject.toString());Hope this helps!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.