Skip to content

Commit

Permalink
refactor method names
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaghHegde committed Nov 6, 2024
1 parent 4e18827 commit 21a3ea9
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Key> {
String getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ public String getRandomAppCardColor() {
@Override
public Mono<Integer> setAppTheme(
String applicationId, String editModeThemeId, String publishedModeThemeId, AclPermission aclPermission) {
return repository.setAppTheme(applicationId, editModeThemeId, publishedModeThemeId, aclPermission);
return repository.updateAppTheme(applicationId, editModeThemeId, publishedModeThemeId, aclPermission);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Mono<Datasource> create(Datasource datasource) {
@Override
public Mono<Datasource> createWithoutPermissions(
Datasource datasource, Map<DBOpsType, List<DatasourceStorage>> datasourceStorageDryRunQueries) {
return createEx(datasource, null, true, datasourceStorageDryRunQueries);
return createEx(datasource, null, false, datasourceStorageDryRunQueries);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private Mono<Map<String, String>> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Mono<Void> importEntities(
customJSLib.setCreatedAt(null);
customJSLib.setUpdatedAt(null);
return customJSLibService.persistCustomJSLibMetaDataIfDoesNotExistAndGetDTO(
customJSLib, false, mappedImportableResourcesDTO.getCustomJSLibsDryOps(), true);
customJSLib, false, mappedImportableResourcesDTO.getCustomJSLibsDryOps(), false);
})
.collectList()
.doOnNext(mappedImportableResourcesDTO::setInstalledJsLibsList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Mono<Application> getApplicationByGitBranchAndBaseApplicationId(

Flux<Application> getApplicationByGitBaseApplicationId(String baseApplicationId, AclPermission permission);

Mono<Integer> setAppTheme(
Mono<Integer> updateAppTheme(
String applicationId, String editModeThemeId, String publishedModeThemeId, AclPermission aclPermission);

Mono<Long> getGitConnectedApplicationWithPrivateRepoCount(String workspaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public Mono<Application> getApplicationByBaseApplicationIdAndDefaultBranch(Strin
}

@Override
public Mono<Integer> setAppTheme(
public Mono<Integer> updateAppTheme(
String applicationId, String editModeThemeId, String publishedModeThemeId, AclPermission aclPermission) {
BridgeUpdate updateObj = Bridge.update();
if (StringUtils.hasLength(editModeThemeId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ public Mono<Theme> changeCurrentTheme(String newThemeId, String branchedApplicat
// customizations
return repository
.delete(currentTheme)
.then(applicationRepository.setAppTheme(
.then(applicationRepository.updateAppTheme(
application.getId(),
savedTheme.getId(),
null,
applicationPermission.getEditPermission()))
.thenReturn(savedTheme);
} else {
return applicationRepository
.setAppTheme(
.updateAppTheme(
application.getId(),
savedTheme.getId(),
null,
Expand Down Expand Up @@ -254,7 +254,7 @@ public Mono<Theme> 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(),
Expand Down Expand Up @@ -321,7 +321,7 @@ private Mono<Theme> saveThemeForApplication(
if (savedThemeTuple.getT2()) { // new theme created, update the application
if (applicationMode == ApplicationMode.EDIT) {
return applicationRepository
.setAppTheme(
.updateAppTheme(
application.getId(),
theme.getId(),
null,
Expand All @@ -331,7 +331,7 @@ private Mono<Theme> saveThemeForApplication(
.thenReturn(theme);
} else {
return applicationRepository
.setAppTheme(
.updateAppTheme(
application.getId(),
null,
theme.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,11 @@ public Mono<Void> 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();
});
Expand All @@ -114,7 +111,7 @@ private Mono<Theme> 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);
Expand All @@ -128,7 +125,7 @@ private Mono<Theme> 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,
Expand All @@ -139,7 +136,7 @@ private Mono<Theme> 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(
Expand All @@ -154,10 +151,6 @@ private Mono<Theme> updateExistingAppThemeFromJSON(
});
} else {
themeFromJson.setId(existingThemeId);
addDryOpsForEntity(
DBOpsType.UPDATE,
mappedImportableResourcesDTO.getThemeDryRunQueries(),
themeFromJson);
return Mono.just(themeFromJson);
}
}
Expand Down Expand Up @@ -189,14 +182,4 @@ private void addDryOpsForEntity(DBOpsType queryType, Map<String, List<Theme>> dr
dryRunOpsMap.put(queryType.name(), themes);
}
}

private void addDryOpsForApplication(Map<String, List<Application>> dryRunOpsMap, Application application) {
if (dryRunOpsMap.containsKey(DBOpsType.UPDATE.name())) {
dryRunOpsMap.get(DBOpsType.UPDATE.name()).add(application);
} else {
List<Application> applicationList = new ArrayList<>();
applicationList.add(application);
dryRunOpsMap.put(DBOpsType.UPDATE.name(), applicationList);
}
}
}

0 comments on commit 21a3ea9

Please sign in to comment.