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 0e435ae596..e1bb2e6fac 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 @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.index.CompoundIndex; import org.springframework.data.mongodb.core.mapping.Document; @@ -23,6 +24,7 @@ public class Action extends BaseDomain { String name; + @Transient Datasource datasource; @JsonIgnore 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 7648fc01b0..53c15c1549 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 @@ -213,8 +213,8 @@ public class ActionServiceImpl extends BaseService datasourceMono; if (action.getDatasource().getId() == null) { - datasourceMono = Mono.just(action.getDatasource()) - .flatMap(datasourceService::validateDatasource); + //No data source exists. The action is also trying to create the data source. + datasourceMono = datasourceService.create(action.getDatasource()); } else { //Data source already exists. Find the same. datasourceMono = datasourceService.findById(action.getDatasource().getId()) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java index 3088b3a57f..33f2dcb5de 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/CurlImporterService.java @@ -33,13 +33,10 @@ public class CurlImporterService extends BaseApiImporter { private static final String headerRegex = "\\-H\\s+\\'(.+?)\\'"; private static final String methodRegex = "\\-X\\s+(.+?)\\b"; private static final String bodyRegex = "\\-d\\s+\\'(.+?)\\'"; - private static final String pluginName = "RestTemplatePluginExecutor"; private final ActionService actionService; - private final PluginService pluginService; - public CurlImporterService(ActionService actionService, PluginService pluginService) { + public CurlImporterService(ActionService actionService) { this.actionService = actionService; - this.pluginService = pluginService; } @Override @@ -134,21 +131,14 @@ public class CurlImporterService extends BaseApiImporter { } action.setActionConfiguration(actionConfiguration); datasource.setDatasourceConfiguration(datasourceConfiguration); + action.setDatasource(datasource); action.setName(name); action.setPageId(pageId); - // Set the default values for datasource (plugin, name) and then create the action - // with embedded datasource - return pluginService.findByName(pluginName) - .map(plugin -> { - datasource.setName(datasourceConfiguration.getUrl()); - datasource.setPluginId(plugin.getId()); - return datasource; - }) - .map(datasource1 -> { - action.setDatasource(datasource1); - return action; - }) - .flatMap(actionService::create); + /** + * TODO + * Instead of save, call create to allow of validation & setup of default values. + */ + return actionService.save(action); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceService.java index 07ea0c7fd9..642947498e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceService.java @@ -12,6 +12,4 @@ public interface DatasourceService extends CrudService { Mono findById(String id); Set extractKeysFromDatasource(Datasource datasource); - - Mono validateDatasource(Datasource datasource); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java index 9b991abaad..cdb0a64b6f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/DatasourceServiceImpl.java @@ -87,8 +87,7 @@ public class DatasourceServiceImpl extends BaseService validateDatasource(Datasource datasource) { + private Mono validateAndSaveDatasourceToRepository(Datasource datasource) { Set invalids = new HashSet<>(); Mono userMono = sessionUserService.getCurrentUser(); @@ -142,13 +141,8 @@ public class DatasourceServiceImpl extends BaseService validateAndSaveDatasourceToRepository(Datasource datasource) { - return Mono.just(datasource) - .flatMap(this::validateDatasource) - .flatMap(repository::save); + }) + .flatMap(super::create); } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java index d75e2f9a62..9d37aece1d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java @@ -358,15 +358,12 @@ public class LayoutActionServiceImpl implements LayoutActionService { Boolean actionUpdateRequired = false; ActionConfiguration actionConfiguration = action.getActionConfiguration(); Set jsonPathKeys = action.getJsonPathKeys(); - - if (jsonPathKeys != null || !jsonPathKeys.isEmpty()) { - // Since json path keys actually contain the entire inline js function instead of just the widget/action - // name, we can not simply use the set.contains(obj) function. We need to iterate over all the keys - // in the set and see if the old name is a substring of the json path key. - for (String key : jsonPathKeys) { - if (key.contains(oldName)) { - actionUpdateRequired = true; - } + // Since json path keys actually contain the entire inline js function instead of just the widget/action + // name, we can not simply use the set.contains(obj) function. We need to iterate over all the keys + // in the set and see if the old name is a substring of the json path key. + for (String key : jsonPathKeys) { + if (key.contains(oldName)) { + actionUpdateRequired = true; } } diff --git a/app/server/appsmith-server/src/main/resources/application.properties b/app/server/appsmith-server/src/main/resources/application.properties index fe8737d96f..e69de29bb2 100644 --- a/app/server/appsmith-server/src/main/resources/application.properties +++ b/app/server/appsmith-server/src/main/resources/application.properties @@ -1 +0,0 @@ -spring.data.mongodb.auto-index-creation=false diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlParserServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlParserServiceTest.java index e80c5d7e96..50818790bc 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlParserServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CurlParserServiceTest.java @@ -1,36 +1,41 @@ package com.appsmith.server.services; +import com.appsmith.server.domains.Action; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.test.context.junit4.SpringRunner; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; -//@RunWith(SpringRunner.class) -//@SpringBootTest -//@Slf4j +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Slf4j public class CurlParserServiceTest { @Autowired CurlImporterService curlImporterService; - /** - * TODO Make the test case run - * Currently the test case doesnt run because the import now requires the rest api plugin during create. This is because - * the datasource needs to be validated (which is done at a plugin level). No current fix exists to mock out the - * plugin as of now. - */ -// @Test -// public void testParser() { -// String command = "curl -X GET http://localhost:8080/api/v1/actions?name=something -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Authorization: Basic YXBpX3VzZXI6OHVBQDsmbUI6Y252Tn57Iw==' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'Cookie: SESSION=97c5def4-4f72-45aa-96fe-e8a9f5ade0b5,SESSION=97c5def4-4f72-45aa-96fe-e8a9f5ade0b5; SESSION=' -H 'Host: localhost:8080' -H 'Postman-Token: 16e4b6bc-2c7a-4ab1-a127-bca382dfc0f0,a6655daa-db07-4c5e-aca3-3fd505bd230d' -H 'User-Agent: PostmanRuntime/7.20.1' -H 'cache-control: no-cache' -d '{someJson}' "; -// Mono action = curlImporterService.importAction(command, "pageId", "actionName"); -// StepVerifier -// .create(action) -// .assertNext(action1 -> { -// assertThat(action1).isNotNull(); -// assertThat(action1.getDatasource()).isNotNull(); -// assertThat(action1.getDatasource().getDatasourceConfiguration()).isNotNull(); -// assertThat(action1.getDatasource().getDatasourceConfiguration().getUrl()).isEqualTo("http://localhost:8080/api/v1/actions"); -// assertThat(action1.getActionConfiguration().getHeaders().size()).isEqualTo(11); -// assertThat(action1.getActionConfiguration().getQueryParameters().size()).isEqualTo(1); -// assertThat(action1.getActionConfiguration().getHttpMethod()).isEqualTo(HttpMethod.GET); -// assertThat(action1.getActionConfiguration().getBody()).isEqualTo("{someJson}"); -// }) -// .verifyComplete(); -// } + @Test + public void testParser() { + String command = "curl -X GET http://localhost:8080/api/v1/actions?name=something -H 'Accept: */*' -H 'Accept-Encoding: gzip, deflate' -H 'Authorization: Basic YXBpX3VzZXI6OHVBQDsmbUI6Y252Tn57Iw==' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Content-Type: application/json' -H 'Cookie: SESSION=97c5def4-4f72-45aa-96fe-e8a9f5ade0b5,SESSION=97c5def4-4f72-45aa-96fe-e8a9f5ade0b5; SESSION=' -H 'Host: localhost:8080' -H 'Postman-Token: 16e4b6bc-2c7a-4ab1-a127-bca382dfc0f0,a6655daa-db07-4c5e-aca3-3fd505bd230d' -H 'User-Agent: PostmanRuntime/7.20.1' -H 'cache-control: no-cache' -d '{someJson}' "; + Mono action = curlImporterService.importAction(command, "pageId", "actionName"); + StepVerifier + .create(action) + .assertNext(action1 -> { + assertThat(action1).isNotNull(); + assertThat(action1.getDatasource()).isNotNull(); + assertThat(action1.getDatasource().getDatasourceConfiguration()).isNotNull(); + assertThat(action1.getDatasource().getDatasourceConfiguration().getUrl()).isEqualTo("http://localhost:8080/api/v1/actions"); + assertThat(action1.getActionConfiguration().getHeaders().size()).isEqualTo(11); + assertThat(action1.getActionConfiguration().getQueryParameters().size()).isEqualTo(1); + assertThat(action1.getActionConfiguration().getHttpMethod()).isEqualTo(HttpMethod.GET); + assertThat(action1.getActionConfiguration().getBody()).isEqualTo("{someJson}"); + }) + .verifyComplete(); + } }