From 1ab5913e61b46d32142316a37a4e282ebfc17c4d Mon Sep 17 00:00:00 2001 From: Nidhi Date: Wed, 25 Oct 2023 09:09:46 +0530 Subject: [PATCH] chore: Refactored import and export svc methods for modularity (#28330) --- ...tionCollectionExportableServiceCEImpl.java | 8 +- ...tionCollectionImportableServiceCEImpl.java | 7 +- .../DatasourceExportableServiceCEImpl.java | 54 +++--- .../DatasourceImportableServiceCEImpl.java | 12 +- .../exportable/ExportableServiceCE.java | 2 +- .../ExportApplicationServiceCEImpl.java | 117 +++++++++--- .../importable/ImportableServiceCE.java | 4 +- .../ImportApplicationServiceCEImpl.java | 171 +++++++++++++----- .../CustomJSLibExportableServiceCEImpl.java | 7 +- .../CustomJSLibImportableServiceCEImpl.java | 14 +- .../NewActionExportableServiceCEImpl.java | 8 +- .../NewActionImportableServiceCEImpl.java | 8 +- .../NewPageExportableServiceCEImpl.java | 15 +- .../NewPageImportableServiceCEImpl.java | 6 +- .../PluginExportableServiceCEImpl.java | 6 +- .../PluginImportableServiceCEImpl.java | 9 +- .../exports/ThemeExportableServiceCEImpl.java | 41 +++-- .../imports/ThemeImportableServiceCEImpl.java | 27 +-- 18 files changed, 340 insertions(+), 176 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java index eec1827e6a..c57b83cdc5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/actioncollections/exports/ActionCollectionExportableServiceCEImpl.java @@ -36,8 +36,11 @@ public class ActionCollectionExportableServiceCEImpl implements ExportableServic this.actionPermission = actionPermission; } + // Requires pageIdToNameMap, pluginMap. + // Updates collectionId to name map in exportable resources. Also directly updates required collection information + // in application json @Override - public Mono> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -94,7 +97,8 @@ public class ActionCollectionExportableServiceCEImpl implements ExportableServic .put(FieldName.ACTION_COLLECTION_LIST, updatedActionCollectionSet); return actionCollections; - }); + }) + .then(); } @Override 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 28d7a16ac6..4e2fb4e6d8 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 @@ -44,8 +44,11 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic this.repository = repository; } + // Requires pageNameMap, pageNameToOldNameMap, pluginMap and actionResultDTO to be present in importable resources. + // Updates actionCollectionResultDTO in importable resources. + // Also directly updates required information in DB @Override - public Mono> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -61,7 +64,7 @@ public class ActionCollectionImportableServiceCEImpl implements ImportableServic return importActionCollectionMono .doOnNext(mappedImportableResourcesDTO::setActionCollectionResultDTO) - .thenReturn(List.of()); + .then(); } private Mono createImportActionCollectionMono( diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/exports/DatasourceExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/exports/DatasourceExportableServiceCEImpl.java index 2f4a24493b..432a17a5dc 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/exports/DatasourceExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/exports/DatasourceExportableServiceCEImpl.java @@ -50,8 +50,10 @@ public class DatasourceExportableServiceCEImpl implements ExportableServiceCE> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -68,32 +70,36 @@ public class DatasourceExportableServiceCEImpl implements ExportableServiceCE { - List datasourceList = tuple2.getT1(); - String environmentId = tuple2.getT2(); - mapNameToIdForExportableEntities(mappedExportableResourcesDTO, datasourceList); + return datasourceFlux + .collectList() + .zipWith(defaultEnvironmentIdMono) + .map(tuple2 -> { + List datasourceList = tuple2.getT1(); + String environmentId = tuple2.getT2(); + mapNameToIdForExportableEntities(mappedExportableResourcesDTO, datasourceList); - List storageList = datasourceList.stream() - .map(datasource -> { - DatasourceStorage storage = - datasourceStorageService.getDatasourceStorageFromDatasource(datasource, environmentId); + List storageList = datasourceList.stream() + .map(datasource -> { + DatasourceStorage storage = datasourceStorageService.getDatasourceStorageFromDatasource( + datasource, environmentId); - if (storage == null) { - // This means we were unable to find a storage for default environment - // We still need the user to be able to configure this datasource in a - // new workspace, - // So we will create a fallback storage using transient fields from the - // datasource - storage = new DatasourceStorage(); - storage.prepareTransientFields(datasource); - } - return storage; - }) - .collect(Collectors.toList()); - applicationJson.setDatasourceList(storageList); + if (storage == null) { + // This means we were unable to find a storage for default environment + // We still need the user to be able to configure this datasource in a + // new workspace, + // So we will create a fallback storage using transient fields from the + // datasource + storage = new DatasourceStorage(); + storage.prepareTransientFields(datasource); + } + return storage; + }) + .collect(Collectors.toList()); + applicationJson.setDatasourceList(storageList); - return datasourceList; - }); + return datasourceList; + }) + .then(); } private void removeSensitiveFields(DatasourceStorage datasourceStorage) { 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 346bfb8f8b..f9a7ed4aed 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 @@ -52,8 +52,11 @@ public class DatasourceImportableServiceCEImpl implements ImportableServiceCE> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -74,10 +77,9 @@ public class DatasourceImportableServiceCEImpl implements ImportableServiceCE { - mappedImportableResourcesDTO.setDatasourceNameToIdMap(datasourceMap); - return List.of(); - }); + return datasourceMapMono + .doOnNext(mappedImportableResourcesDTO::setDatasourceNameToIdMap) + .then(); }); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/exportable/ExportableServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/exportable/ExportableServiceCE.java index d779b87469..33f15a248f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/exportable/ExportableServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/exportable/ExportableServiceCE.java @@ -14,7 +14,7 @@ import java.util.Set; public interface ExportableServiceCE { - Mono> getExportableEntities( + Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java index faf47a905d..9279adf44b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportApplicationServiceCEImpl.java @@ -34,12 +34,14 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import static java.lang.Boolean.TRUE; @@ -136,6 +138,7 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC exportingMetaDTO.setClientSchemaMigrated(isClientSchemaMigrated); exportingMetaDTO.setServerSchemaMigrated(isServerSchemaMigrated); applicationJson.setExportedApplication(application); + applicationJson.setUpdatedResources(new ConcurrentHashMap<>()); List unpublishedPages = application.getPages().stream() .map(ApplicationPage::getId) @@ -143,35 +146,17 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC exportingMetaDTO.setUnpublishedPages(unpublishedPages); - return pluginExportableService - .getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson) - .then(themeExportableService.getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) - .then(newPageExportableService.getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) - .then(datasourceExportableService.getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) - .then(actionCollectionExportableService.getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) - .then(newActionExportableService.getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) - .then(customJSLibExportableService.getExportableEntities( - exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) - .map(newActions -> { - datasourceExportableService.sanitizeEntities( - exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor); - - newPageExportableService.sanitizeEntities( - exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor); - + return getExportableEntities(exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson) + .then(Mono.defer(() -> sanitizeEntities( + serialiseFor, applicationJson, mappedResourcesDTO, exportingMetaDTO))) + .then(Mono.fromCallable(() -> { application.makePristine(); application.sanitiseToExportDBObject(); // Disable exporting the application with datasource config once imported in destination // instance application.setExportWithConfiguration(null); return applicationJson; - }); + })); }) .then(sessionUserService.getCurrentUser()) .map(user -> { @@ -198,6 +183,92 @@ public class ExportApplicationServiceCEImpl implements ExportApplicationServiceC .thenReturn(applicationJson); } + private Mono sanitizeEntities( + SerialiseApplicationObjective serialiseFor, + ApplicationJson applicationJson, + MappedExportableResourcesDTO mappedResourcesDTO, + ExportingMetaDTO exportingMetaDTO) { + datasourceExportableService.sanitizeEntities( + exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor); + + newPageExportableService.sanitizeEntities(exportingMetaDTO, mappedResourcesDTO, applicationJson, serialiseFor); + + return Mono.empty().then(); + } + + private Mono getExportableEntities( + ExportingMetaDTO exportingMetaDTO, + MappedExportableResourcesDTO mappedResourcesDTO, + Mono applicationMono, + ApplicationJson applicationJson) { + + // The idea with both these methods is that any amount of overriding should take care of whether they want to + // zip the additional exportables along with these or sequence them, or combine them using any other logic + return Flux.merge(getPageIndependentExportables( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson)) + .thenMany(Flux.merge(getPageDependentExportables( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson))) + .then(); + } + + protected List> getPageIndependentExportables( + ExportingMetaDTO exportingMetaDTO, + MappedExportableResourcesDTO mappedResourcesDTO, + Mono applicationMono, + ApplicationJson applicationJson) { + // Updates plugin map in exportable resources + Mono pluginExportablesMono = pluginExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + // Directly updates required theme information in application json + Mono themeExportablesMono = themeExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + // Updates pageId to name map in exportable resources. + // Also directly updates required pages information in application json + Mono newPageExportablesMono = newPageExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + // Updates datasourceId to name map in exportable resources. + // Also directly updates required datasources information in application json + Mono datasourceExportablesMono = datasourceExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + // Directly sets required custom JS lib information in application JSON + Mono customJsLibsExportablesMono = customJSLibExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + return List.of( + pluginExportablesMono, + datasourceExportablesMono, + themeExportablesMono, + newPageExportablesMono, + customJsLibsExportablesMono); + } + + protected List> getPageDependentExportables( + ExportingMetaDTO exportingMetaDTO, + MappedExportableResourcesDTO mappedResourcesDTO, + Mono applicationMono, + ApplicationJson applicationJson) { + + // Requires pageIdToNameMap, pluginMap. + // Updates collectionId to name map in exportable resources. + // Also directly updates required collection information in application json + Mono actionCollectionExportablesMono = actionCollectionExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + // Requires datasourceIdToNameMap, pageIdToNameMap, pluginMap, collectionIdToNameMap + // Updates actionId to name map in exportable resources. + // Also directly updates required collection information in application json + Mono newActionExportablesMono = newActionExportableService.getExportableEntities( + exportingMetaDTO, mappedResourcesDTO, applicationMono, applicationJson); + + Mono combinedActionExportablesMono = actionCollectionExportablesMono.then(newActionExportablesMono); + + return List.of(combinedActionExportablesMono); + } + public Mono exportApplicationById(String applicationId, String branchName) { return applicationService .findBranchedApplicationId(branchName, applicationId, applicationPermission.getExportPermission()) 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 644093ece7..ea4fcf62a6 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 @@ -8,11 +8,9 @@ import com.appsmith.server.dtos.ImportingMetaDTO; import com.appsmith.server.dtos.MappedImportableResourcesDTO; import reactor.core.publisher.Mono; -import java.util.List; - public interface ImportableServiceCE { - Mono> importEntities( + Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, 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 cbd0e22adb..e77cdb07d8 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 @@ -50,6 +50,7 @@ import org.springframework.dao.DuplicateKeyException; import org.springframework.http.MediaType; import org.springframework.http.codec.multipart.Part; import org.springframework.transaction.reactive.TransactionalOperator; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.lang.reflect.Type; @@ -516,60 +517,24 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC .cache(); Mono currUserMono = sessionUserService.getCurrentUser().cache(); - Mono> installedJsLibsMono = customJSLibImportableService.importEntities( - importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson); - Mono> installedPluginsMono = pluginImportableService.importEntities( - importingMetaDTO, mappedImportableResourcesDTO, workspaceMono, null, applicationJson); + + Mono applicationSpecificImportedEntitiesMono = + applicationSpecificImportedEntities(applicationJson, importingMetaDTO, mappedImportableResourcesDTO); // Start the stopwatch to log the execution time Stopwatch stopwatch = new Stopwatch(AnalyticsEvents.IMPORT.getEventName()); - final Mono importedApplicationMono = installedJsLibsMono + final Mono importedApplicationMono = applicationSpecificImportedEntitiesMono .then(getImportApplicationMono( importedApplication, importingMetaDTO, mappedImportableResourcesDTO, currUserMono)) .cache(); - Mono> importedThemesMono = themeImportableService.importEntities( - importingMetaDTO, - mappedImportableResourcesDTO, - workspaceMono, - importedApplicationMono, - applicationJson); - - Mono> importedPagesMono = newPageImportableService.importEntities( - importingMetaDTO, - mappedImportableResourcesDTO, - workspaceMono, - importedApplicationMono, - applicationJson); - - Mono> importedDatasourcesMono = datasourceImportableService.importEntities( - importingMetaDTO, - mappedImportableResourcesDTO, - workspaceMono, - importedApplicationMono, - applicationJson); - - Mono> importedNewActionsMono = newActionImportableService.importEntities( - importingMetaDTO, - mappedImportableResourcesDTO, - workspaceMono, - importedApplicationMono, - applicationJson); - - Mono> importedActionCollectionsMono = actionCollectionImportableService.importEntities( - importingMetaDTO, - mappedImportableResourcesDTO, - workspaceMono, - importedApplicationMono, - applicationJson); - Mono importMono = importedApplicationMono - .then(installedPluginsMono) - .then(importedThemesMono) - .then(importedPagesMono) - .then(importedDatasourcesMono) - .then(importedNewActionsMono) - .then(importedActionCollectionsMono) + .then(getImportableEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson)) .then(importedApplicationMono) .flatMap(application -> { return newActionImportableService @@ -643,6 +608,120 @@ public class ImportApplicationServiceCEImpl implements ImportApplicationServiceC return Mono.create(sink -> resultMono.subscribe(sink::success, sink::error, null, sink.currentContext())); } + private Mono getImportableEntities( + ImportingMetaDTO importingMetaDTO, + MappedImportableResourcesDTO mappedImportableResourcesDTO, + Mono workspaceMono, + Mono importedApplicationMono, + ApplicationJson applicationJson) { + + List> pageIndependentImportables = getPageIndependentImportables( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + List> pageDependentImportables = getPageDependentImportables( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + return Flux.merge(pageIndependentImportables) + .thenMany(Flux.merge(pageDependentImportables)) + .then(); + } + + protected List> getPageIndependentImportables( + ImportingMetaDTO importingMetaDTO, + MappedImportableResourcesDTO mappedImportableResourcesDTO, + Mono workspaceMono, + Mono importedApplicationMono, + ApplicationJson applicationJson) { + + // Updates plugin map in importable resources + Mono installedPluginsMono = pluginImportableService.importEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + // Directly updates required theme information in DB + Mono importedThemesMono = themeImportableService.importEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + // Updates pageNametoIdMap and pageNameMap in importable resources. + // Also directly updates required information in DB + Mono importedPagesMono = newPageImportableService.importEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + // Requires pluginMap to be present in importable resources. + // Updates datasourceNameToIdMap in importable resources. + // Also directly updates required information in DB + Mono importedDatasourcesMono = installedPluginsMono.then(datasourceImportableService.importEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson)); + + return List.of(importedDatasourcesMono, importedPagesMono, importedThemesMono); + } + + protected List> getPageDependentImportables( + ImportingMetaDTO importingMetaDTO, + MappedImportableResourcesDTO mappedImportableResourcesDTO, + Mono workspaceMono, + Mono importedApplicationMono, + ApplicationJson applicationJson) { + + // Requires pageNameMap, pageNameToOldNameMap, pluginMap and datasourceNameToIdMap to be present in importable + // resources. + // Updates actionResultDTO in importable resources. + // Also directly updates required information in DB + Mono importedNewActionsMono = newActionImportableService.importEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + // Requires pageNameMap, pageNameToOldNameMap, pluginMap and actionResultDTO to be present in importable + // resources. + // Updates actionCollectionResultDTO in importable resources. + // Also directly updates required information in DB + Mono importedActionCollectionsMono = actionCollectionImportableService.importEntities( + importingMetaDTO, + mappedImportableResourcesDTO, + workspaceMono, + importedApplicationMono, + applicationJson); + + Mono combinedActionExportablesMono = importedNewActionsMono.then(importedActionCollectionsMono); + return List.of(combinedActionExportablesMono); + } + + private Mono applicationSpecificImportedEntities( + ApplicationJson applicationJson, + ImportingMetaDTO importingMetaDTO, + MappedImportableResourcesDTO mappedImportableResourcesDTO) { + // Persists relevant information and updates mapped resources + Mono installedJsLibsMono = customJSLibImportableService.importEntities( + importingMetaDTO, mappedImportableResourcesDTO, null, null, applicationJson); + return installedJsLibsMono; + } + @Override public Mono getApplicationImportDTO( String applicationId, String workspaceId, Application application) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/exports/CustomJSLibExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/exports/CustomJSLibExportableServiceCEImpl.java index 283a71ddb1..50232e5889 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/exports/CustomJSLibExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/exports/CustomJSLibExportableServiceCEImpl.java @@ -26,8 +26,9 @@ public class CustomJSLibExportableServiceCEImpl implements ExportableServiceCE> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -62,7 +63,6 @@ public class CustomJSLibExportableServiceCEImpl implements ExportableServiceCE lib.getUidString()) .collect(Collectors.toSet()); } - applicationJson.getUpdatedResources().put(FieldName.CUSTOM_JS_LIB_LIST, updatedCustomJSLibSet); /** @@ -73,6 +73,7 @@ public class CustomJSLibExportableServiceCEImpl implements ExportableServiceCE> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -46,15 +47,10 @@ public class CustomJSLibImportableServiceCEImpl implements ImportableServiceCE { - mappedImportableResourcesDTO.setInstalledJsLibsList(customJSLibApplicationDTOS); - return List.of(); - }) + .doOnNext(mappedImportableResourcesDTO::setInstalledJsLibsList) .elapsed() - .map(objects -> { - log.debug("time to import custom jslibs: {}", objects.getT1()); - return objects.getT2(); - }) + .doOnNext(objects -> log.debug("time to import custom jslibs: {}", objects.getT1())) + .then() .onErrorResume(e -> { log.error("Error importing custom jslibs", e); return Mono.error(e); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java index f1b840983d..8ff63967c2 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/newactions/exports/NewActionExportableServiceCEImpl.java @@ -37,8 +37,11 @@ public class NewActionExportableServiceCEImpl implements ExportableServiceCE> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -101,7 +104,8 @@ public class NewActionExportableServiceCEImpl implements ExportableServiceCE !dbNamesUsedInActions.contains(datasource.getName())); return actionList; - }); + }) + .then(); } @Override 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 c5598d40a6..de78e94f2e 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 @@ -56,8 +56,12 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -124,7 +128,7 @@ public class NewActionImportableServiceCEImpl implements ImportableServiceCE> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -109,13 +110,11 @@ public class NewPageExportableServiceCEImpl implements ExportableServiceCE() { - { - put(FieldName.PAGE_LIST, updatedPageSet); - } - }); + applicationJson.getUpdatedResources().put(FieldName.PAGE_LIST, updatedPageSet); + return newPageList; - }); + }) + .then(); } @Override 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 eecca835f6..d6b24f7eb1 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 @@ -60,8 +60,10 @@ public class NewPageImportableServiceCEImpl implements ImportableServiceCE> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -104,7 +106,7 @@ public class NewPageImportableServiceCEImpl implements ImportableServiceCE> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -49,6 +50,7 @@ public class PluginExportableServiceCEImpl implements ExportableServiceCE> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -50,9 +51,7 @@ public class PluginImportableServiceCEImpl implements ImportableServiceCE { - log.debug("time to get plugin map: {}", tuples.getT1()); - return tuples.getT2(); - }); + .doOnNext(tuples -> log.debug("time to get plugin map: {}", tuples.getT1())) + .then(); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/exports/ThemeExportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/exports/ThemeExportableServiceCEImpl.java index acb62087e5..73d7d8821f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/exports/ThemeExportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/exports/ThemeExportableServiceCEImpl.java @@ -23,8 +23,9 @@ public class ThemeExportableServiceCEImpl implements ExportableServiceCE this.themeService = themeService; } + // Directly sets required theme information in application json @Override - public Mono> getExportableEntities( + public Mono getExportableEntities( ExportingMetaDTO exportingMetaDTO, MappedExportableResourcesDTO mappedExportableResourcesDTO, Mono applicationMono, @@ -38,23 +39,25 @@ public class ThemeExportableServiceCEImpl implements ExportableServiceCE }) .cache(); - return applicationMono.flatMap(application -> themeService - .getThemeById(application.getEditModeThemeId(), READ_THEMES) - .switchIfEmpty(Mono.defer(() -> defaultThemeMono)) // setting default theme if theme is missing - .zipWith( - themeService - .getThemeById(application.getPublishedModeThemeId(), READ_THEMES) - .switchIfEmpty( - Mono.defer(() -> defaultThemeMono)) // setting default theme if theme is missing - ) - .map(themesTuple -> { - Theme editModeTheme = themesTuple.getT1(); - Theme publishedModeTheme = themesTuple.getT2(); - editModeTheme.sanitiseToExportDBObject(); - publishedModeTheme.sanitiseToExportDBObject(); - applicationJson.setEditModeTheme(editModeTheme); - applicationJson.setPublishedTheme(publishedModeTheme); - return List.of(themesTuple.getT1(), themesTuple.getT2()); - })); + return applicationMono + .flatMap(application -> themeService + .getThemeById(application.getEditModeThemeId(), READ_THEMES) + .switchIfEmpty(Mono.defer(() -> defaultThemeMono)) // setting default theme if theme is missing + .zipWith( + themeService + .getThemeById(application.getPublishedModeThemeId(), READ_THEMES) + .switchIfEmpty(Mono.defer( + () -> defaultThemeMono)) // setting default theme if theme is missing + ) + .map(themesTuple -> { + Theme editModeTheme = themesTuple.getT1(); + Theme publishedModeTheme = themesTuple.getT2(); + editModeTheme.sanitiseToExportDBObject(); + publishedModeTheme.sanitiseToExportDBObject(); + applicationJson.setEditModeTheme(editModeTheme); + applicationJson.setPublishedTheme(publishedModeTheme); + return List.of(themesTuple.getT1(), themesTuple.getT2()); + })) + .then(); } } 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 34bca98bf2..5042859a61 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 @@ -6,8 +6,6 @@ import com.appsmith.server.domains.Workspace; import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.dtos.ImportingMetaDTO; import com.appsmith.server.dtos.MappedImportableResourcesDTO; -import com.appsmith.server.exceptions.AppsmithError; -import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.imports.importable.ImportableServiceCE; import com.appsmith.server.repositories.ThemeRepository; import com.appsmith.server.services.ApplicationService; @@ -16,8 +14,6 @@ import com.appsmith.server.themes.base.ThemeService; import org.springframework.util.StringUtils; import reactor.core.publisher.Mono; -import java.util.List; - import static com.appsmith.server.acl.AclPermission.MANAGE_THEMES; public class ThemeImportableServiceCEImpl implements ImportableServiceCE { @@ -48,11 +44,11 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE * - If current theme is a customized one and source theme is system theme, set the current theme to system and delete the old one * - If current theme is system theme, update the current theme as per source theme * - * @param applicationJson ApplicationJSON from file or Git + * @param applicationJson ApplicationJSON from file or Git * @return Updated application that has editModeThemeId and publishedModeThemeId set */ @Override - public Mono> importEntities( + public Mono importEntities( ImportingMetaDTO importingMetaDTO, MappedImportableResourcesDTO mappedImportableResourcesDTO, Mono workspaceMono, @@ -60,7 +56,7 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE ApplicationJson applicationJson) { if (Boolean.TRUE.equals(importingMetaDTO.getAppendToApp())) { // appending to existing app, theme should not change - return Mono.just(List.of()); + return Mono.empty().then(); } return applicationMono.flatMap(destinationApp -> { Mono editModeTheme = updateExistingAppThemeFromJSON( @@ -78,18 +74,13 @@ public class ThemeImportableServiceCEImpl implements ImportableServiceCE destinationApp.setEditModeThemeId(editModeThemeId); destinationApp.setPublishedModeThemeId(publishedModeThemeId); // this will update the theme id in DB - // also returning the updated application object so that theme id are available to the next - // pipeline - return applicationService - .setAppTheme( - destinationApp.getId(), - editModeThemeId, - publishedModeThemeId, - applicationPermission.getEditPermission()) - .thenReturn(List.of()); + return applicationService.setAppTheme( + destinationApp.getId(), + editModeThemeId, + publishedModeThemeId, + applicationPermission.getEditPermission()); }) - .switchIfEmpty(Mono.error( - new AppsmithException(AppsmithError.GENERIC_BAD_REQUEST, "Failed to import theme"))); + .then(); }); }