Skip to content

Commit

Permalink
removed published theme from import
Browse files Browse the repository at this point in the history
  • Loading branch information
sondermanish committed Jan 22, 2025
1 parent b14669e commit 0e9f7c2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -361,11 +363,18 @@ public Mono<Application> updateAndSaveArtifactInContext(
application.setWorkspaceId(importingMetaDTO.getWorkspaceId());
application.setIsPublic(null);
application.setPolicies(null);
Map<String, List<ApplicationPage>> mapOfApplicationPageList = Map.of(
FieldName.PUBLISHED,
application.getPublishedPages(),
FieldName.UNPUBLISHED,
application.getPages());

List<ApplicationPage> unPublishedPages = CollectionUtils.isEmpty(application.getPages())
? new ArrayList<>()
: application.getPages();

List<ApplicationPage> publishedPages = CollectionUtils.isEmpty(application.getPublishedPages())
? new ArrayList<>()
: application.getPublishedPages();

Map<String, List<ApplicationPage>> mapOfApplicationPageList =
Map.of(PUBLISHED, publishedPages, UNPUBLISHED, unPublishedPages);

mappedImportableResourcesDTO
.getResourceStoreFromArtifactExchangeJson()
.putAll(mapOfApplicationPageList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,18 @@ public Mono<Theme> 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<String> 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));
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,21 @@ public Mono<Void> importEntities(
return Mono.empty().then();
}
return importableArtifactMono.flatMap(importableArtifact -> {
Mono<Theme> editModeTheme = updateExistingAppThemeFromJSON(
Mono<Theme> editModeThemeMono = updateExistingAppThemeFromJSON(
importableArtifact,
importableArtifact.getUnpublishedThemeId(),
artifactExchangeJson.getUnpublishedTheme(),
mappedImportableResourcesDTO);

Mono<Theme> 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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0e9f7c2

Please sign in to comment.