diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java index cfb7ffbeca..9a9cfb53b7 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Action.java @@ -20,5 +20,7 @@ public class Action extends BaseDomain { String pluginId; + String pageId; + ActionConfiguration actionConfiguration; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Page.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Page.java index cbf9b29a57..46d2f96e23 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Page.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Page.java @@ -21,4 +21,6 @@ public class Page extends BaseDomain { String applicationId; List layouts; + + List actions; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/PageAction.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/PageAction.java new file mode 100644 index 0000000000..f6f5f9db8a --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/PageAction.java @@ -0,0 +1,22 @@ +package com.appsmith.server.domains; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.List; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@Document +public class PageAction { + String id; + + String name; + + List jsonPathKeys; +} 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 a5768681f2..8c23f11f7c 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 @@ -12,9 +12,11 @@ public enum AppsmithError { PLUGIN_NOT_INSTALLED(400, 4001, "Plugin {0} not installed"), PLUGIN_ID_NOT_GIVEN(400, 4002, "Missing plugin id. Please input correct plugin id"), RESOURCE_ID_NOT_GIVEN(400, 4003, "Missing resource id. Please input correct resource id"), + PAGE_ID_NOT_GIVEN(400, 4004, "Missing page id. Pleaes input correct page id"), PAGE_DOESNT_BELONG_TO_USER_ORGANIZATION(400, 4006, "Page {0} does not belong to the current user {1} organization."), UNAUTHORIZED_DOMAIN(401, 4001, "Invalid email domain provided. Please sign in with a valid work email ID"), - INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request"); + INTERNAL_SERVER_ERROR(500, 5000, "Internal server error while processing request"), + REPOSITORY_SAVE_FAILED(500, 5001, "Repository save failed."); private Integer httpErrorCode; private Integer appErrorCode; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java index f8fa09e10d..b154a39c5b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java @@ -24,7 +24,7 @@ public class GlobalExceptionHandler { * * @param e AppsmithException that will be caught by the function * @param exchange ServerWebExchange contract in order to extract the response and set the http status code - * @return Mono> + * @return Mono> */ @ExceptionHandler @ResponseBody @@ -40,7 +40,7 @@ public class GlobalExceptionHandler { * * @param e Exception that will be caught by the function * @param exchange ServerWebExchange contract in order to extract the response and set the http status code - * @return Mono> + * @return Mono> */ @ExceptionHandler @ResponseBody 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 8353b9c16f..5342222397 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 @@ -1,6 +1,8 @@ package com.appsmith.server.services; import com.appsmith.server.domains.Action; +import com.appsmith.server.domains.Page; +import com.appsmith.server.domains.PageAction; import com.appsmith.server.domains.Plugin; import com.appsmith.server.domains.Resource; import com.appsmith.server.exceptions.AppsmithError; @@ -16,6 +18,8 @@ import reactor.core.scheduler.Scheduler; import javax.validation.Validator; import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.List; @Slf4j @Service @@ -24,6 +28,7 @@ public class ActionServiceImpl extends BaseService resourceMono = resourceService.findById(action.getResourceId()); Mono pluginMono = resourceMono.flatMap(resource -> pluginService.findById(resource.getPluginId())); - - return pluginMono + Mono pageMono = pageService.findById(action.getPageId()); + Mono savedActionMono = pluginMono //Set plugin in the action before saving. .map(plugin -> { action.setPluginId(plugin.getId()); return action; }) - .flatMap(repository::save); + .flatMap(repository::save) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.REPOSITORY_SAVE_FAILED))); + + return savedActionMono + //Now that the action has been stored, add it to the page + .flatMap(action1 -> { + return pageMono + .map(page -> { + PageAction pageAction = new PageAction(); + pageAction.setId(action1.getId()); + pageAction.setName(action1.getName()); + pageAction.setJsonPathKeys(new ArrayList<>()); + + List actions = page.getActions(); + + if (actions == null) { + actions = new ArrayList<>(); + } + + actions.add(pageAction); + page.setActions(actions); + return page; + }) + .flatMap(pageService::save) + .then(Mono.just(action1)); + }); } } diff --git a/app/server/appsmith-server/src/main/resources/application-local.properties b/app/server/appsmith-server/src/main/resources/application-local.properties index 3e8a1acfe6..573b245504 100644 --- a/app/server/appsmith-server/src/main/resources/application-local.properties +++ b/app/server/appsmith-server/src/main/resources/application-local.properties @@ -5,7 +5,7 @@ spring.data.mongodb.port=27017 #spring.data.mongodb.username= #spring.data.mongodb.password= -logging.level.root=debug +logging.level.root=info logging.level.com.appsmith=debug logging.pattern.console=%X - %m%n