Search in sources :

Example 66 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by adobe.

the class ExperienceFragmentImplTest method testValidXFInTemplateWithLocalizationWithDifferentLivecopy.

/**
 * Site with region localization (current page is a livecopy)
 * XF component is defined in the template
 * XF component points to a different region branch as the page
 */
@Test
void testValidXFInTemplateWithLocalizationWithDifferentLivecopy() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-61a", LIVECOPY_PAGE);
    assertEquals(XF_NAME, experienceFragment.getName());
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf61a"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 67 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by adobe.

the class ExperienceFragmentImplTest method testUndefinedXFInPageWithLocalizationWithDifferentCountry_Language.

/**
 * Site with country_language localization
 * XF component is defined in the page
 * fragmentVariationPath is undefined
 */
@Test
void testUndefinedXFInPageWithLocalizationWithDifferentCountry_Language() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(CH_FR_PAGE + "/jcr:content/root/xf-component-42");
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf42"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 68 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by adobe.

the class ExperienceFragmentImplTest method testValidXFInTemplateLocalizationWithSameLivecopy.

/**
 * Site with region localization (current page is a livecopy)
 * XF component is defined in the template
 * XF component points to the same region branch as the page
 */
@Test
void testValidXFInTemplateLocalizationWithSameLivecopy() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(PRODUCT_PAGE_TEMPLATE + "/structure/jcr:content/xf-component-60a", LIVECOPY_PAGE);
    assertEquals(XF_NAME, experienceFragment.getName());
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf60a"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 69 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by adobe.

the class ExperienceFragmentImplTest method testValidXFInPageWithLocalizationWithDifferentBlueprint.

/**
 * Site with region localization (current page is a blueprint)
 * XF component is defined in the page
 * XF component points to a different region branch as the page
 */
@Test
void testValidXFInPageWithLocalizationWithDifferentBlueprint() {
    ExperienceFragment experienceFragment = getExperienceFragmentUnderTest(BLUEPRINT_PAGE + "/jcr:content/root/xf-component-51");
    assertEquals(XF_NAME, experienceFragment.getName());
    Utils.testJSONExport(experienceFragment, Utils.getTestExporterJSONPath(TEST_BASE, "xf51"));
}
Also used : ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Test(org.junit.jupiter.api.Test)

Example 70 with ExperienceFragment

use of com.adobe.cq.wcm.core.components.models.ExperienceFragment in project aem-core-wcm-components by adobe.

the class ExperienceFragmentDataImpl method getLocalizedFragmentVariationPath.

/**
 * Returns the localized path of the experience fragment variation if the experience fragment resource is defined
 * in a template.
 *
 * @return Localized experience fragment variation path
 * @see ExperienceFragment#getLocalizedFragmentVariationPath()
 */
@Nullable
public String getLocalizedFragmentVariationPath() {
    if (localizedFragmentVariationPath != null) {
        return localizedFragmentVariationPath;
    }
    // get the configured fragment variation path
    String fragmentVariationPath = resource.getValueMap().get(ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, String.class);
    if (currentPage != null && inTemplate()) {
        final Resource pageResource = Optional.ofNullable(currentPage).map(p -> p.adaptTo(Resource.class)).orElse(null);
        final String currentPageRootPath = pageResource != null ? LocalizationUtils.getLocalizationRoot(pageResource, resourceResolver, languageManager, relationshipManager) : null;
        // we should use getLocalizationRoot instead of getXfLocalizationRoot once the XF UI supports creating Live and Language Copies
        String xfRootPath = getXfLocalizationRoot(fragmentVariationPath, currentPageRootPath);
        if (StringUtils.isNotEmpty(currentPageRootPath) && StringUtils.isNotEmpty(xfRootPath)) {
            String xfRelativePath = StringUtils.substring(fragmentVariationPath, xfRootPath.length());
            String localizedXfRootPath = StringUtils.replace(currentPageRootPath, CONTENT_ROOT, ExperienceFragmentsConstants.CONTENT_PATH, 1);
            localizedFragmentVariationPath = StringUtils.join(localizedXfRootPath, xfRelativePath, PATH_DELIMITER_CHAR, NN_CONTENT);
        }
    }
    String xfContentPath = String.join(Character.toString(PATH_DELIMITER_CHAR), fragmentVariationPath, NN_CONTENT);
    if (!resourceExists(localizedFragmentVariationPath) && resourceExists(xfContentPath)) {
        localizedFragmentVariationPath = xfContentPath;
    }
    if (!isExperienceFragmentVariation(localizedFragmentVariationPath)) {
        localizedFragmentVariationPath = null;
    }
    return localizedFragmentVariationPath;
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ExperienceFragmentsConstants(com.adobe.cq.xf.ExperienceFragmentsConstants) Resource(org.apache.sling.api.resource.Resource) ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Text(com.day.text.Text) LanguageManager(com.day.cq.wcm.api.LanguageManager) NN_CONTENT(com.day.cq.wcm.api.NameConstants.NN_CONTENT) StringUtils(org.apache.commons.lang3.StringUtils) Page(com.day.cq.wcm.api.Page) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) LiveRelationshipManager(com.day.cq.wcm.msm.api.LiveRelationshipManager) LocalizationUtils(com.adobe.cq.wcm.core.components.util.LocalizationUtils) PageManager(com.day.cq.wcm.api.PageManager) Nullable(org.jetbrains.annotations.Nullable) ScriptVariable(org.apache.sling.models.annotations.injectorspecific.ScriptVariable) InjectionStrategy(org.apache.sling.models.annotations.injectorspecific.InjectionStrategy) Template(com.day.cq.wcm.api.Template) Model(org.apache.sling.models.annotations.Model) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) OSGiService(org.apache.sling.models.annotations.injectorspecific.OSGiService) SlingObject(org.apache.sling.models.annotations.injectorspecific.SlingObject) Resource(org.apache.sling.api.resource.Resource) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExperienceFragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment)90 Test (org.junit.jupiter.api.Test)88 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)4 Resource (org.apache.sling.api.resource.Resource)4 LocalizationUtils (com.adobe.cq.wcm.core.components.util.LocalizationUtils)2 ExperienceFragmentsConstants (com.adobe.cq.xf.ExperienceFragmentsConstants)2 LanguageManager (com.day.cq.wcm.api.LanguageManager)2 NN_CONTENT (com.day.cq.wcm.api.NameConstants.NN_CONTENT)2 Page (com.day.cq.wcm.api.Page)2 PageManager (com.day.cq.wcm.api.PageManager)2 Template (com.day.cq.wcm.api.Template)2 LiveRelationshipManager (com.day.cq.wcm.msm.api.LiveRelationshipManager)2 Text (com.day.text.Text)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 PostConstruct (javax.annotation.PostConstruct)2 StringUtils (org.apache.commons.lang3.StringUtils)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 Model (org.apache.sling.models.annotations.Model)2 InjectionStrategy (org.apache.sling.models.annotations.injectorspecific.InjectionStrategy)2