From f715cfd50270c230e8d0e3d5a5ec0f16b93b4ab8 Mon Sep 17 00:00:00 2001 From: Nilesh Sarupriya Date: Wed, 28 Feb 2024 02:42:59 -0600 Subject: [PATCH] chore: code split for entity search (#31332) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description > Code split for entity search. > 1. Move the methods to SearchEntityHelper to be readily available for re-use. > 2. Rename SearchEntitySolutionTest -> SearchEntitySolutionCETest #### PR fixes following issue(s) Fixes [[Task]: Add search functionality for workflows #30843](https://github.com/appsmithorg/appsmith/issues/30843) #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing > #### How Has This Been Tested? > None, as this is just a refactor. #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed ## Summary by CodeRabbit - **Refactor** - Improved code efficiency in search functionality by centralizing the logic for creating pageable and sort objects. - **Tests** - Renamed a test class to better reflect its purpose. --------- Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> --- .../searchentities/SearchEntitySolutionCEImpl.java | 6 ++++-- .../searchentities/helpers/SearchEntityHelper.java | 12 ++++++++++++ ...tionTest.java => SearchEntitySolutionCETest.java} | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) rename app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/{SearchEntitySolutionTest.java => SearchEntitySolutionCETest.java} (99%) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/SearchEntitySolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/SearchEntitySolutionCEImpl.java index 0853a442bf..eddd2004d2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/SearchEntitySolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/SearchEntitySolutionCEImpl.java @@ -19,6 +19,8 @@ import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.List; +import static com.appsmith.server.searchentities.helpers.SearchEntityHelper.getPageable; +import static com.appsmith.server.searchentities.helpers.SearchEntityHelper.getSort; import static com.appsmith.server.searchentities.helpers.SearchEntityHelper.shouldSearchEntity; @RequiredArgsConstructor @@ -55,8 +57,8 @@ public class SearchEntitySolutionCEImpl implements SearchEntitySolutionCE { if (size == 0) { return Mono.just(new SearchEntityDTO()); } - Pageable pageable = Pageable.ofSize(size).withPage(page); - Sort sort = Sort.by(Sort.Direction.DESC, FieldName.UPDATED_AT); + Pageable pageable = getPageable(page, size); + Sort sort = getSort(); searchString = StringUtils.hasLength(searchString) ? searchString.trim() : ""; // If no entities are specified, search for all entities. Mono> workspacesMono = Mono.just(new ArrayList<>()); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/helpers/SearchEntityHelper.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/helpers/SearchEntityHelper.java index 77bcc00b6c..0ebc56b9cf 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/helpers/SearchEntityHelper.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/searchentities/helpers/SearchEntityHelper.java @@ -1,5 +1,9 @@ package com.appsmith.server.searchentities.helpers; +import com.appsmith.server.constants.FieldName; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; + public class SearchEntityHelper { /** * This method checks if the entity should be searched based on the entities list provided. If the entities list is null or empty, then all entities are searched. @@ -19,4 +23,12 @@ public class SearchEntityHelper { } return false; } + + public static Sort getSort() { + return Sort.by(Sort.Direction.DESC, FieldName.UPDATED_AT); + } + + public static Pageable getPageable(int page, int size) { + return Pageable.ofSize(size).withPage(page); + } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/SearchEntitySolutionTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/SearchEntitySolutionCETest.java similarity index 99% rename from app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/SearchEntitySolutionTest.java rename to app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/SearchEntitySolutionCETest.java index cf73f375fd..f67e350bd8 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/SearchEntitySolutionTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/searchentities/SearchEntitySolutionCETest.java @@ -24,7 +24,7 @@ import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; import static org.junit.jupiter.api.Assertions.assertNotNull; @SpringBootTest -class SearchEntitySolutionTest { +class SearchEntitySolutionCETest { @Autowired ApplicationPageService applicationPageService;