Hi @mahesh_gunaje You can use the QueryBuilder API in AEM to achieve this. Here's an example of how you can write the query using Java Stream:
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import java.util.List;
import java.util.stream.Stream;
@Component
public class MyQueryBuilder {
@Reference
private ResourceResolverFactory resourceResolverFactory;
public List<myPage> getPagesWithArticleProperty() {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
Resource rootResource = resourceResolver.getResource("/content/abc/us/en");
QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
Query query = queryBuilder.createQuery(PredicateGroup.create(
predicate("article", "blog")
), queryBuilder.getResourceFactory());
SearchResult result = query.execute();
Stream<Resource> resourceStream = StreamSupport.stream(result.getResources().spliterator(), false);
return resourceStream
.map(resource -> resource.adaptTo(myPage.class))
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}
In this example, we first get the ResourceResolver instance and then get the root resource using the path /content/abc/us/en. We then create a QueryBuilder instance and define a query using the PredicateGroup API. In this case, we're searching for resources that have a property named "article" with a value of "blog".
We then execute the query and get the search result. We use the StreamSupport class to convert the Resource iterator to a Stream. We then map each Resource to an instance of myPage using the adaptTo method, filter out any null values, and collect the results into a list.
Note that you'll need to inject the ResourceResolverFactory instance using the @Reference annotation, and also make sure that you have the necessary dependencies in your project's pom file.