Search in sources :

Example 1 with ExperienceFragmentSocialVariation

use of com.adobe.cq.xf.social.ExperienceFragmentSocialVariation in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class MockXFFactory method getExperienceFragmentSocialVariation.

public static ExperienceFragmentSocialVariation getExperienceFragmentSocialVariation(Page page) {
    ExperienceFragmentSocialVariation socialVariation = mock(ExperienceFragmentSocialVariation.class);
    StringBuilder stringBuilder = new StringBuilder();
    String image = null;
    for (Resource resource : page.getContentResource().getChild("root").getChildren()) {
        if (resource.isResourceType(IMAGE_RT) && StringUtils.isEmpty(image)) {
            image = resource.getValueMap().get("fileReference", String.class);
        }
        String text = resource.getValueMap().get("text", String.class);
        if (StringUtils.isNotEmpty(text)) {
            stringBuilder.append(text);
        }
    }
    when(socialVariation.getText()).thenReturn(stringBuilder.toString());
    when(socialVariation.getImagePath()).thenReturn(image);
    return socialVariation;
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Resource(org.apache.sling.api.resource.Resource)

Example 2 with ExperienceFragmentSocialVariation

use of com.adobe.cq.xf.social.ExperienceFragmentSocialVariation in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class SocialMediaHelperImpl method createMetadataProvider.

/**
 * Instantiates the suitable metadata provider based on the contents of the current page.
 */
private WebsiteMetadata createMetadataProvider() {
    try {
        Product product = CommerceHelper.findCurrentProduct(currentPage);
        ExperienceFragmentSocialVariation smVariant = findExperienceFragmentSocialVariation();
        if (product == null) {
            if (smVariant == null) {
                return new WebsiteMetadataProvider();
            } else {
                return new ExperienceFragmentWebsiteMetadataProvider(smVariant);
            }
        } else {
            if (smVariant == null) {
                return new ProductMetadataProvider(product);
            } else {
                return new ExperienceFragmentProductMetadataProvider(product, smVariant);
            }
        }
    } catch (NoClassDefFoundError e) {
        return new WebsiteMetadataProvider();
    }
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Product(com.adobe.cq.commerce.api.Product)

Example 3 with ExperienceFragmentSocialVariation

use of com.adobe.cq.xf.social.ExperienceFragmentSocialVariation in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class SocialMediaHelperImpl method createMetadataProvider.

/**
     * Instantiates the suitable metadata provider based on the contents of the current page.
     */
private WebsiteMetadata createMetadataProvider() {
    Product product = CommerceHelper.findCurrentProduct(currentPage);
    ExperienceFragmentSocialVariation smVariant = findExperienceFragmentSocialVariation();
    if (product == null) {
        if (smVariant == null) {
            return new WebsiteMetadataProvider();
        } else {
            return new ExperienceFragmentWebsiteMetadataProvider(smVariant);
        }
    } else {
        if (smVariant == null) {
            return new ProductMetadataProvider(product);
        } else {
            return new ExperienceFragmentProductMetadataProvider(product, smVariant);
        }
    }
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Product(com.adobe.cq.commerce.api.Product)

Example 4 with ExperienceFragmentSocialVariation

use of com.adobe.cq.xf.social.ExperienceFragmentSocialVariation in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class SocialMediaHelperImpl method findExperienceFragmentSocialVariation.

private ExperienceFragmentSocialVariation findExperienceFragmentSocialVariation() {
    Page variantPage = currentPage.getPageManager().getPage(variantPath);
    if (variantPage == null)
        return null;
    ExperienceFragmentSocialVariation socialVariant = variantPage.adaptTo(ExperienceFragmentSocialVariation.class);
    return socialVariant;
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Page(com.day.cq.wcm.api.Page)

Example 5 with ExperienceFragmentSocialVariation

use of com.adobe.cq.xf.social.ExperienceFragmentSocialVariation in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class MockXFFactory method getExperienceFragmentSocialVariation.

public static ExperienceFragmentSocialVariation getExperienceFragmentSocialVariation(Page page) {
    ExperienceFragmentSocialVariation socialVariation = mock(ExperienceFragmentSocialVariation.class);
    StringBuilder stringBuilder = new StringBuilder();
    String image = null;
    for (Resource resource : page.getContentResource().getChild("root").getChildren()) {
        if (resource.isResourceType(IMAGE_RT) && StringUtils.isEmpty(image)) {
            image = resource.getValueMap().get("fileReference", String.class);
        }
        String text = resource.getValueMap().get("text", String.class);
        if (StringUtils.isNotEmpty(text)) {
            stringBuilder.append(text);
        }
    }
    when(socialVariation.getText()).thenReturn(stringBuilder.toString());
    when(socialVariation.getImagePath()).thenReturn(image);
    return socialVariation;
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Resource(org.apache.sling.api.resource.Resource)

Aggregations

ExperienceFragmentSocialVariation (com.adobe.cq.xf.social.ExperienceFragmentSocialVariation)6 Product (com.adobe.cq.commerce.api.Product)2 Page (com.day.cq.wcm.api.Page)2 Resource (org.apache.sling.api.resource.Resource)2