diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceCEImpl.java index ba6da316a370..4a594718bde8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceCEImpl.java @@ -46,6 +46,7 @@ public class ApplicationExportServiceCEImpl implements ArtifactBasedExportServic protected final ExportableService actionCollectionExportableService; private final ExportableService themeExportableService; private final Map applicationConstantsMap = new HashMap<>(); + private final JsonSchemaVersions jsonSchemaVersions; public ApplicationExportServiceCEImpl( ApplicationService applicationService, @@ -53,13 +54,15 @@ public ApplicationExportServiceCEImpl( ExportableService newPageExportableService, ExportableService newActionExportableService, ExportableService actionCollectionExportableService, - ExportableService themeExportableService) { + ExportableService themeExportableService, + JsonSchemaVersions jsonSchemaVersions) { this.applicationService = applicationService; this.newPageExportableService = newPageExportableService; this.newActionExportableService = newActionExportableService; this.actionCollectionExportableService = actionCollectionExportableService; this.themeExportableService = themeExportableService; this.applicationPermission = applicationPermission; + this.jsonSchemaVersions = jsonSchemaVersions; applicationConstantsMap.putAll( Map.of(FieldName.ARTIFACT_CONTEXT, FieldName.APPLICATION, FieldName.ID, FieldName.APPLICATION_ID)); } @@ -120,8 +123,10 @@ public Mono getArtifactReadyForExport( GitArtifactMetadata gitArtifactMetadata = application.getGitApplicationMetadata(); Instant applicationLastCommittedAt = gitArtifactMetadata != null ? gitArtifactMetadata.getLastCommittedAt() : null; - boolean isClientSchemaMigrated = !JsonSchemaVersions.clientVersion.equals(application.getClientSchemaVersion()); - boolean isServerSchemaMigrated = !JsonSchemaVersions.serverVersion.equals(application.getServerSchemaVersion()); + boolean isClientSchemaMigrated = + !jsonSchemaVersions.getClientVersion().equals(application.getClientSchemaVersion()); + boolean isServerSchemaMigrated = + !jsonSchemaVersions.getServerVersion().equals(application.getServerSchemaVersion()); exportingMetaDTO.setArtifactLastCommittedAt(applicationLastCommittedAt); exportingMetaDTO.setClientSchemaMigrated(isClientSchemaMigrated); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceImpl.java index 0704c66f9b8c..7eb3e0c83b85 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/exports/ApplicationExportServiceImpl.java @@ -9,6 +9,7 @@ import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.exports.exportable.ExportableService; import com.appsmith.server.exports.internal.artifactbased.ArtifactBasedExportService; +import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.solutions.ApplicationPermission; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -24,7 +25,8 @@ public ApplicationExportServiceImpl( ExportableService newPageExportableService, ExportableService newActionExportableService, ExportableService actionCollectionExportableService, - ExportableService themeExportableService) { + ExportableService themeExportableService, + JsonSchemaVersions jsonSchemaVersions) { super( applicationService, @@ -32,6 +34,7 @@ public ApplicationExportServiceImpl( newPageExportableService, newActionExportableService, actionCollectionExportableService, - themeExportableService); + themeExportableService, + jsonSchemaVersions); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCECompatibleImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCECompatibleImpl.java index d27b2068d16e..a713b1a2b955 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCECompatibleImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCECompatibleImpl.java @@ -6,6 +6,7 @@ import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; import com.appsmith.server.helpers.ResponseUtils; +import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; import com.appsmith.server.services.ApplicationPageService; @@ -19,7 +20,7 @@ public class GitApplicationHelperCECompatibleImpl extends GitApplicationHelperCEImpl implements GitArtifactHelperCECompatible { public GitApplicationHelperCECompatibleImpl( - CommonGitFileUtils gitFileUtils, + CommonGitFileUtils commonGitFileUtils, GitPrivateRepoHelper gitPrivateRepoHelper, ApplicationService applicationService, ApplicationPageService applicationPageService, @@ -27,9 +28,10 @@ public GitApplicationHelperCECompatibleImpl( NewPageService newPageService, ActionCollectionService actionCollectionService, NewActionService newActionService, - ResponseUtils responseUtils) { + ResponseUtils responseUtils, + JsonSchemaVersions jsonSchemaVersions) { super( - gitFileUtils, + commonGitFileUtils, gitPrivateRepoHelper, applicationService, applicationPageService, @@ -37,6 +39,7 @@ public GitApplicationHelperCECompatibleImpl( newPageService, actionCollectionService, newActionService, - responseUtils); + responseUtils, + jsonSchemaVersions); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java index 83356f1ed84b..b7dfd83d4b0d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperCEImpl.java @@ -59,6 +59,7 @@ public class GitApplicationHelperCEImpl implements GitArtifactHelperCE updateArtifactWithSchemaVersions(Artifact artifact) { Application update = new Application(); // Reset migration related fields before commit to detect the updates correctly between the commits - update.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - update.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + update.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + update.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); update.setIsManualUpdate(false); return applicationService.update(artifact.getId(), update); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperImpl.java index fa29626f67bf..1faeff54d0d9 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/GitApplicationHelperImpl.java @@ -6,6 +6,7 @@ import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.GitPrivateRepoHelper; import com.appsmith.server.helpers.ResponseUtils; +import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; import com.appsmith.server.services.ApplicationPageService; @@ -28,7 +29,8 @@ public GitApplicationHelperImpl( NewPageService newPageService, ActionCollectionService actionCollectionService, NewActionService newActionService, - ResponseUtils responseUtils) { + ResponseUtils responseUtils, + JsonSchemaVersions jsonSchemaVersions) { super( gitFileUtils, gitPrivateRepoHelper, @@ -38,6 +40,7 @@ public GitApplicationHelperImpl( newPageService, actionCollectionService, newActionService, - responseUtils); + responseUtils, + jsonSchemaVersions); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceCEImpl.java index 52073ca67e2c..c4ac38b47771 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceCEImpl.java @@ -53,6 +53,7 @@ public class ExportServiceCEImpl implements ExportServiceCE { private final ExportableService pluginExportableService; private final ExportableService customJSLibExportableService; protected final Gson gson; + private final JsonSchemaVersions jsonSchemaVersions; public ExportServiceCEImpl( SessionUserService sessionUserService, @@ -62,7 +63,8 @@ public ExportServiceCEImpl( Gson gson, ExportableService datasourceExportableService, ExportableService pluginExportableService, - ExportableService customJSLibExportableService) { + ExportableService customJSLibExportableService, + JsonSchemaVersions jsonSchemaVersions) { this.sessionUserService = sessionUserService; this.analyticsService = analyticsService; this.workspaceService = workspaceService; @@ -71,6 +73,7 @@ public ExportServiceCEImpl( this.datasourceExportableService = datasourceExportableService; this.pluginExportableService = pluginExportableService; this.customJSLibExportableService = customJSLibExportableService; + this.jsonSchemaVersions = jsonSchemaVersions; } @Override @@ -122,8 +125,8 @@ public Mono exportByExportableArtifactIdAndBranc ArtifactExchangeJson artifactExchangeJson = artifactBasedExportService.createNewArtifactExchangeJson(); // Set json schema version which will be used to check the compatibility while importing the JSON - artifactExchangeJson.setServerSchemaVersion(JsonSchemaVersions.serverVersion); - artifactExchangeJson.setClientSchemaVersion(JsonSchemaVersions.clientVersion); + artifactExchangeJson.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); + artifactExchangeJson.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); // Find the transaction artifact with appropriate permission Mono exportableArtifactMono = artifactBasedExportService diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceImpl.java index 0541b8c2fdef..b48dc7f42f59 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/ExportServiceImpl.java @@ -7,6 +7,7 @@ import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.exports.exportable.ExportableService; import com.appsmith.server.exports.internal.artifactbased.ArtifactBasedExportService; +import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.SessionUserService; import com.appsmith.server.services.WorkspaceService; @@ -26,7 +27,8 @@ public ExportServiceImpl( Gson gson, ExportableService datasourceExportableService, ExportableService pluginExportableService, - ExportableService customJSLibExportableService) { + ExportableService customJSLibExportableService, + JsonSchemaVersions jsonSchemaVersions) { super( sessionUserService, analyticsService, @@ -35,6 +37,7 @@ public ExportServiceImpl( gson, datasourceExportableService, pluginExportableService, - customJSLibExportableService); + customJSLibExportableService, + jsonSchemaVersions); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceCEImpl.java index 3bbe923e9e35..9488b4e19579 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceCEImpl.java @@ -57,6 +57,7 @@ public class PartialExportServiceCEImpl implements PartialExportServiceCE { private final ExportableService actionCollectionExportableService; private final SessionUserService sessionUserService; private final AnalyticsService analyticsService; + private final JsonSchemaVersions jsonSchemaVersions; @Override public Mono getPartialExportResources( @@ -77,8 +78,8 @@ public Mono getPartialExportResources( exportingMetaDTO.setExportWithConfiguration(false); // Set json schema version which will be used to check the compatibility while importing the JSON - applicationJson.setServerSchemaVersion(JsonSchemaVersions.serverVersion); - applicationJson.setClientSchemaVersion(JsonSchemaVersions.clientVersion); + applicationJson.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); + applicationJson.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); AclPermission permission = applicationPermission.getExportPermission(false, false); Mono branchedPageIdMono = diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceImpl.java index baefd4fd4e1e..c3836133f66c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exports/internal/partial/PartialExportServiceImpl.java @@ -8,6 +8,7 @@ import com.appsmith.server.domains.Plugin; import com.appsmith.server.exports.exportable.ExportableService; import com.appsmith.server.jslibs.base.CustomJSLibService; +import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.newactions.base.NewActionService; import com.appsmith.server.newpages.base.NewPageService; import com.appsmith.server.services.AnalyticsService; @@ -31,7 +32,8 @@ public PartialExportServiceImpl( ExportableService newActionExportableService, ExportableService actionCollectionExportableService, SessionUserService sessionUserService, - AnalyticsService analyticsService) { + AnalyticsService analyticsService, + JsonSchemaVersions jsonSchemaVersions) { super( applicationService, applicationPermission, @@ -44,6 +46,7 @@ public PartialExportServiceImpl( newActionExportableService, actionCollectionExportableService, sessionUserService, - analyticsService); + analyticsService, + jsonSchemaVersions); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java index 2e96e38c51d7..4886234416c0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperImpl.java @@ -33,6 +33,7 @@ public class AutoCommitEligibilityHelperImpl extends AutoCommitEligibilityHelper private final CommonGitFileUtils commonGitFileUtils; private final DSLMigrationUtils dslMigrationUtils; private final GitRedisUtils gitRedisUtils; + private final JsonSchemaVersions jsonSchemaVersions; @Override @FeatureFlagged(featureFlagName = FeatureFlagEnum.release_git_autocommit_eligibility_enabled) @@ -49,7 +50,7 @@ public Mono isServerAutoCommitRequired(String workspaceId, GitArtifactM defaultApplicationId, branchName, serverSchemaVersion); - return JsonSchemaVersions.serverVersion > serverSchemaVersion ? TRUE : FALSE; + return jsonSchemaVersions.getServerVersion() > serverSchemaVersion ? TRUE : FALSE; }) .defaultIfEmpty(FALSE) .cache(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java index ea3a9e7eaf5f..e8324f564b63 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/CommonGitFileUtils.java @@ -5,6 +5,7 @@ import com.appsmith.external.models.ApplicationGitReference; import com.appsmith.git.files.FileUtilsImpl; import com.appsmith.server.helpers.ce.CommonGitFileUtilsCE; +import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.SessionUserService; import com.google.gson.Gson; @@ -23,7 +24,14 @@ public CommonGitFileUtils( FileOperations fileOperations, AnalyticsService analyticsService, SessionUserService sessionUserService, - Gson gson) { - super(applicationGitFileUtils, fileUtils, fileOperations, analyticsService, sessionUserService); + Gson gson, + JsonSchemaVersions jsonSchemaVersions) { + super( + applicationGitFileUtils, + fileUtils, + fileOperations, + analyticsService, + sessionUserService, + jsonSchemaVersions); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ResponseUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ResponseUtils.java index aeea1fcd6a21..e9f771db2c1b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ResponseUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ResponseUtils.java @@ -1,9 +1,15 @@ package com.appsmith.server.helpers; import com.appsmith.server.helpers.ce.ResponseUtilsCE; +import com.appsmith.server.migrations.JsonSchemaVersions; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @Slf4j @Component -public class ResponseUtils extends ResponseUtilsCE {} +public class ResponseUtils extends ResponseUtilsCE { + + public ResponseUtils(JsonSchemaVersions jsonSchemaVersions) { + super(jsonSchemaVersions); + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java index f5a0a66ed695..dbaf54e9ee29 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/CommonGitFileUtilsCE.java @@ -64,6 +64,8 @@ public class CommonGitFileUtilsCE { @Value("${appsmith.index.lock.file.time}") public final int INDEX_LOCK_FILE_STALE_TIME = 300; + private final JsonSchemaVersions jsonSchemaVersions; + private ArtifactGitFileUtils getArtifactBasedFileHelper(ArtifactType artifactType) { if (ArtifactType.APPLICATION.equals(artifactType)) { return applicationGitFileUtils; @@ -359,7 +361,7 @@ public Mono getMetadataServerSchemaMigrationVersion( workspaceId, defaultArtifactId, repoName, branchName, isResetToLastCommitRequired, artifactType) .map(metadataMap -> { return metadataMap.getOrDefault( - CommonConstants.SERVER_SCHEMA_VERSION, JsonSchemaVersions.serverVersion); + CommonConstants.SERVER_SCHEMA_VERSION, jsonSchemaVersions.getServerVersion()); }); return Mono.create( @@ -422,7 +424,7 @@ public Mono getPageDslVersionNumber( private Integer getServerSchemaVersion(JsonObject metadataJsonObject) { if (metadataJsonObject == null) { - return JsonSchemaVersions.serverVersion; + return jsonSchemaVersions.getServerVersion(); } JsonElement serverSchemaVersion = metadataJsonObject.get(SERVER_SCHEMA_VERSION); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ResponseUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ResponseUtilsCE.java index 8cf4a00cd890..4480c04ddaee 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ResponseUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ResponseUtilsCE.java @@ -17,6 +17,7 @@ import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.migrations.JsonSchemaVersions; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component; @@ -26,8 +27,11 @@ @Slf4j @Component +@RequiredArgsConstructor public class ResponseUtilsCE { + protected final JsonSchemaVersions jsonSchemaVersions; + public PageDTO updatePageDTOWithDefaultResources(PageDTO page) { DefaultResources defaultResourceIds = page.getDefaultResources(); if (defaultResourceIds == null @@ -315,8 +319,8 @@ public Application updateApplicationWithDefaultResources(Application application if (application.getClientSchemaVersion() == null || application.getServerSchemaVersion() == null - || (JsonSchemaVersions.clientVersion.equals(application.getClientSchemaVersion()) - && JsonSchemaVersions.serverVersion.equals(application.getServerSchemaVersion()))) { + || (jsonSchemaVersions.getClientVersion().equals(application.getClientSchemaVersion()) + && jsonSchemaVersions.getServerVersion().equals(application.getServerSchemaVersion()))) { application.setIsAutoUpdate(false); } else { application.setIsAutoUpdate(true); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java index 0229867cf4b7..6c62de863c2c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceCEImpl.java @@ -65,6 +65,7 @@ public class ImportServiceCEImpl implements ImportServiceCE { private final ImportableService datasourceImportableService; private final GsonBuilder gsonBuilder; private final ArtifactExchangeJsonAdapter artifactExchangeJsonAdapter; + private final JsonSchemaMigration jsonSchemaMigration; /** * This method provides the importService specific to the artifact based on the ArtifactType. @@ -420,7 +421,7 @@ private Mono importArtifactInWorkspace( String artifactContextString = artifactSpecificConstantsMap.get(FieldName.ARTIFACT_CONTEXT); // step 1: Schema Migration - ArtifactExchangeJson importedDoc = JsonSchemaMigration.migrateArtifactToLatestSchema(artifactExchangeJson); + ArtifactExchangeJson importedDoc = jsonSchemaMigration.migrateArtifactToLatestSchema(artifactExchangeJson); // Step 2: Validation of artifact Json // check for validation error and raise exception if error found diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceImpl.java index 17cfcc254b7b..b325a019733f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/imports/internal/ImportServiceImpl.java @@ -8,6 +8,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.migrations.JsonSchemaMigration; import com.appsmith.server.repositories.PermissionGroupRepository; import com.appsmith.server.services.AnalyticsService; import com.appsmith.server.services.SessionUserService; @@ -28,7 +29,8 @@ public ImportServiceImpl( ImportableService pluginImportableService, ImportableService datasourceImportableService, GsonBuilder gsonBuilder, - ArtifactExchangeJsonAdapter artifactExchangeJsonAdapter) { + ArtifactExchangeJsonAdapter artifactExchangeJsonAdapter, + JsonSchemaMigration jsonSchemaMigration) { super( applicationImportService, sessionUserService, @@ -39,6 +41,7 @@ public ImportServiceImpl( pluginImportableService, datasourceImportableService, gsonBuilder, - artifactExchangeJsonAdapter); + artifactExchangeJsonAdapter, + jsonSchemaMigration); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java index 545686921c16..851b3173b605 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java @@ -16,17 +16,31 @@ @RequiredArgsConstructor public class JsonSchemaMigration { - private static boolean isCompatible(ApplicationJson applicationJson) { - return (applicationJson.getClientSchemaVersion() <= JsonSchemaVersions.clientVersion) - && (applicationJson.getServerSchemaVersion() <= JsonSchemaVersions.serverVersion); + private final JsonSchemaVersions jsonSchemaVersions; + + private boolean isCompatible(ApplicationJson applicationJson) { + return (applicationJson.getClientSchemaVersion() <= jsonSchemaVersions.getClientVersion()) + && (applicationJson.getServerSchemaVersion() <= jsonSchemaVersions.getServerVersion()); + } + + /** + * This is a temporary check which is being placed for the compatibility of server versions in scenarios + * where user is moving a json from an instance which has + * release_autocommit_feature_enabled true to an instance which has the flag as false. In that case the server + * version number of json would be 8 and in new instance it would be not compatible. + * @param applicationJson + * @return + */ + private boolean isAutocommitVersionBump(ApplicationJson applicationJson) { + return jsonSchemaVersions.getServerVersion() == 7 && applicationJson.getServerSchemaVersion() == 8; } - private static void setSchemaVersions(ApplicationJson applicationJson) { + private void setSchemaVersions(ApplicationJson applicationJson) { applicationJson.setServerSchemaVersion(getCorrectSchemaVersion(applicationJson.getServerSchemaVersion())); applicationJson.setClientSchemaVersion(getCorrectSchemaVersion(applicationJson.getClientSchemaVersion())); } - private static Integer getCorrectSchemaVersion(Integer schemaVersion) { + private Integer getCorrectSchemaVersion(Integer schemaVersion) { return schemaVersion == null ? 0 : schemaVersion; } @@ -52,6 +66,10 @@ public Mono migrateApplicationJsonToLatestSchema(ApplicationJso return migrateServerSchema(applicationJson); } + if (isAutocommitVersionBump(applicationJson)) { + return migrateServerSchema(applicationJson); + } + return null; }) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON))); @@ -64,7 +82,7 @@ public Mono migrateApplicationJsonToLatestSchema(ApplicationJso * @return transformed artifact exchange json */ @Deprecated - public static ArtifactExchangeJson migrateArtifactToLatestSchema(ArtifactExchangeJson artifactExchangeJson) { + public ArtifactExchangeJson migrateArtifactToLatestSchema(ArtifactExchangeJson artifactExchangeJson) { if (!ArtifactType.APPLICATION.equals(artifactExchangeJson.getArtifactJsonType())) { return artifactExchangeJson; @@ -73,7 +91,9 @@ public static ArtifactExchangeJson migrateArtifactToLatestSchema(ArtifactExchang ApplicationJson applicationJson = (ApplicationJson) artifactExchangeJson; setSchemaVersions(applicationJson); if (!isCompatible(applicationJson)) { - throw new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON); + if (!isAutocommitVersionBump(applicationJson)) { + throw new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON); + } } return migrateServerSchema(applicationJson); } @@ -83,8 +103,8 @@ public static ArtifactExchangeJson migrateArtifactToLatestSchema(ArtifactExchang * @param applicationJson : applicationJson which needs to be transformed * @return : transformed applicationJson */ - private static ApplicationJson migrateServerSchema(ApplicationJson applicationJson) { - if (JsonSchemaVersions.serverVersion.equals(applicationJson.getServerSchemaVersion())) { + private ApplicationJson migrateServerSchema(ApplicationJson applicationJson) { + if (jsonSchemaVersions.getServerVersion().equals(applicationJson.getServerSchemaVersion())) { // No need to run server side migration return applicationJson; } @@ -127,6 +147,12 @@ private static ApplicationJson migrateServerSchema(ApplicationJson applicationJs default: // Unable to detect the serverSchema } + + if (applicationJson.getServerSchemaVersion().equals(jsonSchemaVersions.getServerVersion())) { + return applicationJson; + } + + applicationJson.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); return applicationJson; } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersions.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersions.java index 2b81d9a020af..18365ebda339 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersions.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersions.java @@ -1,6 +1,8 @@ package com.appsmith.server.migrations; -import lombok.Getter; +import com.appsmith.external.annotations.FeatureFlagged; +import com.appsmith.external.enums.FeatureFlagEnum; +import org.springframework.stereotype.Component; /** * This class represents the JSON schema versions those are supported for the current instance. Whenever we run the @@ -10,8 +12,16 @@ * Having said that during import server will have to check the compatibility for both client * (widget dsl) and server-side resources, so that imported application will be in sane state after import is successful */ -@Getter -public class JsonSchemaVersions { - public static final Integer serverVersion = 7; - public static final Integer clientVersion = 1; +@Component +public class JsonSchemaVersions extends JsonSchemaVersionsFallback { + + /** + * Only tenant level flags would work over here. + * @return an Integer which is server version + */ + @Override + @FeatureFlagged(featureFlagName = FeatureFlagEnum.release_git_autocommit_feature_enabled) + public Integer getServerVersion() { + return super.getServerVersion() + 1; + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersionsFallback.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersionsFallback.java new file mode 100644 index 000000000000..ac8f0fe579aa --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersionsFallback.java @@ -0,0 +1,39 @@ +package com.appsmith.server.migrations; + +import org.springframework.stereotype.Component; + +@Component +public class JsonSchemaVersionsFallback { + private static final Integer serverVersion = 7; + public static final Integer clientVersion = 1; + + public Integer getServerVersion() { + return serverVersion; + } + + public Integer getClientVersion() { + return clientVersion; + } + + /** + * This method is separately described from the instance method. + * Since the instance method is feature flagged to yield different results based on + * value of flag release_git_autocommit_feature_enabled. + * Now some of the use case requires the value which is present in the static variable server version. + * That can be accessed via the instance method of fallback implementation, but would cost more memory + * to instantiate. + * @return server version from the private variable + */ + public static Integer getStaticServerVersion() { + return serverVersion; + } + + /** + * The client version can be accessed via the instance method of fallback implementation, + * but would cost more memory to instantiate. hence a parallel static implementation. + * @return client version from the private variable + */ + public static Integer getStaticClientVersion() { + return clientVersion; + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/CreateDBTablePageSolutionImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/CreateDBTablePageSolutionImpl.java index fb5cfc05e207..69956e2ebeb5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/CreateDBTablePageSolutionImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/CreateDBTablePageSolutionImpl.java @@ -6,6 +6,7 @@ import com.appsmith.server.helpers.PluginExecutorHelper; import com.appsmith.server.helpers.ResponseUtils; import com.appsmith.server.layouts.UpdateLayoutService; +import com.appsmith.server.migrations.JsonSchemaMigration; import com.appsmith.server.newpages.base.NewPageService; import com.appsmith.server.plugins.base.PluginService; import com.appsmith.server.services.AnalyticsService; @@ -20,6 +21,7 @@ @Slf4j public class CreateDBTablePageSolutionImpl extends CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolution { + public CreateDBTablePageSolutionImpl( DatasourceService datasourceService, DatasourceStorageService datasourceStorageService, @@ -37,7 +39,8 @@ public CreateDBTablePageSolutionImpl( ApplicationPermission applicationPermission, PagePermission pagePermission, DatasourceStructureSolution datasourceStructureSolution, - EnvironmentPermission environmentPermission) { + EnvironmentPermission environmentPermission, + JsonSchemaMigration jsonSchemaMigration) { super( datasourceService, datasourceStorageService, @@ -55,6 +58,7 @@ public CreateDBTablePageSolutionImpl( applicationPermission, pagePermission, datasourceStructureSolution, - environmentPermission); + environmentPermission, + jsonSchemaMigration); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/CreateDBTablePageSolutionCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/CreateDBTablePageSolutionCEImpl.java index aaaf45f144cb..159aafd1d043 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/CreateDBTablePageSolutionCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/CreateDBTablePageSolutionCEImpl.java @@ -95,6 +95,7 @@ public class CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolutio private final PagePermission pagePermission; private final DatasourceStructureSolution datasourceStructureSolution; private final EnvironmentPermission environmentPermission; + private final JsonSchemaMigration jsonSchemaMigration; private static final String FILE_PATH = "CRUD-DB-Table-Template-Application.json"; @@ -571,7 +572,7 @@ private ApplicationJson fetchTemplateApplication(String filePath) throws IOExcep new DefaultResourceLoader().getResource(filePath).getInputStream(), Charset.defaultCharset()); ApplicationJson applicationJson = gson.fromJson(jsonContent, ApplicationJson.class); - return (ApplicationJson) JsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson); + return (ApplicationJson) jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson); } /** diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java index 229ef9831f13..cab998ec48d6 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/exports/internal/ExportServiceTests.java @@ -189,6 +189,9 @@ public class ExportServiceTests { @Autowired SessionUserService sessionUserService; + @Autowired + JsonSchemaVersions jsonSchemaVersions; + @BeforeEach public void setup() { Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())) @@ -729,8 +732,10 @@ public void createExportAppJsonForGitTest() { NewPage newPage = pageList.get(0); - assertThat(applicationJson.getServerSchemaVersion()).isEqualTo(JsonSchemaVersions.serverVersion); - assertThat(applicationJson.getClientSchemaVersion()).isEqualTo(JsonSchemaVersions.clientVersion); + assertThat(applicationJson.getServerSchemaVersion()) + .isEqualTo(jsonSchemaVersions.getServerVersion()); + assertThat(applicationJson.getClientSchemaVersion()) + .isEqualTo(jsonSchemaVersions.getClientVersion()); assertThat(exportedApp.getName()).isNotNull(); assertThat(exportedApp.getWorkspaceId()).isNull(); @@ -1916,8 +1921,8 @@ public void exportApplicationByWhen_WhenGitConnectedAndPageRenamed_QueriesAreInU testApplication.setWorkspaceId(workspaceId); testApplication.setUpdatedAt(Instant.now()); testApplication.setLastDeployedAt(Instant.now()); - testApplication.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - testApplication.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + testApplication.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + testApplication.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); Mono applicationJsonMono = applicationPageService .createApplication(testApplication, workspaceId) @@ -2015,8 +2020,8 @@ public void exportApplicationByWhen_WhenGitConnectedAndDatasourceRenamed_Queries testApplication.setWorkspaceId(workspaceId); testApplication.setUpdatedAt(Instant.now()); testApplication.setLastDeployedAt(Instant.now()); - testApplication.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - testApplication.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + testApplication.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + testApplication.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); Mono applicationJsonMono = applicationPageService .createApplication(testApplication, workspaceId) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java index 05be8d1c0bf1..81d1167b9a91 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/CommonGitServiceCETest.java @@ -230,6 +230,12 @@ public class CommonGitServiceCETest { @Autowired CacheableRepositoryHelper cacheableRepositoryHelper; + @Autowired + JsonSchemaMigration jsonSchemaMigration; + + @Autowired + JsonSchemaVersions jsonSchemaVersions; + @SpyBean AnalyticsService analyticsService; @@ -290,7 +296,7 @@ private Mono createAppJson(String filePath) { return stringifiedFile .map(data -> gson.fromJson(data, ApplicationJson.class)) - .map(JsonSchemaMigration::migrateArtifactToLatestSchema) + .map(jsonSchemaMigration::migrateArtifactToLatestSchema) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } @@ -2295,8 +2301,8 @@ public void commitAndPushApplication_commitAndPushChanges_success() throws GitAP Application application = tuple.getT2(); assertThat(commitMsg).contains("sample response for commit"); assertThat(commitMsg).contains("pushed successfully"); - assertThat(application.getClientSchemaVersion()).isEqualTo(JsonSchemaVersions.clientVersion); - assertThat(application.getServerSchemaVersion()).isEqualTo(JsonSchemaVersions.serverVersion); + assertThat(application.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion()); + assertThat(application.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); assertThat(application.getIsManualUpdate()).isFalse(); }) .verifyComplete(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java index 204755223404..044d40468923 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java @@ -103,6 +103,8 @@ public class AutoCommitEventHandlerImplTest { AutoCommitEventHandler autoCommitEventHandler; + JsonSchemaVersions jsonSchemaVersions = new JsonSchemaVersions(); + private static final String defaultApplicationId = "default-app-id", branchName = "develop", workspaceId = "test-workspace-id"; @@ -439,7 +441,7 @@ public void autoCommitServerMigration_WhenServerHasNoChanges_NoCommitMade() thro ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(applicationJson, applicationJson1); - applicationJson1.setServerSchemaVersion(JsonSchemaVersions.serverVersion + 1); + applicationJson1.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() + 1); doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) @@ -573,7 +575,7 @@ public void autocommitServerMigration_WhenJsonSchemaMigrationPresent_CommitSucce ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(applicationJson, applicationJson1); - applicationJson1.setServerSchemaVersion(JsonSchemaVersions.serverVersion + 1); + applicationJson1.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() + 1); doReturn(Mono.just(applicationJson1)).when(jsonSchemaMigration).migrateApplicationJsonToLatestSchema(any()); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java index bdf2d4984e15..aeba6837eb2f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java @@ -16,6 +16,7 @@ import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.dtos.AutoCommitResponseDTO; import com.appsmith.server.dtos.PageDTO; +import com.appsmith.server.featureflags.CachedFeatures; import com.appsmith.server.git.autocommit.helpers.AutoCommitEligibilityHelper; import com.appsmith.server.git.common.CommonGitService; import com.appsmith.server.helpers.CommonGitFileUtils; @@ -38,6 +39,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; +import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -53,6 +55,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -122,6 +125,8 @@ public class AutoCommitServiceTest { Path baseRepoSuffix; + JsonSchemaVersions jsonSchemaVersions = new JsonSchemaVersions(); + private static final Integer DSL_VERSION_NUMBER = 88; private static final String WORKSPACE_ID = "test-workspace"; private static final String REPO_NAME = "test-repo"; @@ -133,7 +138,6 @@ public class AutoCommitServiceTest { private static final String PRIVATE_KEY = "private-key"; private static final String REPO_URL = "domain.xy"; private static final String DEFAULT_APP_ID = "default-app-id", DEFAULT_BRANCH_NAME = "master"; - private static final Integer SERVER_SCHEMA_VERSION = JsonSchemaVersions.serverVersion; private Application createApplication() { Application application = new Application(); @@ -196,8 +200,9 @@ private void mockAutoCommitTriggerResponse(Boolean serverMigration, Boolean clie .when(commonGitFileUtils) .getPageDslVersionNumber(anyString(), any(), any(), anyBoolean(), any()); + Integer serverVersion = jsonSchemaVersions.getServerVersion(); Integer dslVersionNumber = clientMigration ? DSL_VERSION_NUMBER + 1 : DSL_VERSION_NUMBER; - Integer serverSchemaVersionNumber = serverMigration ? SERVER_SCHEMA_VERSION - 1 : SERVER_SCHEMA_VERSION; + Integer serverSchemaVersionNumber = serverMigration ? serverVersion - 1 : serverVersion; doReturn(Mono.just(dslVersionNumber)).when(dslMigrationUtils).getLatestDslVersion(); @@ -226,6 +231,12 @@ public void beforeTest() { DEFAULT_APP_ID, pagePermission.getEditPermission(), ApplicationMode.PUBLISHED)) .thenReturn(Flux.just(pageDTO)); + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + Mockito.when(featureFlagService.check(FeatureFlagEnum.release_git_autocommit_eligibility_enabled)) .thenReturn(Mono.just(TRUE)); @@ -266,7 +277,7 @@ public void testAutoCommit_whenOnlyServerIsEligibleForMigration_commitSuccess() ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(applicationJson, applicationJson1); - applicationJson1.setServerSchemaVersion(JsonSchemaVersions.serverVersion + 1); + applicationJson1.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() + 1); doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) @@ -547,7 +558,7 @@ public void testAutoCommit_whenAutoCommitEligibleButPrerequisiteNotComplete_retu ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(applicationJson, applicationJson1); - applicationJson1.setServerSchemaVersion(JsonSchemaVersions.serverVersion + 1); + applicationJson1.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() + 1); doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) @@ -620,7 +631,7 @@ public void testAutoCommit_whenServerIsRunningMigrationCallsAutocommitAgainOnDif ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNewFieldValuesIntoOldObject(applicationJson, applicationJson1); - applicationJson1.setServerSchemaVersion(JsonSchemaVersions.serverVersion + 1); + applicationJson1.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() + 1); doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java index 01feec431786..8d4416c8c5a5 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/AutoCommitEligibilityHelperTest.java @@ -10,6 +10,7 @@ import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.dtos.AutoCommitTriggerDTO; import com.appsmith.server.dtos.PageDTO; +import com.appsmith.server.featureflags.CachedFeatures; import com.appsmith.server.git.GitRedisUtils; import com.appsmith.server.helpers.CommonGitFileUtils; import com.appsmith.server.helpers.DSLMigrationUtils; @@ -23,6 +24,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; +import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -34,8 +36,10 @@ import java.io.IOException; import java.util.HashSet; import java.util.List; +import java.util.Map; import static com.appsmith.external.git.constants.ce.GitConstantsCE.GitCommandConstantsCE.AUTO_COMMIT_ELIGIBILITY; +import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; @Slf4j @@ -61,6 +65,8 @@ public class AutoCommitEligibilityHelperTest { @Autowired GitFileSystemTestHelper gitFileSystemTestHelper; + JsonSchemaVersions jsonSchemaVersions = new JsonSchemaVersions(); + private static final int RANDOM_DSL_VERSION_NUMBER = 123; private static final String REPO_NAME = "test-repo"; private static final String BRANCH_NAME = "develop"; @@ -125,7 +131,7 @@ public void isAutoCommitRequired_whenClientAndServerAreEligible_verifyDTOReturns WORKSPACE_ID, gitArtifactMetadata, pageDTO, Boolean.TRUE, ArtifactType.APPLICATION); // this leads to server migration requirement as true - Mockito.doReturn(Mono.just(JsonSchemaVersions.serverVersion - 1)) + Mockito.doReturn(Mono.just(jsonSchemaVersions.getServerVersion() - 1)) .when(commonGitFileUtils) .getMetadataServerSchemaMigrationVersion( WORKSPACE_ID, gitArtifactMetadata, Boolean.TRUE, ArtifactType.APPLICATION); @@ -156,7 +162,7 @@ public void isAutoCommitRequired_whenClientAndServerAreNotEligible_verifyDTORetu WORKSPACE_ID, gitArtifactMetadata, pageDTO, Boolean.TRUE, ArtifactType.APPLICATION); // this leads to server migration requirement as false - Mockito.doReturn(Mono.just(JsonSchemaVersions.serverVersion)) + Mockito.doReturn(Mono.just(jsonSchemaVersions.getServerVersion())) .when(commonGitFileUtils) .getMetadataServerSchemaMigrationVersion( WORKSPACE_ID, gitArtifactMetadata, Boolean.FALSE, ArtifactType.APPLICATION); @@ -187,7 +193,7 @@ public void isAutoCommitRequired_whenOnlyClientIsEligible_verifyDTOReturnTrue() WORKSPACE_ID, gitArtifactMetadata, pageDTO, Boolean.TRUE, ArtifactType.APPLICATION); // this leads to server migration requirement as false - Mockito.doReturn(Mono.just(JsonSchemaVersions.serverVersion)) + Mockito.doReturn(Mono.just(jsonSchemaVersions.getServerVersion())) .when(commonGitFileUtils) .getMetadataServerSchemaMigrationVersion( WORKSPACE_ID, gitArtifactMetadata, Boolean.FALSE, ArtifactType.APPLICATION); @@ -209,6 +215,11 @@ public void isAutoCommitRequired_whenOnlyClientIsEligible_verifyDTOReturnTrue() @Test public void isAutoCommitRequired_whenOnlyServerIsEligible_verifyDTOReturnTrue() { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); GitArtifactMetadata gitArtifactMetadata = createGitMetadata(); PageDTO pageDTO = createPageDTO(RANDOM_DSL_VERSION_NUMBER); @@ -219,7 +230,7 @@ public void isAutoCommitRequired_whenOnlyServerIsEligible_verifyDTOReturnTrue() WORKSPACE_ID, gitArtifactMetadata, pageDTO, Boolean.TRUE, ArtifactType.APPLICATION); // this leads to server migration requirement as true - Mockito.doReturn(Mono.just(JsonSchemaVersions.serverVersion - 1)) + Mockito.doReturn(Mono.just(jsonSchemaVersions.getServerVersion() - 1)) .when(commonGitFileUtils) .getMetadataServerSchemaMigrationVersion( WORKSPACE_ID, gitArtifactMetadata, Boolean.FALSE, ArtifactType.APPLICATION); @@ -243,7 +254,7 @@ public void isServerMigrationRequired_whenJsonSchemaIsNotAhead_returnsFalse() { GitArtifactMetadata gitArtifactMetadata = createGitMetadata(); // this leads to server migration requirement as false - Mockito.doReturn(Mono.just(JsonSchemaVersions.serverVersion)) + Mockito.doReturn(Mono.just(jsonSchemaVersions.getServerVersion())) .when(commonGitFileUtils) .getMetadataServerSchemaMigrationVersion( WORKSPACE_ID, gitArtifactMetadata, Boolean.TRUE, ArtifactType.APPLICATION); @@ -261,8 +272,14 @@ public void isServerMigrationRequired_whenJsonSchemaIsNotAhead_returnsFalse() { public void isServerMigrationRequired_whenJsonSchemaIsAhead_returnsTrue() { GitArtifactMetadata gitArtifactMetadata = createGitMetadata(); + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + // this leads to server migration requirement as true - Mockito.doReturn(Mono.just(JsonSchemaVersions.serverVersion - 1)) + Mockito.doReturn(Mono.just(jsonSchemaVersions.getServerVersion() - 1)) .when(commonGitFileUtils) .getMetadataServerSchemaMigrationVersion( WORKSPACE_ID, gitArtifactMetadata, Boolean.FALSE, ArtifactType.APPLICATION); @@ -372,6 +389,12 @@ public void isAutoCommitRequired_whenFeatureIsFlagFalse_returnsAllFalse() { @Test public void isServerMigrationRequired_fileSystemOperation_returnsTrue() throws GitAPIException, IOException { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + ApplicationJson applicationJson = new ApplicationJson(); Application application = new Application(); @@ -385,8 +408,8 @@ public void isServerMigrationRequired_fileSystemOperation_returnsTrue() throws G applicationJson.setPageList(List.of()); applicationJson.setPublishedTheme(new Theme()); applicationJson.setEditModeTheme(new Theme()); - applicationJson.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - applicationJson.setServerSchemaVersion(JsonSchemaVersions.serverVersion - 1); + applicationJson.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + applicationJson.setServerSchemaVersion(jsonSchemaVersions.getServerVersion() - 1); ModifiedResources modifiedResources = new ModifiedResources(); modifiedResources.setAllModified(true); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/gac/DefaultBranchGACTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/gac/DefaultBranchGACTest.java new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/gac/GitServiceWithRBACTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/gac/GitServiceWithRBACTest.java new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java index 5f261a1ca6f7..8ae698c2b842 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitFileUtilsTest.java @@ -64,6 +64,9 @@ public class GitFileUtilsTest { @Autowired Gson gson; + @Autowired + JsonSchemaMigration jsonSchemaMigration; + private Mono createAppJson(String filePath) { FilePart filePart = Mockito.mock(FilePart.class, Mockito.RETURNS_DEEP_STUBS); Flux dataBufferFlux = DataBufferUtils.read( @@ -84,7 +87,7 @@ private Mono createAppJson(String filePath) { .map(data -> { return gson.fromJson(data, ApplicationJson.class); }) - .map(JsonSchemaMigration::migrateArtifactToLatestSchema) + .map(jsonSchemaMigration::migrateArtifactToLatestSchema) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ResponseUtilsTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ResponseUtilsTest.java index 2b531df77636..db27144d6bf8 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ResponseUtilsTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/ResponseUtilsTest.java @@ -38,6 +38,9 @@ public class ResponseUtilsTest { @Autowired ResponseUtils responseUtils; + @Autowired + JsonSchemaVersions jsonSchemaVersions; + Gson gson = new Gson(); @SneakyThrows @@ -184,13 +187,13 @@ public void getApplication_withMultipleSchemaVersions_returnsCorrectManualUpdate application.setIsAutoUpdate(null); application.setClientSchemaVersion(1000); - application.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + application.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); responseUtils.updateApplicationWithDefaultResources(application); assertEquals(application.getIsAutoUpdate(), true); application.setIsAutoUpdate(null); - application.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - application.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + application.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + application.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); responseUtils.updateApplicationWithDefaultResources(application); assertEquals(application.getIsAutoUpdate(), false); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java index e8c8cc365546..0f03290799b7 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java @@ -232,6 +232,12 @@ public class ImportServiceTests { @Autowired SessionUserService sessionUserService; + @Autowired + JsonSchemaMigration jsonSchemaMigration; + + @Autowired + JsonSchemaVersions jsonSchemaVersions; + @BeforeEach public void setup() { Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())) @@ -354,7 +360,7 @@ private Mono createAppJson(String filePath) { .map(data -> { return gson.fromJson(data, ApplicationJson.class); }) - .map(JsonSchemaMigration::migrateArtifactToLatestSchema) + .map(jsonSchemaMigration::migrateArtifactToLatestSchema) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } @@ -747,8 +753,10 @@ public void createExportAppJsonForGitTest() { NewPage newPage = pageList.get(0); - assertThat(applicationJson.getServerSchemaVersion()).isEqualTo(JsonSchemaVersions.serverVersion); - assertThat(applicationJson.getClientSchemaVersion()).isEqualTo(JsonSchemaVersions.clientVersion); + assertThat(applicationJson.getServerSchemaVersion()) + .isEqualTo(jsonSchemaVersions.getServerVersion()); + assertThat(applicationJson.getClientSchemaVersion()) + .isEqualTo(jsonSchemaVersions.getClientVersion()); assertThat(exportedApp.getName()).isNotNull(); assertThat(exportedApp.getWorkspaceId()).isNull(); @@ -2713,7 +2721,7 @@ public void applySchemaMigration_jsonFileWithFirstVersion_migratedToLatestVersio Mono migratedApplicationMono = v1ApplicationMono.map(applicationJson -> { ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNestedNonNullProperties(applicationJson, applicationJson1); - return (ApplicationJson) JsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson1); + return (ApplicationJson) jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson1); }); StepVerifier.create(Mono.zip(v1ApplicationMono, migratedApplicationMono)) @@ -2725,9 +2733,9 @@ public void applySchemaMigration_jsonFileWithFirstVersion_migratedToLatestVersio assertThat(v1ApplicationJson.getClientSchemaVersion()).isEqualTo(1); assertThat(latestApplicationJson.getServerSchemaVersion()) - .isEqualTo(JsonSchemaVersions.serverVersion); + .isEqualTo(jsonSchemaVersions.getServerVersion()); assertThat(latestApplicationJson.getClientSchemaVersion()) - .isEqualTo(JsonSchemaVersions.clientVersion); + .isEqualTo(jsonSchemaVersions.getClientVersion()); }) .verifyComplete(); } @@ -5021,8 +5029,8 @@ public void exportApplicationByWhen_WhenGitConnectedAndPageRenamed_QueriesAreInU testApplication.setWorkspaceId(workspaceId); testApplication.setUpdatedAt(Instant.now()); testApplication.setLastDeployedAt(Instant.now()); - testApplication.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - testApplication.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + testApplication.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + testApplication.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); Mono applicationJsonMono = applicationPageService .createApplication(testApplication, workspaceId) @@ -5119,8 +5127,8 @@ public void exportApplicationByWhen_WhenGitConnectedAndDatasourceRenamed_Queries testApplication.setWorkspaceId(workspaceId); testApplication.setUpdatedAt(Instant.now()); testApplication.setLastDeployedAt(Instant.now()); - testApplication.setClientSchemaVersion(JsonSchemaVersions.clientVersion); - testApplication.setServerSchemaVersion(JsonSchemaVersions.serverVersion); + testApplication.setClientSchemaVersion(jsonSchemaVersions.getClientVersion()); + testApplication.setServerSchemaVersion(jsonSchemaVersions.getServerVersion()); Mono applicationJsonMono = applicationPageService .createApplication(testApplication, workspaceId) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaMigrationTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaMigrationTest.java new file mode 100644 index 000000000000..91af7aa64212 --- /dev/null +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaMigrationTest.java @@ -0,0 +1,144 @@ +package com.appsmith.server.migrations; + +import com.appsmith.external.enums.FeatureFlagEnum; +import com.appsmith.server.dtos.ApplicationJson; +import com.appsmith.server.dtos.ArtifactExchangeJson; +import com.appsmith.server.featureflags.CachedFeatures; +import com.appsmith.server.services.FeatureFlagService; +import com.appsmith.server.testhelpers.git.GitFileSystemTestHelper; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Map; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; +import static org.assertj.core.api.Assertions.assertThat; + +@Slf4j +@SpringBootTest +@ExtendWith(SpringExtension.class) +public class JsonSchemaMigrationTest { + + @MockBean + FeatureFlagService featureFlagService; + + @Autowired + JsonSchemaMigration jsonSchemaMigration; + + @Autowired + JsonSchemaVersions jsonSchemaVersions; + + @Autowired + JsonSchemaVersionsFallback jsonSchemaVersionsFallback; + + @Autowired + GitFileSystemTestHelper gitFileSystemTestHelper; + + @Test + public void migrateArtifactToLatestSchema_whenFeatureFlagIsOff_returnsFallbackValue() + throws URISyntaxException, IOException { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), FALSE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + + ApplicationJson applicationJson = + gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); + + ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson); + + assertThat(artifactExchangeJson.getServerSchemaVersion()) + .isEqualTo(jsonSchemaVersionsFallback.getServerVersion()); + assertThat(artifactExchangeJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); + assertThat(artifactExchangeJson.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion()); + assertThat(artifactExchangeJson.getClientSchemaVersion()) + .isEqualTo(jsonSchemaVersionsFallback.getClientVersion()); + } + + @Test + public void migrateArtifactToLatestSchema_whenFeatureFlagIsOn_returnsIncrementedValue() + throws URISyntaxException, IOException { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + + ApplicationJson applicationJson = + gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); + + ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration.migrateArtifactToLatestSchema(applicationJson); + + assertThat(artifactExchangeJson.getServerSchemaVersion()) + .isNotEqualTo(jsonSchemaVersionsFallback.getServerVersion()); + assertThat(artifactExchangeJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); + assertThat(artifactExchangeJson.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion()); + assertThat(artifactExchangeJson.getClientSchemaVersion()) + .isEqualTo(jsonSchemaVersionsFallback.getClientVersion()); + } + + @Test + public void migrateApplicationJsonToLatestSchema_whenFeatureFlagIsOn_returnsIncrementedValue() + throws URISyntaxException, IOException { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + + ApplicationJson applicationJson = + gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); + + Mono applicationJsonMono = + jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson); + StepVerifier.create(applicationJsonMono) + .assertNext(appJson -> { + assertThat(appJson.getServerSchemaVersion()) + .isNotEqualTo(jsonSchemaVersionsFallback.getServerVersion()); + assertThat(appJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); + assertThat(appJson.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion()); + assertThat(appJson.getClientSchemaVersion()) + .isEqualTo(jsonSchemaVersionsFallback.getClientVersion()); + }) + .verifyComplete(); + } + + @Test + public void migrateApplicationJsonToLatestSchema_whenFeatureFlagIsOff_returnsFallbackValue() + throws URISyntaxException, IOException { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), FALSE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + + ApplicationJson applicationJson = + gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); + + Mono applicationJsonMono = + jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson); + StepVerifier.create(applicationJsonMono) + .assertNext(appJson -> { + assertThat(appJson.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion()); + assertThat(appJson.getClientSchemaVersion()) + .isEqualTo(jsonSchemaVersionsFallback.getClientVersion()); + assertThat(appJson.getServerSchemaVersion()) + .isEqualTo(jsonSchemaVersionsFallback.getServerVersion()); + assertThat(appJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); + }) + .verifyComplete(); + } +} diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java new file mode 100644 index 000000000000..31cbcdcf2b66 --- /dev/null +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/migrations/JsonSchemaVersionsTest.java @@ -0,0 +1,61 @@ +package com.appsmith.server.migrations; + +import com.appsmith.external.enums.FeatureFlagEnum; +import com.appsmith.server.featureflags.CachedFeatures; +import com.appsmith.server.services.FeatureFlagService; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import java.util.Map; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; +import static org.assertj.core.api.Assertions.assertThat; + +@Slf4j +@SpringBootTest +@ExtendWith(SpringExtension.class) +public class JsonSchemaVersionsTest { + + @MockBean + FeatureFlagService featureFlagService; + + @Autowired + JsonSchemaVersions jsonSchemaVersions; + + @Autowired + JsonSchemaVersionsFallback jsonSchemaVersionsFallback; + + @Test + public void getServerVersion_whenFeatureFlagIsOff_returnsFallbackValue() { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), FALSE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + + assertThat(jsonSchemaVersions.getServerVersion()).isEqualTo(jsonSchemaVersionsFallback.getServerVersion()); + assertThat(jsonSchemaVersions.getClientVersion()).isEqualTo(jsonSchemaVersionsFallback.getClientVersion()); + } + + @Test + public void getServerVersion_whenFeatureFlagIsOn_returnsIncremented() { + CachedFeatures cachedFeatures = new CachedFeatures(); + cachedFeatures.setFeatures(Map.of(FeatureFlagEnum.release_git_autocommit_feature_enabled.name(), TRUE)); + + Mockito.when(featureFlagService.getCachedTenantFeatureFlags()) + .thenAnswer((Answer) invocations -> cachedFeatures); + + assertThat(jsonSchemaVersions.getServerVersion()).isNotEqualTo(jsonSchemaVersionsFallback.getServerVersion()); + assertThat(jsonSchemaVersions.getServerVersion()).isEqualTo(jsonSchemaVersionsFallback.getServerVersion() + 1); + + assertThat(jsonSchemaVersions.getClientVersion()).isEqualTo(jsonSchemaVersionsFallback.getClientVersion()); + } +} diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ee/ImportExportApplicationServiceEETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ee/ImportExportApplicationServiceEETest.java new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ee/ImportExportApplicationServiceGACTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ee/ImportExportApplicationServiceGACTest.java new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java index d6d0b3b8e075..7e46d65bf6a0 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/transactions/ImportApplicationTransactionServiceTest.java @@ -85,6 +85,9 @@ public class ImportApplicationTransactionServiceTest { @Autowired private Gson gson; + @Autowired + JsonSchemaMigration jsonSchemaMigration; + Long applicationCount = 0L, pageCount = 0L, actionCount = 0L, actionCollectionCount = 0L; private ApplicationJson applicationJson = new ApplicationJson(); @@ -127,7 +130,7 @@ private Mono createAppJson(String filePath) { .map(data -> { return gson.fromJson(data, ApplicationJson.class); }) - .map(JsonSchemaMigration::migrateArtifactToLatestSchema) + .map(jsonSchemaMigration::migrateArtifactToLatestSchema) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } diff --git a/app/server/appsmith-server/src/test/resources/com/appsmith/server/migrations/application.json b/app/server/appsmith-server/src/test/resources/com/appsmith/server/migrations/application.json new file mode 100644 index 000000000000..def16682e2bc --- /dev/null +++ b/app/server/appsmith-server/src/test/resources/com/appsmith/server/migrations/application.json @@ -0,0 +1,144 @@ +{ + "artifactJsonType": "APPLICATION", + "clientSchemaVersion": 1.0, + "serverSchemaVersion": 7.0, + "exportedApplication": { + "name": "json-schema-migration", + "isPublic": false, + "pages": [ + { + "id": "Page1", + "isDefault": true + } + ], + "publishedPages": [ + { + "id": "Page1", + "isDefault": true + } + ], + "viewMode": false, + "appIsExample": false, + "unreadCommentThreads": 0.0, + "unpublishedApplicationDetail": { + "appPositioning": { + "type": "FIXED" + }, + "navigationSetting": {} + }, + "publishedApplicationDetail": { + "appPositioning": { + "type": "FIXED" + }, + "navigationSetting": {} + }, + "color": "#C2DAF0", + "icon": "bicycle", + "slug": "json-schema-migration", + "unpublishedCustomJSLibs": [], + "publishedCustomJSLibs": [], + "evaluationVersion": 2.0, + "applicationVersion": 2.0, + "collapseInvisibleWidgets": true, + "isManualUpdate": false, + "deleted": false + }, + "datasourceList": [], + "customJSLibList": [], + "pageList": [ + { + "unpublishedPage": { + "name": "Page1", + "slug": "page1", + "layouts": [ + { + "viewMode": false, + "dsl": { + "widgetName": "MainContainer", + "backgroundColor": "none", + "rightColumn": 4896.0, + "snapColumns": 64.0, + "detachFromLayout": true, + "widgetId": "0", + "topRow": 0.0, + "bottomRow": 5000.0, + "containerStyle": "none", + "snapRows": 124.0, + "parentRowSpace": 1.0, + "type": "CANVAS_WIDGET", + "canExtend": true, + "version": 89.0, + "minHeight": 1292.0, + "dynamicTriggerPathList": [], + "parentColumnSpace": 1.0, + "dynamicBindingPathList": [], + "leftColumn": 0.0, + "children": [] + }, + "validOnPageLoadActions": true, + "id": "Page1", + "deleted": false, + "policies": [], + "userPermissions": [] + } + ], + "userPermissions": [], + "policies": [] + }, + "publishedPage": { + "name": "Page1", + "slug": "page1", + "layouts": [ + { + "viewMode": false, + "dsl": { + "widgetName": "MainContainer", + "backgroundColor": "none", + "rightColumn": 1224.0, + "snapColumns": 16.0, + "detachFromLayout": true, + "widgetId": "0", + "topRow": 0.0, + "bottomRow": 1250.0, + "containerStyle": "none", + "snapRows": 33.0, + "parentRowSpace": 1.0, + "type": "CANVAS_WIDGET", + "canExtend": true, + "version": 4.0, + "minHeight": 1292.0, + "dynamicTriggerPathList": [], + "parentColumnSpace": 1.0, + "dynamicBindingPathList": [], + "leftColumn": 0.0, + "children": [] + }, + "validOnPageLoadActions": true, + "id": "Page1", + "deleted": false, + "policies": [], + "userPermissions": [] + } + ], + "userPermissions": [], + "policies": [] + }, + "deleted": false, + "gitSyncId": "66696d2a56058477333bde6d_c547bd78-3732-4ef1-9f5b-ef1809056f4a" + } + ], + "actionList": [], + "actionCollectionList": [], + "editModeTheme": { + "name": "Default-New", + "displayName": "Modern", + "isSystemTheme": true, + "deleted": false + }, + "publishedTheme": { + "name": "Default-New", + "displayName": "Modern", + "isSystemTheme": true, + "deleted": false + } +}