chore: removed non reactive json migration (#36413)
This commit is contained in:
parent
e89fb0c2e4
commit
9bbf794a85
|
|
@ -27,6 +27,7 @@ import com.appsmith.server.imports.importable.ImportableService;
|
|||
import com.appsmith.server.imports.internal.artifactbased.ArtifactBasedImportServiceCE;
|
||||
import com.appsmith.server.layouts.UpdateLayoutService;
|
||||
import com.appsmith.server.migrations.ApplicationVersion;
|
||||
import com.appsmith.server.migrations.JsonSchemaMigration;
|
||||
import com.appsmith.server.newactions.base.NewActionService;
|
||||
import com.appsmith.server.services.ApplicationPageService;
|
||||
import com.appsmith.server.solutions.ActionPermission;
|
||||
|
|
@ -53,6 +54,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static com.appsmith.server.helpers.ImportExportUtils.setPropertiesToExistingApplication;
|
||||
import static com.appsmith.server.helpers.ImportExportUtils.setPublishedApplicationProperties;
|
||||
import static org.springframework.util.StringUtils.hasText;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
|
|
@ -69,6 +71,7 @@ public class ApplicationImportServiceCEImpl
|
|||
private final ApplicationPermission applicationPermission;
|
||||
private final PagePermission pagePermission;
|
||||
private final ActionPermission actionPermission;
|
||||
private final JsonSchemaMigration jsonSchemaMigration;
|
||||
private final ImportableService<Theme> themeImportableService;
|
||||
private final ImportableService<NewPage> newPageImportableService;
|
||||
private final ImportableService<CustomJSLib> customJSLibImportableService;
|
||||
|
|
@ -639,4 +642,26 @@ public class ApplicationImportServiceCEImpl
|
|||
public Flux<String> getBranchedArtifactIdsByBranchedArtifactId(String branchedArtifactId) {
|
||||
return applicationService.findAllBranchedApplicationIdsByBranchedApplicationId(branchedArtifactId, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ApplicationJson> migrateArtifactExchangeJson(
|
||||
String branchedArtifactId, ArtifactExchangeJson artifactExchangeJson) {
|
||||
ApplicationJson applicationJson = (ApplicationJson) artifactExchangeJson;
|
||||
|
||||
if (!hasText(branchedArtifactId)) {
|
||||
return jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null);
|
||||
}
|
||||
|
||||
return applicationService.findById(branchedArtifactId).flatMap(application -> {
|
||||
String baseArtifactId = application.getBaseId();
|
||||
String branchName = null;
|
||||
|
||||
if (application.getGitArtifactMetadata() != null) {
|
||||
branchName = application.getGitArtifactMetadata().getBranchName();
|
||||
}
|
||||
|
||||
return jsonSchemaMigration.migrateApplicationJsonToLatestSchema(
|
||||
applicationJson, baseArtifactId, branchName);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.appsmith.server.dtos.ApplicationJson;
|
|||
import com.appsmith.server.imports.importable.ImportableService;
|
||||
import com.appsmith.server.imports.internal.artifactbased.ArtifactBasedImportService;
|
||||
import com.appsmith.server.layouts.UpdateLayoutService;
|
||||
import com.appsmith.server.migrations.JsonSchemaMigration;
|
||||
import com.appsmith.server.newactions.base.NewActionService;
|
||||
import com.appsmith.server.services.ApplicationPageService;
|
||||
import com.appsmith.server.solutions.ActionPermission;
|
||||
|
|
@ -35,6 +36,7 @@ public class ApplicationImportServiceImpl extends ApplicationImportServiceCEImpl
|
|||
ApplicationPermission applicationPermission,
|
||||
PagePermission pagePermission,
|
||||
ActionPermission actionPermission,
|
||||
JsonSchemaMigration jsonSchemaMigration,
|
||||
ImportableService<Theme> themeImportableService,
|
||||
ImportableService<NewPage> newPageImportableService,
|
||||
ImportableService<CustomJSLib> customJSLibImportableService,
|
||||
|
|
@ -50,6 +52,7 @@ public class ApplicationImportServiceImpl extends ApplicationImportServiceCEImpl
|
|||
applicationPermission,
|
||||
pagePermission,
|
||||
actionPermission,
|
||||
jsonSchemaMigration,
|
||||
themeImportableService,
|
||||
newPageImportableService,
|
||||
customJSLibImportableService,
|
||||
|
|
|
|||
|
|
@ -411,23 +411,32 @@ public class ImportServiceCEImpl implements ImportServiceCE {
|
|||
String artifactContextString = artifactSpecificConstantsMap.get(FieldName.ARTIFACT_CONTEXT);
|
||||
|
||||
// step 1: Schema Migration
|
||||
ArtifactExchangeJson importedDoc = jsonSchemaMigration.migrateArtifactToLatestSchema(artifactExchangeJson);
|
||||
Mono<? extends ArtifactExchangeJson> migratedArtifactJsonMono = artifactBasedImportService
|
||||
.migrateArtifactExchangeJson(branchedArtifactId, artifactExchangeJson)
|
||||
.flatMap(importedDoc -> {
|
||||
// Step 2: Validation of artifact Json
|
||||
// check for validation error and raise exception if error found
|
||||
String errorField = validateArtifactExchangeJson(importedDoc);
|
||||
if (!errorField.isEmpty()) {
|
||||
log.error("Error in importing {}. Field {} is missing", artifactContextString, errorField);
|
||||
|
||||
// Step 2: Validation of artifact Json
|
||||
// check for validation error and raise exception if error found
|
||||
String errorField = validateArtifactExchangeJson(importedDoc);
|
||||
if (!errorField.isEmpty()) {
|
||||
log.error("Error in importing {}. Field {} is missing", artifactContextString, errorField);
|
||||
if (errorField.equals(artifactContextString)) {
|
||||
return Mono.error(
|
||||
new AppsmithException(
|
||||
if (errorField.equals(artifactContextString)) {
|
||||
return Mono.error(
|
||||
new AppsmithException(
|
||||
AppsmithError.VALIDATION_FAILURE,
|
||||
"Field '" + artifactContextString
|
||||
+ "'. Sorry! It seems you've imported a page-level JSON instead of an application. Please use the import within the page."));
|
||||
}
|
||||
|
||||
return Mono.error(new AppsmithException(
|
||||
AppsmithError.VALIDATION_FAILURE,
|
||||
"Field '" + artifactContextString
|
||||
+ "' Sorry! Seems like you've imported a page-level json instead of an application. Please use the import within the page."));
|
||||
}
|
||||
return Mono.error(new AppsmithException(
|
||||
AppsmithError.VALIDATION_FAILURE, "Field '" + errorField + "' is missing in the JSON."));
|
||||
}
|
||||
"Field '" + errorField + "' is missing in the JSON."));
|
||||
}
|
||||
|
||||
artifactBasedImportService.syncClientAndSchemaVersion(importedDoc);
|
||||
return Mono.just(importedDoc);
|
||||
})
|
||||
.cache();
|
||||
|
||||
ImportingMetaDTO importingMetaDTO = new ImportingMetaDTO(
|
||||
workspaceId,
|
||||
|
|
@ -441,7 +450,6 @@ public class ImportServiceCEImpl implements ImportServiceCE {
|
|||
permissionGroups);
|
||||
|
||||
MappedImportableResourcesDTO mappedImportableResourcesDTO = new MappedImportableResourcesDTO();
|
||||
artifactBasedImportService.syncClientAndSchemaVersion(importedDoc);
|
||||
|
||||
Mono<Workspace> workspaceMono = workspaceService
|
||||
.findById(workspaceId, permissionProvider.getRequiredPermissionOnTargetWorkspace())
|
||||
|
|
@ -469,56 +477,63 @@ public class ImportServiceCEImpl implements ImportServiceCE {
|
|||
.switchIfEmpty(Mono.just(List.of()))
|
||||
.doOnNext(importingMetaDTO::setBranchedArtifactIds);
|
||||
|
||||
// this would import customJsLibs for all type of artifacts
|
||||
Mono<Void> artifactSpecificImportableEntities =
|
||||
artifactBasedImportService.generateArtifactSpecificImportableEntities(
|
||||
importedDoc, importingMetaDTO, mappedImportableResourcesDTO);
|
||||
final Mono<? extends Artifact> resultMono = migratedArtifactJsonMono.flatMap(importedDoc -> {
|
||||
|
||||
/*
|
||||
Calling the workspaceMono first to avoid creating multiple mongo transactions.
|
||||
If the first db call inside a transaction is a Flux, then there's a chance of creating multiple mongo
|
||||
transactions which will lead to NoSuchTransaction exception.
|
||||
*/
|
||||
final Mono<? extends Artifact> importableArtifactMono = workspaceMono
|
||||
.then(Mono.defer(() -> Mono.when(branchedArtifactIdsMono, artifactSpecificImportableEntities)))
|
||||
.then(Mono.defer(() -> artifactBasedImportService.updateAndSaveArtifactInContext(
|
||||
importedDoc.getArtifact(), importingMetaDTO, mappedImportableResourcesDTO, currUserMono)))
|
||||
.cache();
|
||||
// this would import customJsLibs for all type of artifacts
|
||||
Mono<Void> artifactSpecificImportableEntities =
|
||||
artifactBasedImportService.generateArtifactSpecificImportableEntities(
|
||||
importedDoc, importingMetaDTO, mappedImportableResourcesDTO);
|
||||
|
||||
final Mono<? extends Artifact> importMono = importableArtifactMono
|
||||
.then(Mono.defer(() -> generateImportableEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importableArtifactMono,
|
||||
importedDoc)))
|
||||
.then(importableArtifactMono)
|
||||
.flatMap(importableArtifact -> updateImportableEntities(
|
||||
artifactBasedImportService, importableArtifact, mappedImportableResourcesDTO, importingMetaDTO))
|
||||
.flatMap(importableArtifact -> updateImportableArtifact(artifactBasedImportService, importableArtifact))
|
||||
.onErrorResume(throwable -> {
|
||||
String errorMessage = ImportExportUtils.getErrorMessage(throwable);
|
||||
log.error("Error importing {}. Error: {}", artifactContextString, errorMessage, throwable);
|
||||
return Mono.error(
|
||||
new AppsmithException(AppsmithError.GENERIC_JSON_IMPORT_ERROR, workspaceId, errorMessage));
|
||||
})
|
||||
// execute dry run for datasource
|
||||
.flatMap(importableArtifact -> dryOperationRepository
|
||||
.executeAllDbOps(mappedImportableResourcesDTO)
|
||||
.thenReturn(importableArtifact))
|
||||
.as(transactionalOperator::transactional);
|
||||
/*
|
||||
Calling the workspaceMono first to avoid creating multiple mongo transactions.
|
||||
If the first db call inside a transaction is a Flux, then there's a chance of creating multiple mongo
|
||||
transactions which will lead to NoSuchTransaction exception.
|
||||
*/
|
||||
final Mono<? extends Artifact> importableArtifactMono = workspaceMono
|
||||
.then(Mono.defer(() -> Mono.when(branchedArtifactIdsMono, artifactSpecificImportableEntities)))
|
||||
.then(Mono.defer(() -> artifactBasedImportService.updateAndSaveArtifactInContext(
|
||||
importedDoc.getArtifact(), importingMetaDTO, mappedImportableResourcesDTO, currUserMono)))
|
||||
.cache();
|
||||
|
||||
final Mono<? extends Artifact> resultMono = importMono
|
||||
.flatMap(importableArtifact -> sendImportedContextAnalyticsEvent(
|
||||
artifactBasedImportService, importableArtifact, AnalyticsEvents.IMPORT))
|
||||
.zipWith(currUserMono)
|
||||
.flatMap(tuple -> {
|
||||
Artifact importableArtifact = tuple.getT1();
|
||||
User user = tuple.getT2();
|
||||
stopwatch.stopTimer();
|
||||
stopwatch.stopAndLogTimeInMillis();
|
||||
return sendImportRelatedAnalyticsEvent(importedDoc, importableArtifact, stopwatch, user);
|
||||
});
|
||||
final Mono<? extends Artifact> importMono = importableArtifactMono
|
||||
.then(Mono.defer(() -> generateImportableEntities(
|
||||
importingMetaDTO,
|
||||
mappedImportableResourcesDTO,
|
||||
workspaceMono,
|
||||
importableArtifactMono,
|
||||
importedDoc)))
|
||||
.then(importableArtifactMono)
|
||||
.flatMap(importableArtifact -> updateImportableEntities(
|
||||
artifactBasedImportService,
|
||||
importableArtifact,
|
||||
mappedImportableResourcesDTO,
|
||||
importingMetaDTO))
|
||||
.flatMap(importableArtifact ->
|
||||
updateImportableArtifact(artifactBasedImportService, importableArtifact))
|
||||
.onErrorResume(throwable -> {
|
||||
String errorMessage = ImportExportUtils.getErrorMessage(throwable);
|
||||
log.error("Error importing {}. Error: {}", artifactContextString, errorMessage, throwable);
|
||||
return Mono.error(new AppsmithException(
|
||||
AppsmithError.GENERIC_JSON_IMPORT_ERROR, workspaceId, errorMessage));
|
||||
})
|
||||
// execute dry run for datasource
|
||||
.flatMap(importableArtifact -> dryOperationRepository
|
||||
.executeAllDbOps(mappedImportableResourcesDTO)
|
||||
.thenReturn(importableArtifact))
|
||||
.as(transactionalOperator::transactional);
|
||||
|
||||
return importMono
|
||||
.flatMap(importableArtifact -> sendImportedContextAnalyticsEvent(
|
||||
artifactBasedImportService, importableArtifact, AnalyticsEvents.IMPORT))
|
||||
.zipWith(currUserMono)
|
||||
.flatMap(tuple -> {
|
||||
Artifact importableArtifact = tuple.getT1();
|
||||
User user = tuple.getT2();
|
||||
stopwatch.stopTimer();
|
||||
stopwatch.stopAndLogTimeInMillis();
|
||||
return sendImportRelatedAnalyticsEvent(importedDoc, importableArtifact, stopwatch, user);
|
||||
});
|
||||
});
|
||||
|
||||
// Import Context is currently a slow API because it needs to import and create context, pages, actions
|
||||
// and action collection. This process may take time and the client may cancel the request. This leads to the
|
||||
|
|
|
|||
|
|
@ -153,4 +153,6 @@ public interface ArtifactBasedImportServiceCE<
|
|||
Mono<Set<String>> getDatasourceIdSetConsumedInArtifact(String baseArtifactId);
|
||||
|
||||
Flux<String> getBranchedArtifactIdsByBranchedArtifactId(String branchedArtifactId);
|
||||
|
||||
Mono<V> migrateArtifactExchangeJson(String branchedArtifactId, ArtifactExchangeJson artifactExchangeJson);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
|
|
@ -37,15 +35,21 @@ public class JsonSchemaMigration {
|
|||
}
|
||||
|
||||
/**
|
||||
* This method migrates the server schema of artifactExchangeJson after choosing the right method for migration
|
||||
* this will likely be overridden in EE codebase for more choices
|
||||
* @param artifactExchangeJson artifactExchangeJson which is imported
|
||||
* Migrates the server schema of the given ArtifactExchangeJson by selecting the appropriate migration method.
|
||||
* This method may be overridden in the EE codebase for additional migration choices.
|
||||
*
|
||||
* @param artifactExchangeJson The artifact to be imported.
|
||||
* @param baseArtifactId The base application ID to which it's being imported,
|
||||
* if it's a Git-connected artifact; otherwise, null.
|
||||
* @param branchName The branch name of the artifact being imported,
|
||||
* if it's a Git-connected application; otherwise, null.
|
||||
*/
|
||||
public Mono<? extends ArtifactExchangeJson> migrateArtifactExchangeJsonToLatestSchema(
|
||||
ArtifactExchangeJson artifactExchangeJson) {
|
||||
ArtifactExchangeJson artifactExchangeJson, String baseArtifactId, String branchName) {
|
||||
|
||||
if (ArtifactType.APPLICATION.equals(artifactExchangeJson.getArtifactJsonType())) {
|
||||
return migrateApplicationJsonToLatestSchema((ApplicationJson) artifactExchangeJson, null, null);
|
||||
return migrateApplicationJsonToLatestSchema(
|
||||
(ApplicationJson) artifactExchangeJson, baseArtifactId, branchName);
|
||||
}
|
||||
|
||||
return Mono.fromCallable(() -> artifactExchangeJson);
|
||||
|
|
@ -62,82 +66,28 @@ public class JsonSchemaMigration {
|
|||
return Mono.empty();
|
||||
}
|
||||
|
||||
// Taking a tech debt over here for import of file application.
|
||||
// All migration above version 9 is reactive
|
||||
// TODO: make import flow migration reactive
|
||||
return Mono.just(migrateServerSchema(appJson))
|
||||
.flatMap(migratedApplicationJson -> {
|
||||
// In Server version 9, there was a bug where the Embedded REST API datasource URL
|
||||
// was not being persisted correctly. Once the bug was fixed,
|
||||
// any previously uncommitted changes started appearing as uncommitted modifications
|
||||
// in the apps. To automatically commit these changes
|
||||
// (which were now appearing as uncommitted), a migration process was needed.
|
||||
// This migration fetches the datasource URL from the database
|
||||
// and serializes it in Git if the URL exists.
|
||||
// If the URL is missing, it copies the empty datasource configuration
|
||||
// if the configuration is present in the database.
|
||||
// Otherwise, it leaves the configuration unchanged.
|
||||
// Due to an update in the migration logic after version 10 was shipped,
|
||||
// the entire migration process was moved to version 11.
|
||||
// This adjustment ensures that the same operation can be
|
||||
// performed again for the changes introduced in version 10.
|
||||
if (migratedApplicationJson.getServerSchemaVersion() == 9) {
|
||||
migratedApplicationJson.setServerSchemaVersion(10);
|
||||
}
|
||||
|
||||
if (migratedApplicationJson.getServerSchemaVersion() == 10) {
|
||||
if (Boolean.TRUE.equals(MigrationHelperMethods.doesRestApiRequireMigration(
|
||||
migratedApplicationJson))) {
|
||||
return jsonSchemaMigrationHelper
|
||||
.addDatasourceConfigurationToDefaultRestApiActions(
|
||||
baseApplicationId, branchName, migratedApplicationJson);
|
||||
}
|
||||
|
||||
migratedApplicationJson.setServerSchemaVersion(11);
|
||||
}
|
||||
|
||||
return Mono.just(migratedApplicationJson);
|
||||
})
|
||||
.map(migratedAppJson -> {
|
||||
applicationJson.setServerSchemaVersion(jsonSchemaVersions.getServerVersion());
|
||||
return applicationJson;
|
||||
});
|
||||
return migrateServerSchema(applicationJson, baseApplicationId, branchName);
|
||||
})
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON)));
|
||||
}
|
||||
|
||||
/**
|
||||
* migrate artifacts to latest schema by adding the right DTOs, or any migration.
|
||||
* This method would be deprecated soon enough
|
||||
* @param artifactExchangeJson : the json to be imported
|
||||
* @return transformed artifact exchange json
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "Use migrateArtifactJsonToLatestSchema")
|
||||
public ArtifactExchangeJson migrateArtifactToLatestSchema(ArtifactExchangeJson artifactExchangeJson) {
|
||||
|
||||
if (!ArtifactType.APPLICATION.equals(artifactExchangeJson.getArtifactJsonType())) {
|
||||
return artifactExchangeJson;
|
||||
}
|
||||
|
||||
ApplicationJson applicationJson = (ApplicationJson) artifactExchangeJson;
|
||||
setSchemaVersions(applicationJson);
|
||||
if (!isCompatible(applicationJson)) {
|
||||
throw new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON);
|
||||
}
|
||||
|
||||
applicationJson = migrateServerSchema(applicationJson);
|
||||
return nonReactiveServerMigrationForImport(applicationJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method may be moved to the publisher chain itself
|
||||
* @param applicationJson : applicationJson which needs to be transformed
|
||||
*
|
||||
* @param applicationJson : applicationJson which needs to be transformed
|
||||
* @param baseApplicationId : baseApplicationId of the application to which it's being imported,
|
||||
* if it's a git connected artifact, otherwise a null value would be passed.
|
||||
* @param branchName : branch name of the artifact for which application json is getting imported
|
||||
* if it's a git connected application. Otherwise, the value would be null
|
||||
* @return : transformed applicationJson
|
||||
*/
|
||||
private ApplicationJson migrateServerSchema(ApplicationJson applicationJson) {
|
||||
private Mono<ApplicationJson> migrateServerSchema(
|
||||
ApplicationJson applicationJson, String baseApplicationId, String branchName) {
|
||||
Mono<ApplicationJson> migrateApplicationJsonMono = Mono.just(applicationJson);
|
||||
|
||||
if (jsonSchemaVersions.getServerVersion().equals(applicationJson.getServerSchemaVersion())) {
|
||||
// No need to run server side migration
|
||||
return applicationJson;
|
||||
return migrateApplicationJsonMono;
|
||||
}
|
||||
// Run migration linearly
|
||||
// Updating the schema version after each migration is not required as we are not exiting by breaking the switch
|
||||
|
|
@ -180,38 +130,33 @@ public class JsonSchemaMigration {
|
|||
case 8:
|
||||
MigrationHelperMethods.migrateThemeSettingsForAnvil(applicationJson);
|
||||
applicationJson.setServerSchemaVersion(9);
|
||||
|
||||
// This is not supposed to have anymore additions to the schema.
|
||||
default:
|
||||
// Unable to detect the serverSchema
|
||||
|
||||
}
|
||||
|
||||
return applicationJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is an alternative to reactive way of adding migrations to application json.
|
||||
* this is getting used by flows which haven't implemented the reactive way yet.
|
||||
* @param applicationJson : application json for which migration has to be done.
|
||||
* @return return application json after migration
|
||||
*/
|
||||
private ApplicationJson nonReactiveServerMigrationForImport(ApplicationJson applicationJson) {
|
||||
if (jsonSchemaVersions.getServerVersion().equals(applicationJson.getServerSchemaVersion())) {
|
||||
return applicationJson;
|
||||
}
|
||||
|
||||
switch (applicationJson.getServerSchemaVersion()) {
|
||||
// In Server version 9, there was a bug where the Embedded REST API datasource URL
|
||||
// was not being persisted correctly. Once the bug was fixed,
|
||||
// any previously uncommitted changes started appearing as uncommitted modifications
|
||||
// in the apps. To automatically commit these changes
|
||||
// (which were now appearing as uncommitted), a migration process was needed.
|
||||
// This migration fetches the datasource URL from the database
|
||||
// and serializes it in Git if the URL exists.
|
||||
// If the URL is missing, it copies the empty datasource configuration
|
||||
// if the configuration is present in the database.
|
||||
// Otherwise, it leaves the configuration unchanged.
|
||||
// Due to an update in the migration logic after version 10 was shipped,
|
||||
// the entire migration process was moved to version 11.
|
||||
// This adjustment ensures that the same operation can be
|
||||
// performed again for the changes introduced in version 10.
|
||||
case 9:
|
||||
applicationJson.setServerSchemaVersion(10);
|
||||
case 10:
|
||||
// this if for cases where we have empty datasource configs
|
||||
MigrationHelperMethods.migrateApplicationJsonToVersionTen(applicationJson, Map.of());
|
||||
if (Boolean.TRUE.equals(MigrationHelperMethods.doesRestApiRequireMigration(applicationJson))) {
|
||||
migrateApplicationJsonMono = migrateApplicationJsonMono.flatMap(
|
||||
migratedJson -> jsonSchemaMigrationHelper.addDatasourceConfigurationToDefaultRestApiActions(
|
||||
baseApplicationId, branchName, migratedJson));
|
||||
}
|
||||
applicationJson.setServerSchemaVersion(11);
|
||||
default:
|
||||
}
|
||||
|
||||
applicationJson.setServerSchemaVersion(jsonSchemaVersions.getServerVersion());
|
||||
return applicationJson;
|
||||
return migrateApplicationJsonMono;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ import org.springframework.util.CollectionUtils;
|
|||
import org.springframework.util.StreamUtils;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
|
|
@ -236,21 +237,8 @@ public class CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolutio
|
|||
.switchIfEmpty(Mono.error(
|
||||
new AppsmithException(AppsmithError.INVALID_DATASOURCE, FieldName.DATASOURCE, datasourceId)));
|
||||
|
||||
return datasourceStorageMono
|
||||
.zipWhen(datasourceStorage -> Mono.zip(
|
||||
pageMono,
|
||||
pluginService.findById(datasourceStorage.getPluginId()),
|
||||
datasourceStructureSolution.getStructure(datasourceStorage, false)))
|
||||
.flatMap(tuple -> {
|
||||
DatasourceStorage datasourceStorage = tuple.getT1();
|
||||
NewPage page = tuple.getT2().getT1();
|
||||
Plugin plugin = tuple.getT2().getT2();
|
||||
DatasourceStructure datasourceStructure = tuple.getT2().getT3();
|
||||
|
||||
final String layoutId =
|
||||
page.getUnpublishedPage().getLayouts().get(0).getId();
|
||||
final String savedPageId = page.getId();
|
||||
|
||||
// Should this be subscribed on a scheduler?
|
||||
Mono<ApplicationJson> applicationJsonMono = Mono.fromCallable(() -> {
|
||||
ApplicationJson applicationJson = new ApplicationJson();
|
||||
try {
|
||||
AppsmithBeanUtils.copyNestedNonNullProperties(
|
||||
|
|
@ -258,6 +246,29 @@ public class CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolutio
|
|||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
return applicationJson;
|
||||
})
|
||||
.subscribeOn(Schedulers.boundedElastic())
|
||||
.flatMap(applicationJson ->
|
||||
jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null));
|
||||
|
||||
return datasourceStorageMono
|
||||
.zipWhen(datasourceStorage -> Mono.zip(
|
||||
pageMono,
|
||||
pluginService.findById(datasourceStorage.getPluginId()),
|
||||
datasourceStructureSolution.getStructure(datasourceStorage, false),
|
||||
applicationJsonMono))
|
||||
.flatMap(tuple -> {
|
||||
DatasourceStorage datasourceStorage = tuple.getT1();
|
||||
NewPage page = tuple.getT2().getT1();
|
||||
Plugin plugin = tuple.getT2().getT2();
|
||||
DatasourceStructure datasourceStructure = tuple.getT2().getT3();
|
||||
ApplicationJson applicationJson = tuple.getT2().getT4();
|
||||
|
||||
final String layoutId =
|
||||
page.getUnpublishedPage().getLayouts().get(0).getId();
|
||||
final String savedPageId = page.getId();
|
||||
List<NewPage> pageList = applicationJson.getPageList();
|
||||
|
||||
if (pageList.isEmpty()) {
|
||||
|
|
@ -558,8 +569,7 @@ public class CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolutio
|
|||
final String jsonContent = StreamUtils.copyToString(
|
||||
new DefaultResourceLoader().getResource(filePath).getInputStream(), Charset.defaultCharset());
|
||||
|
||||
ApplicationJson applicationJson = gson.fromJson(jsonContent, ApplicationJson.class);
|
||||
return (ApplicationJson) jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson);
|
||||
return gson.fromJson(jsonContent, ApplicationJson.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -291,7 +291,8 @@ public class CommonGitServiceCETest {
|
|||
|
||||
return stringifiedFile
|
||||
.map(data -> gson.fromJson(data, ApplicationJson.class))
|
||||
.map(jsonSchemaMigration::migrateArtifactToLatestSchema)
|
||||
.flatMap(applicationJson ->
|
||||
jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null))
|
||||
.map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ public class GitFileUtilsTest {
|
|||
.map(data -> {
|
||||
return gson.fromJson(data, ApplicationJson.class);
|
||||
})
|
||||
.map(jsonSchemaMigration::migrateArtifactToLatestSchema)
|
||||
.flatMap(applicationJson ->
|
||||
jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null))
|
||||
.map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -357,7 +357,8 @@ public class ImportServiceTests {
|
|||
.map(data -> {
|
||||
return gson.fromJson(data, ApplicationJson.class);
|
||||
})
|
||||
.map(jsonSchemaMigration::migrateArtifactToLatestSchema)
|
||||
.flatMap(applicationJson ->
|
||||
jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null))
|
||||
.map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson);
|
||||
}
|
||||
|
||||
|
|
@ -2718,11 +2719,13 @@ public class ImportServiceTests {
|
|||
})
|
||||
.cache();
|
||||
|
||||
Mono<ApplicationJson> migratedApplicationMono = v1ApplicationMono.map(applicationJson -> {
|
||||
ApplicationJson applicationJson1 = new ApplicationJson();
|
||||
AppsmithBeanUtils.copyNestedNonNullProperties(applicationJson, applicationJson1);
|
||||
return (ApplicationJson) jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson1);
|
||||
});
|
||||
Mono<ApplicationJson> migratedApplicationMono = v1ApplicationMono
|
||||
.flatMap(applicationJson -> {
|
||||
ApplicationJson applicationJson1 = new ApplicationJson();
|
||||
AppsmithBeanUtils.copyNestedNonNullProperties(applicationJson, applicationJson1);
|
||||
return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson1, null, null);
|
||||
})
|
||||
.map(applicationJson -> (ApplicationJson) applicationJson);
|
||||
|
||||
StepVerifier.create(Mono.zip(v1ApplicationMono, migratedApplicationMono))
|
||||
.assertNext(tuple -> {
|
||||
|
|
|
|||
|
|
@ -55,7 +55,9 @@ public class JsonSchemaMigrationTest {
|
|||
ApplicationJson applicationJson =
|
||||
gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json"));
|
||||
|
||||
ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson);
|
||||
ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration
|
||||
.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null)
|
||||
.block();
|
||||
|
||||
assertThat(artifactExchangeJson.getServerSchemaVersion())
|
||||
.isEqualTo(jsonSchemaVersionsFallback.getServerVersion());
|
||||
|
|
@ -77,7 +79,9 @@ public class JsonSchemaMigrationTest {
|
|||
ApplicationJson applicationJson =
|
||||
gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json"));
|
||||
|
||||
ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson);
|
||||
ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration
|
||||
.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null)
|
||||
.block();
|
||||
assertThat(artifactExchangeJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion());
|
||||
assertThat(artifactExchangeJson.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion());
|
||||
assertThat(artifactExchangeJson.getClientSchemaVersion())
|
||||
|
|
|
|||
|
|
@ -130,7 +130,8 @@ public class ImportApplicationTransactionServiceTest {
|
|||
.map(data -> {
|
||||
return gson.fromJson(data, ApplicationJson.class);
|
||||
})
|
||||
.map(jsonSchemaMigration::migrateArtifactToLatestSchema)
|
||||
.flatMap(applicationJson ->
|
||||
jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null))
|
||||
.map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user