From e49bf30fb7949fac68f4f9f27a8caa2e3db40294 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Mon, 16 Dec 2024 15:03:39 -0600 Subject: [PATCH 1/4] #30937 --- .../velocity/services/ContainerLoader.java | 10 +++--- .../viewtools/content/util/ContentUtils.java | 35 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java index ebd5bc3c7475..34634d13a8cc 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java @@ -269,6 +269,7 @@ private InputStream buildVelocity(final Container container, final String uuid, velocityCodeBuilder.append("#set($_show_working_=false)"); //Time-machine block begin + /* velocityCodeBuilder.append("#if($UtilMethods.isSet($request.getSession(false)) && $request.session.getAttribute(\"tm_date\"))"); velocityCodeBuilder.append("#set($_tmdate=$date.toDate($webapi.parseLong($request.session.getAttribute(\"tm_date\"))))"); @@ -290,9 +291,9 @@ private InputStream buildVelocity(final Container container, final String uuid, velocityCodeBuilder.append("#if(!$UtilMethods.isSet($user)) ") .append("#set($user = $cmsuser.getLoggedInUser($request)) ") .append("#end"); - - //end of time-machine block + //end of time-machine block velocityCodeBuilder.append("#end"); + */ velocityCodeBuilder.append("#set($CONTENT_INODE = '')"); velocityCodeBuilder.append("#set($CONTENT_BASE_TYPE = '')"); @@ -408,8 +409,9 @@ private InputStream buildVelocity(final Container container, final String uuid, } - - return writeOutVelocity(filePath, velocityCodeBuilder.toString()); + final String containerCode = velocityCodeBuilder.toString(); + Logger.debug(this, "DotResourceLoader:\tWriting out container code = " + containerCode); + return writeOutVelocity(filePath, containerCode); } diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java index 6ae989917d1a..2c9c492b1c17 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java @@ -8,6 +8,7 @@ import com.dotcms.rest.api.v1.DotObjectMapperProvider; import com.dotcms.util.ConversionUtils; import com.dotcms.util.TimeMachineUtil; +import com.dotcms.variant.VariantAPI; import com.dotmarketing.beans.Identifier; import com.dotmarketing.business.APILocator; import com.dotmarketing.business.web.WebAPILocator; @@ -36,6 +37,7 @@ import java.util.HashMap; import java.util.List; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; @@ -80,7 +82,8 @@ public ContentUtils getInstance() * @return The requested {@link Contentlet} object. */ public static Contentlet find(final String inodeOrIdentifier, final User user, final boolean EDIT_OR_PREVIEW_MODE, final long sessionLang){ - return find(inodeOrIdentifier,user,null,EDIT_OR_PREVIEW_MODE, sessionLang); + final Optional timeMachineDate = TimeMachineUtil.getTimeMachineDate(); + return find(inodeOrIdentifier,user,timeMachineDate.orElse(null),EDIT_OR_PREVIEW_MODE, sessionLang); } private static Contentlet fixRecurringDates(Contentlet contentlet, String[] recDates) { @@ -120,25 +123,31 @@ public static Contentlet find(final String inodeOrIdentifierIn, final User user, return fixRecurringDates(contentlet, recDates); } - // timemachine + // time-machine if (tmDate != null) { // timemachine future dates final Date ffdate = new Date(Long.parseLong(tmDate)); - final Identifier ident = APILocator.getIdentifierAPI().find(inodeOrIdentifier); - if (ident == null || !UtilMethods.isSet(ident.getId())) { - return null; - } + //final Identifier ident = APILocator.getIdentifierAPI().find(inodeOrIdentifier); + //if (ident == null || !UtilMethods.isSet(ident.getId())) { + // return null; + //} // timemachine content has expired. return nothing - if (UtilMethods.isSet(ident.getSysExpireDate()) && ffdate.after(ident.getSysExpireDate())) { - return null; - } + //if (UtilMethods.isSet(ident.getSysExpireDate()) && ffdate.after(ident.getSysExpireDate())) { + // return null; + //} // timemachine content to be published in the future, return the working version - if (UtilMethods.isSet(ident.getSysPublishDate()) && ffdate.after(ident.getSysPublishDate())) { - return conAPI.findContentletByIdentifierOrFallback(inodeOrIdentifier, false, sessionLang, user, true) - .orElse(null); - } + //if (UtilMethods.isSet(ident.getSysPublishDate()) && ffdate.after(ident.getSysPublishDate())) { + //return conAPI.findContentletByIdentifierOrFallback(inodeOrIdentifier, false, sessionLang, user, true).orElse(null); + final PageMode pageMode = PageMode.get(); + final Optional futureContent = conAPI.findContentletByIdentifierOrFallback( + inodeOrIdentifier, sessionLang, VariantAPI.DEFAULT_VARIANT.name(), + ffdate, user, pageMode.respectAnonPerms); + if (futureContent.isPresent()) { + return futureContent.get(); + } + //} } final ContentletVersionInfo contentletVersionInfoByFallback = WebAPILocator.getVariantWebAPI() From 298188fd32a9374f8aa3258c839fb28f521de8bd Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Tue, 17 Dec 2024 10:46:15 -0600 Subject: [PATCH 2/4] #30937 --- .../com/dotcms/rendering/velocity/services/ContainerLoader.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java index 34634d13a8cc..a27f10601996 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/services/ContainerLoader.java @@ -269,7 +269,6 @@ private InputStream buildVelocity(final Container container, final String uuid, velocityCodeBuilder.append("#set($_show_working_=false)"); //Time-machine block begin - /* velocityCodeBuilder.append("#if($UtilMethods.isSet($request.getSession(false)) && $request.session.getAttribute(\"tm_date\"))"); velocityCodeBuilder.append("#set($_tmdate=$date.toDate($webapi.parseLong($request.session.getAttribute(\"tm_date\"))))"); @@ -293,7 +292,6 @@ private InputStream buildVelocity(final Container container, final String uuid, .append("#end"); //end of time-machine block velocityCodeBuilder.append("#end"); - */ velocityCodeBuilder.append("#set($CONTENT_INODE = '')"); velocityCodeBuilder.append("#set($CONTENT_BASE_TYPE = '')"); From 30875593bcbf8ed44fe1f642a9d28e7a6b57ab65 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Tue, 17 Dec 2024 14:34:36 -0600 Subject: [PATCH 3/4] #30937 --- .../viewtools/content/util/ContentUtils.java | 18 +++---------- .../graphql/ftm/CheckingTimeMachine.feature | 27 +++++++++---------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java index 2c9c492b1c17..292dd663c0e1 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/util/ContentUtils.java @@ -125,21 +125,8 @@ public static Contentlet find(final String inodeOrIdentifierIn, final User user, // time-machine if (tmDate != null) { - // timemachine future dates + // This should take care of the rendering bits for the time machine final Date ffdate = new Date(Long.parseLong(tmDate)); - //final Identifier ident = APILocator.getIdentifierAPI().find(inodeOrIdentifier); - //if (ident == null || !UtilMethods.isSet(ident.getId())) { - // return null; - //} - - // timemachine content has expired. return nothing - //if (UtilMethods.isSet(ident.getSysExpireDate()) && ffdate.after(ident.getSysExpireDate())) { - // return null; - //} - - // timemachine content to be published in the future, return the working version - //if (UtilMethods.isSet(ident.getSysPublishDate()) && ffdate.after(ident.getSysPublishDate())) { - //return conAPI.findContentletByIdentifierOrFallback(inodeOrIdentifier, false, sessionLang, user, true).orElse(null); final PageMode pageMode = PageMode.get(); final Optional futureContent = conAPI.findContentletByIdentifierOrFallback( inodeOrIdentifier, sessionLang, VariantAPI.DEFAULT_VARIANT.name(), @@ -147,7 +134,8 @@ public static Contentlet find(final String inodeOrIdentifierIn, final User user, if (futureContent.isPresent()) { return futureContent.get(); } - //} + // If the content is not found or has expired + // No need to return null we continue to the next step to try to find the content in the live or working version } final ContentletVersionInfo contentletVersionInfoByFallback = WebAPILocator.getVariantWebAPI() diff --git a/test-karate/src/test/java/tests/graphql/ftm/CheckingTimeMachine.feature b/test-karate/src/test/java/tests/graphql/ftm/CheckingTimeMachine.feature index 4bd6dd382506..2a3210c9d9bd 100644 --- a/test-karate/src/test/java/tests/graphql/ftm/CheckingTimeMachine.feature +++ b/test-karate/src/test/java/tests/graphql/ftm/CheckingTimeMachine.feature @@ -1,6 +1,11 @@ Feature: Test Time Machine functionality Background: + + * def CONTENTLET_ONE_V1 = 'test 1' + * def CONTENTLET_ONE_V2 = 'test 1 v2 (This ver will be publshed in the future)' + * def CONTENTLET_TWO_V2 = 'test 2 v2' + * callonce read('classpath:graphql/ftm/setup.feature') @smoke @positive @@ -10,15 +15,11 @@ Feature: Test Time Machine functionality When method GET Then status 200 * def pageContents = extractContentlets (response) - - * def contentPieceOne = getContentletByUUID(contentPieceOne, contentPieceOneId) - * def contentPieceTwo = getContentletByUUID(contentPieceTwo, contentPieceTwoId) - * def titles = pageContents.map(x => x.title) # This is the first version of the content, test 1 v2 as the title says it will be published in the future - * match titles contains 'test 1' + * match titles contains CONTENTLET_ONE_V1 # This is the second version of the content, Thisone is already published therefore it should be displayed - * match titles contains 'test 2 v2' + * match titles contains CONTENTLET_TWO_V2 @positive Scenario: Test Time Machine functionality when a publish date is provided expect the future content to be displayed @@ -27,13 +28,11 @@ Feature: Test Time Machine functionality And headers commonHeaders When method GET Then status 200 + * def rendered = response.entity.page.rendered + * match rendered contains CONTENTLET_ONE_V2 * def pageContents = extractContentlets (response) - - * def contentPieceOne = getContentletByUUID(contentPieceOne, contentPieceOneId) - * def contentPieceTwo = getContentletByUUID(contentPieceTwo, contentPieceTwoId) - * def titles = pageContents.map(x => x.title) - * match titles contains 'test 1 v2 (This ver will be publshed in the future)' + * match titles contains CONTENTLET_TWO_V2 @smoke @positive Scenario: Send GraphQL query to fetch page details no publish date is sent @@ -46,8 +45,8 @@ Feature: Test Time Machine functionality Then status 200 * def contentlets = contentletsFromGraphQlResponse(response) * karate.log('contentlets:', contentlets) - * match contentlets contains 'test 1' - * match contentlets contains 'test 2 v2' + * match contentlets contains CONTENTLET_ONE_V1 + * match contentlets contains CONTENTLET_TWO_V2 @smoke @positive Scenario: Send GraphQL query to fetch page details, publish date is sent expect the future content to be displayed @@ -60,4 +59,4 @@ Feature: Test Time Machine functionality Then status 200 * def contentlets = contentletsFromGraphQlResponse(response) * karate.log('contentlets:', contentlets) - * match contentlets contains 'test 1 v2 (This ver will be publshed in the future)' + * match contentlets contains CONTENTLET_ONE_V2 From 5b3a44d67db12b314e72b3f96fadae52dff58d09 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Wed, 18 Dec 2024 09:08:48 -0600 Subject: [PATCH 4/4] #30937 --- test-karate/src/test/java/graphql/ftm/newContainer.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-karate/src/test/java/graphql/ftm/newContainer.feature b/test-karate/src/test/java/graphql/ftm/newContainer.feature index b52636cb9147..47d6d8212e1c 100644 --- a/test-karate/src/test/java/graphql/ftm/newContainer.feature +++ b/test-karate/src/test/java/graphql/ftm/newContainer.feature @@ -15,7 +15,7 @@ Feature: Create a Container "containerStructures":[ { "structureId":"#(contentTypeId)", - "code":"$!{dotContentMap.title}" + "code":"
$!{dotContentMap.title}
" } ] }