Search in sources :

Example 21 with List

use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ListImplTest method testListRenderedAsTeaserItems.

@Test
protected void testListRenderedAsTeaserItems() {
    List list = getListUnderTest(LIST_20);
    assertEquals(3, list.getListItems().size());
    Collection<ListItem> items = list.getListItems();
    // The featured image of the page exists: the featured image node of the page is used to render the teaser item
    ListItem item0 = (ListItem) items.toArray()[0];
    Resource teaserResource0 = item0.getTeaserResource();
    ValueMap teaserProperties = teaserResource0.getValueMap();
    String linkURL = teaserProperties.get("linkURL", String.class);
    String fileReference = teaserProperties.get("fileReference", String.class);
    String title = teaserProperties.get("jcr:title", String.class);
    String description = teaserProperties.get("jcr:description", String.class);
    assertEquals("/content/list/pages/page_1/page_1_1/jcr:content/cq:featuredimage", teaserResource0.getPath(), "image resource: path");
    assertEquals("core/wcm/components/teaser/v2/teaser", teaserResource0.getResourceType(), "image resource: resource type");
    assertEquals("/content/list/pages/page_1/page_1_1", linkURL, "image resource: linkURL");
    assertEquals("/content/dam/core/images/Adobe_Systems_logo_and_wordmark.png", fileReference, "image resource: fileReference");
    assertEquals("Page 1.1", title, "image resource: title");
    assertEquals("Description for Page 1.1", description, "image resource: description");
    // The featured image of the page does not exist: the content node of the page is used to render the teaser item
    ListItem item2 = (ListItem) items.toArray()[2];
    Resource teaserResource2 = item2.getTeaserResource();
    assertEquals("/content/list/pages/page_1/page_1_3/jcr:content", teaserResource2.getPath(), "image resource: path");
    Utils.testJSONExport(list, Utils.getTestExporterJSONPath(testBase, LIST_20));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) List(com.adobe.cq.wcm.core.components.models.List) ListItem(com.adobe.cq.wcm.core.components.models.ListItem) Test(org.junit.jupiter.api.Test)

Example 22 with List

use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ListImpl method getSearchListItems.

/**
 * Get the list items if using the search source type.
 *
 * @return The search list items.
 */
private Stream<Page> getSearchListItems() {
    Optional<Page> searchRoot = getRootPage(PN_SEARCH_IN);
    String query = properties.get(PN_SEARCH_QUERY, String.class);
    if (!StringUtils.isBlank(query) && searchRoot.isPresent()) {
        SimpleSearch search = resource.adaptTo(SimpleSearch.class);
        if (search != null) {
            search.setQuery(query);
            search.setSearchIn(searchRoot.get().getPath());
            search.addPredicate(new Predicate("type", "type").set("type", NameConstants.NT_PAGE));
            int limit = properties.get(PN_SEARCH_LIMIT, SEARCH_LIMIT_DEFAULT);
            search.setHitsPerPage(limit);
            return safeGetSearchResult(search).map(SearchResult::getResources).map(it -> (Iterable<Resource>) () -> it).map(it -> StreamSupport.stream(it.spliterator(), false)).orElseGet(Stream::empty).filter(Objects::nonNull).map(currentPage.getPageManager()::getContainingPage).filter(Objects::nonNull);
        }
    }
    return Stream.empty();
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) ArrayUtils(org.apache.commons.lang3.ArrayUtils) StringUtils(org.apache.commons.lang3.StringUtils) Page(com.day.cq.wcm.api.Page) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) TagManager(com.day.cq.tagging.TagManager) Style(com.day.cq.wcm.api.designer.Style) SearchResult(com.day.cq.search.result.SearchResult) ScriptVariable(org.apache.sling.models.annotations.injectorspecific.ScriptVariable) RepositoryException(javax.jcr.RepositoryException) Locale(java.util.Locale) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Model(org.apache.sling.models.annotations.Model) StreamSupport(java.util.stream.StreamSupport) Predicate(com.day.cq.search.Predicate) ComponentExporter(com.adobe.cq.export.json.ComponentExporter) Collator(java.text.Collator) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) SimpleSearch(com.day.cq.search.SimpleSearch) List(com.adobe.cq.wcm.core.components.models.List) Collection(java.util.Collection) Resource(org.apache.sling.api.resource.Resource) Collectors(java.util.stream.Collectors) Exporter(org.apache.sling.models.annotations.Exporter) Serializable(java.io.Serializable) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) Stream(java.util.stream.Stream) ExporterConstants(com.adobe.cq.export.json.ExporterConstants) NameConstants(com.day.cq.wcm.api.NameConstants) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) AbstractComponentImpl(com.adobe.cq.wcm.core.components.util.AbstractComponentImpl) SimpleSearch(com.day.cq.search.SimpleSearch) Objects(java.util.Objects) Page(com.day.cq.wcm.api.Page) SearchResult(com.day.cq.search.result.SearchResult) Predicate(com.day.cq.search.Predicate)

Example 23 with List

use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ListImplTest method testChildrenListTypeWithDepth.

@Test
public void testChildrenListTypeWithDepth() throws Exception {
    Resource resource = context.currentResource("/content/list/listTypes/childrenListTypeWithDepth");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    List list = context.request().adaptTo(List.class);
    assertEquals(4, list.getItems().size());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) List(com.adobe.cq.wcm.core.components.models.List) Test(org.junit.Test)

Example 24 with List

use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ListImplTest method testOrderDescBy.

@Test
public void testOrderDescBy() throws Exception {
    Resource resource = context.currentResource("/content/list/listTypes/staticOrderByTitleDescListType");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    List list2 = context.request().adaptTo(List.class);
    checkListConsistency(list2, new String[] { "Page 2", "Page 1" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) List(com.adobe.cq.wcm.core.components.models.List) Test(org.junit.Test)

Example 25 with List

use of com.adobe.cq.wcm.core.components.models.List in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ListImplTest method testOrderBy.

@Test
public void testOrderBy() throws Exception {
    Resource resource = context.currentResource("/content/list/listTypes/staticOrderByTitleListType");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    List list = context.request().adaptTo(List.class);
    checkListConsistency(list, new String[] { "Page 1", "Page 2" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) List(com.adobe.cq.wcm.core.components.models.List) Test(org.junit.Test)

Aggregations

List (com.adobe.cq.wcm.core.components.models.List)32 Test (org.junit.jupiter.api.Test)20 Resource (org.apache.sling.api.resource.Resource)13 ValueMap (org.apache.sling.api.resource.ValueMap)13 MockStyle (com.adobe.cq.wcm.core.components.context.MockStyle)11 Test (org.junit.Test)11 SearchResult (com.day.cq.search.result.SearchResult)3 SimpleSearch (com.day.cq.search.SimpleSearch)2 ComponentExporter (com.adobe.cq.export.json.ComponentExporter)1 ExporterConstants (com.adobe.cq.export.json.ExporterConstants)1 ListItem (com.adobe.cq.wcm.core.components.models.ListItem)1 AbstractComponentImpl (com.adobe.cq.wcm.core.components.util.AbstractComponentImpl)1 Predicate (com.day.cq.search.Predicate)1 Hit (com.day.cq.search.result.Hit)1 TagManager (com.day.cq.tagging.TagManager)1 NameConstants (com.day.cq.wcm.api.NameConstants)1 Page (com.day.cq.wcm.api.Page)1 Style (com.day.cq.wcm.api.designer.Style)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 Serializable (java.io.Serializable)1