From da2e1c2822003942f772c61fa2c17ba4d2740bd4 Mon Sep 17 00:00:00 2001 From: subratadeypappu Date: Tue, 28 Nov 2023 11:14:27 +0600 Subject: [PATCH] chore: Split update layout (#29149) --- .../server/layouts/UpdateLayoutServiceCE.java | 2 + .../layouts/UpdateLayoutServiceCEImpl.java | 18 ++++++++ .../services/ce/LayoutActionServiceCE.java | 2 - .../ce/LayoutActionServiceCEImpl.java | 46 ++++++------------- .../ce/LayoutCollectionServiceCEImpl.java | 4 +- .../ActionCollectionServiceImplTest.java | 6 +-- .../services/LayoutActionServiceTest.java | 14 +++--- .../services/ce/ActionServiceCE_Test.java | 6 +-- 8 files changed, 50 insertions(+), 48 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCE.java index c859c28656..6d53ad2fbc 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCE.java @@ -16,4 +16,6 @@ public interface UpdateLayoutServiceCE { String defaultApplicationId, String branchName, UpdateMultiplePageLayoutDTO updateMultiplePageLayoutDTO); JSONObject unescapeMongoSpecialCharacters(Layout layout); + + Mono updatePageLayoutsByPageId(String pageId); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java index dc92c260ec..c519221c7c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/layouts/UpdateLayoutServiceCEImpl.java @@ -285,6 +285,24 @@ public class UpdateLayoutServiceCEImpl implements UpdateLayoutServiceCE { return dsl; } + @Override + public Mono updatePageLayoutsByPageId(String pageId) { + return Mono.justOrEmpty(pageId) + // fetch the unpublished page + .flatMap(id -> newPageService.findPageById(id, pagePermission.getEditPermission(), false)) + .flatMapMany(page -> { + if (page.getLayouts() == null) { + return Mono.empty(); + } + return Flux.fromIterable(page.getLayouts()).flatMap(layout -> { + layout.setDsl(this.unescapeMongoSpecialCharacters(layout)); + return this.updateLayout(page.getId(), page.getApplicationId(), layout.getId(), layout); + }); + }) + .collectList() + .then(Mono.just(pageId)); + } + private JSONObject unEscapeDslKeys(JSONObject dsl, Set escapedWidgetNames) { String widgetName = (String) dsl.get(FieldName.WIDGET_NAME); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java index 5af6adeef2..ebb438eb38 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/LayoutActionServiceCE.java @@ -15,8 +15,6 @@ public interface LayoutActionServiceCE { Mono updateSingleAction(String id, ActionDTO action); - Mono updatePageLayoutsByPageId(String pageId); - Mono updateSingleActionWithBranchName(String id, ActionDTO action, String branchName); Mono setExecuteOnLoad(String id, Boolean isExecuteOnLoad); 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 43a2f936b5..9bac89c814 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 @@ -74,9 +74,9 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { // The change was not in CollectionId, just go ahead and update normally if (action.getCollectionId() == null) { - return this.updateSingleAction(id, action) - .flatMap(updatedAction -> this.updatePageLayoutsByPageId(updatedAction.getPageId()) - .thenReturn(updatedAction)); + return this.updateSingleAction(id, action).flatMap(updatedAction -> updateLayoutService + .updatePageLayoutsByPageId(updatedAction.getPageId()) + .thenReturn(updatedAction)); } else if (action.getCollectionId().length() == 0) { // The Action has been removed from existing collection. return newActionService @@ -86,9 +86,9 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { .flatMap(action1 -> { log.debug("Action {} has been removed from its collection.", action1.getId()); action.setCollectionId(null); - return this.updateSingleAction(id, action) - .flatMap(updatedAction -> this.updatePageLayoutsByPageId(updatedAction.getPageId()) - .thenReturn(updatedAction)); + return this.updateSingleAction(id, action).flatMap(updatedAction -> updateLayoutService + .updatePageLayoutsByPageId(updatedAction.getPageId()) + .thenReturn(updatedAction)); }); } else { // If the code flow has reached this point, that means that the collectionId has been changed to another @@ -114,9 +114,9 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { log.debug( "Action {} removed from its previous collection and added to the new collection", action1.getId()); - return this.updateSingleAction(id, action) - .flatMap(updatedAction -> this.updatePageLayoutsByPageId(updatedAction.getPageId()) - .thenReturn(updatedAction)); + return this.updateSingleAction(id, action).flatMap(updatedAction -> updateLayoutService + .updatePageLayoutsByPageId(updatedAction.getPageId()) + .thenReturn(updatedAction)); }); } } @@ -260,7 +260,8 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { return newActionService .findByBranchNameAndDefaultActionId(branchName, defaultActionId, actionPermission.getEditPermission()) .flatMap(newAction -> updateSingleAction(newAction.getId(), action)) - .flatMap(updatedAction -> this.updatePageLayoutsByPageId(pageId).thenReturn(updatedAction)) + .flatMap(updatedAction -> + updateLayoutService.updatePageLayoutsByPageId(pageId).thenReturn(updatedAction)) .map(responseUtils::updateActionDTOWithDefaultResources) .zipWith( newPageService.findPageById(pageId, pagePermission.getEditPermission(), false), @@ -287,7 +288,8 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { newAction.setUnpublishedAction(action); - return newActionService.save(newAction).flatMap(savedAction -> updatePageLayoutsByPageId( + return newActionService.save(newAction).flatMap(savedAction -> updateLayoutService + .updatePageLayoutsByPageId( savedAction.getUnpublishedAction().getPageId()) .then(newActionService.generateActionByViewMode(savedAction, false))); }); @@ -308,7 +310,8 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { public Mono deleteUnpublishedAction(String id) { return newActionService .deleteUnpublishedAction(id) - .flatMap(actionDTO -> Mono.zip(Mono.just(actionDTO), updatePageLayoutsByPageId(actionDTO.getPageId()))) + .flatMap(actionDTO -> Mono.zip( + Mono.just(actionDTO), updateLayoutService.updatePageLayoutsByPageId(actionDTO.getPageId()))) .flatMap(tuple -> { ActionDTO actionDTO = tuple.getT1(); return Mono.just(actionDTO); @@ -322,25 +325,6 @@ public class LayoutActionServiceCEImpl implements LayoutActionServiceCE { .map(responseUtils::updateActionDTOWithDefaultResources); } - @Override - public Mono updatePageLayoutsByPageId(String pageId) { - return Mono.justOrEmpty(pageId) - // fetch the unpublished page - .flatMap(id -> newPageService.findPageById(id, pagePermission.getEditPermission(), false)) - .flatMapMany(page -> { - if (page.getLayouts() == null) { - return Mono.empty(); - } - return Flux.fromIterable(page.getLayouts()).flatMap(layout -> { - layout.setDsl(updateLayoutService.unescapeMongoSpecialCharacters(layout)); - return updateLayoutService.updateLayout( - page.getId(), page.getApplicationId(), layout.getId(), layout); - }); - }) - .collectList() - .then(Mono.just(pageId)); - } - @Override public Mono createSingleActionWithBranch(ActionDTO action, String branchName) { 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 b0bda45cc5..698776184e 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 @@ -231,7 +231,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE actionDTOList, false)); }) - .flatMap(updatedCollection -> layoutActionService + .flatMap(updatedCollection -> updateLayoutService .updatePageLayoutsByPageId(updatedCollection.getPageId()) .thenReturn(updatedCollection)); }); @@ -578,7 +578,7 @@ public class LayoutCollectionServiceCEImpl implements LayoutCollectionServiceCE }) .flatMap(actionCollection -> actionCollectionService.update(actionCollection.getId(), actionCollection)) .flatMap(actionCollectionRepository::setUserPermissionsInObject) - .flatMap(savedActionCollection -> layoutActionService + .flatMap(savedActionCollection -> updateLayoutService .updatePageLayoutsByPageId( savedActionCollection.getUnpublishedCollection().getPageId()) .thenReturn(savedActionCollection)) 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 2f286d685c..9630e99784 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 @@ -289,7 +289,7 @@ public class ActionCollectionServiceImplTest { Mockito.when(layoutActionService.createAction(Mockito.any())).thenReturn(Mono.just(new ActionDTO())); - Mockito.when(layoutActionService.updatePageLayoutsByPageId(Mockito.anyString())) + Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString())) .thenAnswer(invocationOnMock -> { return Mono.just(actionCollectionDTO.getPageId()); }); @@ -359,7 +359,7 @@ public class ActionCollectionServiceImplTest { return Mono.just(argument); }); - Mockito.when(layoutActionService.updatePageLayoutsByPageId(Mockito.anyString())) + Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString())) .thenAnswer(invocationOnMock -> { return Mono.just(actionCollectionDTO.getPageId()); }); @@ -530,7 +530,7 @@ public class ActionCollectionServiceImplTest { Mockito.when(actionCollectionRepository.setUserPermissionsInObject(Mockito.any())) .thenReturn(Mono.just(modifiedActionCollection)); - Mockito.when(layoutActionService.updatePageLayoutsByPageId(Mockito.anyString())) + Mockito.when(updateLayoutService.updatePageLayoutsByPageId(Mockito.anyString())) .thenAnswer(invocationOnMock -> { return Mono.just(actionCollection.getUnpublishedCollection().getPageId()); }); 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 a80b47fa4f..97fc7ebcd1 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 @@ -293,7 +293,7 @@ public class LayoutActionServiceTest { // Save updated configuration and re-compute on page load actions. return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }) @@ -362,7 +362,7 @@ public class LayoutActionServiceTest { updates.setDatasource(datasource); return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }) @@ -375,7 +375,7 @@ public class LayoutActionServiceTest { updates.setDatasource(datasource); return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }) @@ -390,7 +390,7 @@ public class LayoutActionServiceTest { updates.setDatasource(d2); return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }) @@ -564,7 +564,7 @@ public class LayoutActionServiceTest { updates.setDatasource(ds); return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }); @@ -836,7 +836,7 @@ public class LayoutActionServiceTest { // Save updated configuration and re-compute on page load actions. return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }) @@ -852,7 +852,7 @@ public class LayoutActionServiceTest { // Save updated configuration and re-compute on page load actions. return layoutActionService .updateSingleAction(savedAction.getId(), updates) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ActionServiceCE_Test.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ActionServiceCE_Test.java index 1daf5909ae..6bf9026b10 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ActionServiceCE_Test.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ActionServiceCE_Test.java @@ -848,7 +848,7 @@ public class ActionServiceCE_Test { actionUpdate.getActionConfiguration().setBody("New Body"); return layoutActionService .updateSingleAction(preUpdateAction.getId(), actionUpdate) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }); @@ -1069,7 +1069,7 @@ public class ActionServiceCE_Test { actionUpdate.getActionConfiguration().setBody("New Body"); return layoutActionService .updateSingleAction(preUpdateAction.getId(), actionUpdate) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); }); @@ -1105,7 +1105,7 @@ public class ActionServiceCE_Test { action.getActionConfiguration().setBody("New Body"); return layoutActionService .updateSingleAction(preUpdateAction.getId(), action) - .flatMap(updatedAction -> layoutActionService + .flatMap(updatedAction -> updateLayoutService .updatePageLayoutsByPageId(updatedAction.getPageId()) .thenReturn(updatedAction)); });