dhulipudi / webextest

test
0 stars 0 forks source link

Test#2 #2

Open dhulipudi opened 6 months ago

dhulipudi commented 6 months ago

Testing 2

title.html

=====

${title}

==== secondary-description.html

${secondaryDescription @ context="html"}

======pretitle.html ===

${heroSpot.pretitle}

======image.html====

=======herospot.html====

<div data-sly-use.heroSpot="com.vanguard.retail.ui.common.core.models.HeroSpot" data-sly-use.component="com.adobe.cq.wcm.core.components.models.Component" data-sly-use.templates="core/wcm/components/commons/v1/templates.html" data-sly-use.imageTemplate="image.html" data-sly-use.pretitleTemplate="pretitle.html" data-sly-use.titleTemplate="title.html" data-sly-use.descriptionTemplate="description.html" data-sly-use.actionsTemplate="actions.html" data-sly-use.secondaryDescriptionTemplate="secondary-description.html" data-sly-test.hasContent="${heroSpot.imageResource || heroSpot.pretitle || heroSpot.title || heroSpot.description || heroSpot.customActions.size > 0}" class="${heroSpot.layoutCssClass}"> <div id="${component.id}" class="cmp-hero-spot${!wcmmode.disabled && heroSpot.imageResource ? ' cq-dd-image' : ''}" data-cmp-data-layer="${heroSpot.data.json}">

=====================description.html=========

${description @ context="html"}

================actions.html===========

=============================action.html====

${action.title}

======\components\herospot\v1\herospot.content.xml====

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="cq:Component" jcr:title="Hero spot" sling:resourceSuperType="vanguard-retail-common/components/teaser/v1/teaser" componentGroup="Retail Marketing Common Project - Content" imageDelegate="marketing-site/components/image"/>

================components\herospot\v1\herospot_cq_dialog ====

<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="nt:unstructured" jcr:title="Hero spot" sling:resourceType="cq/gui/components/authoring/dialog" extraClientlibs="[core.wcm.components.teaser.v1.editor,vanguard-retail-common.components.herospot.v1.editor]" helpPath="https://www.adobe.com/go/aem_cmp_teaser_v1" trackingFeature="core-components:teaser:v1"> <content granite:class="cmp-teaser__editor" jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/container">

</content>

</jcr:root> =========================================HeroSpot.java====

package com.vd.retail.ui.common.core.models;

public interface HeroSpot extends Teaser {

String getLayoutCssClass();
Boolean getPretitleHeader();

}

============== IMPL ===HeroSpotImpl.java

package com.vrd.retail.ui.common.core.models.impl;

import com.adobe.cq.export.json.ComponentExporter; import com.adobe.cq.export.json.ExporterConstants; import com.vd.retail.ui.common.core.models.HeroSpot; import lombok.Getter; import lombok.experimental.Delegate; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Exporter; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Via; import org.apache.sling.models.annotations.injectorspecific.Self; import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; import org.apache.sling.models.annotations.via.ResourceSuperType;

@Model( adaptables = SlingHttpServletRequest.class, adapters = {HeroSpot.class, ComponentExporter.class}, resourceType = HeroSpotImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL ) @Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)

public class HeroSpotImpl implements HeroSpot { static final String RESOURCE_TYPE = "vanguard-retail-common/components/herospot/v1/herospot";

@Delegate()
@Self
@Via(type = ResourceSuperType.class)
private com.vanguard.retail.ui.common.core.models.Teaser teaser;

enum Layout {
    fullImage,
    halfImage,
    halfIllustration,
    card,
    pattern;
}

@ValueMapValue
@Getter
private String layout;

@ValueMapValue
@Getter
private String textColor;

@ValueMapValue
@Getter
private String backgroundColor;

@ValueMapValue
@Getter
private String patternColor;

@ValueMapValue
@Getter
private Boolean pretitleHeader = false;

@ValueMapValue
@Getter
private String secondaryDescription;

@Override
public String getLayoutCssClass() {

    Layout layoutSelected = Layout.valueOf(layout);
    String cssClass;
    switch (layoutSelected) {
        case fullImage:
            cssClass = String.format("cmp-hero-spot--full-image %s %s", textColor, backgroundColor);
            break;
        case halfImage:
            cssClass = String.format("cmp-hero-spot--half-image %s", backgroundColor);
            break;
        case halfIllustration:
            cssClass = String.format("cmp-hero-spot--half-illustration %s", backgroundColor);
            break;
        case pattern:
            cssClass = String.format("cmp-hero-spot--pattern %s", patternColor);
            break;
        default:
            cssClass = "";
            break;
    }
    return cssClass;
}

}

dhulipudi commented 6 months ago

package com.vd.ret.ui.common.core.models.impl;

import com.adobe.cq.export.json.ComponentExporter; import com.adobe.cq.export.json.ExporterConstants; import com.adobe.cq.wcm.core.components.models.ListItem; import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData; import com.adobe.cq.wcm.core.components.models.datalayer.builder.DataLayerBuilder; import com.adobe.cq.wcm.core.components.util.ComponentUtils; import com.day.cq.wcm.api.Page; import com.day.cq.wcm.api.PageManager; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.vd.ret.ui.common.core.models.Teaser; import lombok.experimental.Delegate; import lombok.Getter; import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Exporter; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Via; import org.apache.sling.models.annotations.injectorspecific.ScriptVariable; import org.apache.sling.models.annotations.injectorspecific.Self; import org.apache.sling.models.annotations.via.ResourceSuperType; import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;

import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport;

import static com.adobe.cq.wcm.core.components.util.ComponentUtils.ID_SEPARATOR; import static java.util.Objects.nonNull;

@Model( adaptables = SlingHttpServletRequest.class, adapters = {Teaser.class, ComponentExporter.class}, resourceType = TeaserImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL ) @Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) public class TeaserImpl implements Teaser { static final String RESOURCE_TYPE = "vanguard-retail-common/components/teaser/v1/teaser";

@Self
@Delegate(excludes = TeaserImpl.Exclusion.class)
@Via(type = ResourceSuperType.class)
com.adobe.cq.wcm.core.components.models.Teaser teaser;

@Self
private SlingHttpServletRequest request;

@ValueMapValue
@Getter
private Boolean listDisabled = false;

@ValueMapValue
@Getter
private Boolean isButton;

@ScriptVariable
private PageManager pageManager;

private List<Action> actions;

@Override
public List<Action> getCustomActions() {
    if (this.actions == null) {
        this.actions = Optional.ofNullable(this.isActionsEnabled() ? request.getResource().getChild(com.adobe.cq.wcm.core.components.models.Teaser.NN_ACTIONS) : null)
                .map(Resource::getChildren)
                .map(Iterable::spliterator)
                .map(s -> StreamSupport.stream(s, false))
                .orElseGet(Stream::empty)
                .map(action -> new Action(action, teaser.getId()))
                .collect(Collectors.toList());
    }
    return this.actions;
}

@Override
public String getExportedType() {
    return request.getResource().getResourceType();
}

@Override
public ComponentData getData() {

    return DataLayerBuilder.forComponent()
            .withId(() -> teaser.getId())
            .withType(() -> request.getResource().getResourceType())
            .withLinkUrl(() -> teaser.getData().getLinkUrl())
            .withLastModifiedDate(() -> teaser.getData().getLastModifiedDate())
            .withTitle(() -> teaser.getData().getTitle())
            .withParentId(() -> teaser.getData().getParentId())
            .build();
}

private interface Exclusion {
    String getExportedType();

    ComponentData getData();
}

@JsonIgnoreProperties({"path", "description", "lastModified", "name"})
public class Action implements ListItem {
    static final String CTA_ID_PREFIX = "cta";
    private static final String LEADING = "leading";
    private static final String TRAILING = "trailing";
    ValueMap properties;
    String title;
    String url;
    String target;
    String linkIcon;
    String iconPosition;
    Boolean clickDelay;
    String parentId;
    Page page;
    String ctaId;
    Resource ctaResource;

    public Action(Resource actionRes, String parentId) {

        this.properties = actionRes.getValueMap();
        this.title = this.properties.get("text", String.class);
        this.url = this.properties.get("link", String.class);
        String linkTarget = this.properties.get("linkTarget", String.class);
        this.target = nonNull(linkTarget) && linkTarget.equalsIgnoreCase("true") ? "_blank" : "_self";
        String icon = this.properties.get("linkIcon", String.class);
        this.linkIcon = nonNull(icon) ? icon : StringUtils.EMPTY;
        Boolean isTrailing = this.properties.get("iconPosition", Boolean.class);
        this.iconPosition = nonNull(isTrailing) && isTrailing ? TRAILING : LEADING;
        this.clickDelay = this.properties.get("clickDelay", Boolean.class);
        this.parentId = parentId;
        this.ctaResource = actionRes;
        if (nonNull(this.url) && this.url.startsWith("/")) {
            this.page = TeaserImpl.this.pageManager.getPage(this.url);
        }
    }

    @Override
    public String getId() {
        if (ctaId == null) {
            ctaId = Optional.ofNullable(ctaResource.getValueMap().get(com.adobe.cq.wcm.core.components.models.Component.PN_ID, String.class))
                    .filter(StringUtils::isNotEmpty)
                    .map(id -> StringUtils.replace(StringUtils.normalizeSpace(StringUtils.trim(id)), " ", ID_SEPARATOR))
                    .orElseGet(() ->
                            ComponentUtils.generateId(StringUtils.join(parentId, ID_SEPARATOR, CTA_ID_PREFIX), this.ctaResource.getPath())
                    );
        }
        return ctaId;
    }

    @Override
    public ComponentData getData() {
        return DataLayerBuilder.forComponent()
                .withId(this::getId)
                .withType(() -> request.getResource().getResourceType() + "/cta")
                .withLinkUrl(this::getPath)
                .withLastModifiedDate(teaser.getData()::getLastModifiedDate)
                .withTitle(this::getTitle)
                .withParentId(() -> parentId)
                .build();
    }

    @Override
    public String getTitle() {
        return this.title;
    }

    @Override
    public String getPath() {
        return this.url;
    }

    @Override
    public String getURL() {
        return nonNull(page) ? getUrlLink() : this.url;
    }

    public String getTarget() {
        return target;
    }

    public String getLinkIcon() {
        return linkIcon;
    }

    public String getIconPosition() {
        return iconPosition;
    }

    public Boolean getClickDelay() {
        return clickDelay;
    }

    private String getUrlLink() {
        String vanityURL = page.getVanityUrl();
        return StringUtils.isEmpty(vanityURL) ? request.getContextPath() + page.getPath() + ".html" : request.getContextPath() + vanityURL;
    }
}

}