diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java index 2118aef793..291fbdeeb0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/imports/ActionCollectionImportableServiceCEImpl.java @@ -53,7 +53,8 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { List importedActionCollectionList = CollectionUtils.isEmpty(applicationJson.getActionCollectionList()) ? new ArrayList<>() diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/imports/DatasourceImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/imports/DatasourceImportableServiceCEImpl.java index f9a7ed4aed..58b91708fe 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/imports/DatasourceImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/imports/DatasourceImportableServiceCEImpl.java @@ -61,7 +61,8 @@ public class DatasourceImportableServiceCEImpl implements ImportableServiceCE workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { return workspaceMono.flatMap(workspace -> { final Flux existingDatasourceFlux = datasourceService .getAllByWorkspaceIdWithStorages(workspace.getId(), Optional.empty()) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/importable/ImportableServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/importable/ImportableServiceCE.java index ea4fcf62a6..05ac52dcf6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/importable/ImportableServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/importable/ImportableServiceCE.java @@ -15,12 +15,14 @@ public interface ImportableServiceCE { MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, Mono applicationMono, - ApplicationJson applicationJson); + ApplicationJson applicationJson, + boolean isPartialImport); default Mono updateImportedEntities( Application application, ImportingMetaDTO importingMetaDTO, - MappedImportableResourcesDTO mappedImportableResourcesDTO) { + MappedImportableResourcesDTO mappedImportableResourcesDTO, + boolean isPartialImport) { return null; } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java index 939c71e32b..2e7d30c977 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportApplicationServiceCEImpl.java @@ -554,9 +554,9 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC .then(importedApplicationMono) .flatMap(application -> { return newActionImportableService - .updateImportedEntities(application, importingMetaDTO, mappedImportableResourcesDTO) + .updateImportedEntities(application, importingMetaDTO, mappedImportableResourcesDTO, false) .then(newPageImportableService.updateImportedEntities( - application, importingMetaDTO, mappedImportableResourcesDTO)) + application, importingMetaDTO, mappedImportableResourcesDTO, false)) .thenReturn(application); }) .flatMap(application -> { @@ -663,7 +663,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + false); // Directly updates required theme information in DB Mono importedThemesMono = themeImportableService.importEntities( @@ -671,7 +672,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + false); // Updates pageNametoIdMap and pageNameMap in importable resources. // Also directly updates required information in DB @@ -680,7 +682,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + false); // Requires pluginMap to be present in importable resources. // Updates datasourceNameToIdMap in importable resources. @@ -690,7 +693,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson)); + applicationJson, + false)); return List.of(importedDatasourcesMono, importedPagesMono, importedThemesMono); } @@ -711,7 +715,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + false); // Requires pageNameMap, pageNameToOldNameMap, pluginMap and actionResultDTO to be present in importable // resources. @@ -722,7 +727,8 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + false); Mono combinedActionExportablesMono = importedNewActionsMono.then(importedActionCollectionsMono); return List.of(combinedActionExportablesMono); @@ -734,7 +740,7 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC MappedImportableResourcesDTO mappedImportableResourcesDTO) { // Persists relevant information and updates mapped resources Mono installedJsLibsMono = customJSLibImportableService.importEntities( - importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson); + importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson, false); return installedJsLibsMono; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java index f5eda35b6d..025c883685 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/PartialImportServiceCEImpl.java @@ -147,9 +147,9 @@ public class PartialImportServiceCEImpl implements PartialImportServiceCE { } return newActionImportableService .updateImportedEntities( - application, importingMetaDTO, mappedImportableResourcesDTO) + application, importingMetaDTO, mappedImportableResourcesDTO, true) .then(newPageImportableService.updateImportedEntities( - application, importingMetaDTO, mappedImportableResourcesDTO)) + application, importingMetaDTO, mappedImportableResourcesDTO, true)) .thenReturn(application); }); }) @@ -209,17 +209,19 @@ public class PartialImportServiceCEImpl implements PartialImportServiceCE { mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + true); Mono datasourceMono = datasourceImportableService.importEntities( importingMetaDTO, mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + true); Mono customJsLibMono = customJSLibImportableService.importEntities( - importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson); + importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson, true); return pluginMono.then(datasourceMono).then(customJsLibMono).then(); } @@ -235,14 +237,16 @@ public class PartialImportServiceCEImpl implements PartialImportServiceCE { mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + true); Mono actionCollectionMono = actionCollectionImportableService.importEntities( importingMetaDTO, mappedImportableResourcesDTO, workspaceMono, importedApplicationMono, - applicationJson); + applicationJson, + true); return actionMono.then(actionCollectionMono).then(); } @@ -283,9 +287,10 @@ public class PartialImportServiceCEImpl implements PartialImportServiceCE { return Mono.just(pageName); } applicationJson.getActionCollectionList().forEach(actionCollection -> { - actionCollection.getPublishedCollection().setPageId(pageName); actionCollection.getUnpublishedCollection().setPageId(pageName); - + if (actionCollection.getPublishedCollection() != null) { + actionCollection.getPublishedCollection().setPageId(pageName); + } String collectionName = actionCollection.getId().split("_")[1]; actionCollection.setId(pageName + "_" + collectionName); actionCollection.setGitSyncId(null); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/imports/CustomJSLibImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/imports/CustomJSLibImportableServiceCEImpl.java index a05597421e..a6f6d67d29 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/imports/CustomJSLibImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/imports/CustomJSLibImportableServiceCEImpl.java @@ -30,7 +30,8 @@ public class CustomJSLibImportableServiceCEImpl implements ImportableServiceCE workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { List customJSLibs = applicationJson.getCustomJSLibList(); if (customJSLibs == null) { customJSLibs = new ArrayList<>(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/imports/NewActionImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/imports/NewActionImportableServiceCEImpl.java index 07cda3c385..1b469b784e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/imports/NewActionImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/imports/NewActionImportableServiceCEImpl.java @@ -66,7 +66,8 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { List importedNewActionList = applicationJson.getActionList(); @@ -105,9 +106,13 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE invalidActionIds = new HashSet<>(); - for (NewAction action : importActionResultDTO.getExistingActions()) { - if (!importActionResultDTO.getImportedActionIds().contains(action.getId())) { - invalidActionIds.add(action.getId()); + if (Boolean.FALSE.equals(isPartialImport)) { + for (NewAction action : importActionResultDTO.getExistingActions()) { + if (!importActionResultDTO + .getImportedActionIds() + .contains(action.getId())) { + invalidActionIds.add(action.getId()); + } } } log.info("Deleting {} actions which are no more used", invalidActionIds.size()); @@ -136,7 +141,8 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE updateImportedEntities( Application application, ImportingMetaDTO importingMetaDTO, - MappedImportableResourcesDTO mappedImportableResourcesDTO) { + MappedImportableResourcesDTO mappedImportableResourcesDTO, + boolean isPartialImport) { ImportActionResultDTO importActionResultDTO = mappedImportableResourcesDTO.getActionResultDTO(); ImportActionCollectionResultDTO importActionCollectionResultDTO = @@ -157,7 +163,8 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE invalidCollectionIds = new HashSet<>(); for (ActionCollection collection : diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/imports/NewPageImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/imports/NewPageImportableServiceCEImpl.java index 74d12d1ca0..d20b8186a0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/imports/NewPageImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newpages/imports/NewPageImportableServiceCEImpl.java @@ -68,7 +68,8 @@ public class NewPageImportableServiceCEImpl implements ImportableServiceCE workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { List importedNewPageList = applicationJson.getPageList(); @@ -113,7 +114,8 @@ public class NewPageImportableServiceCEImpl implements ImportableServiceCE updateImportedEntities( Application application, ImportingMetaDTO importingMetaDTO, - MappedImportableResourcesDTO mappedImportableResourcesDTO) { + MappedImportableResourcesDTO mappedImportableResourcesDTO, + boolean isPartialImport) { ImportedActionAndCollectionMapsDTO actionAndCollectionMapsDTO = mappedImportableResourcesDTO.getActionAndCollectionMapsDTO(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/imports/PluginImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/imports/PluginImportableServiceCEImpl.java index 7db5353606..c824ce1df2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/imports/PluginImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/imports/PluginImportableServiceCEImpl.java @@ -33,7 +33,8 @@ public class PluginImportableServiceCEImpl implements ImportableServiceCE workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { return workspaceMono .map(workspace -> workspace.getPlugins().stream() .map(WorkspacePlugin::getPluginId) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/imports/ThemeImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/imports/ThemeImportableServiceCEImpl.java index f387f53da2..40949be952 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/imports/ThemeImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/imports/ThemeImportableServiceCEImpl.java @@ -53,7 +53,8 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, Mono applicationMono, - ApplicationJson applicationJson) { + ApplicationJson applicationJson, + boolean isPartialImport) { if (Boolean.TRUE.equals(importingMetaDTO.getAppendToApp())) { // appending to existing app, theme should not change return Mono.empty().then(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ThemeImportableServiceCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ThemeImportableServiceCETest.java index e2a42c6035..adde9b9407 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ThemeImportableServiceCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ThemeImportableServiceCETest.java @@ -180,7 +180,8 @@ public class ThemeImportableServiceCETest { new MappedImportableResourcesDTO(), null, Mono.just(application), - applicationJson) + applicationJson, + false) .thenReturn(savedApplication.getId())) .flatMap(applicationId -> applicationRepository.findById(applicationId, MANAGE_APPLICATIONS)); @@ -224,7 +225,8 @@ public class ThemeImportableServiceCETest { new MappedImportableResourcesDTO(), null, Mono.just(savedApplication), - applicationJson) + applicationJson, + false) .thenReturn(savedApplication.getId()); }) .flatMap(applicationId -> applicationRepository.findById(applicationId, MANAGE_APPLICATIONS)); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java index eb46120fe2..232f8e65dc 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java @@ -45,6 +45,7 @@ import reactor.test.StepVerifier; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; // All the test case are for failure or exception. Test cases for valid json file is already present in // ImportExportApplicationServiceTest class @@ -135,7 +136,7 @@ public class ImportApplicationTransactionServiceTest { Workspace newWorkspace = new Workspace(); newWorkspace.setName("Template Workspace"); - Mockito.when(newActionImportableService.importEntities(any(), any(), any(), any(), any())) + Mockito.when(newActionImportableService.importEntities(any(), any(), any(), any(), any(), anyBoolean())) .thenReturn(Mono.error(new AppsmithException(AppsmithError.GENERIC_BAD_REQUEST))); Workspace createdWorkspace = workspaceService.create(newWorkspace).block(); @@ -166,7 +167,7 @@ public class ImportApplicationTransactionServiceTest { Workspace newWorkspace = new Workspace(); newWorkspace.setName("Template Workspace"); - Mockito.when(newActionImportableService.importEntities(any(), any(), any(), any(), any())) + Mockito.when(newActionImportableService.importEntities(any(), any(), any(), any(), any(), anyBoolean())) .thenReturn(Mono.error(new MongoTransactionException( "Command failed with error 251 (NoSuchTransaction): 'Transaction 1 has been aborted.'")));