use of com.day.cq.search.result.SearchResult in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ListImplTest method testSearchListType.
@Test
public void testSearchListType() throws Exception {
SearchResult searchResult = mock(SearchResult.class);
Hit hit = mock(Hit.class);
when(mockSimpleSearch.getResult()).thenReturn(searchResult);
when(searchResult.getHits()).thenReturn(Collections.singletonList(hit));
Resource contentResource = context.currentResource("/content/list/pages/page_1/jcr:content");
when(hit.getResource()).thenReturn(contentResource);
Resource resource = context.currentResource("/content/list/listTypes/searchListType");
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
List list = context.request().adaptTo(List.class);
assertEquals(1, list.getItems().size());
}
use of com.day.cq.search.result.SearchResult in project acs-aem-commons by Adobe-Consulting-Services.
the class OnDeployScriptBase method searchAndUpdateResourceType.
/**
* Searches for the current sling:resourceType under /content and replaces any nodes it finds
* with the newResourceType.
*
* @param oldResourceType The current sling:resourceType.
* @param newResourceType The new sling:resourceType to be used.
*/
protected final void searchAndUpdateResourceType(String oldResourceType, String newResourceType) throws RepositoryException {
Map<String, String> map = new HashMap<>();
map.put("p.limit", "-1");
map.put("path", "/content");
map.put("1_property", SLING_RESOURCE_TYPE);
map.put("1_property.value", oldResourceType);
logger.info("Finding all nodes under /content with resource type: {}", oldResourceType);
Query query = resourceResolver.adaptTo(QueryBuilder.class).createQuery(PredicateGroup.create(map), session);
SearchResult result = query.getResult();
Iterator<Node> nodeItr = result.getNodes();
if (nodeItr.hasNext()) {
while (nodeItr.hasNext()) {
Node node = nodeItr.next();
updateResourceType(node, newResourceType);
}
} else {
logger.info("No nodes found with resource type: {}", oldResourceType);
}
}
use of com.day.cq.search.result.SearchResult in project acs-aem-commons by Adobe-Consulting-Services.
the class TwitterFeedUpdaterImpl method findTwitterResources.
private List<Resource> findTwitterResources(ResourceResolver resourceResolver) {
List<Resource> twitterResources = new ArrayList<>();
Map<String, String> predicateMap = new HashMap<>();
predicateMap.put("path", "/content");
predicateMap.put("property", "sling:resourceType");
int counter = 1;
for (String path : twitterComponentPaths) {
predicateMap.put("property." + (counter++) + "_value", path);
}
predicateMap.put("p.limit", "-1");
QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
Session session = resourceResolver.adaptTo(Session.class);
Query query = queryBuilder.createQuery(PredicateGroup.create(predicateMap), session);
SearchResult result = query.getResult();
Iterator<Resource> resources = result.getResources();
while (resources.hasNext()) {
twitterResources.add(resources.next());
}
return twitterResources;
}
use of com.day.cq.search.result.SearchResult in project acs-aem-commons by Adobe-Consulting-Services.
the class QueryBuilderViewQuery method execute.
@Override
public Collection<com.day.cq.wcm.core.contentfinder.Hit> execute() {
final List<com.day.cq.wcm.core.contentfinder.Hit> hits = new ArrayList<com.day.cq.wcm.core.contentfinder.Hit>();
if (this.query == null) {
return hits;
}
final SearchResult result = this.query.getResult();
// iterating over the results
for (Hit hit : result.getHits()) {
try {
hits.add(createHit(hit));
} catch (RepositoryException e) {
log.error("Could not return required information for Content Finder result: {}", hit.toString());
}
}
return hits;
}
use of com.day.cq.search.result.SearchResult in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContentFragmentListImplTest method testListWithOneFragment.
@SuppressWarnings("unchecked")
private void testListWithOneFragment(String listName) {
Resource resource = context.resourceResolver().getResource("/content/dam/contentfragments-for-list/text-only");
if (resource != null) {
Resource DAMFragment = Mockito.spy(resource);
Query query = Mockito.mock(Query.class);
SearchResult searchResult = Mockito.mock(SearchResult.class);
Iterator<Resource> iterator = Mockito.mock(Iterator.class);
ResourceResolver spyResolver = Mockito.spy(DAMFragment.getResourceResolver());
when(query.getResult()).thenReturn(searchResult);
when(searchResult.getResources()).thenReturn(iterator);
when(iterator.hasNext()).thenReturn(true, false);
when(iterator.next()).thenReturn(DAMFragment);
when(DAMFragment.getResourceResolver()).thenReturn(spyResolver);
Mockito.doNothing().when(spyResolver).close();
when(queryBuilderMock.createQuery(Mockito.any(PredicateGroup.class), Mockito.any(Session.class))).thenReturn(query);
ContentFragmentList contentFragmentList = getModelInstanceUnderTest(listName);
assertEquals(ContentFragmentListImpl.RESOURCE_TYPE_V1, contentFragmentList.getExportedType());
assertEquals(contentFragmentList.getListItems().size(), 1);
Utils.testJSONExport(contentFragmentList, Utils.getTestExporterJSONPath(TEST_BASE, listName));
Mockito.doCallRealMethod().when(spyResolver).close();
}
}
Aggregations