From df904539ca8286f846e1a3a8c4b8559579df1883 Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Wed, 13 Nov 2019 05:51:01 +0000 Subject: [PATCH] Datasource instead of DatasourceId is expected as part of Action. During create and update action, datasource can also be created, which is automatically saved as part of datasource collection --- .../server/exceptions/AppsmithError.java | 1 + .../server/services/ActionServiceImpl.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java index fad6f661e6..a5360ca2b2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/AppsmithError.java @@ -18,6 +18,7 @@ public enum AppsmithError { ACTION_RUN_KEY_VALUE_INVALID(400, 4008, "Invalid template param key value pair: {0}:{1}"), UNAUTHORIZED_DOMAIN(401, 4001, "Invalid email domain provided. Please sign in with a valid work email ID"), UNAUTHORIZED_ACCESS(401, 4002, "Unauthorized access"), + INVALID_ACTION_NAME(401, 4003, "Action name is invalid. Please input syntactically correct name"), INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request"), REPOSITORY_SAVE_FAILED(500, 5001, "Repository save failed"), PLUGIN_INSTALLATION_FAILED_DOWNLOAD_ERROR(500, 5002, "Due to error in downloading the plugin from remote repository, plugin installation has failed. Check the jar location and try again"), diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java index 56f74782ef..f29f3199f0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java @@ -31,6 +31,7 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; +import javax.lang.model.SourceVersion; import javax.validation.Validator; import javax.validation.constraints.NotNull; import java.io.StringReader; @@ -97,6 +98,12 @@ public class ActionServiceImpl extends BaseService replaceOrCreateNewDataSourceMono = replaceOrCreateNewDataSource(action); Mono dbActionMono = repository.findById(id) @@ -148,13 +155,24 @@ public class ActionServiceImpl extends BaseService create(@NotNull Action action) { if (action.getId() != null) { return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "id")); - } else if (action.getDatasource() == null) { + } + if (action.getDatasource() == null) { return Mono.error(new AppsmithException(AppsmithError.DATASOURCE_NOT_GIVEN)); } + if (!validateActionName(action.getName())) { + return Mono.error(new AppsmithException(AppsmithError.INVALID_ACTION_NAME)); + } Mono datasourceMono; if (action.getDatasource().getId() == null) {