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();
}
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());
}
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"));
}
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"));
}
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());
}
Aggregations