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

This commit is contained in:
Trisha Anand 2019-11-13 05:51:01 +00:00
parent 923159e2cd
commit df904539ca
2 changed files with 20 additions and 1 deletions

View File

@ -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"),

View File

@ -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<ActionRepository, Action, Str
if (id == null) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID));
}
if (action.getName() != null) {
// There is a change in the name of the action. Validate
if (!validateActionName(action.getName())) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_ACTION_NAME));
}
}
Mono<Action> replaceOrCreateNewDataSourceMono = replaceOrCreateNewDataSource(action);
Mono<Action> dbActionMono = repository.findById(id)
@ -148,13 +155,24 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
return Mono.just(action);
}
private Boolean validateActionName(String name) {
boolean isValidName = SourceVersion.isName(name);
String pattern = "^((?=[A-Za-z0-9_])(?![\\\\-]).)*$";
boolean doesPatternMatch = name.matches(pattern);
return (isValidName && doesPatternMatch);
}
@Override
public Mono<Action> 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<Datasource> datasourceMono;
if (action.getDatasource().getId() == null) {