chore: Refactoring for entity validation (#29176)

This commit is contained in:
Nidhi 2023-11-29 00:47:49 +05:30 committed by GitHub
parent 666493fab9
commit d07f02b359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 150 additions and 116 deletions

View File

@ -47,11 +47,6 @@ public class ActionCollectionRefactoringServiceCEImpl implements EntityRefactori
return REFACTOR_JSOBJECT; return REFACTOR_JSOBJECT;
} }
@Override
public Mono<Boolean> validateName(String name) {
return Mono.just(Boolean.TRUE);
}
@Override @Override
public Mono<Void> refactorReferencesInExistingEntities( public Mono<Void> refactorReferencesInExistingEntities(
RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) {

View File

@ -3,7 +3,7 @@ package com.appsmith.server.controllers;
import com.appsmith.server.actioncollections.base.ActionCollectionService; import com.appsmith.server.actioncollections.base.ActionCollectionService;
import com.appsmith.server.constants.Url; import com.appsmith.server.constants.Url;
import com.appsmith.server.controllers.ce.ActionCollectionControllerCE; 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 com.appsmith.server.services.LayoutCollectionService;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -15,7 +15,7 @@ public class ActionCollectionController extends ActionCollectionControllerCE {
public ActionCollectionController( public ActionCollectionController(
ActionCollectionService actionCollectionService, ActionCollectionService actionCollectionService,
LayoutCollectionService layoutCollectionService, LayoutCollectionService layoutCollectionService,
RefactoringSolution refactoringSolution) { RefactoringService refactoringService) {
super(actionCollectionService, layoutCollectionService, refactoringSolution); super(actionCollectionService, layoutCollectionService, refactoringService);
} }
} }

View File

@ -4,7 +4,7 @@ import com.appsmith.server.constants.Url;
import com.appsmith.server.controllers.ce.ActionControllerCE; import com.appsmith.server.controllers.ce.ActionControllerCE;
import com.appsmith.server.helpers.OtlpTelemetry; import com.appsmith.server.helpers.OtlpTelemetry;
import com.appsmith.server.newactions.base.NewActionService; 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.services.LayoutActionService;
import com.appsmith.server.solutions.ActionExecutionSolution; import com.appsmith.server.solutions.ActionExecutionSolution;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -19,10 +19,10 @@ public class ActionController extends ActionControllerCE {
public ActionController( public ActionController(
LayoutActionService layoutActionService, LayoutActionService layoutActionService,
NewActionService newActionService, NewActionService newActionService,
RefactoringSolution refactoringSolution, RefactoringService refactoringService,
ActionExecutionSolution actionExecutionSolution, ActionExecutionSolution actionExecutionSolution,
OtlpTelemetry otlpTelemetry) { OtlpTelemetry otlpTelemetry) {
super(layoutActionService, newActionService, refactoringSolution, actionExecutionSolution, otlpTelemetry); super(layoutActionService, newActionService, refactoringService, actionExecutionSolution, otlpTelemetry);
} }
} }

View File

@ -3,7 +3,7 @@ package com.appsmith.server.controllers;
import com.appsmith.server.constants.Url; import com.appsmith.server.constants.Url;
import com.appsmith.server.controllers.ce.LayoutControllerCE; import com.appsmith.server.controllers.ce.LayoutControllerCE;
import com.appsmith.server.layouts.UpdateLayoutService; 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.appsmith.server.services.LayoutService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -17,7 +17,7 @@ public class LayoutController extends LayoutControllerCE {
public LayoutController( public LayoutController(
LayoutService layoutService, LayoutService layoutService,
UpdateLayoutService updateLayoutService, UpdateLayoutService updateLayoutService,
RefactoringSolution refactoringSolution) { RefactoringService refactoringService) {
super(layoutService, updateLayoutService, refactoringSolution); super(layoutService, updateLayoutService, refactoringService);
} }
} }

View File

@ -11,7 +11,7 @@ import com.appsmith.server.dtos.EntityType;
import com.appsmith.server.dtos.LayoutDTO; import com.appsmith.server.dtos.LayoutDTO;
import com.appsmith.server.dtos.RefactorEntityNameDTO; import com.appsmith.server.dtos.RefactorEntityNameDTO;
import com.appsmith.server.dtos.ResponseDTO; 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.appsmith.server.services.LayoutCollectionService;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -38,16 +38,16 @@ import java.util.List;
public class ActionCollectionControllerCE { public class ActionCollectionControllerCE {
private final ActionCollectionService actionCollectionService; private final ActionCollectionService actionCollectionService;
private final LayoutCollectionService layoutCollectionService; private final LayoutCollectionService layoutCollectionService;
private final RefactoringSolution refactoringSolution; private final RefactoringService refactoringService;
@Autowired @Autowired
public ActionCollectionControllerCE( public ActionCollectionControllerCE(
ActionCollectionService actionCollectionService, ActionCollectionService actionCollectionService,
LayoutCollectionService layoutCollectionService, LayoutCollectionService layoutCollectionService,
RefactoringSolution refactoringSolution) { RefactoringService refactoringService) {
this.actionCollectionService = actionCollectionService; this.actionCollectionService = actionCollectionService;
this.layoutCollectionService = layoutCollectionService; this.layoutCollectionService = layoutCollectionService;
this.refactoringSolution = refactoringSolution; this.refactoringService = refactoringService;
} }
@JsonView(Views.Public.class) @JsonView(Views.Public.class)
@ -98,7 +98,7 @@ public class ActionCollectionControllerCE {
@RequestBody RefactorEntityNameDTO refactorEntityNameDTO, @RequestBody RefactorEntityNameDTO refactorEntityNameDTO,
@RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) {
refactorEntityNameDTO.setEntityType(EntityType.JS_OBJECT); refactorEntityNameDTO.setEntityType(EntityType.JS_OBJECT);
return refactoringSolution return refactoringService
.refactorEntityName(refactorEntityNameDTO, branchName) .refactorEntityName(refactorEntityNameDTO, branchName)
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null)); .map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
} }
@ -140,7 +140,7 @@ public class ActionCollectionControllerCE {
refactorEntityNameDTO.getActionCollection().getId()); refactorEntityNameDTO.getActionCollection().getId());
refactorEntityNameDTO.setEntityType(EntityType.JS_ACTION); refactorEntityNameDTO.setEntityType(EntityType.JS_ACTION);
return refactoringSolution return refactoringService
.refactorEntityName(refactorEntityNameDTO, branchName) .refactorEntityName(refactorEntityNameDTO, branchName)
.map(updatedResource -> new ResponseDTO<>(HttpStatus.OK.value(), updatedResource, null)); .map(updatedResource -> new ResponseDTO<>(HttpStatus.OK.value(), updatedResource, null));
} }

View File

@ -13,7 +13,7 @@ import com.appsmith.server.dtos.RefactorEntityNameDTO;
import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.helpers.OtlpTelemetry; import com.appsmith.server.helpers.OtlpTelemetry;
import com.appsmith.server.newactions.base.NewActionService; 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.services.LayoutActionService;
import com.appsmith.server.solutions.ActionExecutionSolution; import com.appsmith.server.solutions.ActionExecutionSolution;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
@ -47,7 +47,7 @@ public class ActionControllerCE {
private final LayoutActionService layoutActionService; private final LayoutActionService layoutActionService;
private final NewActionService newActionService; private final NewActionService newActionService;
private final RefactoringSolution refactoringSolution; private final RefactoringService refactoringService;
private final ActionExecutionSolution actionExecutionSolution; private final ActionExecutionSolution actionExecutionSolution;
private final OtlpTelemetry otlpTelemetry; private final OtlpTelemetry otlpTelemetry;
@ -55,12 +55,12 @@ public class ActionControllerCE {
public ActionControllerCE( public ActionControllerCE(
LayoutActionService layoutActionService, LayoutActionService layoutActionService,
NewActionService newActionService, NewActionService newActionService,
RefactoringSolution refactoringSolution, RefactoringService refactoringService,
ActionExecutionSolution actionExecutionSolution, ActionExecutionSolution actionExecutionSolution,
OtlpTelemetry otlpTelemetry) { OtlpTelemetry otlpTelemetry) {
this.layoutActionService = layoutActionService; this.layoutActionService = layoutActionService;
this.newActionService = newActionService; this.newActionService = newActionService;
this.refactoringSolution = refactoringSolution; this.refactoringService = refactoringService;
this.actionExecutionSolution = actionExecutionSolution; this.actionExecutionSolution = actionExecutionSolution;
this.otlpTelemetry = otlpTelemetry; this.otlpTelemetry = otlpTelemetry;
} }
@ -128,7 +128,7 @@ public class ActionControllerCE {
@RequestBody RefactorEntityNameDTO refactorEntityNameDTO, @RequestBody RefactorEntityNameDTO refactorEntityNameDTO,
@RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) {
refactorEntityNameDTO.setEntityType(EntityType.ACTION); refactorEntityNameDTO.setEntityType(EntityType.ACTION);
return refactoringSolution return refactoringService
.refactorEntityName(refactorEntityNameDTO, branchName) .refactorEntityName(refactorEntityNameDTO, branchName)
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null)); .map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
} }

View File

@ -10,7 +10,7 @@ import com.appsmith.server.dtos.RefactorEntityNameDTO;
import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.dtos.UpdateMultiplePageLayoutDTO; import com.appsmith.server.dtos.UpdateMultiplePageLayoutDTO;
import com.appsmith.server.layouts.UpdateLayoutService; 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.appsmith.server.services.LayoutService;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -33,16 +33,16 @@ public class LayoutControllerCE {
private final LayoutService service; private final LayoutService service;
private final UpdateLayoutService updateLayoutService; private final UpdateLayoutService updateLayoutService;
private final RefactoringSolution refactoringSolution; private final RefactoringService refactoringService;
@Autowired @Autowired
public LayoutControllerCE( public LayoutControllerCE(
LayoutService layoutService, LayoutService layoutService,
UpdateLayoutService updateLayoutService, UpdateLayoutService updateLayoutService,
RefactoringSolution refactoringSolution) { RefactoringService refactoringService) {
this.service = layoutService; this.service = layoutService;
this.updateLayoutService = updateLayoutService; this.updateLayoutService = updateLayoutService;
this.refactoringSolution = refactoringSolution; this.refactoringService = refactoringService;
} }
@JsonView(Views.Public.class) @JsonView(Views.Public.class)
@ -107,7 +107,7 @@ public class LayoutControllerCE {
@RequestBody RefactorEntityNameDTO refactorEntityNameDTO, @RequestBody RefactorEntityNameDTO refactorEntityNameDTO,
@RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) {
refactorEntityNameDTO.setEntityType(EntityType.WIDGET); refactorEntityNameDTO.setEntityType(EntityType.WIDGET);
return refactoringSolution return refactoringService
.refactorEntityName(refactorEntityNameDTO, branchName) .refactorEntityName(refactorEntityNameDTO, branchName)
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null)); .map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
} }

View File

@ -32,4 +32,7 @@ public class RefactorEntityNameCE_DTO {
@JsonView(Views.Internal.class) @JsonView(Views.Internal.class)
String newFullyQualifiedName; String newFullyQualifiedName;
@JsonView(Views.Internal.class)
Boolean isInternal;
} }

View File

@ -28,8 +28,6 @@ import java.util.Set;
public interface NewActionServiceCE extends CrudService<NewAction, String> { public interface NewActionServiceCE extends CrudService<NewAction, String> {
Boolean validateActionName(String name);
void setCommonFieldsFromActionDTOIntoNewAction(ActionDTO action, NewAction newAction); void setCommonFieldsFromActionDTOIntoNewAction(ActionDTO action, NewAction newAction);
Mono<ActionDTO> generateActionByViewMode(NewAction newAction, Boolean viewMode); Mono<ActionDTO> generateActionByViewMode(NewAction newAction, Boolean viewMode);

View File

@ -54,6 +54,7 @@ import com.appsmith.server.solutions.ApplicationPermission;
import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.DatasourcePermission;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
import com.appsmith.server.solutions.PolicySolution; import com.appsmith.server.solutions.PolicySolution;
import com.appsmith.server.validations.EntityValidationService;
import com.mongodb.bulk.BulkWriteResult; import com.mongodb.bulk.BulkWriteResult;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
import jakarta.validation.Validator; import jakarta.validation.Validator;
@ -74,7 +75,6 @@ import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Scheduler;
import reactor.util.function.Tuple2; import reactor.util.function.Tuple2;
import javax.lang.model.SourceVersion;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -127,6 +127,7 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
private final ApplicationPermission applicationPermission; private final ApplicationPermission applicationPermission;
private final PagePermission pagePermission; private final PagePermission pagePermission;
protected final ActionPermission actionPermission; protected final ActionPermission actionPermission;
private final EntityValidationService entityValidationService;
private final ObservationRegistry observationRegistry; private final ObservationRegistry observationRegistry;
private final Map<String, Plugin> defaultPluginMap = new HashMap<>(); private final Map<String, Plugin> defaultPluginMap = new HashMap<>();
@ -154,6 +155,7 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
ApplicationPermission applicationPermission, ApplicationPermission applicationPermission,
PagePermission pagePermission, PagePermission pagePermission,
ActionPermission actionPermission, ActionPermission actionPermission,
EntityValidationService entityValidationService,
ObservationRegistry observationRegistry) { ObservationRegistry observationRegistry) {
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService); super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
@ -167,6 +169,7 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
this.applicationService = applicationService; this.applicationService = applicationService;
this.policySolution = policySolution; this.policySolution = policySolution;
this.permissionGroupService = permissionGroupService; this.permissionGroupService = permissionGroupService;
this.entityValidationService = entityValidationService;
this.observationRegistry = observationRegistry; this.observationRegistry = observationRegistry;
this.responseUtils = responseUtils; this.responseUtils = responseUtils;
this.configService = configService; this.configService = configService;
@ -176,14 +179,6 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
this.actionPermission = actionPermission; this.actionPermission = actionPermission;
} }
@Override
public Boolean validateActionName(String name) {
boolean isValidName = SourceVersion.isName(name);
String pattern = "^((?=[A-Za-z0-9_])(?![\\\\-]).)*$";
boolean doesPatternMatch = name.matches(pattern);
return (isValidName && doesPatternMatch);
}
private void setCommonFieldsFromNewActionIntoAction(NewAction newAction, ActionDTO action) { private void setCommonFieldsFromNewActionIntoAction(NewAction newAction, ActionDTO action) {
// Set the fields from NewAction into Action // Set the fields from NewAction into Action
@ -292,7 +287,7 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
this.validateCreatorId(action); this.validateCreatorId(action);
if (!validateActionName(action.getName())) { if (!entityValidationService.validateName(action.getName())) {
action.setIsValid(false); action.setIsValid(false);
invalids.add(AppsmithError.INVALID_ACTION_NAME.getMessage()); invalids.add(AppsmithError.INVALID_ACTION_NAME.getMessage());
} }

View File

@ -17,6 +17,7 @@ import com.appsmith.server.solutions.ApplicationPermission;
import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.DatasourcePermission;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
import com.appsmith.server.solutions.PolicySolution; import com.appsmith.server.solutions.PolicySolution;
import com.appsmith.server.validations.EntityValidationService;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
import jakarta.validation.Validator; import jakarta.validation.Validator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -51,6 +52,7 @@ public class NewActionServiceImpl extends NewActionServiceCEImpl implements NewA
ApplicationPermission applicationPermission, ApplicationPermission applicationPermission,
PagePermission pagePermission, PagePermission pagePermission,
ActionPermission actionPermission, ActionPermission actionPermission,
EntityValidationService entityValidationService,
ObservationRegistry observationRegistry) { ObservationRegistry observationRegistry) {
super( super(
@ -75,6 +77,7 @@ public class NewActionServiceImpl extends NewActionServiceCEImpl implements NewA
applicationPermission, applicationPermission,
pagePermission, pagePermission,
actionPermission, actionPermission,
entityValidationService,
observationRegistry); observationRegistry);
} }
} }

View File

@ -43,11 +43,6 @@ public class JsActionRefactoringServiceCEImpl implements EntityRefactoringServic
RefactoringUtils.updateFQNUsingCollectionName(refactorEntityNameDTO); RefactoringUtils.updateFQNUsingCollectionName(refactorEntityNameDTO);
} }
@Override
public Mono<Boolean> validateName(String name) {
return Mono.just(newActionService.validateActionName(name));
}
@Override @Override
public Mono<Void> refactorReferencesInExistingEntities( public Mono<Void> refactorReferencesInExistingEntities(
RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) {

View File

@ -55,11 +55,6 @@ public class NewActionRefactoringServiceCEImpl implements EntityRefactoringServi
RefactoringUtils.updateFQNUsingCollectionName(refactorEntityNameDTO); RefactoringUtils.updateFQNUsingCollectionName(refactorEntityNameDTO);
} }
@Override
public Mono<Boolean> validateName(String name) {
return Mono.just(newActionService.validateActionName(name));
}
@Override @Override
public Mono<Void> refactorReferencesInExistingEntities( public Mono<Void> refactorReferencesInExistingEntities(
RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) {

View File

@ -0,0 +1,3 @@
package com.appsmith.server.refactors.applications;
public interface RefactoringService extends RefactoringServiceCE {}

View File

@ -7,7 +7,7 @@ import reactor.core.publisher.Mono;
import java.util.Set; import java.util.Set;
public interface RefactoringSolutionCE { public interface RefactoringServiceCE {
Mono<LayoutDTO> refactorEntityName(RefactorEntityNameDTO refactorEntityNameDTO, String branchName); Mono<LayoutDTO> refactorEntityName(RefactorEntityNameDTO refactorEntityNameDTO, String branchName);

View File

@ -20,6 +20,7 @@ import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.ApplicationService; import com.appsmith.server.services.ApplicationService;
import com.appsmith.server.services.SessionUserService; import com.appsmith.server.services.SessionUserService;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
import com.appsmith.server.validations.EntityValidationService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.reactive.TransactionalOperator; import org.springframework.transaction.reactive.TransactionalOperator;
@ -40,7 +41,7 @@ import static com.appsmith.server.services.ce.ApplicationPageServiceCEImpl.EVALU
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
public class RefactoringSolutionCEImpl implements RefactoringSolutionCE { public class RefactoringServiceCEImpl implements RefactoringServiceCE {
private final NewPageService newPageService; private final NewPageService newPageService;
private final ResponseUtils responseUtils; private final ResponseUtils responseUtils;
private final UpdateLayoutService updateLayoutService; private final UpdateLayoutService updateLayoutService;
@ -49,6 +50,7 @@ public class RefactoringSolutionCEImpl implements RefactoringSolutionCE {
private final AnalyticsService analyticsService; private final AnalyticsService analyticsService;
private final SessionUserService sessionUserService; private final SessionUserService sessionUserService;
private final TransactionalOperator transactionalOperator; private final TransactionalOperator transactionalOperator;
private final EntityValidationService entityValidationService;
protected final EntityRefactoringService<Void> jsActionEntityRefactoringService; protected final EntityRefactoringService<Void> jsActionEntityRefactoringService;
protected final EntityRefactoringService<NewAction> newActionEntityRefactoringService; protected final EntityRefactoringService<NewAction> newActionEntityRefactoringService;
@ -151,7 +153,8 @@ public class RefactoringSolutionCEImpl implements RefactoringSolutionCE {
service.sanitizeRefactorEntityDTO(refactorEntityNameDTO); service.sanitizeRefactorEntityDTO(refactorEntityNameDTO);
// Validate whether this name is allowed based on the type of entity // Validate whether this name is allowed based on the type of entity
Mono<Boolean> isValidNameMono = service.validateName(refactorEntityNameDTO.getNewName()) Mono<Boolean> isValidNameMono = Mono.just(
entityValidationService.validateName(refactorEntityNameDTO.getNewName()))
.flatMap(isValid -> { .flatMap(isValid -> {
if (!isValid) { if (!isValid) {
return Mono.error(new AppsmithException(AppsmithError.INVALID_ACTION_NAME)); return Mono.error(new AppsmithException(AppsmithError.INVALID_ACTION_NAME));

View File

@ -11,15 +11,16 @@ import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.ApplicationService; import com.appsmith.server.services.ApplicationService;
import com.appsmith.server.services.SessionUserService; import com.appsmith.server.services.SessionUserService;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
import com.appsmith.server.validations.EntityValidationService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.reactive.TransactionalOperator; import org.springframework.transaction.reactive.TransactionalOperator;
@Service @Service
@Slf4j @Slf4j
public class RefactoringSolutionImpl extends RefactoringSolutionCEImpl implements RefactoringSolution { public class RefactoringServiceImpl extends RefactoringServiceCEImpl implements RefactoringService {
public RefactoringSolutionImpl( public RefactoringServiceImpl(
NewPageService newPageService, NewPageService newPageService,
ResponseUtils responseUtils, ResponseUtils responseUtils,
UpdateLayoutService updateLayoutService, UpdateLayoutService updateLayoutService,
@ -28,6 +29,7 @@ public class RefactoringSolutionImpl extends RefactoringSolutionCEImpl implement
AnalyticsService analyticsService, AnalyticsService analyticsService,
SessionUserService sessionUserService, SessionUserService sessionUserService,
TransactionalOperator transactionalOperator, TransactionalOperator transactionalOperator,
EntityValidationService entityValidationService,
EntityRefactoringService<Void> jsActionEntityRefactoringService, EntityRefactoringService<Void> jsActionEntityRefactoringService,
EntityRefactoringService<NewAction> newActionEntityRefactoringService, EntityRefactoringService<NewAction> newActionEntityRefactoringService,
EntityRefactoringService<ActionCollection> actionCollectionEntityRefactoringService, EntityRefactoringService<ActionCollection> actionCollectionEntityRefactoringService,
@ -41,6 +43,7 @@ public class RefactoringSolutionImpl extends RefactoringSolutionCEImpl implement
analyticsService, analyticsService,
sessionUserService, sessionUserService,
transactionalOperator, transactionalOperator,
entityValidationService,
jsActionEntityRefactoringService, jsActionEntityRefactoringService,
newActionEntityRefactoringService, newActionEntityRefactoringService,
actionCollectionEntityRefactoringService, actionCollectionEntityRefactoringService,

View File

@ -1,3 +0,0 @@
package com.appsmith.server.refactors.applications;
public interface RefactoringSolution extends RefactoringSolutionCE {}

View File

@ -17,8 +17,6 @@ public interface EntityRefactoringServiceCE<T> {
refactorEntityNameDTO.setNewFullyQualifiedName(refactorEntityNameDTO.getNewName()); refactorEntityNameDTO.setNewFullyQualifiedName(refactorEntityNameDTO.getNewName());
} }
Mono<Boolean> validateName(String newName);
Mono<Void> refactorReferencesInExistingEntities( Mono<Void> refactorReferencesInExistingEntities(
RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO); RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO);

View File

@ -5,7 +5,7 @@ import com.appsmith.server.helpers.ResponseUtils;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.services.ce.LayoutActionServiceCEImpl;
import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.ActionPermission;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
@ -20,7 +20,7 @@ public class LayoutActionServiceImpl extends LayoutActionServiceCEImpl implement
AnalyticsService analyticsService, AnalyticsService analyticsService,
NewPageService newPageService, NewPageService newPageService,
NewActionService newActionService, NewActionService newActionService,
RefactoringSolution refactoringSolution, RefactoringService refactoringService,
CollectionService collectionService, CollectionService collectionService,
UpdateLayoutService updateLayoutService, UpdateLayoutService updateLayoutService,
ResponseUtils responseUtils, ResponseUtils responseUtils,
@ -31,7 +31,7 @@ public class LayoutActionServiceImpl extends LayoutActionServiceCEImpl implement
analyticsService, analyticsService,
newPageService, newPageService,
newActionService, newActionService,
refactoringSolution, refactoringService,
collectionService, collectionService,
updateLayoutService, updateLayoutService,
responseUtils, responseUtils,

View File

@ -5,7 +5,7 @@ import com.appsmith.server.helpers.ResponseUtils;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.repositories.ActionCollectionRepository;
import com.appsmith.server.services.ce.LayoutCollectionServiceCEImpl; import com.appsmith.server.services.ce.LayoutCollectionServiceCEImpl;
import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.ActionPermission;
@ -21,7 +21,7 @@ public class LayoutCollectionServiceImpl extends LayoutCollectionServiceCEImpl i
NewPageService newPageService, NewPageService newPageService,
LayoutActionService layoutActionService, LayoutActionService layoutActionService,
UpdateLayoutService updateLayoutService, UpdateLayoutService updateLayoutService,
RefactoringSolution refactoringSolution, RefactoringService refactoringService,
ActionCollectionService actionCollectionService, ActionCollectionService actionCollectionService,
NewActionService newActionService, NewActionService newActionService,
AnalyticsService analyticsService, AnalyticsService analyticsService,
@ -33,7 +33,7 @@ public class LayoutCollectionServiceImpl extends LayoutCollectionServiceCEImpl i
newPageService, newPageService,
layoutActionService, layoutActionService,
updateLayoutService, updateLayoutService,
refactoringSolution, refactoringService,
actionCollectionService, actionCollectionService,
newActionService, newActionService,
analyticsService, analyticsService,

View File

@ -21,7 +21,7 @@ import com.appsmith.server.helpers.ResponseUtils;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.AnalyticsService;
import com.appsmith.server.services.CollectionService; import com.appsmith.server.services.CollectionService;
import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.ActionPermission;
@ -44,7 +44,7 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
private final AnalyticsService analyticsService; private final AnalyticsService analyticsService;
private final NewPageService newPageService; private final NewPageService newPageService;
private final NewActionService newActionService; private final NewActionService newActionService;
private final RefactoringSolution refactoringSolution; private final RefactoringService refactoringService;
private final CollectionService collectionService; private final CollectionService collectionService;
private final UpdateLayoutService updateLayoutService; private final UpdateLayoutService updateLayoutService;
private final ResponseUtils responseUtils; private final ResponseUtils responseUtils;
@ -396,7 +396,7 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE {
String name = action.getValidName(); String name = action.getValidName();
CreatorContextType contextType = CreatorContextType contextType =
action.getContextType() == null ? CreatorContextType.PAGE : action.getContextType(); 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 -> { .flatMap(nameAllowed -> {
// If the name is allowed, return pageMono for further processing // If the name is allowed, return pageMono for further processing

View File

@ -19,7 +19,7 @@ import com.appsmith.server.helpers.ResponseUtils;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.repositories.ActionCollectionRepository;
import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.LayoutActionService; import com.appsmith.server.services.LayoutActionService;
@ -52,7 +52,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE
private final NewPageService newPageService; private final NewPageService newPageService;
private final LayoutActionService layoutActionService; private final LayoutActionService layoutActionService;
private final UpdateLayoutService updateLayoutService; private final UpdateLayoutService updateLayoutService;
private final RefactoringSolution refactoringSolution; private final RefactoringService refactoringService;
private final ActionCollectionService actionCollectionService; private final ActionCollectionService actionCollectionService;
private final NewActionService newActionService; private final NewActionService newActionService;
private final AnalyticsService analyticsService; private final AnalyticsService analyticsService;
@ -96,7 +96,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE
CreatorContextType contextType = CreatorContextType contextType =
collection.getContextType() == null ? CreatorContextType.PAGE : collection.getContextType(); collection.getContextType() == null ? CreatorContextType.PAGE : collection.getContextType();
// Check against widget names and action names // Check against widget names and action names
return refactoringSolution.isNameAllowed( return refactoringService.isNameAllowed(
page.getId(), contextType, layout.getId(), collection.getName()); page.getId(), contextType, layout.getId(), collection.getName());
}) })
.flatMap(isNameAllowed -> { .flatMap(isNameAllowed -> {

View File

@ -0,0 +1,3 @@
package com.appsmith.server.validations;
public interface EntityValidationService extends EntityValidationServiceCE {}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,6 @@
package com.appsmith.server.validations;
import org.springframework.stereotype.Service;
@Service
public class EntityValidationServiceImpl extends EntityValidationServiceCEImpl implements EntityValidationService {}

View File

@ -53,11 +53,6 @@ public class WidgetRefactoringServiceCEImpl implements EntityRefactoringServiceC
return REFACTOR_WIDGET; return REFACTOR_WIDGET;
} }
@Override
public Mono<Boolean> validateName(String name) {
return Mono.just(Boolean.TRUE);
}
@Override @Override
public Mono<Void> refactorReferencesInExistingEntities( public Mono<Void> refactorReferencesInExistingEntities(
RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) { RefactorEntityNameDTO refactorEntityNameDTO, RefactoringMetaDTO refactoringMetaDTO) {

View File

@ -19,7 +19,7 @@ import com.appsmith.server.imports.internal.ImportApplicationService;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.NewActionRepository;
import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.repositories.PluginRepository;
import com.appsmith.server.services.ApplicationPageService; import com.appsmith.server.services.ApplicationPageService;
@ -86,7 +86,7 @@ public class RefactoringSolutionTest {
UpdateLayoutService updateLayoutService; UpdateLayoutService updateLayoutService;
@Autowired @Autowired
RefactoringSolution refactoringSolution; RefactoringService refactoringService;
@Autowired @Autowired
LayoutCollectionService layoutCollectionService; LayoutCollectionService layoutCollectionService;
@ -249,7 +249,7 @@ public class RefactoringSolutionTest {
Mockito.when(actionCollectionService.getActionCollectionsByViewMode(Mockito.any(), Mockito.anyBoolean())) Mockito.when(actionCollectionService.getActionCollectionsByViewMode(Mockito.any(), Mockito.anyBoolean()))
.thenReturn(Flux.just(mockActionCollectionDTO)); .thenReturn(Flux.just(mockActionCollectionDTO));
Mono<Boolean> nameAllowedMono = refactoringSolution.isNameAllowed( Mono<Boolean> nameAllowedMono = refactoringService.isNameAllowed(
testPage.getId(), testPage.getId(),
CreatorContextType.PAGE, CreatorContextType.PAGE,
testPage.getLayouts().get(0).getId(), testPage.getLayouts().get(0).getId(),
@ -284,7 +284,7 @@ public class RefactoringSolutionTest {
Mockito.when(actionCollectionService.getActionCollectionsByViewMode(Mockito.any(), Mockito.anyBoolean())) Mockito.when(actionCollectionService.getActionCollectionsByViewMode(Mockito.any(), Mockito.anyBoolean()))
.thenReturn(Flux.just(mockActionCollectionDTO)); .thenReturn(Flux.just(mockActionCollectionDTO));
Mono<Boolean> nameAllowedMono = refactoringSolution.isNameAllowed( Mono<Boolean> nameAllowedMono = refactoringService.isNameAllowed(
testPage.getId(), testPage.getId(),
CreatorContextType.PAGE, CreatorContextType.PAGE,
testPage.getLayouts().get(0).getId(), testPage.getLayouts().get(0).getId(),

View File

@ -24,7 +24,7 @@ import com.appsmith.server.helpers.ResponseUtils;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.repositories.ActionCollectionRepository;
import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.ActionPermission;
import com.appsmith.server.solutions.ActionPermissionImpl; import com.appsmith.server.solutions.ActionPermissionImpl;
@ -87,7 +87,7 @@ public class ActionCollectionServiceImplTest {
UpdateLayoutService updateLayoutService; UpdateLayoutService updateLayoutService;
@MockBean @MockBean
RefactoringSolution refactoringSolution; RefactoringService refactoringService;
@MockBean @MockBean
ActionCollectionRepository actionCollectionRepository; ActionCollectionRepository actionCollectionRepository;
@ -146,7 +146,7 @@ public class ActionCollectionServiceImplTest {
newPageService, newPageService,
layoutActionService, layoutActionService,
updateLayoutService, updateLayoutService,
refactoringSolution, refactoringService,
actionCollectionService, actionCollectionService,
newActionService, newActionService,
analyticsService, analyticsService,
@ -234,7 +234,7 @@ public class ActionCollectionServiceImplTest {
final NewPage newPage = objectMapper.convertValue(jsonNode.get("newPage"), NewPage.class); final NewPage newPage = objectMapper.convertValue(jsonNode.get("newPage"), NewPage.class);
Mockito.when(newPageService.findById(Mockito.any(), Mockito.<AclPermission>any())) Mockito.when(newPageService.findById(Mockito.any(), Mockito.<AclPermission>any()))
.thenReturn(Mono.just(newPage)); .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)); .thenReturn(Mono.just(false));
Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch(
@ -275,7 +275,7 @@ public class ActionCollectionServiceImplTest {
Mockito.when(newPageService.findById(Mockito.any(), Mockito.<AclPermission>any())) Mockito.when(newPageService.findById(Mockito.any(), Mockito.<AclPermission>any()))
.thenReturn(Mono.just(newPage)); .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)); .thenReturn(Mono.just(true));
Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch(
@ -340,7 +340,7 @@ public class ActionCollectionServiceImplTest {
Mockito.when(newPageService.findById(Mockito.any(), Mockito.<AclPermission>any())) Mockito.when(newPageService.findById(Mockito.any(), Mockito.<AclPermission>any()))
.thenReturn(Mono.just(newPage)); .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)); .thenReturn(Mono.just(true));
Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch( Mockito.when(actionCollectionRepository.findAllActionCollectionsByNamePageIdsViewModeAndBranch(

View File

@ -29,7 +29,7 @@ import com.appsmith.server.helpers.PluginExecutorHelper;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; import com.appsmith.server.newpages.base.NewPageService;
import com.appsmith.server.plugins.base.PluginService; 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.ActionCollectionRepository;
import com.appsmith.server.repositories.PermissionGroupRepository; import com.appsmith.server.repositories.PermissionGroupRepository;
import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.repositories.PluginRepository;
@ -91,7 +91,7 @@ public class ActionCollectionServiceTest {
LayoutActionService layoutActionService; LayoutActionService layoutActionService;
@Autowired @Autowired
RefactoringSolution refactoringSolution; RefactoringService refactoringService;
@Autowired @Autowired
NewPageService newPageService; NewPageService newPageService;
@ -411,7 +411,7 @@ public class ActionCollectionServiceTest {
refactorActionNameDTO.setOldName("testAction1"); refactorActionNameDTO.setOldName("testAction1");
refactorActionNameDTO.setNewName("newTestAction1"); refactorActionNameDTO.setNewName("newTestAction1");
final LayoutDTO layoutDTO = refactoringSolution final LayoutDTO layoutDTO = refactoringService
.refactorEntityName(refactorActionNameDTO, null) .refactorEntityName(refactorActionNameDTO, null)
.block(); .block();
@ -503,7 +503,7 @@ public class ActionCollectionServiceTest {
refactorActionNameDTO.setOldName("run"); refactorActionNameDTO.setOldName("run");
refactorActionNameDTO.setNewName("newRun"); refactorActionNameDTO.setNewName("newRun");
final LayoutDTO layoutDTO = refactoringSolution final LayoutDTO layoutDTO = refactoringService
.refactorEntityName(refactorActionNameDTO, null) .refactorEntityName(refactorActionNameDTO, null)
.block(); .block();

View File

@ -31,7 +31,7 @@ import com.appsmith.server.imports.internal.ImportApplicationService;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.NewActionRepository;
import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.repositories.PluginRepository;
import com.appsmith.server.solutions.ApplicationPermission; import com.appsmith.server.solutions.ApplicationPermission;
@ -109,7 +109,7 @@ public class LayoutActionServiceTest {
UpdateLayoutService updateLayoutService; UpdateLayoutService updateLayoutService;
@Autowired @Autowired
RefactoringSolution refactoringSolution; RefactoringService refactoringService;
@Autowired @Autowired
LayoutCollectionService layoutCollectionService; LayoutCollectionService layoutCollectionService;
@ -1288,7 +1288,7 @@ public class LayoutActionServiceTest {
refactorActionNameDTO.setPageId(testPage.getId()); refactorActionNameDTO.setPageId(testPage.getId());
refactorActionNameDTO.setActionId(createdAction.getId()); refactorActionNameDTO.setActionId(createdAction.getId());
Mono<LayoutDTO> layoutDTOMono = refactoringSolution.refactorEntityName(refactorActionNameDTO, null); Mono<LayoutDTO> layoutDTOMono = refactoringService.refactorEntityName(refactorActionNameDTO, null);
StepVerifier.create(layoutDTOMono.map( StepVerifier.create(layoutDTOMono.map(
layoutDTO -> layoutDTO.getLayoutOnLoadActionErrors().size())) layoutDTO -> layoutDTO.getLayoutOnLoadActionErrors().size()))
.expectNext(1) .expectNext(1)

View File

@ -24,6 +24,7 @@ import com.appsmith.server.solutions.ApplicationPermission;
import com.appsmith.server.solutions.DatasourcePermission; import com.appsmith.server.solutions.DatasourcePermission;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
import com.appsmith.server.solutions.PolicySolution; import com.appsmith.server.solutions.PolicySolution;
import com.appsmith.server.validations.EntityValidationService;
import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.ObservationRegistry;
import jakarta.validation.Validator; import jakarta.validation.Validator;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -110,6 +111,9 @@ public class NewActionServiceUnitTest {
@MockBean @MockBean
PagePermission pagePermission; PagePermission pagePermission;
@MockBean
EntityValidationService entityValidationService;
ActionPermission actionPermission = new ActionPermissionImpl(); ActionPermission actionPermission = new ActionPermissionImpl();
@MockBean @MockBean
@ -139,11 +143,13 @@ public class NewActionServiceUnitTest {
applicationPermission, applicationPermission,
pagePermission, pagePermission,
actionPermission, actionPermission,
entityValidationService,
observationRegistry); observationRegistry);
ObservationRegistry.ObservationConfig mockObservationConfig = ObservationRegistry.ObservationConfig mockObservationConfig =
Mockito.mock(ObservationRegistry.ObservationConfig.class); Mockito.mock(ObservationRegistry.ObservationConfig.class);
Mockito.when(observationRegistry.observationConfig()).thenReturn(mockObservationConfig); Mockito.when(observationRegistry.observationConfig()).thenReturn(mockObservationConfig);
Mockito.doReturn(true).when(entityValidationService).validateName(Mockito.anyString());
} }
@Test @Test

View File

@ -19,7 +19,7 @@ import com.appsmith.server.helpers.ResponseUtils;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.refactors.entities.EntityRefactoringService;
import com.appsmith.server.repositories.ActionCollectionRepository; import com.appsmith.server.repositories.ActionCollectionRepository;
import com.appsmith.server.services.AnalyticsService; 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.services.SessionUserService;
import com.appsmith.server.solutions.ActionPermission; import com.appsmith.server.solutions.ActionPermission;
import com.appsmith.server.solutions.PagePermission; import com.appsmith.server.solutions.PagePermission;
import com.appsmith.server.validations.EntityValidationService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.minidev.json.JSONObject; import net.minidev.json.JSONObject;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -54,8 +55,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@Slf4j @Slf4j
@SpringBootTest @SpringBootTest
class RefactoringSolutionCEImplTest { class RefactoringServiceCEImplTest {
RefactoringSolutionCEImpl refactoringSolutionCE; RefactoringServiceCEImpl refactoringServiceCE;
@Autowired @Autowired
PagePermission pagePermission; PagePermission pagePermission;
@ -102,12 +103,15 @@ class RefactoringSolutionCEImplTest {
@Autowired @Autowired
private TransactionalOperator transactionalOperator; private TransactionalOperator transactionalOperator;
@Autowired
private EntityValidationService entityValidationService;
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
Mockito.when(sessionUserService.getCurrentUser()).thenReturn(Mono.just(new User())); Mockito.when(sessionUserService.getCurrentUser()).thenReturn(Mono.just(new User()));
refactoringSolutionCE = new RefactoringSolutionCEImpl( refactoringServiceCE = new RefactoringServiceCEImpl(
newPageService, newPageService,
responseUtils, responseUtils,
updateLayoutService, updateLayoutService,
@ -116,6 +120,7 @@ class RefactoringSolutionCEImplTest {
analyticsService, analyticsService,
sessionUserService, sessionUserService,
transactionalOperator, transactionalOperator,
entityValidationService,
jsActionEntityRefactoringService, jsActionEntityRefactoringService,
newActionEntityRefactoringService, newActionEntityRefactoringService,
actionCollectionEntityRefactoringService, actionCollectionEntityRefactoringService,
@ -188,7 +193,7 @@ class RefactoringSolutionCEImplTest {
.getExistingEntityNames(Mockito.anyString(), Mockito.any(), Mockito.anyString()); .getExistingEntityNames(Mockito.anyString(), Mockito.any(), Mockito.anyString());
final Mono<LayoutDTO> layoutDTOMono = final Mono<LayoutDTO> layoutDTOMono =
refactoringSolutionCE.refactorEntityName(refactorActionCollectionNameDTO, null); refactoringServiceCE.refactorEntityName(refactorActionCollectionNameDTO, null);
StepVerifier.create(layoutDTOMono) StepVerifier.create(layoutDTOMono)
.assertNext(layoutDTO -> { .assertNext(layoutDTO -> {
@ -241,7 +246,7 @@ class RefactoringSolutionCEImplTest {
Mockito.when(newPageService.getById(Mockito.anyString())).thenReturn(Mono.just(newPage)); Mockito.when(newPageService.getById(Mockito.anyString())).thenReturn(Mono.just(newPage));
final Mono<LayoutDTO> layoutDTOMono = final Mono<LayoutDTO> layoutDTOMono =
refactoringSolutionCE.refactorEntityName(refactorActionCollectionNameDTO, null); refactoringServiceCE.refactorEntityName(refactorActionCollectionNameDTO, null);
StepVerifier.create(layoutDTOMono) StepVerifier.create(layoutDTOMono)
.expectErrorMatches(e -> AppsmithError.NAME_CLASH_NOT_ALLOWED_IN_REFACTOR .expectErrorMatches(e -> AppsmithError.NAME_CLASH_NOT_ALLOWED_IN_REFACTOR
@ -330,7 +335,7 @@ class RefactoringSolutionCEImplTest {
.getExistingEntityNames(Mockito.anyString(), Mockito.any(), Mockito.anyString()); .getExistingEntityNames(Mockito.anyString(), Mockito.any(), Mockito.anyString());
final Mono<LayoutDTO> layoutDTOMono = final Mono<LayoutDTO> layoutDTOMono =
refactoringSolutionCE.refactorEntityName(refactorActionCollectionNameDTO, null); refactoringServiceCE.refactorEntityName(refactorActionCollectionNameDTO, null);
StepVerifier.create(layoutDTOMono) StepVerifier.create(layoutDTOMono)
.assertNext(layoutDTO -> { .assertNext(layoutDTO -> {

View File

@ -30,7 +30,7 @@ import com.appsmith.server.imports.internal.ImportApplicationService;
import com.appsmith.server.layouts.UpdateLayoutService; import com.appsmith.server.layouts.UpdateLayoutService;
import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newactions.base.NewActionService;
import com.appsmith.server.newpages.base.NewPageService; 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.NewActionRepository;
import com.appsmith.server.repositories.PluginRepository; import com.appsmith.server.repositories.PluginRepository;
import com.appsmith.server.services.ApplicationPageService; import com.appsmith.server.services.ApplicationPageService;
@ -79,7 +79,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest @SpringBootTest
@Slf4j @Slf4j
@DirtiesContext @DirtiesContext
class RefactoringSolutionCETest { class RefactoringServiceCETest {
@SpyBean @SpyBean
NewActionService newActionService; NewActionService newActionService;
@ -106,7 +106,7 @@ class RefactoringSolutionCETest {
UpdateLayoutService updateLayoutService; UpdateLayoutService updateLayoutService;
@Autowired @Autowired
RefactoringSolution refactoringSolution; RefactoringService refactoringService;
@Autowired @Autowired
LayoutCollectionService layoutCollectionService; LayoutCollectionService layoutCollectionService;
@ -307,7 +307,7 @@ class RefactoringSolutionCETest {
refactorActionNameDTO.setNewName("PostNameChange"); refactorActionNameDTO.setNewName("PostNameChange");
refactorActionNameDTO.setActionId(createdAction.getId()); refactorActionNameDTO.setActionId(createdAction.getId());
LayoutDTO postNameChangeLayout = refactoringSolution LayoutDTO postNameChangeLayout = refactoringService
.refactorEntityName(refactorActionNameDTO, null) .refactorEntityName(refactorActionNameDTO, null)
.block(); .block();
@ -383,7 +383,7 @@ class RefactoringSolutionCETest {
refactorActionNameDTO.setNewName("PostNameChange"); refactorActionNameDTO.setNewName("PostNameChange");
refactorActionNameDTO.setActionId(createdAction.getId()); refactorActionNameDTO.setActionId(createdAction.getId());
LayoutDTO postNameChangeLayout = refactoringSolution LayoutDTO postNameChangeLayout = refactoringService
.refactorEntityName(refactorActionNameDTO, null) .refactorEntityName(refactorActionNameDTO, null)
.block(); .block();
@ -460,7 +460,7 @@ class RefactoringSolutionCETest {
refactorActionNameDTO.setNewName("NewActionName"); refactorActionNameDTO.setNewName("NewActionName");
refactorActionNameDTO.setActionId(firstAction.getId()); refactorActionNameDTO.setActionId(firstAction.getId());
refactoringSolution.refactorEntityName(refactorActionNameDTO, null).block(); refactoringService.refactorEntityName(refactorActionNameDTO, null).block();
Mono<NewAction> postNameChangeActionMono = newActionService.findById(secondAction.getId(), READ_ACTIONS); Mono<NewAction> postNameChangeActionMono = newActionService.findById(secondAction.getId(), READ_ACTIONS);
@ -513,7 +513,7 @@ class RefactoringSolutionCETest {
assert createdAction != null; assert createdAction != null;
refactorActionNameDTO.setActionId(createdAction.getId()); refactorActionNameDTO.setActionId(createdAction.getId());
final Mono<LayoutDTO> layoutDTOMono = refactoringSolution.refactorEntityName(refactorActionNameDTO, null); final Mono<LayoutDTO> layoutDTOMono = refactoringService.refactorEntityName(refactorActionNameDTO, null);
StepVerifier.create(layoutDTOMono) StepVerifier.create(layoutDTOMono)
.expectErrorMatches(e -> e instanceof AppsmithException .expectErrorMatches(e -> e instanceof AppsmithException
@ -585,7 +585,7 @@ class RefactoringSolutionCETest {
refactorActionNameDTO.setNewName("newName"); refactorActionNameDTO.setNewName("newName");
refactorActionNameDTO.setActionId(firstAction.getId()); refactorActionNameDTO.setActionId(firstAction.getId());
LayoutDTO postNameChangeLayout = refactoringSolution LayoutDTO postNameChangeLayout = refactoringService
.refactorEntityName(refactorActionNameDTO, null) .refactorEntityName(refactorActionNameDTO, null)
.block(); .block();
@ -638,7 +638,7 @@ class RefactoringSolutionCETest {
refactorNameDTO.setNewName("NewNameTable1"); refactorNameDTO.setNewName("NewNameTable1");
Mono<LayoutDTO> widgetRenameMono = Mono<LayoutDTO> widgetRenameMono =
refactoringSolution.refactorEntityName(refactorNameDTO, null).cache(); refactoringService.refactorEntityName(refactorNameDTO, null).cache();
Mono<PageDTO> pageFromRepoMono = Mono<PageDTO> pageFromRepoMono =
widgetRenameMono.then(newPageService.findPageById(testPage.getId(), READ_PAGES, false)); widgetRenameMono.then(newPageService.findPageById(testPage.getId(), READ_PAGES, false));
@ -688,7 +688,7 @@ class RefactoringSolutionCETest {
refactorNameDTO.setNewName("NewNameTable1"); refactorNameDTO.setNewName("NewNameTable1");
Mono<LayoutDTO> widgetRenameMono = Mono<LayoutDTO> widgetRenameMono =
refactoringSolution.refactorEntityName(refactorNameDTO, null).cache(); refactoringService.refactorEntityName(refactorNameDTO, null).cache();
Mono<PageDTO> pageFromRepoMono = Mono<PageDTO> pageFromRepoMono =
widgetRenameMono.then(newPageService.findPageById(testPage.getId(), READ_PAGES, false)); widgetRenameMono.then(newPageService.findPageById(testPage.getId(), READ_PAGES, false));
@ -740,7 +740,7 @@ class RefactoringSolutionCETest {
refactorNameDTO.setOldName("oldWidgetName"); refactorNameDTO.setOldName("oldWidgetName");
refactorNameDTO.setNewName("newWidgetName"); refactorNameDTO.setNewName("newWidgetName");
Mono<LayoutDTO> widgetRenameMono = refactoringSolution.refactorEntityName(refactorNameDTO, null); Mono<LayoutDTO> widgetRenameMono = refactoringService.refactorEntityName(refactorNameDTO, null);
StepVerifier.create(widgetRenameMono) StepVerifier.create(widgetRenameMono)
.assertNext(updatedLayout -> { .assertNext(updatedLayout -> {
@ -801,7 +801,7 @@ class RefactoringSolutionCETest {
refactorNameDTO.setNewName("NewNameTable1"); refactorNameDTO.setNewName("NewNameTable1");
LayoutDTO updatedLayout = LayoutDTO updatedLayout =
refactoringSolution.refactorEntityName(refactorNameDTO, null).block(); refactoringService.refactorEntityName(refactorNameDTO, null).block();
assert createdActionCollectionDTO1 != null; assert createdActionCollectionDTO1 != null;
final Mono<ActionCollection> actionCollectionMono = final Mono<ActionCollection> actionCollectionMono =
@ -873,7 +873,7 @@ class RefactoringSolutionCETest {
refactorActionNameInCollectionDTO.setNewName("newTestAction"); refactorActionNameInCollectionDTO.setNewName("newTestAction");
refactorActionNameInCollectionDTO.setCollectionName("originalName"); refactorActionNameInCollectionDTO.setCollectionName("originalName");
final Mono<Tuple2<ActionCollection, NewAction>> tuple2Mono = refactoringSolution final Mono<Tuple2<ActionCollection, NewAction>> tuple2Mono = refactoringService
.refactorEntityName(refactorActionNameInCollectionDTO, null) .refactorEntityName(refactorActionNameInCollectionDTO, null)
.then(actionCollectionService .then(actionCollectionService
.getById(dto.getId()) .getById(dto.getId())