From ba1e58d99e9b4e3f2b370bd89455194a1099ed5e Mon Sep 17 00:00:00 2001 From: erickgonzalez Date: Mon, 17 Jun 2024 10:14:53 -0600 Subject: [PATCH] #28769 include in 23.10.24 LTS --- dotCMS/hotfix_tracking.md | 3 +- .../web/VariantWebAPIImplIntegrationTest.java | 28 ++++++++++++++++++- .../business/web/VariantWebAPIImpl.java | 6 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/dotCMS/hotfix_tracking.md b/dotCMS/hotfix_tracking.md index 9ce6d91a3b5b..21d54d952757 100644 --- a/dotCMS/hotfix_tracking.md +++ b/dotCMS/hotfix_tracking.md @@ -114,4 +114,5 @@ This maintenance release includes the following code fixes: 107. https://github.com/dotCMS/private-issues/issues/34 108. https://github.com/dotCMS/core/issues/28785 : APIs return incorrect information for pages with fields using the variable name "description" #28785 109. https://github.com/dotCMS/core/issues/28695 : UT210901 UpdateDateTimezones has wrong DST query #28695 -110. https://github.com/dotCMS/core/issues/28760 : Template Evaluation for Non-Default Language Pages #28760 \ No newline at end of file +110. https://github.com/dotCMS/core/issues/28760 : Template Evaluation for Non-Default Language Pages #28760 +111. https://github.com/dotCMS/core/issues/28769 : Language Fallback not working. #28769 \ No newline at end of file diff --git a/dotCMS/src/integration-test/java/com/dotcms/variant/business/web/VariantWebAPIImplIntegrationTest.java b/dotCMS/src/integration-test/java/com/dotcms/variant/business/web/VariantWebAPIImplIntegrationTest.java index 48fd1e0d00a0..ac805b00e714 100644 --- a/dotCMS/src/integration-test/java/com/dotcms/variant/business/web/VariantWebAPIImplIntegrationTest.java +++ b/dotCMS/src/integration-test/java/com/dotcms/variant/business/web/VariantWebAPIImplIntegrationTest.java @@ -3,19 +3,28 @@ import static org.junit.Assert.assertEquals; import com.dotcms.api.web.HttpServletRequestThreadLocal; +import com.dotcms.datagen.LanguageDataGen; +import com.dotcms.datagen.TestDataUtils; import com.dotcms.datagen.VariantDataGen; import com.dotcms.mock.request.MockSession; import com.dotcms.util.IntegrationTestInitService; import com.dotcms.variant.VariantAPI; import com.dotcms.variant.model.Variant; +import com.dotmarketing.business.APILocator; import com.dotmarketing.business.web.WebAPILocator; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; + +import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.portlets.contentlet.model.Contentlet; +import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo; +import com.dotmarketing.portlets.languagesmanager.model.Language; +import com.dotmarketing.util.PageMode; +import com.liferay.portal.model.User; import net.bytebuddy.utility.RandomString; import org.apache.commons.lang.RandomStringUtils; import org.junit.BeforeClass; import org.junit.Test; - import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -246,4 +255,21 @@ private static HttpServletRequest createHttpServletRequest(final Variant variant when(request.getSession(true)).thenReturn(mockSession); return request; } + + /** + * Method to test {@link VariantWebAPIImpl#getContentletVersionInfoByFallback(long, String, PageMode, User, boolean)} + * When: The contentlet does not have a version for the language + * Should: Return the default contentlet + * @throws DotDataException + */ + @Test + public void test_getContentletVersionInfoByFallback_should_get_default_content() throws DotDataException { + final Contentlet content = TestDataUtils.getFileAssetContent(true, APILocator.getLanguageAPI().getDefaultLanguage().getId()); + final Language language = new LanguageDataGen().nextPersisted(); + + final VariantWebAPI variantWebAPI = WebAPILocator.getVariantWebAPI(); + ContentletVersionInfo cvi = variantWebAPI.getContentletVersionInfoByFallback(language.getId(), content.getIdentifier(), PageMode.LIVE, APILocator.getUserAPI().getAnonymousUser()); + + assertNotNull(cvi); + } } \ No newline at end of file diff --git a/dotCMS/src/main/java/com/dotcms/variant/business/web/VariantWebAPIImpl.java b/dotCMS/src/main/java/com/dotcms/variant/business/web/VariantWebAPIImpl.java index a75f3f5ee583..c85ba3282779 100644 --- a/dotCMS/src/main/java/com/dotcms/variant/business/web/VariantWebAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/variant/business/web/VariantWebAPIImpl.java @@ -238,6 +238,7 @@ private boolean shouldFallbackByLang(final ContentletVersionInfo contentletVersi return Boolean.TRUE.equals(contentlet.isHTMLPage()) || forceFallbackByContentType(type) || + isFileFallback(type) || isContentletFallback(type) || isWidgetFallback(type); } @@ -247,6 +248,11 @@ private static boolean isWidgetFallback(ContentType type) { && APILocator.getLanguageAPI().canDefaultWidgetToDefaultLanguage(); } + private static boolean isFileFallback(ContentType type) { + return type.baseType() == BaseContentType.FILEASSET + && APILocator.getLanguageAPI().canDefaultFileToDefaultLanguage(); + } + private static boolean isContentletFallback(ContentType type) { return type.baseType() == BaseContentType.CONTENT && APILocator.getLanguageAPI().canDefaultContentToDefaultLanguage();