From 05465c76455826107b653c624e78bd0b9398865b Mon Sep 17 00:00:00 2001 From: subrata Date: Tue, 20 Jun 2023 12:38:43 +0600 Subject: [PATCH] Do PoC on module action entering into action execution flow (#24645) --- .../appsmith/external/models/ActionDTO.java | 4 + .../appsmith/external/models/ModuleDTO.java | 203 ++++++++++++++++++ .../server/controllers/ModuleController.java | 28 +++ .../controllers/ce/ModuleControllerCE.java | 63 ++++++ .../com/appsmith/server/domains/Module.java | 46 ++++ .../appsmith/server/domains/NewAction.java | 2 + .../appsmith/server/dtos/ApplicationJson.java | 3 + .../repositories/CustomModuleRepository.java | 7 + .../CustomModuleRepositoryImpl.java | 13 ++ .../server/repositories/ModuleRepository.java | 9 + .../ce/CustomModuleRepositoryCE.java | 8 + .../ce/CustomModuleRepositoryCEImpl.java | 15 ++ .../repositories/ce/ModuleRepositoryCE.java | 9 + .../server/services/ModuleService.java | 7 + .../server/services/ModuleServiceImpl.java | 17 ++ .../ce/LayoutActionServiceCEImpl.java | 7 + .../server/services/ce/ModuleServiceCE.java | 11 + .../services/ce/ModuleServiceCEImpl.java | 78 +++++++ .../ImportExportApplicationServiceImpl.java | 12 +- .../ImportExportApplicationServiceCEImpl.java | 34 ++- .../ce/PageLoadActionsUtilCEImpl.java | 8 + 21 files changed, 567 insertions(+), 17 deletions(-) create mode 100644 app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ModuleDTO.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ModuleController.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ModuleControllerCE.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Module.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepository.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepositoryImpl.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ModuleRepository.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCE.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCEImpl.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ModuleRepositoryCE.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleService.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleServiceImpl.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCE.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCEImpl.java diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionDTO.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionDTO.java index a4e824b5745..c7da734c453 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionDTO.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ActionDTO.java @@ -33,6 +33,10 @@ public class ActionDTO implements Identifiable { @JsonView(Views.Public.class) String applicationId; + @Transient + @JsonView(Views.Public.class) + String moduleId; + @Transient @JsonView(Views.Public.class) String workspaceId; diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ModuleDTO.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ModuleDTO.java new file mode 100644 index 00000000000..76b3728727d --- /dev/null +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/ModuleDTO.java @@ -0,0 +1,203 @@ +package com.appsmith.external.models; + +import com.appsmith.external.exceptions.ErrorDTO; +import com.appsmith.external.helpers.Identifiable; +import com.appsmith.external.views.Views; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.data.annotation.Transient; + +import java.time.Instant; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Getter +@Setter +@NoArgsConstructor +@ToString +public class ModuleDTO implements Identifiable { + + @Transient + @JsonView(Views.Public.class) + private String id; + + @Transient + @JsonView(Views.Public.class) + private String publicActionId; + + @Transient + @JsonView(Views.Public.class) + String packageId; + + @Transient + @JsonView(Views.Public.class) + String workspaceId; + + @Transient + @JsonView(Views.Public.class) + PluginType pluginType; + + // name of the plugin. used to log analytics events where pluginName is a required attribute + // It'll be null if not set + @Transient + @JsonView(Views.Public.class) + String pluginName; + + @Transient + @JsonView(Views.Public.class) + String pluginId; + + @JsonView(Views.Public.class) + String name; + + // The FQN for an action will also include any collection it is a part of as collectionName.actionName + @JsonView(Views.Public.class) + String fullyQualifiedName; + + @JsonView(Views.Public.class) + Datasource datasource; + + @JsonView(Views.Public.class) + String pageId; + + @JsonView(Views.Public.class) + ActionConfiguration actionConfiguration; + + //this attribute carries error messages while processing the actionCollection + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @Transient + @JsonView(Views.Public.class) + List errorReports; + + @JsonView(Views.Public.class) + Boolean executeOnLoad; + + @JsonView(Views.Public.class) + Boolean clientSideExecution; + + /* + * This is a list of fields specified by the client to signify which fields have dynamic bindings in them. + * TODO: The server can use this field to simplify our Mustache substitutions in the future + */ + @JsonView(Views.Public.class) + List dynamicBindingPathList; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonView(Views.Public.class) + Boolean isValid; + + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonView(Views.Public.class) + Set invalids; + + @Transient + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonView(Views.Public.class) + Set messages = new HashSet<>(); + + + // This is a list of keys that the client whose values the client needs to send during action execution. + // These are the Mustache keys that the server will replace before invoking the API + @JsonProperty(access = JsonProperty.Access.READ_ONLY) + @JsonView(Views.Public.class) + Set jsonPathKeys; + + @JsonView(Views.Internal.class) + String cacheResponse; + + @Transient + @JsonView(Views.Public.class) + String templateId; //If action is created via a template, store the id here. + + @Transient + @JsonView(Views.Public.class) + String providerId; //If action is created via a template, store the template's provider id here. + + @Transient + @JsonView(Views.Public.class) + ActionProvider provider; + + @JsonView(Views.Internal.class) + Boolean userSetOnLoad = false; + + @JsonView(Views.Public.class) + Boolean confirmBeforeExecute = false; + + @Transient + @JsonView(Views.Public.class) + Documentation documentation; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC") + @JsonView(Views.Public.class) + Instant deletedAt = null; + + @Deprecated + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC") + @JsonView(Views.Public.class) + Instant archivedAt = null; + + @Transient + @JsonView(Views.Internal.class) + protected Set policies = new HashSet<>(); + + @Transient + @JsonView(Views.Public.class) + public Set userPermissions = new HashSet<>(); + + // This field will be used to store the default/root actionId and applicationId for actions generated for git + // connected applications and will be used to connect actions across the branches + @JsonView(Views.Internal.class) + DefaultResources defaultResources; + + @JsonView(Views.Internal.class) + protected Instant createdAt; + + @JsonView(Views.Internal.class) + protected Instant updatedAt; + + /** + * If the Datasource is null, create one and set the autoGenerated flag to true. This is required because spring-data + * cannot add the createdAt and updatedAt properties for null embedded objects. At this juncture, we couldn't find + * a way to disable the auditing for nested objects. + * + * @return + */ + @JsonView(Views.Public.class) + public Datasource getDatasource() { + if (this.datasource == null) { + this.datasource = new Datasource(); + this.datasource.setIsAutoGenerated(true); + } + return datasource; + } + + @JsonView(Views.Public.class) + public String getValidName() { + if (this.fullyQualifiedName == null) { + return this.name; + } else { + return this.fullyQualifiedName; + } + } + + public void sanitiseToExportDBObject() { + this.setDefaultResources(null); + this.setCacheResponse(null); + if (this.getDatasource() != null) { + this.getDatasource().setCreatedAt(null); + this.getDatasource().setDatasourceStorages(null); + } + if (this.getUserPermissions() != null) { + this.getUserPermissions().clear(); + } + if (this.getPolicies() != null) { + this.getPolicies().clear(); + } + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ModuleController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ModuleController.java new file mode 100644 index 00000000000..ebb0c27ce27 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ModuleController.java @@ -0,0 +1,28 @@ +package com.appsmith.server.controllers; + +import com.appsmith.server.constants.Url; +import com.appsmith.server.controllers.ce.ActionControllerCE; +import com.appsmith.server.controllers.ce.ModuleControllerCE; +import com.appsmith.server.repositories.CustomModuleRepository; +import com.appsmith.server.repositories.ModuleRepository; +import com.appsmith.server.services.LayoutActionService; +import com.appsmith.server.services.ModuleService; +import com.appsmith.server.services.NewActionService; +import com.appsmith.server.solutions.ActionExecutionSolution; +import com.appsmith.server.solutions.RefactoringSolution; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1/modules") +@Slf4j +public class ModuleController extends ModuleControllerCE { + + public ModuleController(ModuleService moduleService, + ModuleRepository moduleRepository, + LayoutActionService layoutActionService) { + super(moduleService, moduleRepository, layoutActionService); + } + +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ModuleControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ModuleControllerCE.java new file mode 100644 index 00000000000..e8659391725 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ModuleControllerCE.java @@ -0,0 +1,63 @@ +package com.appsmith.server.controllers.ce; + +import com.appsmith.external.helpers.AppsmithEventContext; +import com.appsmith.external.helpers.AppsmithEventContextType; +import com.appsmith.external.models.ActionDTO; +import com.appsmith.external.models.ModuleDTO; +import com.appsmith.external.views.Views; +import com.appsmith.server.constants.FieldName; +import com.appsmith.server.dtos.ResponseDTO; +import com.appsmith.server.repositories.CustomModuleRepository; +import com.appsmith.server.repositories.ModuleRepository; +import com.appsmith.server.services.LayoutActionService; +import com.appsmith.server.services.ModuleService; +import com.fasterxml.jackson.annotation.JsonView; +import jakarta.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +@Slf4j +@RequestMapping("/api/v1/modules") +public class ModuleControllerCE { + + private final ModuleService moduleService; + private final ModuleRepository moduleRepository; + private final LayoutActionService layoutActionService; + + @Autowired + public ModuleControllerCE(ModuleService moduleService, + ModuleRepository moduleRepository, + LayoutActionService layoutActionService) { + this.moduleService = moduleService; + this.moduleRepository = moduleRepository; + this.layoutActionService = layoutActionService; + } + + @JsonView(Views.Public.class) + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + public Mono> createModule(@Valid @RequestBody ModuleDTO resource, + @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName, + @RequestHeader(name = "Origin", required = false) String originHeader, + ServerWebExchange exchange) { + log.debug("Going to create resource {}", resource.getClass().getName()); + return moduleService.createModule(resource) + .map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null)); + } + + @JsonView(Views.Public.class) + @PostMapping("/action") + @ResponseStatus(HttpStatus.CREATED) + public Mono> createAction(@Valid @RequestBody ActionDTO resource, + @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName, + @RequestHeader(name = "Origin", required = false) String originHeader, + ServerWebExchange exchange) { + log.debug("Going to create resource {}", resource.getClass().getName()); + return layoutActionService.createAction(resource, new AppsmithEventContext(AppsmithEventContextType.DEFAULT), false) + .map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null)); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Module.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Module.java new file mode 100644 index 00000000000..639f05fe077 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/Module.java @@ -0,0 +1,46 @@ +package com.appsmith.server.domains; + +import com.appsmith.external.models.ActionDTO; +import com.appsmith.external.models.BranchAwareDomain; +import com.appsmith.external.models.Documentation; +import com.appsmith.external.models.PluginType; +import com.appsmith.external.views.Views; +import com.fasterxml.jackson.annotation.JsonView; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.springframework.data.mongodb.core.mapping.Document; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@Document +public class Module extends BranchAwareDomain { + + // Fields in action that are not allowed to change between published and unpublished versions + @JsonView(Views.Public.class) + String packageId; + + @JsonView(Views.Public.class) + String workspaceId; + + @JsonView(Views.Public.class) + PluginType pluginType; + + @JsonView(Views.Public.class) + String pluginId; + + @JsonView(Views.Public.class) + String templateId; //If action is created via a template, store the id here. + + @JsonView(Views.Public.class) + Documentation documentation; // Documentation for the template using which this action was created + + // Action specific fields that are allowed to change between published and unpublished versions + @JsonView(Views.Public.class) + String publicActionId; + + +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/NewAction.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/NewAction.java index f7a3e021c4a..3d87e3fd10c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/NewAction.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/domains/NewAction.java @@ -23,6 +23,8 @@ public class NewAction extends BranchAwareDomain { @JsonView(Views.Public.class) String applicationId; + @JsonView(Views.Public.class) + String moduleId; //Organizations migrated to workspaces, kept the field as deprecated to support the old migration @Deprecated @JsonView(Views.Public.class) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationJson.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationJson.java index 3daf89170ed..ee4e59dcded 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationJson.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ApplicationJson.java @@ -8,6 +8,7 @@ import com.appsmith.server.domains.ActionCollection; import com.appsmith.server.domains.Application; import com.appsmith.server.domains.CustomJSLib; +import com.appsmith.server.domains.Module; import com.appsmith.server.domains.NewAction; import com.appsmith.server.domains.NewPage; import com.appsmith.server.domains.Theme; @@ -110,4 +111,6 @@ public class ApplicationJson { @Deprecated @JsonView(Views.Public.class) Map> unpublishedLayoutmongoEscapedWidgets; + + List modules; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepository.java new file mode 100644 index 00000000000..7124b88815a --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepository.java @@ -0,0 +1,7 @@ +package com.appsmith.server.repositories; + +import com.appsmith.server.repositories.ce.CustomModuleRepositoryCE; + +public interface CustomModuleRepository extends CustomModuleRepositoryCE { + +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepositoryImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepositoryImpl.java new file mode 100644 index 00000000000..369f8a3f3ce --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/CustomModuleRepositoryImpl.java @@ -0,0 +1,13 @@ +package com.appsmith.server.repositories; + +import com.appsmith.server.repositories.ce.CustomModuleRepositoryCEImpl; +import org.springframework.data.mongodb.core.ReactiveMongoOperations; +import org.springframework.data.mongodb.core.convert.MongoConverter; + +public class CustomModuleRepositoryImpl extends CustomModuleRepositoryCEImpl + implements CustomModuleRepository { + + public CustomModuleRepositoryImpl(ReactiveMongoOperations mongoOperations, MongoConverter mongoConverter, CacheableRepositoryHelper cacheableRepositoryHelper) { + super(mongoOperations, mongoConverter, cacheableRepositoryHelper); + } +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ModuleRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ModuleRepository.java new file mode 100644 index 00000000000..940b38ada57 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ModuleRepository.java @@ -0,0 +1,9 @@ +package com.appsmith.server.repositories; + +import com.appsmith.server.repositories.ce.ModuleRepositoryCE; +import org.springframework.stereotype.Repository; + +@Repository +public interface ModuleRepository extends ModuleRepositoryCE, CustomModuleRepository { + +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCE.java new file mode 100644 index 00000000000..d2718c7ed96 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCE.java @@ -0,0 +1,8 @@ +package com.appsmith.server.repositories.ce; + +import com.appsmith.server.domains.Module; +import com.appsmith.server.repositories.AppsmithRepository; + +public interface CustomModuleRepositoryCE extends AppsmithRepository { + +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCEImpl.java new file mode 100644 index 00000000000..3013211d3a4 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomModuleRepositoryCEImpl.java @@ -0,0 +1,15 @@ +package com.appsmith.server.repositories.ce; + +import com.appsmith.server.domains.Module; +import com.appsmith.server.repositories.BaseAppsmithRepositoryImpl; +import com.appsmith.server.repositories.CacheableRepositoryHelper; +import org.springframework.data.mongodb.core.ReactiveMongoOperations; +import org.springframework.data.mongodb.core.convert.MongoConverter; + +public class CustomModuleRepositoryCEImpl extends BaseAppsmithRepositoryImpl + implements CustomModuleRepositoryCE { + + public CustomModuleRepositoryCEImpl(ReactiveMongoOperations mongoOperations, MongoConverter mongoConverter, CacheableRepositoryHelper cacheableRepositoryHelper) { + super(mongoOperations, mongoConverter, cacheableRepositoryHelper); + } +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ModuleRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ModuleRepositoryCE.java new file mode 100644 index 00000000000..94443073a94 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/ModuleRepositoryCE.java @@ -0,0 +1,9 @@ +package com.appsmith.server.repositories.ce; + +import com.appsmith.server.domains.Module; +import com.appsmith.server.repositories.BaseRepository; +import com.appsmith.server.repositories.CustomModuleRepository; + +public interface ModuleRepositoryCE extends BaseRepository, CustomModuleRepository { + +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleService.java new file mode 100644 index 00000000000..bada534e2b6 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleService.java @@ -0,0 +1,7 @@ +package com.appsmith.server.services; + +import com.appsmith.server.services.ce.ModuleServiceCE; + +public interface ModuleService extends ModuleServiceCE { + +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleServiceImpl.java new file mode 100644 index 00000000000..c46b344fe92 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ModuleServiceImpl.java @@ -0,0 +1,17 @@ +package com.appsmith.server.services; + +import com.appsmith.server.repositories.ModuleRepository; +import com.appsmith.server.services.ce.ModuleServiceCEImpl; +import jakarta.validation.Validator; +import org.springframework.data.mongodb.core.ReactiveMongoTemplate; +import org.springframework.data.mongodb.core.convert.MongoConverter; +import org.springframework.stereotype.Service; +import reactor.core.scheduler.Scheduler; + +@Service +public class ModuleServiceImpl extends ModuleServiceCEImpl implements ModuleService { + + public ModuleServiceImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ModuleRepository repository, AnalyticsService analyticsService, NewActionService newActionService) { + super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService, newActionService); + } +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java index 10eb7c77281..d0c374df359 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCEImpl.java @@ -624,6 +624,13 @@ private Mono updateLayoutDsl(String pageId, String layoutId, Layout l } Set widgetNames = new HashSet<>(); + /* + widgetDynamicBindingsMap + Text1.borderRadius -> appsmith.theme.borderRadius.appBorderRadius + Text1.fontFamily -> appsmith.theme.fontFamily.appFont + Text1.text -> "Subrata" [original: Username: {{"Subrata"}}] + Text1.truncateButtonColor -> appsmith.theme.colors.primaryColor + */ Map> widgetDynamicBindingsMap = new HashMap<>(); Set escapedWidgetNames = new HashSet<>(); try { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCE.java new file mode 100644 index 00000000000..5239e86f604 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCE.java @@ -0,0 +1,11 @@ +package com.appsmith.server.services.ce; + +import com.appsmith.external.models.ModuleDTO; +import com.appsmith.server.domains.Module; +import com.appsmith.server.services.CrudService; +import reactor.core.publisher.Mono; + +public interface ModuleServiceCE extends CrudService { + Mono createModule(ModuleDTO moduleDTO); + +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCEImpl.java new file mode 100644 index 00000000000..3d44b0aadee --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/ModuleServiceCEImpl.java @@ -0,0 +1,78 @@ +package com.appsmith.server.services.ce; + +import com.appsmith.external.models.ActionDTO; +import com.appsmith.external.models.ModuleDTO; +import com.appsmith.external.models.Policy; +import com.appsmith.server.acl.AclPermission; +import com.appsmith.server.domains.Module; +import com.appsmith.server.domains.NewAction; +import com.appsmith.server.repositories.ModuleRepository; +import com.appsmith.server.services.AnalyticsService; +import com.appsmith.server.services.BaseService; +import com.appsmith.server.services.NewActionService; +import jakarta.validation.Validator; +import org.springframework.data.mongodb.core.ReactiveMongoTemplate; +import org.springframework.data.mongodb.core.convert.MongoConverter; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Scheduler; + +import java.util.Set; + +public class ModuleServiceCEImpl extends BaseService implements ModuleServiceCE { + + private final ModuleRepository moduleRepository; + private final NewActionService newActionService; + + public ModuleServiceCEImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ModuleRepository repository, AnalyticsService analyticsService, NewActionService newActionService) { + super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService); + this.moduleRepository = repository; + this.newActionService = newActionService; + } + + @Override + public Mono createModule(ModuleDTO moduleDTO) { + Module module = new Module(); + + ActionDTO actionDTO = new ActionDTO(); + actionDTO.setName(moduleDTO.getName()); + actionDTO.setActionConfiguration(moduleDTO.getActionConfiguration()); + actionDTO.setDatasource(moduleDTO.getDatasource()); + + + NewAction moduleAction = new NewAction(); + moduleAction.setPluginId(moduleDTO.getPluginId()); + moduleAction.setPluginType(moduleDTO.getPluginType()); + moduleAction.setWorkspaceId(moduleDTO.getWorkspaceId()); + moduleAction.setUnpublishedAction(actionDTO); + + Policy policy = new Policy(); + policy.setPermission(AclPermission.EXECUTE_ACTIONS.getValue()); + policy.setPermissionGroups( + Set.of( + "642e731932cef56b966a9c99", + "642e731932cef56b966a9c98" + ) + ); + + moduleAction.setPolicies(Set.of(policy)); + + + module.setPackageId(moduleDTO.getPackageId()); + module.setWorkspaceId(moduleDTO.getWorkspaceId()); + + + return moduleRepository.save(module) + .flatMap(savedModule -> { + moduleAction.setModuleId(savedModule.getId()); + return Mono.just(moduleAction); + }).flatMap(mAction -> { + return newActionService.save(mAction) + .flatMap(savedAction-> { + module.setPublicActionId(savedAction.getId()); + moduleDTO.setId(module.getId()); + moduleDTO.setPublicActionId(moduleAction.getId()); + return moduleRepository.save(module).thenReturn(moduleDTO); + }); + }); + } +} \ No newline at end of file diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationServiceImpl.java index bf4d93fdb8d..385f77c4966 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ImportExportApplicationServiceImpl.java @@ -1,11 +1,6 @@ package com.appsmith.server.solutions; -import com.appsmith.server.repositories.ActionCollectionRepository; -import com.appsmith.server.repositories.DatasourceRepository; -import com.appsmith.server.repositories.NewActionRepository; -import com.appsmith.server.repositories.NewPageRepository; -import com.appsmith.server.repositories.PermissionGroupRepository; -import com.appsmith.server.repositories.PluginRepository; +import com.appsmith.server.repositories.*; import com.appsmith.server.services.ActionCollectionService; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.ApplicationPageService; @@ -56,13 +51,14 @@ public ImportExportApplicationServiceImpl(DatasourceService datasourceService, Gson gson, TransactionalOperator transactionalOperator, DatasourceStorageService datasourceStorageService, - PermissionGroupRepository permissionGroupRepository) { + PermissionGroupRepository permissionGroupRepository, + ModuleRepository moduleRepository) { super(datasourceService, sessionUserService, newActionRepository, datasourceRepository, pluginRepository, workspaceService, applicationService, newPageService, applicationPageService, newPageRepository, newActionService, sequenceService, actionCollectionRepository, actionCollectionService, themeService, analyticsService, customJSLibService, datasourcePermission, workspacePermission, applicationPermission, pagePermission, actionPermission, gson, transactionalOperator, datasourceStorageService, - permissionGroupRepository); + permissionGroupRepository, moduleRepository); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java index 955fa0703cf..64ab0250b5a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java @@ -28,6 +28,7 @@ import com.appsmith.server.domains.CustomJSLib; import com.appsmith.server.domains.GitApplicationMetadata; import com.appsmith.server.domains.Layout; +import com.appsmith.server.domains.Module; import com.appsmith.server.domains.NewAction; import com.appsmith.server.domains.NewPage; import com.appsmith.server.domains.Theme; @@ -47,12 +48,7 @@ import com.appsmith.server.migrations.ApplicationVersion; import com.appsmith.server.migrations.JsonSchemaMigration; import com.appsmith.server.migrations.JsonSchemaVersions; -import com.appsmith.server.repositories.ActionCollectionRepository; -import com.appsmith.server.repositories.DatasourceRepository; -import com.appsmith.server.repositories.NewActionRepository; -import com.appsmith.server.repositories.NewPageRepository; -import com.appsmith.server.repositories.PermissionGroupRepository; -import com.appsmith.server.repositories.PluginRepository; +import com.appsmith.server.repositories.*; import com.appsmith.server.services.ActionCollectionService; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.ApplicationPageService; @@ -142,6 +138,7 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica private final TransactionalOperator transactionalOperator; private final DatasourceStorageService datasourceStorageService; private final PermissionGroupRepository permissionGroupRepository; + private final ModuleRepository moduleRepository; private static final Set ALLOWED_CONTENT_TYPES = Set.of(MediaType.APPLICATION_JSON); private static final String INVALID_JSON_FILE = "invalid json file"; @@ -409,6 +406,7 @@ public Mono exportApplicationById(String applicationId, Seriali } return actionCollection; }) + .log() .collectList() .flatMapMany(actionCollections -> { // This object won't have the list of actions but we don't care about that today @@ -483,6 +481,7 @@ public Mono exportApplicationById(String applicationId, Seriali } return newAction; }) + .log() .collectList() .map(actionList -> { Set updatedActionSet = new HashSet<>(); @@ -532,8 +531,25 @@ public Mono exportApplicationById(String applicationId, Seriali application.exportApplicationPages(pageIdToNameMap); // Disable exporting the application with datasource config once imported in destination instance application.setExportWithConfiguration(null); - return applicationJson; - }); + + return moduleRepository.findAllById(List.of("1", "2", "3")); + }) + .flatMapMany(module -> { + return module; + }).map(module -> { + return module; + }) + .collectList(); + }) + .map(modules -> { + System.out.println("Size of modules: "+ modules.size()); + if (modules.size() == 0) { + applicationJson.setModules(null); + } else { + applicationJson.setModules(modules); + } + + return applicationJson; }) .then(allCustomJSLibListMono) .map(allCustomLibList -> { @@ -555,7 +571,7 @@ public Mono exportApplicationById(String applicationId, Seriali return applicationJson; }) .then(sendImportExportApplicationAnalyticsEvent(applicationId, AnalyticsEvents.EXPORT)) - .thenReturn(applicationJson); + .thenReturn(applicationJson).log(); } public Mono exportApplicationById(String applicationId, String branchName) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/PageLoadActionsUtilCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/PageLoadActionsUtilCEImpl.java index f665fd9dae9..7dfba10d618 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/PageLoadActionsUtilCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/PageLoadActionsUtilCEImpl.java @@ -177,6 +177,10 @@ public Mono>> findAllOnLoadActions(String pageId, Map actionNameToActionMap = tuple.getT1(); DirectedAcyclicGraph graph = tuple.getT2(); + for(DefaultEdge e : graph.edgeSet()){ + System.out.println(graph.getEdgeSource(e) + " --> " + graph.getEdgeTarget(e)); + } + return computeOnPageLoadActionsSchedulingOrder(graph, onPageLoadActionSet, actionNameToActionMap, explicitUserSetOnLoadActions); }) .map(onPageLoadActionsSchedulingOrder -> { @@ -390,6 +394,7 @@ private Mono>> getPossibleEntityParentsMap *

* !!! WARNING !!! : This function updates actionsUsedInDSL set which is used to store all the directly referenced * actions in the DSL. + * This function returns the dependency edges between widget <---- action * * @param edges * @param actionsUsedInDSL @@ -623,7 +628,10 @@ private List> computeOnPageLoadActionsSchedulingOrder(DirectedAcycli while (bfsIterator.hasNext()) { String vertex = bfsIterator.next(); + + int level = bfsIterator.getDepth(vertex); + System.out.println(String.format("%s : Level %s", vertex, level)); if (onPageLoadActions.size() <= level) { onPageLoadActions.add(new HashSet<>()); }