diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java index f0ccaa378a..03bf7a0d0a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ImportExportApplicationServiceCEImpl.java @@ -186,6 +186,8 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica applicationJson.setServerSchemaVersion(JsonSchemaVersions.serverVersion); applicationJson.setClientSchemaVersion(JsonSchemaVersions.clientVersion); + Mono defaultThemeMono = themeService.getSystemTheme(Theme.DEFAULT_THEME_NAME).cache(); + return pluginRepository .findAll() .map(plugin -> { @@ -194,10 +196,10 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica }) .then(applicationMono) .flatMap(application -> themeService.getThemeById(application.getEditModeThemeId(), READ_THEMES) - .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.THEME, application.getEditModeThemeId()))) + .switchIfEmpty(defaultThemeMono) // setting default theme if theme is missing .zipWith(themeService .getThemeById(application.getPublishedModeThemeId(), READ_THEMES) - .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.ACL_NO_RESOURCE_FOUND, FieldName.THEME, application.getPublishedModeThemeId()))) + .switchIfEmpty(defaultThemeMono)// setting default theme if theme is missing ) .map(themesTuple -> { Theme editModeTheme = exportTheme(themesTuple.getT1()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java index 0f720b5f20..1aac0fc7cc 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ImportExportApplicationServiceTests.java @@ -94,6 +94,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import static com.appsmith.server.acl.AclPermission.MANAGE_ACTIONS; @@ -2523,5 +2524,28 @@ public class ImportExportApplicationServiceTests { .verifyComplete(); } - + + @Test + @WithUserDetails(value = "api_user") + public void exportApplicationById_WhenThemeDoesNotExist_ExportedWithDefaultTheme() { + Theme customTheme = new Theme(); + customTheme.setName("my-custom-theme"); + + String randomId = UUID.randomUUID().toString(); + Application testApplication = new Application(); + testApplication.setName("Application_" + randomId); + Mono exportedAppJson = applicationPageService.createApplication(testApplication, orgId) + .flatMap(application -> { + application.setEditModeThemeId("invalid-theme-id"); + application.setPublishedModeThemeId("invalid-theme-id"); + String branchName = null; + return applicationService.save(application) + .then(importExportApplicationService.exportApplicationById(application.getId(), branchName)); + }); + + StepVerifier.create(exportedAppJson).assertNext(applicationJson -> { + assertThat(applicationJson.getEditModeTheme().getName()).isEqualTo(Theme.DEFAULT_THEME_NAME); + assertThat(applicationJson.getPublishedTheme().getName()).isEqualTo(Theme.DEFAULT_THEME_NAME); + }).verifyComplete(); + } }