-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36239 from appsmithorg/cp/20240911
- Loading branch information
Showing
8 changed files
with
269 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...-server/src/main/java/com/appsmith/server/migrations/utils/JsonSchemaMigrationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.appsmith.server.migrations.utils; | ||
|
||
import com.appsmith.external.constants.PluginConstants; | ||
import com.appsmith.server.applications.base.ApplicationService; | ||
import com.appsmith.server.domains.Application; | ||
import com.appsmith.server.domains.NewAction; | ||
import com.appsmith.server.dtos.ApplicationJson; | ||
import com.appsmith.server.migrations.MigrationHelperMethods; | ||
import com.appsmith.server.newactions.base.NewActionService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class JsonSchemaMigrationHelper { | ||
|
||
private final ApplicationService applicationService; | ||
private final NewActionService newActionService; | ||
|
||
public Mono<ApplicationJson> addDatasourceConfigurationToDefaultRestApiActions( | ||
String baseApplicationId, String branchName, ApplicationJson applicationJson) { | ||
|
||
Mono<ApplicationJson> contingencyMigrationJson = Mono.defer(() -> Mono.fromCallable(() -> { | ||
MigrationHelperMethods.migrateApplicationJsonToVersionTen(applicationJson, Map.of()); | ||
return applicationJson; | ||
})); | ||
|
||
if (!StringUtils.hasText(baseApplicationId) || !StringUtils.hasText(branchName)) { | ||
return contingencyMigrationJson; | ||
} | ||
|
||
Mono<Application> applicationMono = applicationService | ||
.findByBranchNameAndBaseApplicationId(branchName, baseApplicationId, null) | ||
.cache(); | ||
|
||
return applicationMono | ||
.flatMap(branchedApplication -> { | ||
return newActionService | ||
.findAllByApplicationIdAndViewMode( | ||
branchedApplication.getId(), Boolean.FALSE, Optional.empty(), Optional.empty()) | ||
.filter(action -> { | ||
if (action.getUnpublishedAction() == null | ||
|| action.getUnpublishedAction().getDatasource() == null) { | ||
return false; | ||
} | ||
|
||
boolean reverseFlag = StringUtils.hasText(action.getUnpublishedAction() | ||
.getDatasource() | ||
.getId()) | ||
|| !PluginConstants.DEFAULT_REST_DATASOURCE.equals(action.getUnpublishedAction() | ||
.getDatasource() | ||
.getName()); | ||
|
||
return !reverseFlag; | ||
}) | ||
.collectMap(NewAction::getGitSyncId); | ||
}) | ||
.map(newActionMap -> { | ||
MigrationHelperMethods.migrateApplicationJsonToVersionTen(applicationJson, newActionMap); | ||
return applicationJson; | ||
}) | ||
.switchIfEmpty(contingencyMigrationJson) | ||
.onErrorResume(error -> { | ||
log.error("Error occurred while migrating actions of application json. {}", error.getMessage()); | ||
return contingencyMigrationJson; | ||
}); | ||
} | ||
} |
Oops, something went wrong.