Add Page Actions to Page object.
This commit is contained in:
parent
f5ea85f636
commit
5468436d9f
|
|
@ -20,5 +20,7 @@ public class Action extends BaseDomain {
|
|||
|
||||
String pluginId;
|
||||
|
||||
String pageId;
|
||||
|
||||
ActionConfiguration actionConfiguration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,6 @@ public class Page extends BaseDomain {
|
|||
String applicationId;
|
||||
|
||||
List<Layout> layouts;
|
||||
|
||||
List<PageAction> actions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<ResponseDto < ErrorDTO>>
|
||||
* @return Mono<ResponseDto < ErrorDTO>>
|
||||
*/
|
||||
@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<ResponseDto < ErrorDTO>>
|
||||
* @return Mono<ResponseDto < ErrorDTO>>
|
||||
*/
|
||||
@ExceptionHandler
|
||||
@ResponseBody
|
||||
|
|
|
|||
|
|
@ -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<ActionRepository, Action, Str
|
|||
private final ActionRepository repository;
|
||||
private final ResourceService resourceService;
|
||||
private final PluginService pluginService;
|
||||
private final PageService pageService;
|
||||
|
||||
@Autowired
|
||||
public ActionServiceImpl(Scheduler scheduler,
|
||||
|
|
@ -32,11 +37,13 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
|||
ReactiveMongoTemplate reactiveMongoTemplate,
|
||||
ActionRepository repository,
|
||||
ResourceService resourceService,
|
||||
PluginService pluginService) {
|
||||
PluginService pluginService,
|
||||
PageService pageService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository);
|
||||
this.repository = repository;
|
||||
this.resourceService = resourceService;
|
||||
this.pluginService = pluginService;
|
||||
this.pageService = pageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -45,17 +52,44 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
|||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, "id"));
|
||||
} else if (action.getResourceId() == null) {
|
||||
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<Plugin> pluginMono = resourceMono.flatMap(resource -> pluginService.findById(resource.getPluginId()));
|
||||
|
||||
return pluginMono
|
||||
Mono<Page> pageMono = pageService.findById(action.getPageId());
|
||||
Mono<Action> 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<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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user