From bcf75900ae0580121da9578ced570ca188926d2c Mon Sep 17 00:00:00 2001 From: Nidhi Date: Thu, 23 Nov 2023 13:59:13 +0530 Subject: [PATCH] chore: Split get existing entities for refactor (#29055) --- ...ionCollectionRefactoringServiceCEImpl.java | 54 ++++++++++++------- .../NewActionRefactoringServiceCEImpl.java | 10 ++-- 2 files changed, 43 insertions(+), 21 deletions(-) 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 fcf45a2f9f..798c5bf5a5 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 @@ -68,21 +68,10 @@ public class ActionCollectionRefactoringServiceCEImpl implements EntityRefactori .flatMap(actionCollection -> { final ActionCollectionDTO unpublishedCollection = actionCollection.getUnpublishedCollection(); - return astService - .replaceValueInMustacheKeys( - new HashSet<>(Collections.singletonList( - new MustacheBindingToken(unpublishedCollection.getBody(), 0, true))), - oldName, - newName, - evalVersion, - oldNamePattern, - true) - .flatMap(replacedMap -> { - Optional replacedValue = - replacedMap.values().stream().findFirst(); - // This value should always be there - if (replacedValue.isPresent()) { - unpublishedCollection.setBody(replacedValue.get()); + return this.refactorNameInActionCollection( + unpublishedCollection, oldName, newName, evalVersion, oldNamePattern) + .flatMap(isPresent -> { + if (Boolean.TRUE.equals(isPresent)) { return actionCollectionService.save(actionCollection); } return Mono.just(actionCollection); @@ -93,6 +82,32 @@ public class ActionCollectionRefactoringServiceCEImpl implements EntityRefactori return actionCollectionsMono.then(); } + protected Mono refactorNameInActionCollection( + ActionCollectionDTO unpublishedCollection, + String oldName, + String newName, + int evalVersion, + Pattern oldNamePattern) { + return astService + .replaceValueInMustacheKeys( + new HashSet<>(Collections.singletonList( + new MustacheBindingToken(unpublishedCollection.getBody(), 0, true))), + oldName, + newName, + evalVersion, + oldNamePattern, + true) + .map(replacedMap -> { + Optional replacedValue = + replacedMap.values().stream().findFirst(); + // This value should always be there + if (replacedValue.isPresent()) { + unpublishedCollection.setBody(replacedValue.get()); + } + return replacedValue.isPresent(); + }); + } + @Override public Mono updateRefactoredEntity(RefactorEntityNameDTO refactorEntityNameDTO, String branchName) { String newName = refactorEntityNameDTO.getNewName(); @@ -145,12 +160,15 @@ public class ActionCollectionRefactoringServiceCEImpl implements EntityRefactori @Override public Flux getExistingEntityNames(String contextId, CreatorContextType contextType, String layoutId) { + return getExistingEntities(contextId, contextType, layoutId).map(ActionCollectionDTO::getName); + } + + protected Flux getExistingEntities( + String contextId, CreatorContextType contextType, String layoutId) { MultiValueMap params = new LinkedMultiValueMap<>(); if (StringUtils.hasText(contextId)) { params.add(FieldName.PAGE_ID, contextId); } - return actionCollectionService - .getActionCollectionsByViewMode(params, false) - .map(ActionCollectionDTO::getName); + return actionCollectionService.getActionCollectionsByViewMode(params, false); } } 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 9cffe38470..9dcd788424 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 @@ -133,12 +133,16 @@ public class NewActionRefactoringServiceCEImpl implements EntityRefactoringServi @Override public Flux getExistingEntityNames(String contextId, CreatorContextType contextType, String layoutId) { + return this.getExistingEntities(contextId, contextType, layoutId).map(ActionDTO::getValidName); + } + + protected Flux getExistingEntities(String contextId, CreatorContextType contextType, String layoutId) { MultiValueMap params = new LinkedMultiValueMap<>(); if (contextId != null) { params.add(FieldName.PAGE_ID, contextId); } - return newActionService + Flux actionDTOFlux = newActionService .getUnpublishedActions(params) .flatMap(actionDTO -> { /* @@ -158,8 +162,8 @@ public class NewActionRefactoringServiceCEImpl implements EntityRefactoringServi } else { return Mono.just(actionDTO); } - }) - .map(ActionDTO::getValidName); + }); + return actionDTOFlux; } protected Mono> refactorNameInAction(