From a6476688147a6278d8840edee7b210008b705366 Mon Sep 17 00:00:00 2001 From: Nilesh Sarupriya Date: Thu, 31 Oct 2024 17:10:42 +0530 Subject: [PATCH] base changes to populate system info to executeActionDTO (#37091) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description > This PR is the base change for adding any system related info to the ExecuteActionDTO. Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Sanity" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 2f5ab4b54717c021b780490320924e9b4d93522e > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Thu, 31 Oct 2024 11:33:58 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - Introduced a new interface and implementation for enhanced action execution solutions. - Added functionality to populate action execution data with system and user information. - **Bug Fixes** - Improved structure and maintainability of action execution logic. - **Tests** - Updated test class to include a mock for the new action execution helper, ensuring future compatibility. --------- Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> --- .../ActionExecutionSolutionHelper.java | 5 +++ .../ActionExecutionSolutionHelperImpl.java | 8 ++++ .../ce/ActionExecutionSolutionHelperCE.java | 8 ++++ .../ActionExecutionSolutionHelperCEImpl.java | 13 +++++++ .../ActionExecutionSolutionImpl.java | 7 +++- .../ce/ActionExecutionSolutionCEImpl.java | 38 ++++++++++++++----- .../ce/ActionExecutionSolutionCEImplTest.java | 7 +++- 7 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java new file mode 100644 index 0000000000..76b4011c06 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelper.java @@ -0,0 +1,5 @@ +package com.appsmith.server.helpers; + +import com.appsmith.server.helpers.ce.ActionExecutionSolutionHelperCE; + +public interface ActionExecutionSolutionHelper extends ActionExecutionSolutionHelperCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java new file mode 100644 index 0000000000..b0dcc2884c --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ActionExecutionSolutionHelperImpl.java @@ -0,0 +1,8 @@ +package com.appsmith.server.helpers; + +import com.appsmith.server.helpers.ce.ActionExecutionSolutionHelperCEImpl; +import org.springframework.stereotype.Component; + +@Component +public class ActionExecutionSolutionHelperImpl extends ActionExecutionSolutionHelperCEImpl + implements ActionExecutionSolutionHelper {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java new file mode 100644 index 0000000000..6f48c5a8a0 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCE.java @@ -0,0 +1,8 @@ +package com.appsmith.server.helpers.ce; + +import com.appsmith.external.dtos.ExecuteActionDTO; +import reactor.core.publisher.Mono; + +public interface ActionExecutionSolutionHelperCE { + Mono populateExecuteActionDTOWithSystemInfo(ExecuteActionDTO executeActionDTO); +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java new file mode 100644 index 0000000000..69df9c3282 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ActionExecutionSolutionHelperCEImpl.java @@ -0,0 +1,13 @@ +package com.appsmith.server.helpers.ce; + +import com.appsmith.external.dtos.ExecuteActionDTO; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +@Component +public class ActionExecutionSolutionHelperCEImpl implements ActionExecutionSolutionHelperCE { + @Override + public Mono populateExecuteActionDTOWithSystemInfo(ExecuteActionDTO executeActionDTO) { + return Mono.just(executeActionDTO); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java index de3ae71951..1412bd1b6e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ActionExecutionSolutionImpl.java @@ -4,6 +4,7 @@ import com.appsmith.server.applications.base.ApplicationService; import com.appsmith.server.configurations.CommonConfig; import com.appsmith.server.datasources.base.DatasourceService; import com.appsmith.server.datasourcestorages.base.DatasourceStorageService; +import com.appsmith.server.helpers.ActionExecutionSolutionHelper; import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; @@ -40,7 +41,8 @@ public class ActionExecutionSolutionImpl extends ActionExecutionSolutionCEImpl i EnvironmentPermission environmentPermission, ConfigService configService, TenantService tenantService, - CommonConfig commonConfig) { + CommonConfig commonConfig, + ActionExecutionSolutionHelper actionExecutionSolutionHelper) { super( newActionService, actionPermission, @@ -60,6 +62,7 @@ public class ActionExecutionSolutionImpl extends ActionExecutionSolutionCEImpl i environmentPermission, configService, tenantService, - commonConfig); + commonConfig, + actionExecutionSolutionHelper); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java index fa8172f2fd..c8db695056 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java @@ -34,6 +34,7 @@ import com.appsmith.server.domains.User; import com.appsmith.server.dtos.ExecuteActionMetaDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.ActionExecutionSolutionHelper; import com.appsmith.server.helpers.DatasourceAnalyticsUtils; import com.appsmith.server.helpers.DateUtils; import com.appsmith.server.helpers.PluginExecutorHelper; @@ -119,6 +120,7 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE private final EnvironmentPermission environmentPermission; private final ConfigService configService; private final TenantService tenantService; + private final ActionExecutionSolutionHelper actionExecutionSolutionHelper; private final CommonConfig commonConfig; static final String PARAM_KEY_REGEX = "^k\\d+$"; @@ -147,7 +149,8 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE EnvironmentPermission environmentPermission, ConfigService configService, TenantService tenantService, - CommonConfig commonConfig) { + CommonConfig commonConfig, + ActionExecutionSolutionHelper actionExecutionSolutionHelper) { this.newActionService = newActionService; this.actionPermission = actionPermission; this.observationRegistry = observationRegistry; @@ -167,6 +170,7 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE this.configService = configService; this.tenantService = tenantService; this.commonConfig = commonConfig; + this.actionExecutionSolutionHelper = actionExecutionSolutionHelper; this.patternList.add(Pattern.compile(PARAM_KEY_REGEX)); this.patternList.add(Pattern.compile(BLOB_KEY_REGEX)); @@ -245,15 +249,29 @@ public class ActionExecutionSolutionCEImpl implements ActionExecutionSolutionCE Mono instanceIdMono = configService.getInstanceId(); Mono defaultTenantIdMono = tenantService.getDefaultTenantId(); - return Mono.zip(instanceIdMono, defaultTenantIdMono).map(tuple -> { - String instanceId = tuple.getT1(); - String tenantId = tuple.getT2(); - executeActionDTO.setActionId(newAction.getId()); - executeActionDTO.setWorkspaceId(newAction.getWorkspaceId()); - executeActionDTO.setInstanceId(instanceId); - executeActionDTO.setTenantId(tenantId); - return executeActionDTO; - }); + Mono systemInfoPopulatedExecuteActionDTOMono = + actionExecutionSolutionHelper.populateExecuteActionDTOWithSystemInfo(executeActionDTO); + + return systemInfoPopulatedExecuteActionDTOMono.flatMap( + populatedExecuteActionDTO -> Mono.zip(instanceIdMono, defaultTenantIdMono) + .map(tuple -> { + String instanceId = tuple.getT1(); + String tenantId = tuple.getT2(); + populatedExecuteActionDTO.setActionId(newAction.getId()); + populatedExecuteActionDTO.setWorkspaceId(newAction.getWorkspaceId()); + populatedExecuteActionDTO.setInstanceId(instanceId); + populatedExecuteActionDTO.setTenantId(tenantId); + return populatedExecuteActionDTO; + })); + } + + /** + * Populates the requestParams with logged in userId. + * If the user is not logged in, set the parameter as anonymousUserId + * + */ + protected Mono populateExecuteActionDTOWithUserId(ExecuteActionDTO executeActionDTO) { + return Mono.just(executeActionDTO); } /** diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java index 9aac576ae4..c6c1eb9561 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java @@ -15,6 +15,7 @@ import com.appsmith.server.datasourcestorages.base.DatasourceStorageService; import com.appsmith.server.domains.NewAction; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.helpers.ActionExecutionSolutionHelper; import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; @@ -132,6 +133,9 @@ class ActionExecutionSolutionCEImplTest { @SpyBean CommonConfig commonConfig; + @SpyBean + ActionExecutionSolutionHelper actionExecutionSolutionHelper; + @Autowired EnvironmentPermission environmentPermission; @@ -162,7 +166,8 @@ class ActionExecutionSolutionCEImplTest { environmentPermission, configService, tenantService, - commonConfig); + commonConfig, + actionExecutionSolutionHelper); ObservationRegistry.ObservationConfig mockObservationConfig = Mockito.mock(ObservationRegistry.ObservationConfig.class);