From 389c15af2608cd86a2bb8ca4f12b1224be7268d0 Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Fri, 5 Jul 2024 16:38:22 +0530 Subject: [PATCH 1/2] add datasource validation for action in import flow --- .../newactions/base/NewActionServiceCE.java | 2 ++ .../base/NewActionServiceCEImpl.java | 19 +++++++++++++------ .../NewActionImportableServiceCEImpl.java | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java index da222142a878..ec457dc42fe4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java @@ -39,6 +39,8 @@ public interface NewActionServiceCE extends CrudService { Mono validateAction(NewAction newAction); + Mono validateAction(NewAction newAction, boolean isDryOps); + Mono bulkValidateAndInsertActionInRepository(List newActionList); Mono bulkValidateAndUpdateActionInRepository(List newActionList); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java index bd276c9110c6..115596a412bf 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java @@ -287,6 +287,11 @@ public Mono validateAndSaveActionToRepository(NewAction newAction) { @Override public Mono validateAction(NewAction newAction) { + return validateAction(newAction, false); + } + + @Override + public Mono validateAction(NewAction newAction, boolean isDryOps) { this.setGitSyncIdInNewAction(newAction); ActionDTO action = newAction.getUnpublishedAction(); @@ -373,10 +378,12 @@ public Mono validateAction(NewAction newAction) { datasourceMono = datasourceService .findById(action.getDatasource().getId()) .switchIfEmpty(Mono.defer(() -> { - action.setIsValid(false); - invalids.add(AppsmithError.NO_RESOURCE_FOUND.getMessage( - FieldName.DATASOURCE, - action.getDatasource().getId())); + if (!isDryOps) { + action.setIsValid(false); + invalids.add(AppsmithError.NO_RESOURCE_FOUND.getMessage( + FieldName.DATASOURCE, + action.getDatasource().getId())); + } return Mono.just(action.getDatasource()); })) .map(datasource -> { @@ -441,7 +448,7 @@ public Mono validateAction(NewAction newAction) { @Override public Mono bulkValidateAndInsertActionInRepository(List newActionList) { return Flux.fromIterable(newActionList) - .flatMap(this::validateAction) + .flatMap(newAction -> validateAction(newAction, true)) .collectList() .flatMap(repository::bulkInsert); } @@ -449,7 +456,7 @@ public Mono bulkValidateAndInsertActionInRepository(List newAct @Override public Mono bulkValidateAndUpdateActionInRepository(List newActionList) { return Flux.fromIterable(newActionList) - .flatMap(this::validateAction) + .flatMap(newAction -> validateAction(newAction, true)) .collectList() .flatMap(repository::bulkUpdate); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/importable/NewActionImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/importable/NewActionImportableServiceCEImpl.java index 40af07027215..68d61168fedd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/importable/NewActionImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/importable/NewActionImportableServiceCEImpl.java @@ -571,6 +571,7 @@ private void updateDatasourceInAction( .findFirst() .orElse(datasource); datasource.setIsAutoGenerated(false); + newAction.setWorkspaceId(datasource.getWorkspaceId()); } newAction.getUnpublishedAction().setDatasource(datasource); From 72dc3363fd7fa08ae4bef228eb13573d6f94ccac Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Fri, 5 Jul 2024 19:34:41 +0530 Subject: [PATCH 2/2] refactor isDryOps flag usage in action validate flow --- .../base/NewActionServiceCEImpl.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java index 115596a412bf..07999b8dd873 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java @@ -375,17 +375,23 @@ public Mono validateAction(NewAction newAction, boolean isDryOps) { } else { // TODO: check if datasource should be fetched with edit during action create or update. // Data source already exists. Find the same. - datasourceMono = datasourceService - .findById(action.getDatasource().getId()) - .switchIfEmpty(Mono.defer(() -> { - if (!isDryOps) { - action.setIsValid(false); - invalids.add(AppsmithError.NO_RESOURCE_FOUND.getMessage( - FieldName.DATASOURCE, - action.getDatasource().getId())); - } - return Mono.just(action.getDatasource()); - })) + + if (isDryOps) { + datasourceMono = Mono.just(action.getDatasource()); + } else { + datasourceMono = datasourceService + .findById(action.getDatasource().getId()) + .switchIfEmpty(Mono.defer(() -> { + if (!isDryOps) { + action.setIsValid(false); + invalids.add(AppsmithError.NO_RESOURCE_FOUND.getMessage( + FieldName.DATASOURCE, + action.getDatasource().getId())); + } + return Mono.just(action.getDatasource()); + })); + } + datasourceMono = datasourceMono .map(datasource -> { // datasource is found. Update the action. newAction.setWorkspaceId(datasource.getWorkspaceId());