Merge branch 'bug/#53' into 'master'

Add Page Actions to Page object.

Closes #53

See merge request theappsmith/internal-tools-server!16
This commit is contained in:
Trisha Anand 2019-09-17 06:25:07 +00:00
commit 7c1561a969
7 changed files with 70 additions and 8 deletions

View File

@ -20,5 +20,7 @@ public class Action extends BaseDomain {
String pluginId; String pluginId;
String pageId;
ActionConfiguration actionConfiguration; ActionConfiguration actionConfiguration;
} }

View File

@ -21,4 +21,6 @@ public class Page extends BaseDomain {
String applicationId; String applicationId;
List<Layout> layouts; List<Layout> layouts;
List<PageAction> actions;
} }

View File

@ -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<String> jsonPathKeys;
}

View File

@ -12,9 +12,11 @@ public enum AppsmithError {
PLUGIN_NOT_INSTALLED(400, 4001, "Plugin {0} not installed"), PLUGIN_NOT_INSTALLED(400, 4001, "Plugin {0} not installed"),
PLUGIN_ID_NOT_GIVEN(400, 4002, "Missing plugin id. Please input correct plugin id"), 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"), 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."), 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"), 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 httpErrorCode;
private Integer appErrorCode; private Integer appErrorCode;

View File

@ -24,7 +24,7 @@ public class GlobalExceptionHandler {
* *
* @param e AppsmithException that will be caught by the function * @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 * @param exchange ServerWebExchange contract in order to extract the response and set the http status code
* @return Mono<ResponseDto < ErrorDTO>> * @return Mono<ResponseDto < ErrorDTO>>
*/ */
@ExceptionHandler @ExceptionHandler
@ResponseBody @ResponseBody
@ -40,7 +40,7 @@ public class GlobalExceptionHandler {
* *
* @param e Exception that will be caught by the function * @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 * @param exchange ServerWebExchange contract in order to extract the response and set the http status code
* @return Mono<ResponseDto < ErrorDTO>> * @return Mono<ResponseDto < ErrorDTO>>
*/ */
@ExceptionHandler @ExceptionHandler
@ResponseBody @ResponseBody

View File

@ -1,6 +1,8 @@
package com.appsmith.server.services; package com.appsmith.server.services;
import com.appsmith.server.domains.Action; 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.Plugin;
import com.appsmith.server.domains.Resource; import com.appsmith.server.domains.Resource;
import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithError;
@ -16,6 +18,8 @@ import reactor.core.scheduler.Scheduler;
import javax.validation.Validator; import javax.validation.Validator;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
@Slf4j @Slf4j
@Service @Service
@ -24,6 +28,7 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
private final ActionRepository repository; private final ActionRepository repository;
private final ResourceService resourceService; private final ResourceService resourceService;
private final PluginService pluginService; private final PluginService pluginService;
private final PageService pageService;
@Autowired @Autowired
public ActionServiceImpl(Scheduler scheduler, public ActionServiceImpl(Scheduler scheduler,
@ -32,11 +37,13 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
ReactiveMongoTemplate reactiveMongoTemplate, ReactiveMongoTemplate reactiveMongoTemplate,
ActionRepository repository, ActionRepository repository,
ResourceService resourceService, ResourceService resourceService,
PluginService pluginService) { PluginService pluginService,
PageService pageService) {
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository); super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository);
this.repository = repository; this.repository = repository;
this.resourceService = resourceService; this.resourceService = resourceService;
this.pluginService = pluginService; this.pluginService = pluginService;
this.pageService = pageService;
} }
@Override @Override
@ -45,17 +52,44 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "id")); return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "id"));
} else if (action.getResourceId() == null) { } else if (action.getResourceId() == null) {
return Mono.error(new AppsmithException(AppsmithError.RESOURCE_ID_NOT_GIVEN)); return Mono.error(new AppsmithException(AppsmithError.RESOURCE_ID_NOT_GIVEN));
} else if (action.getPageId() == null) {
return Mono.error(new AppsmithException(AppsmithError.PAGE_ID_NOT_GIVEN));
} }
Mono<Resource> resourceMono = resourceService.findById(action.getResourceId()); Mono<Resource> resourceMono = resourceService.findById(action.getResourceId());
Mono<Plugin> pluginMono = resourceMono.flatMap(resource -> pluginService.findById(resource.getPluginId())); Mono<Plugin> pluginMono = resourceMono.flatMap(resource -> pluginService.findById(resource.getPluginId()));
Mono<Page> pageMono = pageService.findById(action.getPageId());
return pluginMono Mono<Action> savedActionMono = pluginMono
//Set plugin in the action before saving. //Set plugin in the action before saving.
.map(plugin -> { .map(plugin -> {
action.setPluginId(plugin.getId()); action.setPluginId(plugin.getId());
return action; 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<PageAction> actions = page.getActions();
if (actions == null) {
actions = new ArrayList<>();
}
actions.add(pageAction);
page.setActions(actions);
return page;
})
.flatMap(pageService::save)
.then(Mono.just(action1));
});
} }
} }

View File

@ -5,7 +5,7 @@ spring.data.mongodb.port=27017
#spring.data.mongodb.username= #spring.data.mongodb.username=
#spring.data.mongodb.password= #spring.data.mongodb.password=
logging.level.root=debug logging.level.root=info
logging.level.com.appsmith=debug logging.level.com.appsmith=debug
logging.pattern.console=%X - %m%n logging.pattern.console=%X - %m%n