diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java index 6d876dd96c38..94c29a24331c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java @@ -53,6 +53,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.appsmith.server.constants.FieldName.PUBLISHED; +import static com.appsmith.server.constants.FieldName.UNPUBLISHED; import static com.appsmith.server.helpers.ImportExportUtils.setPropertiesToExistingApplication; import static com.appsmith.server.helpers.ImportExportUtils.setPublishedApplicationProperties; import static org.springframework.util.StringUtils.hasText; @@ -361,11 +363,18 @@ public Mono updateAndSaveArtifactInContext( application.setWorkspaceId(importingMetaDTO.getWorkspaceId()); application.setIsPublic(null); application.setPolicies(null); - Map> mapOfApplicationPageList = Map.of( - FieldName.PUBLISHED, - application.getPublishedPages(), - FieldName.UNPUBLISHED, - application.getPages()); + + List unPublishedPages = CollectionUtils.isEmpty(application.getPages()) + ? new ArrayList<>() + : application.getPages(); + + List publishedPages = CollectionUtils.isEmpty(application.getPublishedPages()) + ? new ArrayList<>() + : application.getPublishedPages(); + + Map> mapOfApplicationPageList = + Map.of(PUBLISHED, publishedPages, UNPUBLISHED, unPublishedPages); + mappedImportableResourcesDTO .getResourceStoreFromArtifactExchangeJson() .putAll(mapOfApplicationPageList); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java index 97b3215c3258..49cd7905a529 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/base/ThemeServiceCEImpl.java @@ -260,12 +260,18 @@ public Mono publishTheme(String applicationId) { editModeTheme.getId(), applicationPermission.getEditPermission())) .thenReturn(editModeTheme); - } else { // a customized theme is set as edit mode theme, copy that theme for published mode - return saveThemeForApplication( - application.getPublishedModeThemeId(), - editModeTheme, - application, - ApplicationMode.PUBLISHED); + } else { + // Unlike other entities themes doesn't have a concept of published and unpublished, + // hence while publishing the themes, contents from unpublished needs to be copied to + // published theme and for that the theme needs to exist. + // In cases of import and new application published theme should be null, + // hence the need of default themeId + Mono publishedThemeIdMono = Mono.justOrEmpty(application.getPublishedModeThemeId()) + .switchIfEmpty(getDefaultThemeId()); + + // a customized theme is set as edit mode theme, copy that theme for published mode + return publishedThemeIdMono.flatMap(publishedThemeId -> saveThemeForApplication( + publishedThemeId, editModeTheme, application, ApplicationMode.PUBLISHED)); } }); }); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java index 3ca18b567c6c..7ca9c0d2808e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/themes/importable/ThemeImportableServiceCEImpl.java @@ -71,31 +71,21 @@ public Mono importEntities( return Mono.empty().then(); } return importableArtifactMono.flatMap(importableArtifact -> { - Mono editModeTheme = updateExistingAppThemeFromJSON( + Mono editModeThemeMono = updateExistingAppThemeFromJSON( importableArtifact, importableArtifact.getUnpublishedThemeId(), artifactExchangeJson.getUnpublishedTheme(), mappedImportableResourcesDTO); - Mono publishedModeTheme = updateExistingAppThemeFromJSON( - importableArtifact, - importableArtifact.getPublishedThemeId(), - artifactExchangeJson.getPublishedTheme(), - mappedImportableResourcesDTO); - - return Mono.zip(editModeTheme, publishedModeTheme) - .flatMap(importedThemesTuple -> { - String editModeThemeId = importedThemesTuple.getT1().getId(); - String publishedModeThemeId = - importedThemesTuple.getT2().getId(); - + return editModeThemeMono + .flatMap(editModeTheme -> { + String editModeThemeId = editModeTheme.getId(); importableArtifact.setUnpublishedThemeId(editModeThemeId); - importableArtifact.setPublishedThemeId(publishedModeThemeId); + // this will update the theme in the application and will be updated to db in the dry ops // execution Application application = new Application(); - application.setPublishedModeThemeId(publishedModeThemeId); application.setUnpublishedThemeId(editModeThemeId); application.setId(importableArtifact.getId()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java index 37fd07110d3f..1ac66965af93 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java @@ -1016,7 +1016,7 @@ public void importArtifactFromValidJsonFileTest() { assertThat(application.getModifiedBy()).isEqualTo("api_user"); assertThat(application.getUpdatedAt()).isNotNull(); assertThat(application.getEditModeThemeId()).isNotNull(); - assertThat(application.getPublishedModeThemeId()).isNotNull(); + assertThat(application.getPublishedModeThemeId()).isNull(); assertThat(isPartialImport).isEqualTo(Boolean.TRUE); assertThat(unConfiguredDatasourceList).isNotNull(); @@ -1138,22 +1138,14 @@ public void importApplicationInWorkspace_WhenCustomizedThemes_ThemesCreated() { StepVerifier.create(resultMono.flatMap(applicationImportDTO -> Mono.zip( Mono.just(applicationImportDTO), - themeRepository.findById(applicationImportDTO.getEditModeThemeId()), - themeRepository.findById(applicationImportDTO.getPublishedModeThemeId())))) + themeRepository.findById(applicationImportDTO.getEditModeThemeId())))) .assertNext(tuple -> { - final Application application = tuple.getT1(); Theme editTheme = tuple.getT2(); - Theme publishedTheme = tuple.getT3(); assertThat(editTheme.isSystemTheme()).isFalse(); assertThat(editTheme.getDisplayName()).isEqualTo("Custom edit theme"); assertThat(editTheme.getWorkspaceId()).isNull(); assertThat(editTheme.getApplicationId()).isNull(); - - assertThat(publishedTheme.isSystemTheme()).isFalse(); - assertThat(publishedTheme.getDisplayName()).isEqualTo("Custom published theme"); - assertThat(publishedTheme.getWorkspaceId()).isNullOrEmpty(); - assertThat(publishedTheme.getApplicationId()).isNullOrEmpty(); }) .verifyComplete(); } @@ -1299,7 +1291,7 @@ public void importArtifact_WithoutThemes_LegacyThemesAssigned() { StepVerifier.create(resultMono) .assertNext(applicationImportDTO -> { assertThat(applicationImportDTO.getEditModeThemeId()).isNotEmpty(); - assertThat(applicationImportDTO.getPublishedModeThemeId()).isNotEmpty(); + assertThat(applicationImportDTO.getPublishedModeThemeId()).isNull(); }) .verifyComplete(); } @@ -1532,7 +1524,7 @@ public void importApplication_withUnConfiguredDatasources_Success() { assertThat(application.getModifiedBy()).isEqualTo("api_user"); assertThat(application.getUpdatedAt()).isNotNull(); assertThat(application.getEditModeThemeId()).isNotNull(); - assertThat(application.getPublishedModeThemeId()).isNotNull(); + assertThat(application.getPublishedModeThemeId()).isNull(); assertThat(isPartialImport).isEqualTo(Boolean.TRUE); assertThat(unConfiguredDatasourceList.size()).isNotEqualTo(0); @@ -1860,7 +1852,7 @@ public void discardChange_addNewPageAfterImport_addedPageRemoved() { assertThat(application.getModifiedBy()).isEqualTo("api_user"); assertThat(application.getUpdatedAt()).isNotNull(); assertThat(application.getEditModeThemeId()).isNotNull(); - assertThat(application.getPublishedModeThemeId()).isNotNull(); + assertThat(application.getPublishedModeThemeId()).isNull(); assertThat(pageList).hasSize(3); @@ -4744,7 +4736,7 @@ public void extractFileAndUpdateApplication_addNewPageAfterImport_addedPageRemov assertThat(application.getModifiedBy()).isEqualTo("api_user"); assertThat(application.getUpdatedAt()).isNotNull(); assertThat(application.getEditModeThemeId()).isNotNull(); - assertThat(application.getPublishedModeThemeId()).isNotNull(); + assertThat(application.getPublishedModeThemeId()).isNull(); assertThat(pageList).hasSize(3); @@ -5296,7 +5288,7 @@ public void importApplication_WhenUpdateLayoutFailures_Success() throws URISynta assertThat(application.getModifiedBy()).isEqualTo("api_user"); assertThat(application.getUpdatedAt()).isNotNull(); assertThat(application.getEditModeThemeId()).isNotNull(); - assertThat(application.getPublishedModeThemeId()).isNotNull(); + assertThat(application.getPublishedModeThemeId()).isNull(); assertThat(isPartialImport).isEqualTo(Boolean.TRUE); assertThat(unConfiguredDatasourceList.size()).isNotEqualTo(0);