From 0edc0f6363b26a437f272e7b3a2ef5d996b1f1f0 Mon Sep 17 00:00:00 2001 From: Arpit Mohan Date: Tue, 17 Sep 2019 12:18:23 +0000 Subject: [PATCH] Adding the executeAction API in the ActionController. Also changed the interface for the PluginExecutor to include the resourceConfig and ActionConfig as well. --- app/server/appsmith-interfaces/pom.xml | 18 ++++ .../external/models}/ActionConfiguration.java | 6 +- .../external/models}/AuthenticationDTO.java | 4 +- .../appsmith/external/models}/Property.java | 2 +- .../models}/ResourceConfiguration.java | 5 +- .../external/plugins/PluginExecutor.java | 7 +- .../com/external/plugins/PostgresPlugin.java | 15 +++- .../server/controllers/ActionController.java | 11 +++ .../server/controllers/QueryController.java | 28 ------ .../com/appsmith/server/domains/Action.java | 1 + .../appsmith/server/domains/OldProperty.java | 17 ++++ .../com/appsmith/server/domains/Query.java | 4 +- .../com/appsmith/server/domains/Resource.java | 1 + .../com/appsmith/server/domains/Widget.java | 1 + .../server/dtos/CommandQueryParams.java | 4 +- .../server/dtos/ExecuteActionDTO.java | 18 ++++ .../server/dtos/OldAuthenticationDTO.java | 18 ++++ .../server/dtos/{Param.java => OldParam.java} | 2 +- .../plugins/PostgresDBOldPluginExecutor.java | 88 ------------------- .../RestTemplateOldPluginExecutor.java | 6 +- .../server/repositories/ActionRepository.java | 3 + .../server/repositories/QueryRepository.java | 11 --- .../server/services/ActionService.java | 5 ++ .../server/services/ActionServiceImpl.java | 44 +++++++++- .../server/services/OldPluginExecutor.java | 14 +-- .../server/services/PluginService.java | 9 +- .../server/services/QueryService.java | 10 --- .../server/services/QueryServiceImpl.java | 70 --------------- 28 files changed, 181 insertions(+), 241 deletions(-) rename app/server/{appsmith-server/src/main/java/com/appsmith/server/domains => appsmith-interfaces/src/main/java/com/appsmith/external/models}/ActionConfiguration.java (90%) rename app/server/{appsmith-server/src/main/java/com/appsmith/server/dtos => appsmith-interfaces/src/main/java/com/appsmith/external/models}/AuthenticationDTO.java (88%) rename app/server/{appsmith-server/src/main/java/com/appsmith/server/domains => appsmith-interfaces/src/main/java/com/appsmith/external/models}/Property.java (81%) rename app/server/{appsmith-server/src/main/java/com/appsmith/server/domains => appsmith-interfaces/src/main/java/com/appsmith/external/models}/ResourceConfiguration.java (70%) delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/QueryController.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/domains/OldProperty.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ExecuteActionDTO.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldAuthenticationDTO.java rename app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/{Param.java => OldParam.java} (84%) delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/PostgresDBOldPluginExecutor.java delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/QueryRepository.java delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryService.java delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryServiceImpl.java diff --git a/app/server/appsmith-interfaces/pom.xml b/app/server/appsmith-interfaces/pom.xml index 35e9d8d487..534a55dd1b 100644 --- a/app/server/appsmith-interfaces/pom.xml +++ b/app/server/appsmith-interfaces/pom.xml @@ -40,6 +40,24 @@ 3.2.6.RELEASE + + org.springframework.boot + spring-boot-starter-data-mongodb-reactive + + + + org.json + json + 20190722 + + + + org.springframework + spring-web + 5.1.5.RELEASE + compile + + org.projectlombok lombok diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ActionConfiguration.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionConfiguration.java similarity index 90% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ActionConfiguration.java rename to app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionConfiguration.java index ba57161c26..935f5c11d6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ActionConfiguration.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionConfiguration.java @@ -1,10 +1,10 @@ -package com.appsmith.server.domains; +package com.appsmith.external.models; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.ToString; -import net.minidev.json.JSONObject; +import org.json.JSONObject; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.http.HttpMethod; @@ -15,7 +15,7 @@ import java.util.List; @ToString @NoArgsConstructor @Document -public class ActionConfiguration extends BaseDomain { +public class ActionConfiguration { /* * Any of the fields mentioned below could be represented in mustache * template. If the mustache template is found, it would be replaced diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/AuthenticationDTO.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/AuthenticationDTO.java similarity index 88% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/AuthenticationDTO.java rename to app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/AuthenticationDTO.java index 0e21a64ce0..a1a92dc83d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/AuthenticationDTO.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/AuthenticationDTO.java @@ -1,4 +1,4 @@ -package com.appsmith.server.dtos; +package com.appsmith.external.models; import lombok.AllArgsConstructor; import lombok.Getter; @@ -15,4 +15,4 @@ public class AuthenticationDTO { String authType; String username; String password; -} +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Property.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Property.java similarity index 81% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Property.java rename to app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Property.java index 7768228499..9fa290ec1a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Property.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/Property.java @@ -1,4 +1,4 @@ -package com.appsmith.server.domains; +package com.appsmith.external.models; import lombok.Getter; import lombok.Setter; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ResourceConfiguration.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ResourceConfiguration.java similarity index 70% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ResourceConfiguration.java rename to app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ResourceConfiguration.java index 69a72901e0..0596bd2186 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ResourceConfiguration.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ResourceConfiguration.java @@ -1,6 +1,5 @@ -package com.appsmith.server.domains; +package com.appsmith.external.models; -import com.appsmith.server.dtos.AuthenticationDTO; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -14,7 +13,7 @@ import java.util.List; @ToString @NoArgsConstructor @Document -public class ResourceConfiguration extends BaseDomain { +public class ResourceConfiguration { String url; diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java index 22eab06c55..b44e087560 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/plugins/PluginExecutor.java @@ -1,10 +1,15 @@ package com.appsmith.external.plugins; +import com.appsmith.external.models.ActionConfiguration; import com.appsmith.external.models.CommandParams; +import com.appsmith.external.models.Param; +import com.appsmith.external.models.ResourceConfiguration; import org.pf4j.ExtensionPoint; import reactor.core.publisher.Flux; +import java.util.List; + public interface PluginExecutor extends ExtensionPoint { - Flux execute(String command, CommandParams params); + Flux execute(ResourceConfiguration resourceConfiguration, ActionConfiguration action, List params); } diff --git a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java index 747eb1cb6e..4ad7f852ca 100644 --- a/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java +++ b/app/server/appsmith-plugins/postgresPlugin/src/main/java/com/external/plugins/PostgresPlugin.java @@ -1,6 +1,9 @@ package com.external.plugins; +import com.appsmith.external.models.ActionConfiguration; import com.appsmith.external.models.CommandParams; +import com.appsmith.external.models.Param; +import com.appsmith.external.models.ResourceConfiguration; import com.appsmith.external.plugins.BasePlugin; import com.appsmith.external.plugins.PluginExecutor; import lombok.extern.slf4j.Slf4j; @@ -10,6 +13,7 @@ import org.pf4j.PluginWrapper; import org.springframework.util.Assert; import reactor.core.publisher.Flux; +import javax.annotation.Resource; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -18,6 +22,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; @Slf4j public class PostgresPlugin extends BasePlugin { @@ -70,15 +75,19 @@ public class PostgresPlugin extends BasePlugin { public static class PostgresPluginExecutor implements PluginExecutor { @Override - public Flux execute(String command, CommandParams commandParams) { - log.debug("In the PostgresPlugin execute with command: {}", command); + public Flux execute(ResourceConfiguration resourceConfiguration, + ActionConfiguration actionConfiguration, + List params) { + + log.debug("In the PostgresPlugin execute with resourceConfiguration: {}, ActionConfig: {}", + resourceConfiguration, actionConfiguration); Assert.notNull(conn); ArrayList list = new ArrayList(50); try { Statement statement = conn.createStatement(); - ResultSet resultSet = statement.executeQuery(command); + ResultSet resultSet = statement.executeQuery(actionConfiguration.getQuery()); ResultSetMetaData metaData = resultSet.getMetaData(); Integer colCount = metaData.getColumnCount(); while (resultSet.next()) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java index 216dc32e99..e731f130e4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionController.java @@ -2,9 +2,15 @@ package com.appsmith.server.controllers; import com.appsmith.server.constants.Url; import com.appsmith.server.domains.Action; +import com.appsmith.server.dtos.CommandQueryParams; +import com.appsmith.server.dtos.ExecuteActionDTO; import com.appsmith.server.services.ActionService; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Flux; @RestController @RequestMapping(Url.ACTION_URL) @@ -13,4 +19,9 @@ public class ActionController extends BaseController executeAction(@RequestBody ExecuteActionDTO executeActionDTO) { + return service.executeAction(executeActionDTO); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/QueryController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/QueryController.java deleted file mode 100644 index d661039bf8..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/QueryController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.appsmith.server.controllers; - -import com.appsmith.server.constants.Url; -import com.appsmith.server.domains.Query; -import com.appsmith.server.dtos.CommandQueryParams; -import com.appsmith.server.services.QueryService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import reactor.core.publisher.Flux; - -@RestController -@RequestMapping(Url.QUERY_URL) -public class QueryController extends BaseController { - - @Autowired - public QueryController(QueryService service) { - super(service); - } - - @PostMapping("/execute/{name}") - public Flux executeQuery(@PathVariable String name, @RequestBody CommandQueryParams params) { - return service.executeQuery(name, params); - } -} 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 73e4194c59..dab6cdcb6a 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 @@ -1,5 +1,6 @@ package com.appsmith.server.domains; +import com.appsmith.external.models.ActionConfiguration; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/OldProperty.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/OldProperty.java new file mode 100644 index 0000000000..f4e6b44e51 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/OldProperty.java @@ -0,0 +1,17 @@ +package com.appsmith.server.domains; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class OldProperty { + + String key; + + String value; + + Boolean editable; + + Boolean internal; +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Query.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Query.java index 2590e5e39a..066755d9a3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Query.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Query.java @@ -29,7 +29,7 @@ public class Query extends BaseDomain { @Indexed(unique = true) String name; - List properties; + List properties; - List headers; + List headers; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Resource.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Resource.java index a8a9d97448..7993327b46 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Resource.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Resource.java @@ -1,5 +1,6 @@ package com.appsmith.server.domains; +import com.appsmith.external.models.ResourceConfiguration; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Widget.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Widget.java index a2848df99c..3ef63b6781 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Widget.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Widget.java @@ -1,5 +1,6 @@ package com.appsmith.server.domains; +import com.appsmith.external.models.Property; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/CommandQueryParams.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/CommandQueryParams.java index ef4bca1ad0..8befef8b24 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/CommandQueryParams.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/CommandQueryParams.java @@ -8,7 +8,7 @@ import java.util.List; @Getter @Setter public class CommandQueryParams { - List queryParams; + List queryOldParams; - List headerParams; + List headerOldParams; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ExecuteActionDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ExecuteActionDTO.java new file mode 100644 index 0000000000..fc82d774f6 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ExecuteActionDTO.java @@ -0,0 +1,18 @@ +package com.appsmith.server.dtos; + +import com.appsmith.external.models.Param; +import lombok.Getter; +import lombok.Setter; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@Getter +@Setter +public class ExecuteActionDTO { + + @NotNull + String actionId; + + List params; +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldAuthenticationDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldAuthenticationDTO.java new file mode 100644 index 0000000000..eaa73473ab --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldAuthenticationDTO.java @@ -0,0 +1,18 @@ +package com.appsmith.server.dtos; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class OldAuthenticationDTO { + String authType; + String username; + String password; +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/Param.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldParam.java similarity index 84% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/Param.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldParam.java index 614e96c80c..8238170639 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/Param.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/OldParam.java @@ -5,7 +5,7 @@ import lombok.Setter; @Getter @Setter -public class Param { +public class OldParam { String key; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/PostgresDBOldPluginExecutor.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/PostgresDBOldPluginExecutor.java deleted file mode 100644 index 2def8fd810..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/PostgresDBOldPluginExecutor.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.appsmith.server.plugins; - -import com.appsmith.server.domains.Query; -import com.appsmith.server.dtos.CommandQueryParams; -import com.appsmith.server.services.OldPluginExecutor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import reactor.core.publisher.Flux; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.HashMap; - -@Slf4j -@Component -public class PostgresDBOldPluginExecutor extends OldPluginExecutor { - - // JDBC driver name and database URL - @Value("${jdbc.postgres.driver}") - String JDBC_DRIVER; - - @Value("${jdbc.postgres.url}") - String DB_URL; - - // Database credentials - @Value("${jdbc.postgres.username}") - String DB_USER; - - @Value("${jdbc.postgres.password}") - String DB_PASS; - - Connection conn = null; - - @Override - public Flux execute(Query queryObj, CommandQueryParams params) { - if (conn == null) { - init(); - } - ArrayList list = new ArrayList(50); - try { - Statement statement = conn.createStatement(); - String queryTemplate = queryObj.getCommandTemplate(); - - ResultSet resultSet = statement.executeQuery(queryTemplate); - ResultSetMetaData metaData = resultSet.getMetaData(); - Integer colCount = metaData.getColumnCount(); - while (resultSet.next()) { - HashMap row = new HashMap(colCount); - for (int i = 1; i <= colCount; i++) { - row.put(metaData.getColumnName(i), resultSet.getObject(i)); - } - list.add(row); - } - } catch (SQLException e) { - e.printStackTrace(); - } - return Flux.fromIterable(list); - } - - @Override - public void init() { - log.debug("Going to initialize the PostgresDBPluginExecutor"); - try { - - // Load the class into JVM - Class.forName(JDBC_DRIVER); - log.debug("Got the jdbc url as {}", DB_URL); - // Create the connection - conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASS); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - @Override - public void destroy() { - - } - -} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/RestTemplateOldPluginExecutor.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/RestTemplateOldPluginExecutor.java index e83d470ff6..18d0a88c60 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/RestTemplateOldPluginExecutor.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/RestTemplateOldPluginExecutor.java @@ -1,6 +1,6 @@ package com.appsmith.server.plugins; -import com.appsmith.server.domains.Property; +import com.appsmith.server.domains.OldProperty; import com.appsmith.server.domains.Query; import com.appsmith.server.dtos.CommandQueryParams; import com.appsmith.server.services.OldPluginExecutor; @@ -30,9 +30,9 @@ public class RestTemplateOldPluginExecutor extends OldPluginExecutor { @Override protected Flux execute(Query query, CommandQueryParams params) { String requestBody = query.getCommandTemplate(); - Map propertyMap = query.getProperties() + Map propertyMap = query.getProperties() .stream() - .collect(Collectors.toMap(Property::getKey, prop -> prop)); + .collect(Collectors.toMap(OldProperty::getKey, prop -> prop)); String url = propertyMap.get(PROP_URL).getValue(); String httpMethod = propertyMap.get(PROP_HTTP_METHOD).getValue(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ActionRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ActionRepository.java index 1d8245abbc..d5934c5031 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ActionRepository.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ActionRepository.java @@ -2,7 +2,10 @@ package com.appsmith.server.repositories; import com.appsmith.server.domains.Action; import org.springframework.stereotype.Repository; +import reactor.core.publisher.Mono; @Repository public interface ActionRepository extends BaseRepository { + + Mono findById(String id); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/QueryRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/QueryRepository.java deleted file mode 100644 index 176f2566b8..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/QueryRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.appsmith.server.repositories; - -import com.appsmith.server.domains.Query; -import org.springframework.stereotype.Repository; -import reactor.core.publisher.Mono; - -@Repository -public interface QueryRepository extends BaseRepository { - - Mono findByName(String name); -} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java index 3486ce5d54..635011ccec 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionService.java @@ -1,6 +1,11 @@ package com.appsmith.server.services; import com.appsmith.server.domains.Action; +import com.appsmith.server.dtos.CommandQueryParams; +import com.appsmith.server.dtos.ExecuteActionDTO; +import reactor.core.publisher.Flux; public interface ActionService extends CrudService { + + Flux executeAction(ExecuteActionDTO executeActionDTO); } 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 5342222397..09818da001 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,18 +1,22 @@ package com.appsmith.server.services; +import com.appsmith.external.plugins.PluginExecutor; 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.dtos.ExecuteActionDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.repositories.ActionRepository; import lombok.extern.slf4j.Slf4j; +import org.pf4j.PluginManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.ReactiveMongoTemplate; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; @@ -29,6 +33,7 @@ public class ActionServiceImpl extends BaseService executeAction(ExecuteActionDTO executeActionDTO) { + String actionId = executeActionDTO.getActionId(); + log.debug("Going to execute action with id: {}", actionId); + + // 1. Fetch the query from the DB to get the type + Mono actionMono = repository.findById(actionId) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "action", actionId))); + + // 2. Instantiate the implementation class based on the query type + Mono pluginMono = actionMono.flatMap(action -> pluginService.findById(action.getPluginId())) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin"))); + + Mono resourceMono = actionMono.flatMap(action -> resourceService.findById(action.getResourceId())) + .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "resource"))); + + Mono pluginExecutorMono = pluginMono.flatMap(plugin -> { + List executorList = pluginManager.getExtensions(PluginExecutor.class, plugin.getExecutorClass()); + if (executorList.isEmpty()) { + return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin", plugin.getExecutorClass())); + } + return Mono.just(executorList.get(0)); + } + ); + + // 3. Execute the query + return actionMono.flatMap(action -> resourceMono.zipWith(pluginExecutorMono, (resource, pluginExecutor) -> + { + log.debug("*** About to invoke the plugin**"); + // TODO: The CommandParams is being passed as null here. Move it to interfaces.CommandParams + return pluginExecutor.execute(resource.getResourceConfiguration(), action.getActionConfiguration(), executeActionDTO.getParams()); + })) + .flatMapIterable(Flux::toIterable); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/OldPluginExecutor.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/OldPluginExecutor.java index 0cb6c33cca..4e3b054bf5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/OldPluginExecutor.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/OldPluginExecutor.java @@ -2,7 +2,7 @@ package com.appsmith.server.services; import com.appsmith.server.domains.Query; import com.appsmith.server.dtos.CommandQueryParams; -import com.appsmith.server.dtos.Param; +import com.appsmith.server.dtos.OldParam; import com.github.mustachejava.DefaultMustacheFactory; import com.github.mustachejava.Mustache; import com.github.mustachejava.MustacheFactory; @@ -52,21 +52,21 @@ public abstract class OldPluginExecutor { Map queryMap = new HashMap<>(); Map headerMap = new HashMap<>(); - if (params.getQueryParams() != null) { + if (params.getQueryOldParams() != null) { queryMap = params - .getQueryParams() + .getQueryOldParams() .stream() .collect( - Collectors.toMap(Param::getKey, Param::getValue, + Collectors.toMap(OldParam::getKey, OldParam::getValue, // Incase there's a conflict, we pick the older value (oldValue, newValue) -> oldValue)); } - if (params.getHeaderParams() != null) { + if (params.getHeaderOldParams() != null) { headerMap = params - .getHeaderParams() + .getHeaderOldParams() .stream() .collect( - Collectors.toMap(Param::getKey, Param::getValue, + Collectors.toMap(OldParam::getKey, OldParam::getValue, // Incase there's a conflict, we pick the older value (oldValue, newValue) -> oldValue)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java index 0617e6be58..b0ab2dd79b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PluginService.java @@ -18,12 +18,11 @@ public interface PluginService extends CrudService { */ OldPluginExecutor getPluginExecutor(PluginType pluginType, String className); - public Mono installPlugin(PluginOrgDTO plugin); + Mono installPlugin(PluginOrgDTO plugin); - public Mono uninstallPlugin(PluginOrgDTO plugin); + Mono uninstallPlugin(PluginOrgDTO plugin); - public Mono findByName(String name); - - public Mono findById(String id); + Mono findByName(String name); + Mono findById(String id); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryService.java deleted file mode 100644 index 2abad4d539..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.appsmith.server.services; - -import com.appsmith.server.domains.Query; -import com.appsmith.server.dtos.CommandQueryParams; -import reactor.core.publisher.Flux; - -public interface QueryService extends CrudService { - - Flux executeQuery(String name, CommandQueryParams params); -} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryServiceImpl.java deleted file mode 100644 index f5c90768b2..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/QueryServiceImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.appsmith.server.services; - -import com.appsmith.external.plugins.PluginExecutor; -import com.appsmith.server.domains.Query; -import com.appsmith.server.dtos.CommandQueryParams; -import com.appsmith.server.exceptions.AppsmithError; -import com.appsmith.server.exceptions.AppsmithException; -import com.appsmith.server.repositories.QueryRepository; -import lombok.extern.slf4j.Slf4j; -import org.pf4j.PluginManager; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.ReactiveMongoTemplate; -import org.springframework.data.mongodb.core.convert.MongoConverter; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.core.scheduler.Scheduler; - -import javax.validation.Validator; -import java.util.List; - -@Slf4j -@Service -public class QueryServiceImpl extends BaseService implements QueryService { - - PluginService pluginService; - - PluginManager pluginManager; - - @Autowired - public QueryServiceImpl(Scheduler scheduler, - Validator validator, - MongoConverter mongoConverter, - ReactiveMongoTemplate reactiveMongoTemplate, - QueryRepository repository, - PluginService pluginService, - PluginManager pluginManager) { - super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository); - this.pluginService = pluginService; - this.pluginManager = pluginManager; - } - - - @Override - public Flux executeQuery(String name, CommandQueryParams params) { - log.debug("Going to execute query with name: {}", name); - - // 1. Fetch the query from the DB to get the type - Mono queryMono = repository.findByName(name) - .switchIfEmpty(Mono.defer(() -> Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "query", name)))); - - // 2. Instantiate the implementation class based on the query type - Mono pluginExecutorMono = queryMono.flatMap(queryObj -> { - String pluginId = queryObj.getPlugin().getExecutorClass(); - List executorList = pluginManager.getExtensions(PluginExecutor.class, pluginId); - if (executorList.isEmpty()) { - return Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "plugin")); - } - return Mono.just(executorList.get(0)); - } - ); - - // 3. Execute the query - return queryMono - .zipWith(pluginExecutorMono, (queryObj, pluginExecutor) -> - // TODO: The CommandParams is being passed as null here. Move it to interfaces.CommandParams - pluginExecutor.execute(queryObj.getCommandTemplate(), null)) - .flatMapIterable(Flux::toIterable); - } -}