From d07f02b3599a33280954a63b5dfbf23f0f0c91f2 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Wed, 29 Nov 2023 00:47:49 +0530 Subject: [PATCH] chore: Refactoring for entity validation (#29176) --- ...ionCollectionRefactoringServiceCEImpl.java | 5 ---- .../ActionCollectionController.java | 6 ++--- .../server/controllers/ActionController.java | 6 ++--- .../server/controllers/LayoutController.java | 6 ++--- .../ce/ActionCollectionControllerCE.java | 12 ++++----- .../controllers/ce/ActionControllerCE.java | 10 +++---- .../controllers/ce/LayoutControllerCE.java | 10 +++---- .../dtos/ce/RefactorEntityNameCE_DTO.java | 3 +++ .../newactions/base/NewActionServiceCE.java | 2 -- .../base/NewActionServiceCEImpl.java | 15 ++++------- .../newactions/base/NewActionServiceImpl.java | 3 +++ .../JsActionRefactoringServiceCEImpl.java | 5 ---- .../NewActionRefactoringServiceCEImpl.java | 5 ---- .../applications/RefactoringService.java | 3 +++ ...utionCE.java => RefactoringServiceCE.java} | 2 +- ...mpl.java => RefactoringServiceCEImpl.java} | 7 +++-- ...nImpl.java => RefactoringServiceImpl.java} | 7 +++-- .../applications/RefactoringSolution.java | 3 --- .../entities/EntityRefactoringServiceCE.java | 2 -- .../services/LayoutActionServiceImpl.java | 6 ++--- .../services/LayoutCollectionServiceImpl.java | 6 ++--- .../ce/LayoutActionServiceCEImpl.java | 6 ++--- .../ce/LayoutCollectionServiceCEImpl.java | 6 ++--- .../validations/EntityValidationService.java | 3 +++ .../EntityValidationServiceCE.java | 10 +++++++ .../EntityValidationServiceCEImpl.java | 21 +++++++++++++++ .../EntityValidationServiceImpl.java | 6 +++++ .../WidgetRefactoringServiceCEImpl.java | 5 ---- .../refactors/RefactoringSolutionTest.java | 8 +++--- .../ActionCollectionServiceImplTest.java | 12 ++++----- .../services/ActionCollectionServiceTest.java | 8 +++--- .../services/LayoutActionServiceTest.java | 6 ++--- .../services/ce/NewActionServiceUnitTest.java | 6 +++++ ...java => RefactoringServiceCEImplTest.java} | 19 +++++++++----- ...est.java => RefactoringServiceCETest.java} | 26 +++++++++---------- 35 files changed, 150 insertions(+), 116 deletions(-) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringService.java rename app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/{RefactoringSolutionCE.java => RefactoringServiceCE.java} (93%) rename app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/{RefactoringSolutionCEImpl.java => RefactoringServiceCEImpl.java} (97%) rename app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/{RefactoringSolutionImpl.java => RefactoringServiceImpl.java} (87%) delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolution.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationService.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCE.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCEImpl.java create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceImpl.java rename app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/{RefactoringSolutionCEImplTest.java => RefactoringServiceCEImplTest.java} (95%) rename app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/{RefactoringSolutionCETest.java => RefactoringServiceCETest.java} (97%) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/refactors/ActionCollectionRefactoringServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/refactors/ActionCollectionRefactoringServiceCEImpl.java index 798c5bf5a5..04325776f3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/refactors/ActionCollectionRefactoringServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/refactors/ActionCollectionRefactoringServiceCEImpl.java @@ -47,11 +47,6 @@ public class ActionCollectionRefactoringServiceCEImpl implements EntityRefactori return REFACTOR_JSOBJECT; } - @Override - public Mono validateName(String name) { - return Mono.just(Boolean.TRUE); - } - @Override public Mono refactorReferencesInExistingEntities( RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionCollectionController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionCollectionController.java index ff6020a989..7b7e3d3f88 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionCollectionController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ActionCollectionController.java @@ -3,7 +3,7 @@ package com.appsmith.server.controllers; import com.appsmith.server.actioncollections.base.ActionCollectionService; import com.appsmith.server.constants.Url; import com.appsmith.server.controllers.ce.ActionCollectionControllerCE; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.LayoutCollectionService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,7 +15,7 @@ public class ActionCollectionController extends ActionCollectionControllerCE { public ActionCollectionController( ActionCollectionService actionCollectionService, LayoutCollectionService layoutCollectionService, - RefactoringSolution refactoringSolution) { - super(actionCollectionService, layoutCollectionService, refactoringSolution); + RefactoringService refactoringService) { + super(actionCollectionService, layoutCollectionService, refactoringService); } } 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 dfc11c5260..aac942a6bb 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 @@ -4,7 +4,7 @@ import com.appsmith.server.constants.Url; import com.appsmith.server.controllers.ce.ActionControllerCE; import com.appsmith.server.helpers.OtlpTelemetry; import com.appsmith.server.newactions.base.NewActionService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.LayoutActionService; import com.appsmith.server.solutions.ActionExecutionSolution; import lombok.extern.slf4j.Slf4j; @@ -19,10 +19,10 @@ public class ActionController extends ActionControllerCE { public ActionController( LayoutActionService layoutActionService, NewActionService newActionService, - RefactoringSolution refactoringSolution, + RefactoringService refactoringService, ActionExecutionSolution actionExecutionSolution, OtlpTelemetry otlpTelemetry) { - super(layoutActionService, newActionService, refactoringSolution, actionExecutionSolution, otlpTelemetry); + super(layoutActionService, newActionService, refactoringService, actionExecutionSolution, otlpTelemetry); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java index c376add1e4..8208d83228 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java @@ -3,7 +3,7 @@ package com.appsmith.server.controllers; import com.appsmith.server.constants.Url; import com.appsmith.server.controllers.ce.LayoutControllerCE; import com.appsmith.server.layouts.UpdateLayoutService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.LayoutService; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,7 +17,7 @@ public class LayoutController extends LayoutControllerCE { public LayoutController( LayoutService layoutService, UpdateLayoutService updateLayoutService, - RefactoringSolution refactoringSolution) { - super(layoutService, updateLayoutService, refactoringSolution); + RefactoringService refactoringService) { + super(layoutService, updateLayoutService, refactoringService); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionCollectionControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionCollectionControllerCE.java index 5db9ed41ef..db2672abbd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionCollectionControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionCollectionControllerCE.java @@ -11,7 +11,7 @@ import com.appsmith.server.dtos.EntityType; import com.appsmith.server.dtos.LayoutDTO; import com.appsmith.server.dtos.RefactorEntityNameDTO; import com.appsmith.server.dtos.ResponseDTO; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.LayoutCollectionService; import com.fasterxml.jackson.annotation.JsonView; import jakarta.validation.Valid; @@ -38,16 +38,16 @@ import java.util.List; public class ActionCollectionControllerCE { private final ActionCollectionService actionCollectionService; private final LayoutCollectionService layoutCollectionService; - private final RefactoringSolution refactoringSolution; + private final RefactoringService refactoringService; @Autowired public ActionCollectionControllerCE( ActionCollectionService actionCollectionService, LayoutCollectionService layoutCollectionService, - RefactoringSolution refactoringSolution) { + RefactoringService refactoringService) { this.actionCollectionService = actionCollectionService; this.layoutCollectionService = layoutCollectionService; - this.refactoringSolution = refactoringSolution; + this.refactoringService = refactoringService; } @JsonView(Views.Public.class) @@ -98,7 +98,7 @@ public class ActionCollectionControllerCE { @RequestBody RefactorEntityNameDTO refactorEntityNameDTO, @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { refactorEntityNameDTO.setEntityType(EntityType.JS_OBJECT); - return refactoringSolution + return refactoringService .refactorEntityName(refactorEntityNameDTO, branchName) .map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null)); } @@ -140,7 +140,7 @@ public class ActionCollectionControllerCE { refactorEntityNameDTO.getActionCollection().getId()); refactorEntityNameDTO.setEntityType(EntityType.JS_ACTION); - return refactoringSolution + return refactoringService .refactorEntityName(refactorEntityNameDTO, branchName) .map(updatedResource -> new ResponseDTO<>(HttpStatus.OK.value(), updatedResource, null)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionControllerCE.java index 6770f2d0b0..250c8f7449 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ActionControllerCE.java @@ -13,7 +13,7 @@ import com.appsmith.server.dtos.RefactorEntityNameDTO; import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.helpers.OtlpTelemetry; import com.appsmith.server.newactions.base.NewActionService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.LayoutActionService; import com.appsmith.server.solutions.ActionExecutionSolution; import com.fasterxml.jackson.annotation.JsonView; @@ -47,7 +47,7 @@ public class ActionControllerCE { private final LayoutActionService layoutActionService; private final NewActionService newActionService; - private final RefactoringSolution refactoringSolution; + private final RefactoringService refactoringService; private final ActionExecutionSolution actionExecutionSolution; private final OtlpTelemetry otlpTelemetry; @@ -55,12 +55,12 @@ public class ActionControllerCE { public ActionControllerCE( LayoutActionService layoutActionService, NewActionService newActionService, - RefactoringSolution refactoringSolution, + RefactoringService refactoringService, ActionExecutionSolution actionExecutionSolution, OtlpTelemetry otlpTelemetry) { this.layoutActionService = layoutActionService; this.newActionService = newActionService; - this.refactoringSolution = refactoringSolution; + this.refactoringService = refactoringService; this.actionExecutionSolution = actionExecutionSolution; this.otlpTelemetry = otlpTelemetry; } @@ -128,7 +128,7 @@ public class ActionControllerCE { @RequestBody RefactorEntityNameDTO refactorEntityNameDTO, @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { refactorEntityNameDTO.setEntityType(EntityType.ACTION); - return refactoringSolution + return refactoringService .refactorEntityName(refactorEntityNameDTO, branchName) .map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/LayoutControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/LayoutControllerCE.java index ed6cbac6e6..25d914c41c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/LayoutControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/LayoutControllerCE.java @@ -10,7 +10,7 @@ import com.appsmith.server.dtos.RefactorEntityNameDTO; import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.dtos.UpdateMultiplePageLayoutDTO; import com.appsmith.server.layouts.UpdateLayoutService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.LayoutService; import com.fasterxml.jackson.annotation.JsonView; import jakarta.validation.Valid; @@ -33,16 +33,16 @@ public class LayoutControllerCE { private final LayoutService service; private final UpdateLayoutService updateLayoutService; - private final RefactoringSolution refactoringSolution; + private final RefactoringService refactoringService; @Autowired public LayoutControllerCE( LayoutService layoutService, UpdateLayoutService updateLayoutService, - RefactoringSolution refactoringSolution) { + RefactoringService refactoringService) { this.service = layoutService; this.updateLayoutService = updateLayoutService; - this.refactoringSolution = refactoringSolution; + this.refactoringService = refactoringService; } @JsonView(Views.Public.class) @@ -107,7 +107,7 @@ public class LayoutControllerCE { @RequestBody RefactorEntityNameDTO refactorEntityNameDTO, @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { refactorEntityNameDTO.setEntityType(EntityType.WIDGET); - return refactoringSolution + return refactoringService .refactorEntityName(refactorEntityNameDTO, branchName) .map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/RefactorEntityNameCE_DTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/RefactorEntityNameCE_DTO.java index 17490fb4ad..c34c9ab716 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/RefactorEntityNameCE_DTO.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ce/RefactorEntityNameCE_DTO.java @@ -32,4 +32,7 @@ public class RefactorEntityNameCE_DTO { @JsonView(Views.Internal.class) String newFullyQualifiedName; + + @JsonView(Views.Internal.class) + Boolean isInternal; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java index 80a6f6911b..41f20a9532 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCE.java @@ -28,8 +28,6 @@ import java.util.Set; public interface NewActionServiceCE extends CrudService { - Boolean validateActionName(String name); - void setCommonFieldsFromActionDTOIntoNewAction(ActionDTO action, NewAction newAction); Mono generateActionByViewMode(NewAction newAction, Boolean viewMode); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java index d3b8429173..140e999286 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/base/NewActionServiceCEImpl.java @@ -54,6 +54,7 @@ import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PolicySolution; +import com.appsmith.server.validations.EntityValidationService; import com.mongodb.bulk.BulkWriteResult; import io.micrometer.observation.ObservationRegistry; import jakarta.validation.Validator; @@ -74,7 +75,6 @@ import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.util.function.Tuple2; -import javax.lang.model.SourceVersion; import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; @@ -127,6 +127,7 @@ public class NewActionServiceCEImpl extends BaseService defaultPluginMap = new HashMap<>(); @@ -154,6 +155,7 @@ public class NewActionServiceCEImpl extends BaseService validateName(String name) { - return Mono.just(newActionService.validateActionName(name)); - } - @Override public Mono refactorReferencesInExistingEntities( RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/refactors/NewActionRefactoringServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/refactors/NewActionRefactoringServiceCEImpl.java index 9dcd788424..7e78005370 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/refactors/NewActionRefactoringServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/refactors/NewActionRefactoringServiceCEImpl.java @@ -55,11 +55,6 @@ public class NewActionRefactoringServiceCEImpl implements EntityRefactoringServi RefactoringUtils.updateFQNUsingCollectionName(refactorEntityNameDTO); } - @Override - public Mono validateName(String name) { - return Mono.just(newActionService.validateActionName(name)); - } - @Override public Mono refactorReferencesInExistingEntities( RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringService.java new file mode 100644 index 0000000000..a85fedc7c2 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringService.java @@ -0,0 +1,3 @@ +package com.appsmith.server.refactors.applications; + +public interface RefactoringService extends RefactoringServiceCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCE.java similarity index 93% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionCE.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCE.java index ea423dcee2..c60e70b049 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCE.java @@ -7,7 +7,7 @@ import reactor.core.publisher.Mono; import java.util.Set; -public interface RefactoringSolutionCE { +public interface RefactoringServiceCE { Mono refactorEntityName(RefactorEntityNameDTO refactorEntityNameDTO, String branchName); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java similarity index 97% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionCEImpl.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java index 96bf8365a1..10d9a61bc4 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceCEImpl.java @@ -20,6 +20,7 @@ import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.ApplicationService; import com.appsmith.server.services.SessionUserService; import com.appsmith.server.solutions.PagePermission; +import com.appsmith.server.validations.EntityValidationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.transaction.reactive.TransactionalOperator; @@ -40,7 +41,7 @@ import static com.appsmith.server.services.ce.ApplicationPageServiceCEImpl.EVALU @Slf4j @RequiredArgsConstructor -public class RefactoringSolutionCEImpl implements RefactoringSolutionCE { +public class RefactoringServiceCEImpl implements RefactoringServiceCE { private final NewPageService newPageService; private final ResponseUtils responseUtils; private final UpdateLayoutService updateLayoutService; @@ -49,6 +50,7 @@ public class RefactoringSolutionCEImpl implements RefactoringSolutionCE { private final AnalyticsService analyticsService; private final SessionUserService sessionUserService; private final TransactionalOperator transactionalOperator; + private final EntityValidationService entityValidationService; protected final EntityRefactoringService jsActionEntityRefactoringService; protected final EntityRefactoringService newActionEntityRefactoringService; @@ -151,7 +153,8 @@ public class RefactoringSolutionCEImpl implements RefactoringSolutionCE { service.sanitizeRefactorEntityDTO(refactorEntityNameDTO); // Validate whether this name is allowed based on the type of entity - Mono isValidNameMono = service.validateName(refactorEntityNameDTO.getNewName()) + Mono isValidNameMono = Mono.just( + entityValidationService.validateName(refactorEntityNameDTO.getNewName())) .flatMap(isValid -> { if (!isValid) { return Mono.error(new AppsmithException(AppsmithError.INVALID_ACTION_NAME)); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java similarity index 87% rename from app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionImpl.java rename to app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java index 1f0ae4d1e5..b7ede4fbdd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolutionImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringServiceImpl.java @@ -11,15 +11,16 @@ import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.ApplicationService; import com.appsmith.server.services.SessionUserService; import com.appsmith.server.solutions.PagePermission; +import com.appsmith.server.validations.EntityValidationService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.reactive.TransactionalOperator; @Service @Slf4j -public class RefactoringSolutionImpl extends RefactoringSolutionCEImpl implements RefactoringSolution { +public class RefactoringServiceImpl extends RefactoringServiceCEImpl implements RefactoringService { - public RefactoringSolutionImpl( + public RefactoringServiceImpl( NewPageService newPageService, ResponseUtils responseUtils, UpdateLayoutService updateLayoutService, @@ -28,6 +29,7 @@ public class RefactoringSolutionImpl extends RefactoringSolutionCEImpl implement AnalyticsService analyticsService, SessionUserService sessionUserService, TransactionalOperator transactionalOperator, + EntityValidationService entityValidationService, EntityRefactoringService jsActionEntityRefactoringService, EntityRefactoringService newActionEntityRefactoringService, EntityRefactoringService actionCollectionEntityRefactoringService, @@ -41,6 +43,7 @@ public class RefactoringSolutionImpl extends RefactoringSolutionCEImpl implement analyticsService, sessionUserService, transactionalOperator, + entityValidationService, jsActionEntityRefactoringService, newActionEntityRefactoringService, actionCollectionEntityRefactoringService, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolution.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolution.java deleted file mode 100644 index 25cf8d5396..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/applications/RefactoringSolution.java +++ /dev/null @@ -1,3 +0,0 @@ -package com.appsmith.server.refactors.applications; - -public interface RefactoringSolution extends RefactoringSolutionCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/entities/EntityRefactoringServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/entities/EntityRefactoringServiceCE.java index 10670f37e4..20b7713a89 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/entities/EntityRefactoringServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/refactors/entities/EntityRefactoringServiceCE.java @@ -17,8 +17,6 @@ public interface EntityRefactoringServiceCE { refactorEntityNameDTO.setNewFullyQualifiedName(refactorEntityNameDTO.getNewName()); } - Mono validateName(String newName); - Mono refactorReferencesInExistingEntities( RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO); 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 c47f0fa359..ea11be60b2 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 @@ -5,7 +5,7 @@ import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.ce.LayoutActionServiceCEImpl; import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.PagePermission; @@ -20,7 +20,7 @@ public class LayoutActionServiceImpl extends LayoutActionServiceCEImpl implement AnalyticsService analyticsService, NewPageService newPageService, NewActionService newActionService, - RefactoringSolution refactoringSolution, + RefactoringService refactoringService, CollectionService collectionService, UpdateLayoutService updateLayoutService, ResponseUtils responseUtils, @@ -31,7 +31,7 @@ public class LayoutActionServiceImpl extends LayoutActionServiceCEImpl implement analyticsService, newPageService, newActionService, - refactoringSolution, + refactoringService, collectionService, updateLayoutService, responseUtils, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutCollectionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutCollectionServiceImpl.java index bb1959ff9c..426a0f1484 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutCollectionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutCollectionServiceImpl.java @@ -5,7 +5,7 @@ import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.ActionCollectionRepository; import com.appsmith.server.services.ce.LayoutCollectionServiceCEImpl; import com.appsmith.server.solutions.ActionPermission; @@ -21,7 +21,7 @@ public class LayoutCollectionServiceImpl extends LayoutCollectionServiceCEImpl i NewPageService newPageService, LayoutActionService layoutActionService, UpdateLayoutService updateLayoutService, - RefactoringSolution refactoringSolution, + RefactoringService refactoringService, ActionCollectionService actionCollectionService, NewActionService newActionService, AnalyticsService analyticsService, @@ -33,7 +33,7 @@ public class LayoutCollectionServiceImpl extends LayoutCollectionServiceCEImpl i newPageService, layoutActionService, updateLayoutService, - refactoringSolution, + refactoringService, actionCollectionService, newActionService, analyticsService, 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 9bac89c814..c769f9b189 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 @@ -21,7 +21,7 @@ import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.CollectionService; import com.appsmith.server.solutions.ActionPermission; @@ -44,7 +44,7 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { private final AnalyticsService analyticsService; private final NewPageService newPageService; private final NewActionService newActionService; - private final RefactoringSolution refactoringSolution; + private final RefactoringService refactoringService; private final CollectionService collectionService; private final UpdateLayoutService updateLayoutService; private final ResponseUtils responseUtils; @@ -396,7 +396,7 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { String name = action.getValidName(); CreatorContextType contextType = action.getContextType() == null ? CreatorContextType.PAGE : action.getContextType(); - return refactoringSolution.isNameAllowed(page.getId(), contextType, layout.getId(), name); + return refactoringService.isNameAllowed(page.getId(), contextType, layout.getId(), name); }) .flatMap(nameAllowed -> { // If the name is allowed, return pageMono for further processing diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutCollectionServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutCollectionServiceCEImpl.java index 698776184e..898a91baa2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutCollectionServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutCollectionServiceCEImpl.java @@ -19,7 +19,7 @@ import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.ActionCollectionRepository; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.LayoutActionService; @@ -52,7 +52,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE private final NewPageService newPageService; private final LayoutActionService layoutActionService; private final UpdateLayoutService updateLayoutService; - private final RefactoringSolution refactoringSolution; + private final RefactoringService refactoringService; private final ActionCollectionService actionCollectionService; private final NewActionService newActionService; private final AnalyticsService analyticsService; @@ -96,7 +96,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE CreatorContextType contextType = collection.getContextType() == null ? CreatorContextType.PAGE : collection.getContextType(); // Check against widget names and action names - return refactoringSolution.isNameAllowed( + return refactoringService.isNameAllowed( page.getId(), contextType, layout.getId(), collection.getName()); }) .flatMap(isNameAllowed -> { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationService.java new file mode 100644 index 0000000000..33cdebec72 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationService.java @@ -0,0 +1,3 @@ +package com.appsmith.server.validations; + +public interface EntityValidationService extends EntityValidationServiceCE {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCE.java new file mode 100644 index 0000000000..88a841d49b --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCE.java @@ -0,0 +1,10 @@ +package com.appsmith.server.validations; + +public interface EntityValidationServiceCE { + + boolean validateName(String name, Boolean isInternal); + + default boolean validateName(String name) { + return this.validateName(name, false); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCEImpl.java new file mode 100644 index 0000000000..414075a199 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceCEImpl.java @@ -0,0 +1,21 @@ +package com.appsmith.server.validations; + +import org.springframework.stereotype.Service; + +import javax.lang.model.SourceVersion; + +@Service +public class EntityValidationServiceCEImpl implements EntityValidationServiceCE { + + @Override + public boolean validateName(String name, Boolean isInternal) { + String pattern = "^((?=[A-Za-z0-9_])(?![\\\\-]).)*$"; + return this.validateNameWithPattern(name, pattern); + } + + protected boolean validateNameWithPattern(String name, String pattern) { + boolean isValidName = SourceVersion.isName(name); + boolean doesPatternMatch = name.matches(pattern); + return isValidName && doesPatternMatch; + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceImpl.java new file mode 100644 index 0000000000..7e1f1e41a5 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/validations/EntityValidationServiceImpl.java @@ -0,0 +1,6 @@ +package com.appsmith.server.validations; + +import org.springframework.stereotype.Service; + +@Service +public class EntityValidationServiceImpl extends EntityValidationServiceCEImpl implements EntityValidationService {} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java index 363d334eff..35686e95c6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/widgets/refactors/WidgetRefactoringServiceCEImpl.java @@ -53,11 +53,6 @@ public class WidgetRefactoringServiceCEImpl implements EntityRefactoringServiceC return REFACTOR_WIDGET; } - @Override - public Mono validateName(String name) { - return Mono.just(Boolean.TRUE); - } - @Override public Mono refactorReferencesInExistingEntities( RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/RefactoringSolutionTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/RefactoringSolutionTest.java index 814b6b8d80..f96e3aff0e 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/RefactoringSolutionTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/RefactoringSolutionTest.java @@ -19,7 +19,7 @@ import com.appsmith.server.imports.internal.ImportApplicationService; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.NewActionRepository; import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.services.ApplicationPageService; @@ -86,7 +86,7 @@ public class RefactoringSolutionTest { UpdateLayoutService updateLayoutService; @Autowired - RefactoringSolution refactoringSolution; + RefactoringService refactoringService; @Autowired LayoutCollectionService layoutCollectionService; @@ -249,7 +249,7 @@ public class RefactoringSolutionTest { Mockito.when(actionCollectionService.getActionCollectionsByViewMode(Mockito.any(), Mockito.anyBoolean())) .thenReturn(Flux.just(mockActionCollectionDTO)); - Mono nameAllowedMono = refactoringSolution.isNameAllowed( + Mono nameAllowedMono = refactoringService.isNameAllowed( testPage.getId(), CreatorContextType.PAGE, testPage.getLayouts().get(0).getId(), @@ -284,7 +284,7 @@ public class RefactoringSolutionTest { Mockito.when(actionCollectionService.getActionCollectionsByViewMode(Mockito.any(), Mockito.anyBoolean())) .thenReturn(Flux.just(mockActionCollectionDTO)); - Mono nameAllowedMono = refactoringSolution.isNameAllowed( + Mono nameAllowedMono = refactoringService.isNameAllowed( testPage.getId(), CreatorContextType.PAGE, testPage.getLayouts().get(0).getId(), diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java index 9630e99784..4b4ac45541 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceImplTest.java @@ -24,7 +24,7 @@ import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.ActionCollectionRepository; import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.ActionPermissionImpl; @@ -87,7 +87,7 @@ public class ActionCollectionServiceImplTest { UpdateLayoutService updateLayoutService; @MockBean - RefactoringSolution refactoringSolution; + RefactoringService refactoringService; @MockBean ActionCollectionRepository actionCollectionRepository; @@ -146,7 +146,7 @@ public class ActionCollectionServiceImplTest { newPageService, layoutActionService, updateLayoutService, - refactoringSolution, + refactoringService, actionCollectionService, newActionService, analyticsService, @@ -234,7 +234,7 @@ public class ActionCollectionServiceImplTest { final NewPage newPage = objectMapper.convertValue(jsonNode.get("newPage"), NewPage.class); Mockito.when(newPageService.findById(Mockito.any(), Mockito.any())) .thenReturn(Mono.just(newPage)); - Mockito.when(refactoringSolution.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + Mockito.when(refactoringService.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(Mono.just(false)); Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( @@ -275,7 +275,7 @@ public class ActionCollectionServiceImplTest { Mockito.when(newPageService.findById(Mockito.any(), Mockito.any())) .thenReturn(Mono.just(newPage)); - Mockito.when(refactoringSolution.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + Mockito.when(refactoringService.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(Mono.just(true)); Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( @@ -340,7 +340,7 @@ public class ActionCollectionServiceImplTest { Mockito.when(newPageService.findById(Mockito.any(), Mockito.any())) .thenReturn(Mono.just(newPage)); - Mockito.when(refactoringSolution.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + Mockito.when(refactoringService.isNameAllowed(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(Mono.just(true)); Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java index 3137e7df46..03b4a5e52e 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java @@ -29,7 +29,7 @@ import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; import com.appsmith.server.plugins.base.PluginService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.ActionCollectionRepository; import com.appsmith.server.repositories.PermissionGroupRepository; import com.appsmith.server.repositories.PluginRepository; @@ -91,7 +91,7 @@ public class ActionCollectionServiceTest { LayoutActionService layoutActionService; @Autowired - RefactoringSolution refactoringSolution; + RefactoringService refactoringService; @Autowired NewPageService newPageService; @@ -411,7 +411,7 @@ public class ActionCollectionServiceTest { refactorActionNameDTO.setOldName("testAction1"); refactorActionNameDTO.setNewName("newTestAction1"); - final LayoutDTO layoutDTO = refactoringSolution + final LayoutDTO layoutDTO = refactoringService .refactorEntityName(refactorActionNameDTO, null) .block(); @@ -503,7 +503,7 @@ public class ActionCollectionServiceTest { refactorActionNameDTO.setOldName("run"); refactorActionNameDTO.setNewName("newRun"); - final LayoutDTO layoutDTO = refactoringSolution + final LayoutDTO layoutDTO = refactoringService .refactorEntityName(refactorActionNameDTO, null) .block(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutActionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutActionServiceTest.java index 97fc7ebcd1..a8649d38e0 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutActionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutActionServiceTest.java @@ -31,7 +31,7 @@ import com.appsmith.server.imports.internal.ImportApplicationService; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.NewActionRepository; import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.solutions.ApplicationPermission; @@ -109,7 +109,7 @@ public class LayoutActionServiceTest { UpdateLayoutService updateLayoutService; @Autowired - RefactoringSolution refactoringSolution; + RefactoringService refactoringService; @Autowired LayoutCollectionService layoutCollectionService; @@ -1288,7 +1288,7 @@ public class LayoutActionServiceTest { refactorActionNameDTO.setPageId(testPage.getId()); refactorActionNameDTO.setActionId(createdAction.getId()); - Mono layoutDTOMono = refactoringSolution.refactorEntityName(refactorActionNameDTO, null); + Mono layoutDTOMono = refactoringService.refactorEntityName(refactorActionNameDTO, null); StepVerifier.create(layoutDTOMono.map( layoutDTO -> layoutDTO.getLayoutOnLoadActionErrors().size())) .expectNext(1) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java index 3f4f12d8f7..31d148ca52 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/NewActionServiceUnitTest.java @@ -24,6 +24,7 @@ import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PolicySolution; +import com.appsmith.server.validations.EntityValidationService; import io.micrometer.observation.ObservationRegistry; import jakarta.validation.Validator; import lombok.extern.slf4j.Slf4j; @@ -110,6 +111,9 @@ public class NewActionServiceUnitTest { @MockBean PagePermission pagePermission; + @MockBean + EntityValidationService entityValidationService; + ActionPermission actionPermission = new ActionPermissionImpl(); @MockBean @@ -139,11 +143,13 @@ public class NewActionServiceUnitTest { applicationPermission, pagePermission, actionPermission, + entityValidationService, observationRegistry); ObservationRegistry.ObservationConfig mockObservationConfig = Mockito.mock(ObservationRegistry.ObservationConfig.class); Mockito.when(observationRegistry.observationConfig()).thenReturn(mockObservationConfig); + Mockito.doReturn(true).when(entityValidationService).validateName(Mockito.anyString()); } @Test diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringSolutionCEImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringServiceCEImplTest.java similarity index 95% rename from app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringSolutionCEImplTest.java rename to app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringServiceCEImplTest.java index 5a569195e3..cfe3ffe090 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringSolutionCEImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringServiceCEImplTest.java @@ -19,7 +19,7 @@ import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolutionCEImpl; +import com.appsmith.server.refactors.applications.RefactoringServiceCEImpl; import com.appsmith.server.refactors.entities.EntityRefactoringService; import com.appsmith.server.repositories.ActionCollectionRepository; import com.appsmith.server.services.AnalyticsService; @@ -27,6 +27,7 @@ import com.appsmith.server.services.ApplicationService; import com.appsmith.server.services.SessionUserService; import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.PagePermission; +import com.appsmith.server.validations.EntityValidationService; import lombok.extern.slf4j.Slf4j; import net.minidev.json.JSONObject; import org.junit.jupiter.api.BeforeEach; @@ -54,8 +55,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @ExtendWith(SpringExtension.class) @Slf4j @SpringBootTest -class RefactoringSolutionCEImplTest { - RefactoringSolutionCEImpl refactoringSolutionCE; +class RefactoringServiceCEImplTest { + RefactoringServiceCEImpl refactoringServiceCE; @Autowired PagePermission pagePermission; @@ -102,12 +103,15 @@ class RefactoringSolutionCEImplTest { @Autowired private TransactionalOperator transactionalOperator; + @Autowired + private EntityValidationService entityValidationService; + @BeforeEach public void setUp() { Mockito.when(sessionUserService.getCurrentUser()).thenReturn(Mono.just(new User())); - refactoringSolutionCE = new RefactoringSolutionCEImpl( + refactoringServiceCE = new RefactoringServiceCEImpl( newPageService, responseUtils, updateLayoutService, @@ -116,6 +120,7 @@ class RefactoringSolutionCEImplTest { analyticsService, sessionUserService, transactionalOperator, + entityValidationService, jsActionEntityRefactoringService, newActionEntityRefactoringService, actionCollectionEntityRefactoringService, @@ -188,7 +193,7 @@ class RefactoringSolutionCEImplTest { .getExistingEntityNames(Mockito.anyString(), Mockito.any(), Mockito.anyString()); final Mono layoutDTOMono = - refactoringSolutionCE.refactorEntityName(refactorActionCollectionNameDTO, null); + refactoringServiceCE.refactorEntityName(refactorActionCollectionNameDTO, null); StepVerifier.create(layoutDTOMono) .assertNext(layoutDTO -> { @@ -241,7 +246,7 @@ class RefactoringSolutionCEImplTest { Mockito.when(newPageService.getById(Mockito.anyString())).thenReturn(Mono.just(newPage)); final Mono layoutDTOMono = - refactoringSolutionCE.refactorEntityName(refactorActionCollectionNameDTO, null); + refactoringServiceCE.refactorEntityName(refactorActionCollectionNameDTO, null); StepVerifier.create(layoutDTOMono) .expectErrorMatches(e -> AppsmithError.NAME_CLASH_NOT_ALLOWED_IN_REFACTOR @@ -330,7 +335,7 @@ class RefactoringSolutionCEImplTest { .getExistingEntityNames(Mockito.anyString(), Mockito.any(), Mockito.anyString()); final Mono layoutDTOMono = - refactoringSolutionCE.refactorEntityName(refactorActionCollectionNameDTO, null); + refactoringServiceCE.refactorEntityName(refactorActionCollectionNameDTO, null); StepVerifier.create(layoutDTOMono) .assertNext(layoutDTO -> { diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringSolutionCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringServiceCETest.java similarity index 97% rename from app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringSolutionCETest.java rename to app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringServiceCETest.java index bc7bd589ca..4d2f5720b5 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringSolutionCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/RefactoringServiceCETest.java @@ -30,7 +30,7 @@ import com.appsmith.server.imports.internal.ImportApplicationService; import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; -import com.appsmith.server.refactors.applications.RefactoringSolution; +import com.appsmith.server.refactors.applications.RefactoringService; import com.appsmith.server.repositories.NewActionRepository; import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.services.ApplicationPageService; @@ -79,7 +79,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest @Slf4j @DirtiesContext -class RefactoringSolutionCETest { +class RefactoringServiceCETest { @SpyBean NewActionService newActionService; @@ -106,7 +106,7 @@ class RefactoringSolutionCETest { UpdateLayoutService updateLayoutService; @Autowired - RefactoringSolution refactoringSolution; + RefactoringService refactoringService; @Autowired LayoutCollectionService layoutCollectionService; @@ -307,7 +307,7 @@ class RefactoringSolutionCETest { refactorActionNameDTO.setNewName("PostNameChange"); refactorActionNameDTO.setActionId(createdAction.getId()); - LayoutDTO postNameChangeLayout = refactoringSolution + LayoutDTO postNameChangeLayout = refactoringService .refactorEntityName(refactorActionNameDTO, null) .block(); @@ -383,7 +383,7 @@ class RefactoringSolutionCETest { refactorActionNameDTO.setNewName("PostNameChange"); refactorActionNameDTO.setActionId(createdAction.getId()); - LayoutDTO postNameChangeLayout = refactoringSolution + LayoutDTO postNameChangeLayout = refactoringService .refactorEntityName(refactorActionNameDTO, null) .block(); @@ -460,7 +460,7 @@ class RefactoringSolutionCETest { refactorActionNameDTO.setNewName("NewActionName"); refactorActionNameDTO.setActionId(firstAction.getId()); - refactoringSolution.refactorEntityName(refactorActionNameDTO, null).block(); + refactoringService.refactorEntityName(refactorActionNameDTO, null).block(); Mono postNameChangeActionMono = newActionService.findById(secondAction.getId(), READ_ACTIONS); @@ -513,7 +513,7 @@ class RefactoringSolutionCETest { assert createdAction != null; refactorActionNameDTO.setActionId(createdAction.getId()); - final Mono layoutDTOMono = refactoringSolution.refactorEntityName(refactorActionNameDTO, null); + final Mono layoutDTOMono = refactoringService.refactorEntityName(refactorActionNameDTO, null); StepVerifier.create(layoutDTOMono) .expectErrorMatches(e -> e instanceof AppsmithException @@ -585,7 +585,7 @@ class RefactoringSolutionCETest { refactorActionNameDTO.setNewName("newName"); refactorActionNameDTO.setActionId(firstAction.getId()); - LayoutDTO postNameChangeLayout = refactoringSolution + LayoutDTO postNameChangeLayout = refactoringService .refactorEntityName(refactorActionNameDTO, null) .block(); @@ -638,7 +638,7 @@ class RefactoringSolutionCETest { refactorNameDTO.setNewName("NewNameTable1"); Mono widgetRenameMono = - refactoringSolution.refactorEntityName(refactorNameDTO, null).cache(); + refactoringService.refactorEntityName(refactorNameDTO, null).cache(); Mono pageFromRepoMono = widgetRenameMono.then(newPageService.findPageById(testPage.getId(), READ_PAGES, false)); @@ -688,7 +688,7 @@ class RefactoringSolutionCETest { refactorNameDTO.setNewName("NewNameTable1"); Mono widgetRenameMono = - refactoringSolution.refactorEntityName(refactorNameDTO, null).cache(); + refactoringService.refactorEntityName(refactorNameDTO, null).cache(); Mono pageFromRepoMono = widgetRenameMono.then(newPageService.findPageById(testPage.getId(), READ_PAGES, false)); @@ -740,7 +740,7 @@ class RefactoringSolutionCETest { refactorNameDTO.setOldName("oldWidgetName"); refactorNameDTO.setNewName("newWidgetName"); - Mono widgetRenameMono = refactoringSolution.refactorEntityName(refactorNameDTO, null); + Mono widgetRenameMono = refactoringService.refactorEntityName(refactorNameDTO, null); StepVerifier.create(widgetRenameMono) .assertNext(updatedLayout -> { @@ -801,7 +801,7 @@ class RefactoringSolutionCETest { refactorNameDTO.setNewName("NewNameTable1"); LayoutDTO updatedLayout = - refactoringSolution.refactorEntityName(refactorNameDTO, null).block(); + refactoringService.refactorEntityName(refactorNameDTO, null).block(); assert createdActionCollectionDTO1 != null; final Mono actionCollectionMono = @@ -873,7 +873,7 @@ class RefactoringSolutionCETest { refactorActionNameInCollectionDTO.setNewName("newTestAction"); refactorActionNameInCollectionDTO.setCollectionName("originalName"); - final Mono> tuple2Mono = refactoringSolution + final Mono> tuple2Mono = refactoringService .refactorEntityName(refactorActionNameInCollectionDTO, null) .then(actionCollectionService .getById(dto.getId())