From b26825971c0f510b8bbca1378682bb95a036526c Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 30 Aug 2024 12:22:56 -0600 Subject: [PATCH 1/2] #29288 return total in content pull --- .../viewtools/content/ContentTool.java | 1 + .../viewtools/content/ContentToolTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java index bf2ca7fc5904..2ba1abf9515f 100644 --- a/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java +++ b/dotCMS/src/main/java/com/dotcms/rendering/velocity/viewtools/content/ContentTool.java @@ -176,6 +176,7 @@ public PaginatedArrayList pull(String query, int offset,int limit, S ret.add(new ContentMap(cc,user,EDIT_OR_PREVIEW_MODE,currentHost,context)); } ret.setQuery(cons.getQuery()); + ret.setTotalResults(cons.getTotalResults()); return ret; } catch(Throwable ex) { diff --git a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java index 1c90ada12af3..06884c08b5a6 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java @@ -38,6 +38,7 @@ import com.dotmarketing.portlets.languagesmanager.model.Language; import com.dotmarketing.portlets.structure.model.Relationship; import com.dotmarketing.util.PageMode; +import com.dotmarketing.util.PaginatedArrayList; import com.dotmarketing.util.PaginatedContentList; import com.dotmarketing.util.WebKeys.Relationship.RELATIONSHIP_CARDINALITY; import com.liferay.portal.model.User; @@ -53,6 +54,7 @@ import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.IntStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.velocity.context.Context; @@ -880,4 +882,21 @@ public void testPullRelated_MultiLangContent() throws DotDataException, DotSecur } + + @Test + public void testPull_includeTotal() { + final ContentType blogLikeType = TestDataUtils.getBlogLikeContentType(); + + final ContentletDataGen contentletDataGen = new ContentletDataGen(blogLikeType.inode()).host(defaultHost); + IntStream.range(0, 10).forEach(i -> contentletDataGen.nextPersisted()); + + final ContentTool contentTool = getContentTool(defaultLanguage.getId()); + + final PaginatedArrayList results = contentTool.pull( + "+contentType:" + blogLikeType.variable(), 0, 0, + "modDate desc" + ); + + Assert.assertEquals(10, results.getTotalResults()); + } } From f17a9c4236210d2bd4e6aa5fb3e5f25264f843ba Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Fri, 30 Aug 2024 12:25:09 -0600 Subject: [PATCH 2/2] #29288 javadoc --- .../velocity/viewtools/content/ContentToolTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java index 06884c08b5a6..11305e3fe92a 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rendering/velocity/viewtools/content/ContentToolTest.java @@ -883,6 +883,12 @@ public void testPullRelated_MultiLangContent() throws DotDataException, DotSecur } + /** + * Method to Test: {@link ContentTool#pull(String, int, int, String)}} + * When: pulling content and having more than one content + * Should: Return the total under the key "totalResults" + * + */ @Test public void testPull_includeTotal() { final ContentType blogLikeType = TestDataUtils.getBlogLikeContentType();