Search in sources :

Example 26 with Teaser

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

the class PageImageThumbnail method initModel.

@PostConstruct
protected void initModel() {
    configPath = request.getRequestPathInfo().getResourcePath();
    componentPath = request.getRequestPathInfo().getSuffix();
    if (StringUtils.isBlank(componentPath)) {
        RequestParameter itemParam = request.getRequestParameter("item");
        if (itemParam == null) {
            log.error("Suffix and 'item' param are blank");
            return;
        }
        componentPath = itemParam.getString();
    }
    PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
    if (pageManager == null) {
        log.error("pagemanager is null");
        return;
    }
    Resource component = resourceResolver.getResource(componentPath);
    if (component == null) {
        log.error("the component at {} does not exist", componentPath);
        return;
    }
    Page currentPage = pageManager.getContainingPage(component);
    if (currentPage != null) {
        currentPagePath = currentPage.getPath();
    }
    Page targetPage = null;
    RequestParameter pageLinkParam = request.getRequestParameter("pageLink");
    if (pageLinkParam != null) {
        // retrieve the page link from the request parameter
        String pageLink = pageLinkParam.getString();
        targetPage = pageManager.getPage(pageLink);
    } else {
        // retrieve the page link from the component model
        Teaser teaserModel = modelFactory.getModelFromWrappedRequest(request, component, Teaser.class);
        Link link = null;
        if (teaserModel != null) {
            link = teaserModel.getLink();
        } else {
            Image imageModel = modelFactory.getModelFromWrappedRequest(request, component, Image.class);
            if (imageModel != null) {
                link = imageModel.getImageLink();
            }
        }
        if (link != null) {
            targetPage = (Page) link.getReference();
        } else {
            targetPage = currentPage;
        }
    }
    if (targetPage == null) {
        log.info("A target page cannot be found for the link defined in the request parameter or on the server at {}.", component.getPath());
        return;
    }
    Resource featuredImage = ComponentUtils.getFeaturedImage(targetPage);
    if (featuredImage == null) {
        log.info("No featured image defined for the page at {}", targetPage.getPath());
        return;
    }
    Image imageModel = modelFactory.getModelFromWrappedRequest(request, featuredImage, Image.class);
    if (imageModel == null) {
        log.info("the image model of {} is null", featuredImage.getPath());
        return;
    }
    this.alt = imageModel.getAlt();
    this.src = imageModel.getSrc();
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) Teaser(com.adobe.cq.wcm.core.components.models.Teaser) RequestParameter(org.apache.sling.api.request.RequestParameter) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) Image(com.adobe.cq.wcm.core.components.models.Image) Link(com.adobe.cq.wcm.core.components.commons.link.Link) PostConstruct(javax.annotation.PostConstruct)

Example 27 with Teaser

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

the class TeaserImplTest method testTeaserWithExternalLinkFromAction.

@Test
protected void testTeaserWithExternalLinkFromAction() {
    Teaser teaser = getTeaserUnderTest(TEASER_7);
    assertEquals("http://www.adobe.com", teaser.getLinkURL());
}
Also used : Teaser(com.adobe.cq.wcm.core.components.models.Teaser) Test(org.junit.jupiter.api.Test)

Example 28 with Teaser

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

the class TeaserImplTest method testTeaserWithoutImage.

@Test
protected void testTeaserWithoutImage() {
    Teaser teaser = getTeaserUnderTest(TEASER_9);
    Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser12"));
}
Also used : Teaser(com.adobe.cq.wcm.core.components.models.Teaser) Test(org.junit.jupiter.api.Test)

Example 29 with Teaser

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

the class TeaserImplTest method testTeaserWithTitleTypeOverride.

@Test
void testTeaserWithTitleTypeOverride() {
    Teaser teaser = getTeaserUnderTest(TEASER_13, Teaser.PN_TITLE_TYPE, "h5", Teaser.PN_SHOW_TITLE_TYPE, true);
    assertEquals("h4", teaser.getTitleType(), "Expected title type is not correct");
    Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser13"));
}
Also used : Teaser(com.adobe.cq.wcm.core.components.models.Teaser) Test(org.junit.jupiter.api.Test)

Example 30 with Teaser

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

the class TeaserImplTest method testEmptyFileReference.

@Test
protected void testEmptyFileReference() {
    Teaser teaser = getTeaserUnderTest(TEASER_3);
    assertNull(teaser.getImageResource());
}
Also used : Teaser(com.adobe.cq.wcm.core.components.models.Teaser) Test(org.junit.jupiter.api.Test)

Aggregations

Teaser (com.adobe.cq.wcm.core.components.models.Teaser)37 Test (org.junit.jupiter.api.Test)35 ListItem (com.adobe.cq.wcm.core.components.models.ListItem)4 Link (com.adobe.cq.wcm.core.components.commons.link.Link)3 Resource (org.apache.sling.api.resource.Resource)3 Image (com.adobe.cq.wcm.core.components.models.Image)2 Page (com.day.cq.wcm.api.Page)2 PageManager (com.day.cq.wcm.api.PageManager)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)1 LinkTestUtils.assertValidLink (com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertValidLink)1 CoreResourceWrapper (com.adobe.cq.wcm.core.components.internal.resource.CoreResourceWrapper)1 ExperienceFragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment)1 ComponentUtils (com.adobe.cq.wcm.core.components.util.ComponentUtils)1 DownloadResource (com.day.cq.commons.DownloadResource)1 ImageResource (com.day.cq.commons.ImageResource)1 Template (com.day.cq.wcm.api.Template)1 Designer (com.day.cq.wcm.api.designer.Designer)1 Style (com.day.cq.wcm.api.designer.Style)1 AllowedComponentList (com.day.cq.wcm.foundation.AllowedComponentList)1