is it possible to get only the property's value from a node using JCR query? | Adobe Higher Education
Skip to main content
Level 2
October 4, 2022
Beantwortet

is it possible to get only the property's value from a node using JCR query?

  • October 4, 2022
  • 3 Antworten
  • 1631 Ansichten

I've been trying to parse a node property into a java object, it is a string type that holds my asset path (e.g /content/dam/test).

I'm using the JRC query below but it always returns the full node with all its properties.

SELECT asset.[jcr:content/data/master:image] FROM [dam:Asset] AS asset WHERE ISDESCENDANTNODE(asset, [/content/dam]) AND asset.[jcr:content/data/cq:model] = '/conf/settings/dam/cfm/models/item' AND asset.[jcr:content/data/master/name] IN ("A","B")

 

I was thinking of getting only the property's value, in this case the asset path: "/content/dam/test_cf"  

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von joerghoh

What tool do you use to execute this query? Most tools are designed to display the nodes, not only the requested properties (although the raw JCR API allows you to do that).

 

For example see the QueryResult.getRows() method at https://developer.adobe.com/experience-manager/reference-materials/spec/jsr170/javadocs/jcr-2.0/javax/jcr/query/QueryResult.html

3 Antworten

Saravanan_Dharmaraj
Community Advisor
Community Advisor
October 5, 2022

You can get String path = resource.getPath()  when you iterate the query results of resources. 

 

JCR-SQL2 queries can be invoked from the JCR API:

Session session = ...
QueryManager queryManager = session.getWorkspace.getQueryManager();
Query query = queryManager.createQuery("{QUERY}", Query.JCR_SQL2);
QueryResult result = query.execute();

or through the Sling API:

ResourceResolver resolver = ...
Iterator<Resource> result = resolver.findResources("{QUERY}", Query.JCR_SQL2);

 

ShaileshBassi
Community Advisor
Community Advisor
October 6, 2022

@rute Over here you can get the result and parse the result to get the property value from the result set.

Query query = queryBuilder.createQuery(PredicateGroup.create(queryBuilderMap), session);
SearchResult searchResult = query.getResult();
  if (null != searchResult) {
       for (Hit hit : searchResult.getHits()) {
           Resource resource = hit.getResource();
           String propertyVal = resource.getValueMap().get("property-name", StringUtils.EMPTY);
       }
 }

 Hope this helps!

joerghoh
Adobe Employee
joerghohAdobe EmployeeAntwort
Adobe Employee
October 6, 2022

What tool do you use to execute this query? Most tools are designed to display the nodes, not only the requested properties (although the raw JCR API allows you to do that).

 

For example see the QueryResult.getRows() method at https://developer.adobe.com/experience-manager/reference-materials/spec/jsr170/javadocs/jcr-2.0/javax/jcr/query/QueryResult.html