From 21a3ea956929265b7e5b2d7c6269fbb4997b8174 Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Wed, 6 Nov 2024 11:09:47 +0530 Subject: [PATCH] refactor method names --- .../external/models/DatasourceStructure.java | 7 ++++ .../base/ApplicationServiceCEImpl.java | 2 +- .../base/DatasourceServiceCEImpl.java | 2 +- .../DatasourceImportableServiceCEImpl.java | 2 +- .../CustomJSLibImportableServiceCEImpl.java | 2 +- .../ce/CustomApplicationRepositoryCE.java | 2 +- .../ce/CustomApplicationRepositoryCEImpl.java | 2 +- .../themes/base/ThemeServiceCEImpl.java | 10 +++--- .../ThemeImportableServiceCEImpl.java | 33 +++++-------------- 9 files changed, 26 insertions(+), 36 deletions(-) diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceStructure.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceStructure.java index 7c7a197a67c..c2f8fde2218 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceStructure.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceStructure.java @@ -2,6 +2,8 @@ import com.appsmith.external.exceptions.BaseException; import com.appsmith.external.exceptions.ErrorDTO; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.google.gson.InstanceCreator; import lombok.AllArgsConstructor; import lombok.Data; @@ -60,6 +62,11 @@ public int compareTo(Column other) { } } + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") + @JsonSubTypes({ + @JsonSubTypes.Type(value = DatasourceStructure.PrimaryKey.class, name = "primary key"), + @JsonSubTypes.Type(value = DatasourceStructure.ForeignKey.class, name = "foreign key") + }) public interface Key extends Comparable { String getType(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java index 50872df66db..95d8401a92e 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java @@ -902,7 +902,7 @@ public String getRandomAppCardColor() { @Override public Mono setAppTheme( String applicationId, String editModeThemeId, String publishedModeThemeId, AclPermission aclPermission) { - return repository.setAppTheme(applicationId, editModeThemeId, publishedModeThemeId, aclPermission); + return repository.updateAppTheme(applicationId, editModeThemeId, publishedModeThemeId, aclPermission); } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCEImpl.java index 9d03ab90ae0..16e723ecccd 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/base/DatasourceServiceCEImpl.java @@ -149,7 +149,7 @@ public Mono create(Datasource datasource) { @Override public Mono createWithoutPermissions( Datasource datasource, Map> datasourceStorageDryRunQueries) { - return createEx(datasource, null, true, datasourceStorageDryRunQueries); + return createEx(datasource, null, false, datasourceStorageDryRunQueries); } @Override diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/importable/DatasourceImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/importable/DatasourceImportableServiceCEImpl.java index 83489d22a35..a9bef8de67d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/importable/DatasourceImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/datasources/importable/DatasourceImportableServiceCEImpl.java @@ -213,7 +213,7 @@ private Mono> importDatasources( // Don't update the datasource configuration for already available datasources existingDatasource.setDatasourceConfiguration(null); return datasourceService - .save(existingDatasource, true) + .save(existingDatasource, false) .map(createdDatasource -> { // Add dry run queries for the datasource addDryOpsForEntity( diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/importable/CustomJSLibImportableServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/importable/CustomJSLibImportableServiceCEImpl.java index 136be5b569f..b405c2ef71a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/importable/CustomJSLibImportableServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/jslibs/importable/CustomJSLibImportableServiceCEImpl.java @@ -50,7 +50,7 @@ public Mono importEntities( customJSLib.setCreatedAt(null); customJSLib.setUpdatedAt(null); return customJSLibService.persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO( - customJSLib, false, mappedImportableResourcesDTO.getCustomJSLibsDryOps(), true); + customJSLib, false, mappedImportableResourcesDTO.getCustomJSLibsDryOps(), false); }) .collectList() .doOnNext(mappedImportableResourcesDTO::setInstalledJsLibsList) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCE.java index 33d45af9ece..1b12d5ba790 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCE.java @@ -53,7 +53,7 @@ Mono getApplicationByGitBranchAndBaseApplicationId( Flux getApplicationByGitBaseApplicationId(String baseApplicationId, AclPermission permission); - Mono setAppTheme( + Mono updateAppTheme( String applicationId, String editModeThemeId, String publishedModeThemeId, AclPermission aclPermission); Mono getGitConnectedApplicationWithPrivateRepoCount(String workspaceId); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java index fa4b56c351a..f190c708c53 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomApplicationRepositoryCEImpl.java @@ -199,7 +199,7 @@ public Mono getApplicationByBaseApplicationIdAndDefaultBranch(Strin } @Override - public Mono setAppTheme( + public Mono updateAppTheme( String applicationId, String editModeThemeId, String publishedModeThemeId, AclPermission aclPermission) { BridgeUpdate updateObj = Bridge.update(); if (StringUtils.hasLength(editModeThemeId)) { 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 97b3215c325..938da57501c 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 @@ -177,7 +177,7 @@ public Mono changeCurrentTheme(String newThemeId, String branchedApplicat // customizations return repository .delete(currentTheme) - .then(applicationRepository.setAppTheme( + .then(applicationRepository.updateAppTheme( application.getId(), savedTheme.getId(), null, @@ -185,7 +185,7 @@ public Mono changeCurrentTheme(String newThemeId, String branchedApplicat .thenReturn(savedTheme); } else { return applicationRepository - .setAppTheme( + .updateAppTheme( application.getId(), savedTheme.getId(), null, @@ -254,7 +254,7 @@ public Mono publishTheme(String applicationId) { .then( // Set the system theme id as edit and published mode theme id to // application object - applicationRepository.setAppTheme( + applicationRepository.updateAppTheme( applicationId, editModeTheme.getId(), editModeTheme.getId(), @@ -321,7 +321,7 @@ private Mono saveThemeForApplication( if (savedThemeTuple.getT2()) { // new theme created, update the application if (applicationMode == ApplicationMode.EDIT) { return applicationRepository - .setAppTheme( + .updateAppTheme( application.getId(), theme.getId(), null, @@ -331,7 +331,7 @@ private Mono saveThemeForApplication( .thenReturn(theme); } else { return applicationRepository - .setAppTheme( + .updateAppTheme( application.getId(), null, theme.getId(), 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 3ca18b567c6..bdd25f9100f 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 @@ -94,14 +94,11 @@ public Mono importEntities( // 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()); - - addDryOpsForApplication( - mappedImportableResourcesDTO.getApplicationDryRunQueries(), application); - return Mono.just(importableArtifact); + return applicationService.setAppTheme( + importableArtifact.getId(), + editModeThemeId, + publishedModeThemeId, + applicationPermission.getEditPermission()); }) .then(); }); @@ -114,7 +111,7 @@ private Mono updateExistingAppThemeFromJSON( MappedImportableResourcesDTO mappedImportableResourcesDTO) { if (!StringUtils.hasLength(existingThemeId)) { return themeService - .getOrSaveTheme(themeFromJson, (Application) destinationArtifact, true) + .getOrSaveTheme(themeFromJson, (Application) destinationArtifact, false) .map(createdTheme -> { addDryOpsForEntity( DBOpsType.SAVE, mappedImportableResourcesDTO.getThemeDryRunQueries(), createdTheme); @@ -128,7 +125,7 @@ private Mono updateExistingAppThemeFromJSON( .flatMap(existingTheme -> { if (!StringUtils.hasLength(existingTheme.getId()) || existingTheme.isSystemTheme()) { return themeService - .getOrSaveTheme(themeFromJson, (Application) destinationArtifact, true) + .getOrSaveTheme(themeFromJson, (Application) destinationArtifact, false) .map(createdTheme -> { addDryOpsForEntity( DBOpsType.SAVE, @@ -139,7 +136,7 @@ private Mono updateExistingAppThemeFromJSON( } else { if (themeFromJson.isSystemTheme()) { return themeService - .getOrSaveTheme(themeFromJson, (Application) destinationArtifact, true) + .getOrSaveTheme(themeFromJson, (Application) destinationArtifact, false) .flatMap(importedTheme -> { // need to delete the old existingTheme addDryOpsForEntity( @@ -154,10 +151,6 @@ private Mono updateExistingAppThemeFromJSON( }); } else { themeFromJson.setId(existingThemeId); - addDryOpsForEntity( - DBOpsType.UPDATE, - mappedImportableResourcesDTO.getThemeDryRunQueries(), - themeFromJson); return Mono.just(themeFromJson); } } @@ -189,14 +182,4 @@ private void addDryOpsForEntity(DBOpsType queryType, Map> dr dryRunOpsMap.put(queryType.name(), themes); } } - - private void addDryOpsForApplication(Map> dryRunOpsMap, Application application) { - if (dryRunOpsMap.containsKey(DBOpsType.UPDATE.name())) { - dryRunOpsMap.get(DBOpsType.UPDATE.name()).add(application); - } else { - List applicationList = new ArrayList<>(); - applicationList.add(application); - dryRunOpsMap.put(DBOpsType.UPDATE.name(), applicationList); - } - } }