From 69c6875a9a783077b81026295be170fcb6419128 Mon Sep 17 00:00:00 2001 From: Nilesh Sarupriya Date: Thu, 14 Dec 2023 05:59:56 -0600 Subject: [PATCH] chore: add generate view dto method for overriding (#29595) ## Description > Add generateActionCollectionViewDTO method for overriding purposes #### PR fixes following issue(s) Fixes # (issue number) > if no issue exists, please create an issue and ask the maintainers about this first #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing > This is a refactor, not a change in functionality, hence no test cases. Existing test cases should work fine. #### 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 - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] 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 - **New Features** - Introduced a new data transfer object for action collections to enhance data handling and representation. - **Refactor** - Improved the `getActionCollectionsForViewMode` method for better maintainability and separation of concerns. - **Documentation** - Updated public entity declarations to reflect structural changes in data transfer objects. Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> --- .../base/ActionCollectionServiceCE.java | 2 + .../base/ActionCollectionServiceCEImpl.java | 99 +++++++++---------- .../server/dtos/ActionCollectionViewDTO.java | 17 +--- .../dtos/ce/ActionCollectionViewCE_DTO.java | 26 +++++ 4 files changed, 75 insertions(+), 69 deletions(-) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/ActionCollectionViewCE_DTO.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java index 450fb13b21..1f95d7f46b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCE.java @@ -74,4 +74,6 @@ public interface ActionCollectionServiceCE extends CrudService validateAndSaveCollection(ActionCollection actionCollection); + + Mono generateActionCollectionViewDTO(ActionCollection actionCollection); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java index e0e5d3f294..37ba1ded37 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/base/ActionCollectionServiceCEImpl.java @@ -222,60 +222,51 @@ public class ActionCollectionServiceCEImpl extends BaseService repository .findByApplicationIdAndViewMode( branchedApplicationId, true, actionPermission.getExecutePermission()) - // Filter out all the action collections which haven't been published - .flatMap(actionCollection -> { - if (actionCollection.getPublishedCollection() == null) { - return Mono.empty(); - } - return Mono.just(actionCollection); - }) - .flatMap(actionCollection -> { - ActionCollectionViewDTO actionCollectionViewDTO = new ActionCollectionViewDTO(); - final ActionCollectionDTO publishedCollection = actionCollection.getPublishedCollection(); - actionCollectionViewDTO.setId(actionCollection.getId()); - actionCollectionViewDTO.setName(publishedCollection.getName()); - actionCollectionViewDTO.setPageId(publishedCollection.getPageId()); - actionCollectionViewDTO.setApplicationId(actionCollection.getApplicationId()); - actionCollectionViewDTO.setVariables(publishedCollection.getVariables()); - actionCollectionViewDTO.setBody(publishedCollection.getBody()); - // Update default resources : - // actionCollection.defaultResources contains appId, collectionId and branch(optional). - // Default pageId will be taken from publishedCollection.defaultResources - DefaultResources defaults = actionCollection.getDefaultResources(); - // Consider a situation when collection is not published but user is viewing in deployed - // mode - if (publishedCollection.getDefaultResources() != null && defaults != null) { - defaults.setPageId(publishedCollection - .getDefaultResources() - .getPageId()); - } else { - log.debug( - "Unreachable state, unable to find default ids for actionCollection: {}", - actionCollection.getId()); - if (defaults == null) { - defaults = new DefaultResources(); - defaults.setApplicationId(actionCollection.getApplicationId()); - defaults.setCollectionId(actionCollection.getId()); - } - defaults.setPageId(actionCollection - .getPublishedCollection() - .getPageId()); - } - actionCollectionViewDTO.setDefaultResources(defaults); - return Flux.fromIterable(publishedCollection - .getDefaultToBranchedActionIdsMap() - .values()) - .flatMap(actionId -> { - return newActionService.findActionDTObyIdAndViewMode( - actionId, true, actionPermission.getExecutePermission()); - }) - .collectList() - .map(actionDTOList -> { - actionCollectionViewDTO.setActions(actionDTOList); - return actionCollectionViewDTO; - }); - }) - .map(responseUtils::updateActionCollectionViewDTOWithDefaultResources)); + .flatMap(this::generateActionCollectionViewDTO)); + } + + @Override + public Mono generateActionCollectionViewDTO(ActionCollection actionCollection) { + if (actionCollection.getPublishedCollection() == null) { + return Mono.empty(); + } + ActionCollectionViewDTO actionCollectionViewDTO = new ActionCollectionViewDTO(); + final ActionCollectionDTO publishedCollection = actionCollection.getPublishedCollection(); + actionCollectionViewDTO.setId(actionCollection.getId()); + actionCollectionViewDTO.setName(publishedCollection.getName()); + actionCollectionViewDTO.setPageId(publishedCollection.getPageId()); + actionCollectionViewDTO.setApplicationId(actionCollection.getApplicationId()); + actionCollectionViewDTO.setVariables(publishedCollection.getVariables()); + actionCollectionViewDTO.setBody(publishedCollection.getBody()); + // Update default resources : + // actionCollection.defaultResources contains appId, collectionId and branch(optional). + // Default pageId will be taken from publishedCollection.defaultResources + DefaultResources defaults = actionCollection.getDefaultResources(); + // Consider a situation when collection is not published but user is viewing in deployed + // mode + if (publishedCollection.getDefaultResources() != null && defaults != null) { + defaults.setPageId(publishedCollection.getDefaultResources().getPageId()); + } else { + log.debug( + "Unreachable state, unable to find default ids for actionCollection: {}", actionCollection.getId()); + if (defaults == null) { + defaults = new DefaultResources(); + defaults.setApplicationId(actionCollection.getApplicationId()); + defaults.setCollectionId(actionCollection.getId()); + } + defaults.setPageId(actionCollection.getPublishedCollection().getPageId()); + } + actionCollectionViewDTO.setDefaultResources(defaults); + return Flux.fromIterable( + publishedCollection.getDefaultToBranchedActionIdsMap().values()) + .flatMap(actionId -> newActionService.findActionDTObyIdAndViewMode( + actionId, true, actionPermission.getExecutePermission())) + .collectList() + .map(actionDTOList -> { + actionCollectionViewDTO.setActions(actionDTOList); + return actionCollectionViewDTO; + }) + .map(responseUtils::updateActionCollectionViewDTOWithDefaultResources); } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionCollectionViewDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionCollectionViewDTO.java index e23e957e59..ac8c81c583 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionCollectionViewDTO.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ActionCollectionViewDTO.java @@ -1,26 +1,13 @@ package com.appsmith.server.dtos; -import com.appsmith.external.models.ActionDTO; -import com.appsmith.external.models.DefaultResources; -import com.appsmith.external.models.JSValue; +import com.appsmith.server.dtos.ce.ActionCollectionCE_DTO; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; -import java.util.List; - @Getter @Setter @NoArgsConstructor @ToString -public class ActionCollectionViewDTO { - String id; - String name; - String pageId; - String applicationId; - List variables; - List actions; - String body; - DefaultResources defaultResources; -} +public class ActionCollectionViewDTO extends ActionCollectionCE_DTO {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/ActionCollectionViewCE_DTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/ActionCollectionViewCE_DTO.java new file mode 100644 index 0000000000..2358a2f658 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/ActionCollectionViewCE_DTO.java @@ -0,0 +1,26 @@ +package com.appsmith.server.dtos.ce; + +import com.appsmith.external.models.ActionDTO; +import com.appsmith.external.models.DefaultResources; +import com.appsmith.external.models.JSValue; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@ToString +public class ActionCollectionViewCE_DTO { + String id; + String name; + String pageId; + String applicationId; + List variables; + List actions; + String body; + DefaultResources defaultResources; +}