From 927fc5da33b75ecae6102887a5d9005758e74b49 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Fri, 3 Jan 2025 17:44:22 +0530 Subject: [PATCH 1/6] added git resource map --- .../appsmith/git/files/FileUtilsCEImpl.java | 7 ++ .../appsmith/external/git/FileInterface.java | 2 + .../git/ApplicationGitFileUtilsCEImpl.java | 10 ++ .../git/central/CentralGitServiceCEImpl.java | 3 +- .../server/git/fs/GitFSServiceCEImpl.java | 41 +++++---- .../helpers/ce/ArtifactGitFileUtilsCE.java | 4 + .../helpers/ce/CommonGitFileUtilsCE.java | 91 +++++++++++++++++++ .../migrations/JsonSchemaMigration.java | 1 + 8 files changed, 138 insertions(+), 21 deletions(-) diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java index b7f39502212..7d68aaf19e5 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/files/FileUtilsCEImpl.java @@ -674,6 +674,13 @@ public Mono reconstructApplicationReferenceFromGitRepo( .subscribeOn(scheduler); } + @Override + public Mono constructGitResourceMapFromGitRepo(Path repositorySuffix, String refName) { + // TODO: check that we need to checkout to the ref + Path repositoryPath = Paths.get(gitServiceConfig.getGitRootPath()).resolve(repositorySuffix); + return Mono.fromCallable(() -> fetchGitResourceMap(repositoryPath)).subscribeOn(scheduler); + } + /** * This is used to initialize repo with Readme file when the application is connected to remote repo * diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java index d5422a24ef4..c655ef2bfbe 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/FileInterface.java @@ -50,6 +50,8 @@ Mono saveArtifactToGitRepo(Path baseRepoSuffix, GitResourceMap gitResource Mono reconstructApplicationReferenceFromGitRepo( String organisationId, String baseApplicationId, String repoName, String branchName); + Mono constructGitResourceMapFromGitRepo(Path repositorySuffix, String refName); + /** * This method just reconstructs the metdata of the json from git repo. * diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java index a5628db2df1..a9824225e07 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java @@ -29,6 +29,7 @@ import com.appsmith.server.dtos.PageDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.git.dtos.ArtifactJsonTransformationDTO; import com.appsmith.server.helpers.CollectionUtils; import com.appsmith.server.helpers.ce.ArtifactGitFileUtilsCE; import com.appsmith.server.migrations.JsonSchemaMigration; @@ -471,6 +472,15 @@ public Mono reconstructArtifactExchangeJsonFromFilesInRepo }); } + @Override + public Mono performJsonMigration( + ArtifactJsonTransformationDTO jsonTransformationDTO, ArtifactExchangeJson artifactExchangeJson) { + String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); + String refName = jsonTransformationDTO.getRefName(); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + artifactExchangeJson, baseArtifactId, refName); + } + protected List getApplicationResource(Map resources, Type type) { List deserializedResources = new ArrayList<>(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java index bc6c38ebaba..87702246521 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java @@ -423,6 +423,7 @@ protected Mono checkoutReference( ArtifactJsonTransformationDTO jsonTransformationDTO = new ArtifactJsonTransformationDTO(); jsonTransformationDTO.setWorkspaceId(baseArtifact.getWorkspaceId()); jsonTransformationDTO.setBaseArtifactId(baseGitMetadata.getDefaultArtifactId()); + jsonTransformationDTO.setRefName(finalRefName); jsonTransformationDTO.setRefType(refType); jsonTransformationDTO.setArtifactType(baseArtifact.getArtifactType()); jsonTransformationDTO.setRepoName(baseGitMetadata.getRepoName()); @@ -689,7 +690,7 @@ protected Mono createReference( }) // after the branch is created, we need to reset the older branch to the // clean status, i.e. last commit - .doOnSuccess(newImportedArtifact -> discardChanges(sourceArtifact, gitType)); + .flatMap(newImportedArtifact -> discardChanges(sourceArtifact, gitType)); }) .flatMap(newImportedArtifact -> gitRedisUtils .releaseFileLock( diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java index eafd070e04f..04457a46067 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java @@ -47,6 +47,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException; import org.eclipse.jgit.api.errors.EmptyCommitException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; import org.eclipse.jgit.errors.RepositoryNotFoundException; @@ -209,12 +210,8 @@ public void setRepositoryDetailsInGitArtifactMetadata( @Override public Mono reconstructArtifactJsonFromGitRepository( ArtifactJsonTransformationDTO artifactJsonTransformationDTO) { - return commonGitFileUtils.reconstructArtifactExchangeJsonFromGitRepoWithAnalytics( - artifactJsonTransformationDTO.getWorkspaceId(), - artifactJsonTransformationDTO.getBaseArtifactId(), - artifactJsonTransformationDTO.getRepoName(), - artifactJsonTransformationDTO.getRefName(), - artifactJsonTransformationDTO.getArtifactType()); + return commonGitFileUtils.constructArtifactExchangeJsonFromGitRepositoryWithAnalytics( + artifactJsonTransformationDTO); } @Override @@ -366,18 +363,23 @@ public Mono prepareChangesToBeCommitted( GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); - return commonGitFileUtils - .saveArtifactToLocalRepoWithAnalytics(repoSuffix, artifactExchangeJson, branchName) - .map(ignore -> Boolean.TRUE) - .onErrorResume(e -> { - log.error("Error in commit flow: ", e); - if (e instanceof RepositoryNotFoundException) { - return Mono.error(new AppsmithException(AppsmithError.REPOSITORY_NOT_FOUND, baseArtifactId)); - } else if (e instanceof AppsmithException) { - return Mono.error(e); - } - return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); - }); + try { + return commonGitFileUtils + .saveArtifactToLocalRepoNew(repoSuffix, artifactExchangeJson, branchName) + .map(ignore -> Boolean.TRUE) + .onErrorResume(e -> { + log.error("Error in commit flow: ", e); + if (e instanceof RepositoryNotFoundException) { + return Mono.error( + new AppsmithException(AppsmithError.REPOSITORY_NOT_FOUND, baseArtifactId)); + } else if (e instanceof AppsmithException) { + return Mono.error(e); + } + return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); + }); + } catch (IOException | GitAPIException e) { + return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); + } } @Override @@ -617,8 +619,7 @@ public Mono recreateArtifactJsonFromLastCommit( Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); return fsGitHandler.rebaseBranch(repoSuffix, refName).flatMap(rebaseStatus -> { - return commonGitFileUtils.reconstructArtifactExchangeJsonFromGitRepoWithAnalytics( - workspaceId, baseArtifactId, repoName, refName, artifactType); + return commonGitFileUtils.constructArtifactExchangeJsonFromGitRepository(jsonTransformationDTO); }); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ArtifactGitFileUtilsCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ArtifactGitFileUtilsCE.java index f92820c047a..f20fe5f878d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ArtifactGitFileUtilsCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ArtifactGitFileUtilsCE.java @@ -3,6 +3,7 @@ import com.appsmith.external.git.models.GitResourceMap; import com.appsmith.external.models.ArtifactGitReference; import com.appsmith.server.dtos.ArtifactExchangeJson; +import com.appsmith.server.git.dtos.ArtifactJsonTransformationDTO; import lombok.NonNull; import reactor.core.publisher.Mono; @@ -28,4 +29,7 @@ void addArtifactReferenceFromExportedJson( Path getRepoSuffixPath(String workspaceId, String artifactId, String repoName, @NonNull String... args); void setArtifactDependentPropertiesInJson(GitResourceMap gitResourceMap, ArtifactExchangeJson artifactExchangeJson); + + Mono performJsonMigration( + ArtifactJsonTransformationDTO jsonTransformationDTO, ArtifactExchangeJson artifactExchangeJson); } 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 5349f788df6..cad3822808b 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 @@ -30,6 +30,7 @@ import com.appsmith.server.dtos.PageDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; +import com.appsmith.server.git.dtos.ArtifactJsonTransformationDTO; import com.appsmith.server.helpers.ArtifactGitFileUtils; import com.appsmith.server.migrations.JsonSchemaVersions; import com.appsmith.server.newactions.base.NewActionService; @@ -553,6 +554,96 @@ private void setDatasourcesInArtifactReference( artifactGitReference.setDatasources(resourceMap); } + public Mono constructArtifactExchangeJsonFromGitRepositoryWithAnalytics( + ArtifactJsonTransformationDTO jsonTransformationDTO) { + if (!isJsonTransformationDTOValid(jsonTransformationDTO)) { + return Mono.error(new AppsmithException( + AppsmithError.INVALID_GIT_CONFIGURATION, "ArtifactJSONTransformationDTO is invalid")); + } + + String workspaceId = jsonTransformationDTO.getWorkspaceId(); + String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); + + ArtifactGitFileUtils artifactGitFileUtils = + getArtifactBasedFileHelper(jsonTransformationDTO.getArtifactType()); + Map constantsMap = artifactGitFileUtils.getConstantsMap(); + + return Mono.zip( + constructArtifactExchangeJsonFromGitRepository(jsonTransformationDTO), + sessionUserService.getCurrentUser()) + .flatMap(tuple -> { + final Map data = Map.of( + constantsMap.get(FieldName.ID), + baseArtifactId, + FieldName.WORKSPACE_ID, + workspaceId, + FieldName.FLOW_NAME, + AnalyticsEvents.GIT_DESERIALIZE_APP_RESOURCES_FROM_FILE.getEventName()); + + return analyticsService + .sendEvent( + AnalyticsEvents.UNIT_EXECUTION_TIME.getEventName(), + tuple.getT2().getUsername(), + data) + .thenReturn(tuple.getT1()); + }); + } + + /** + * Method to reconstruct the application from the local git repo + * @param jsonTransformationDTO : DTO which carries the parameter for transformation + * @return an instance of an object which extends artifact exchange json. + * i.e. Application Json, Package Json + */ + public Mono constructArtifactExchangeJsonFromGitRepository( + ArtifactJsonTransformationDTO jsonTransformationDTO) { + ArtifactType artifactType = jsonTransformationDTO.getArtifactType(); + ArtifactGitFileUtils artifactGitFileUtils = getArtifactBasedFileHelper(artifactType); + + // Type is not required as checkout happens in similar fashion + String refName = jsonTransformationDTO.getRefName(); + String workspaceId = jsonTransformationDTO.getWorkspaceId(); + String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); + String repoName = jsonTransformationDTO.getRepoName(); + Path repoSuffixPath = artifactGitFileUtils.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); + + Mono gitResourceMapMono = fileUtils.constructGitResourceMapFromGitRepo(repoSuffixPath, refName); + + return gitResourceMapMono.flatMap(gitResourceMap -> { + ArtifactExchangeJson artifactExchangeJson = createArtifactExchangeJson(gitResourceMap, artifactType); + copyMetadataToArtifactExchangeJson(gitResourceMap, artifactExchangeJson); + return artifactGitFileUtils.performJsonMigration(jsonTransformationDTO, artifactExchangeJson); + }); + } + + /** + * This method copies the metadata from git resource map to artifactExchangeJson + * @param gitResourceMap : git resource map generated from file system + * @param artifactExchangeJson : artifact json constructed from git resource map + */ + protected void copyMetadataToArtifactExchangeJson( + GitResourceMap gitResourceMap, ArtifactExchangeJson artifactExchangeJson) { + GitResourceIdentity metadataIdentity = + new GitResourceIdentity(GitResourceType.ROOT_CONFIG, METADATA + JSON_EXTENSION, ""); + Object metadata = gitResourceMap.getGitResourceMap().get(metadataIdentity); + + Gson gson = new Gson(); + JsonObject metadataJsonObject = gson.toJsonTree(metadata, Object.class).getAsJsonObject(); + + Integer serverSchemaVersion = getServerSchemaVersion(metadataJsonObject); + Integer clientSchemaVersion = getClientSchemaVersion(metadataJsonObject); + + artifactExchangeJson.setServerSchemaVersion(serverSchemaVersion); + artifactExchangeJson.setClientSchemaVersion(clientSchemaVersion); + } + + public boolean isJsonTransformationDTOValid(ArtifactJsonTransformationDTO jsonTransformationDTO) { + return jsonTransformationDTO.getArtifactType() != null + && hasText(jsonTransformationDTO.getWorkspaceId()) + && hasText(jsonTransformationDTO.getBaseArtifactId()) + && hasText(jsonTransformationDTO.getRefName()); + } + /** * Method to reconstruct the application from the local git repo * 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 df6caf59bb1..adbd9b2c83f 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 @@ -44,6 +44,7 @@ private Integer getCorrectSchemaVersion(Integer schemaVersion) { * @param branchName The branch name of the artifact being imported, * if it's a Git-connected application; otherwise, null. */ + // TODO: add refType support public Mono migrateArtifactExchangeJsonToLatestSchema( ArtifactExchangeJson artifactExchangeJson, String baseArtifactId, String branchName) { From 41f5faa8431ca98cac0be74d6abec16b92d3b708 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Fri, 3 Jan 2025 18:15:07 +0530 Subject: [PATCH 2/6] added reviewed comments --- .../server/git/fs/GitFSServiceCEImpl.java | 31 ++++++++----------- .../helpers/ce/CommonGitFileUtilsCE.java | 13 +++++--- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java index 04457a46067..598147b8f81 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java @@ -47,7 +47,6 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException; import org.eclipse.jgit.api.errors.EmptyCommitException; -import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; import org.eclipse.jgit.errors.RepositoryNotFoundException; @@ -363,23 +362,19 @@ public Mono prepareChangesToBeCommitted( GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); - try { - return commonGitFileUtils - .saveArtifactToLocalRepoNew(repoSuffix, artifactExchangeJson, branchName) - .map(ignore -> Boolean.TRUE) - .onErrorResume(e -> { - log.error("Error in commit flow: ", e); - if (e instanceof RepositoryNotFoundException) { - return Mono.error( - new AppsmithException(AppsmithError.REPOSITORY_NOT_FOUND, baseArtifactId)); - } else if (e instanceof AppsmithException) { - return Mono.error(e); - } - return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); - }); - } catch (IOException | GitAPIException e) { - return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); - } + return commonGitFileUtils + .saveArtifactToLocalRepoNew(repoSuffix, artifactExchangeJson, branchName) + .map(ignore -> Boolean.TRUE) + .onErrorResume(e -> { + log.error("Error in commit flow: ", e); + if (e instanceof RepositoryNotFoundException) { + return Mono.error(new AppsmithException(AppsmithError.REPOSITORY_NOT_FOUND, baseArtifactId)); + } else if (e instanceof AppsmithException) { + return Mono.error(e); + } + + return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); + }); } @Override 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 cad3822808b..4ce31654b06 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 @@ -160,16 +160,19 @@ public Mono saveArtifactToLocalRepo( } public Mono saveArtifactToLocalRepoNew( - Path baseRepoSuffix, ArtifactExchangeJson artifactExchangeJson, String branchName) - throws IOException, GitAPIException { + Path baseRepoSuffix, ArtifactExchangeJson artifactExchangeJson, String branchName) { // this should come from the specific files GitResourceMap gitResourceMap = createGitResourceMap(artifactExchangeJson); // Save application to git repo - return fileUtils - .saveArtifactToGitRepo(baseRepoSuffix, gitResourceMap, branchName) - .subscribeOn(Schedulers.boundedElastic()); + try { + return fileUtils + .saveArtifactToGitRepo(baseRepoSuffix, gitResourceMap, branchName) + .subscribeOn(Schedulers.boundedElastic()); + } catch (IOException | GitAPIException exception) { + return Mono.error(exception); + } } public Mono saveArtifactToLocalRepoWithAnalytics( From f464a95233547ea0a0734531d58ba5e0b2ba35e1 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Fri, 3 Jan 2025 18:54:34 +0530 Subject: [PATCH 3/6] added changes --- .../git/ApplicationGitFileUtilsCEImpl.java | 5 +- .../ApplicationImportServiceCEImpl.java | 8 +++- .../git/central/CentralGitServiceCE.java | 18 +++---- .../git/central/CentralGitServiceCEImpl.java | 48 +++++++++---------- .../GitApplicationControllerCE.java | 18 +++---- .../migrations/JsonSchemaMigration.java | 13 ++--- .../ce/CreateDBTablePageSolutionCEImpl.java | 2 +- .../server/git/CommonGitServiceCETest.java | 4 +- .../AutoCommitEventHandlerImplTest.java | 6 ++- .../git/autocommit/AutoCommitServiceTest.java | 7 +-- .../server/git/ops/GitCommitTests.java | 2 +- .../server/git/ops/GitConnectTests.java | 18 +++---- .../server/git/ops/GitDiscardTests.java | 4 +- .../ExchangeJsonConversionTests.java | 2 +- .../server/helpers/GitFileUtilsTest.java | 4 +- .../imports/internal/ImportServiceTests.java | 7 +-- .../migrations/JsonSchemaMigrationTest.java | 4 +- ...portApplicationTransactionServiceTest.java | 4 +- .../server/git/ArtifactBuilderExtension.java | 2 +- 19 files changed, 93 insertions(+), 83 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java index a9824225e07..f4b2f7ee9af 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java @@ -1,6 +1,7 @@ package com.appsmith.server.applications.git; import com.appsmith.external.git.FileInterface; +import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.git.models.GitResourceIdentity; import com.appsmith.external.git.models.GitResourceMap; import com.appsmith.external.git.models.GitResourceType; @@ -468,7 +469,7 @@ public Mono reconstructArtifactExchangeJsonFromFilesInRepo ApplicationJson applicationJson = getApplicationJsonFromGitReference(applicationReference); copyNestedNonNullProperties(metadata, applicationJson); return jsonSchemaMigration.migrateApplicationJsonToLatestSchema( - applicationJson, baseArtifactId, branchName); + applicationJson, baseArtifactId, branchName, RefType.branch); }); } @@ -478,7 +479,7 @@ public Mono performJsonMigration( String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); String refName = jsonTransformationDTO.getRefName(); return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( - artifactExchangeJson, baseArtifactId, refName); + artifactExchangeJson, baseArtifactId, refName, null); } protected List getApplicationResource(Map resources, Type type) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java index 1ab22bc3d8f..6d876dd96c3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/imports/ApplicationImportServiceCEImpl.java @@ -1,5 +1,6 @@ package com.appsmith.server.applications.imports; +import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.models.Datasource; import com.appsmith.external.models.DatasourceStorageDTO; import com.appsmith.server.applications.base.ApplicationService; @@ -643,18 +644,21 @@ public Mono migrateArtifactExchangeJson( ApplicationJson applicationJson = (ApplicationJson) artifactExchangeJson; if (!hasText(branchedArtifactId)) { - return jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null); + return jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null, null); } return applicationService.findById(branchedArtifactId).flatMap(application -> { String baseArtifactId = application.getBaseId(); String refName = null; + RefType refType = null; if (application.getGitArtifactMetadata() != null) { refName = application.getGitArtifactMetadata().getRefName(); + refType = application.getGitArtifactMetadata().getRefType(); } - return jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, baseArtifactId, refName); + return jsonSchemaMigration.migrateApplicationJsonToLatestSchema( + applicationJson, baseArtifactId, refName, refType); }); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java index a9fc22f6a06..ccadec5b3c6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCE.java @@ -25,9 +25,9 @@ Mono importArtifactFromGit( Mono connectArtifactToGit( String baseArtifactId, + ArtifactType artifactType, GitConnectDTO gitConnectDTO, String originHeader, - ArtifactType artifactType, GitType gitType); Mono commitArtifact( @@ -36,44 +36,44 @@ Mono commitArtifact( Mono detachRemote(String branchedArtifactId, ArtifactType artifactType, GitType gitType); Mono> listBranchForArtifact( - String branchedArtifactId, Boolean pruneBranches, ArtifactType artifactType, GitType gitType); + String branchedArtifactId, ArtifactType artifactType, Boolean pruneBranches, GitType gitType); Mono fetchRemoteChanges( String referenceArtifactId, - boolean isFileLock, ArtifactType artifactType, + boolean isFileLock, GitType gitType, RefType refType); Mono discardChanges(String branchedArtifactId, ArtifactType artifactType, GitType gitType); Mono getStatus( - String branchedArtifactId, boolean compareRemote, ArtifactType artifactType, GitType gitType); + String branchedArtifactId, ArtifactType artifactType, boolean compareRemote, GitType gitType); Mono pullArtifact(String branchedArtifactId, ArtifactType artifactType, GitType gitType); Mono checkoutReference( String referenceArtifactId, + ArtifactType artifactType, GitRefDTO gitRefDTO, boolean addFileLock, - ArtifactType artifactType, GitType gitType); Mono createReference( - String referencedArtifactId, GitRefDTO refDTO, ArtifactType artifactType, GitType gitType); + String referencedArtifactId, ArtifactType artifactType, GitRefDTO refDTO, GitType gitType); Mono deleteGitReference( - String baseArtifactId, GitRefDTO gitRefDTO, ArtifactType artifactType, GitType gitType); + String baseArtifactId, ArtifactType artifactType, GitRefDTO gitRefDTO, GitType gitType); Mono> updateProtectedBranches( - String baseArtifactId, List branchNames, ArtifactType artifactType); + String baseArtifactId, ArtifactType artifactType, List branchNames); Mono> getProtectedBranches(String baseArtifactId, ArtifactType artifactType); Mono toggleAutoCommitEnabled(String baseArtifactId, ArtifactType artifactType); Mono getAutoCommitProgress( - String baseArtifactId, String branchName, ArtifactType artifactType); + String baseArtifactId, ArtifactType artifactType, String branchName); Mono generateSSHKey(String keyType); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java index 87702246521..db895a42bb8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/central/CentralGitServiceCEImpl.java @@ -364,9 +364,9 @@ private boolean checkIsDatasourceNameConflict( @Override public Mono checkoutReference( String referenceArtifactId, + ArtifactType artifactType, GitRefDTO gitRefDTO, boolean addFileLock, - ArtifactType artifactType, GitType gitType) { if (gitRefDTO == null || !hasText(gitRefDTO.getRefName())) { @@ -475,7 +475,7 @@ protected Mono checkoutReference( } protected Mono checkoutRemoteReference( - String baseArtifactId, GitRefDTO gitRefDTO, ArtifactType artifactType, GitType gitType) { + String baseArtifactId, ArtifactType artifactType, GitRefDTO gitRefDTO, GitType gitType) { GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); AclPermission artifactEditPermission = gitArtifactHelper.getArtifactEditPermission(); @@ -560,7 +560,7 @@ private Mono checkoutRemoteReference( @Override public Mono createReference( - String referencedArtifactId, GitRefDTO refDTO, ArtifactType artifactType, GitType gitType) { + String referencedArtifactId, ArtifactType artifactType, GitRefDTO refDTO, GitType gitType) { /* 1. Check if the src artifact is available and user have sufficient permissions @@ -730,7 +730,7 @@ protected Mono isValidationForRefCreationComplete( @Override public Mono deleteGitReference( - String baseArtifactId, GitRefDTO gitRefDTO, ArtifactType artifactType, GitType gitType) { + String baseArtifactId, ArtifactType artifactType, GitRefDTO gitRefDTO, GitType gitType) { String refName = gitRefDTO.getRefName(); RefType refType = gitRefDTO.getRefType(); @@ -868,19 +868,19 @@ protected Mono deleteGitReference( * Each artifact is equal to a repo in the git(and each branch creates a new artifact with default artifact as parent) * * @param baseArtifactId : artifactId of the artifact which is getting connected to git - * @param gitConnectDTO artifactId - this is used to link the local git repo to an artifact - * remoteUrl - used for connecting to remote repo etc - * @param originHeader * @param artifactType + * @param gitConnectDTO artifactId - this is used to link the local git repo to an artifact + * remoteUrl - used for connecting to remote repo etc + * @param originHeader * @param gitType * @return an artifact with git metadata */ @Override public Mono connectArtifactToGit( String baseArtifactId, + ArtifactType artifactType, GitConnectDTO gitConnectDTO, String originHeader, - ArtifactType artifactType, GitType gitType) { /* * Connecting the artifact for the first time @@ -1474,31 +1474,31 @@ private boolean isBaseGitMetadataInvalid(GitArtifactMetadata gitArtifactMetadata } private Mono getStatusAfterComparingWithRemote( - String baseArtifactId, boolean isFileLock, ArtifactType artifactType, GitType gitType) { - return getStatus(baseArtifactId, isFileLock, true, artifactType, gitType); + String baseArtifactId, ArtifactType artifactType, boolean isFileLock, GitType gitType) { + return getStatus(baseArtifactId, artifactType, isFileLock, true, gitType); } @Override public Mono getStatus( - String branchedArtifactId, boolean compareRemote, ArtifactType artifactType, GitType gitType) { - return getStatus(branchedArtifactId, true, compareRemote, artifactType, gitType); + String branchedArtifactId, ArtifactType artifactType, boolean compareRemote, GitType gitType) { + return getStatus(branchedArtifactId, artifactType, true, compareRemote, gitType); } /** * Get the status of the artifact for given branched id * * @param branchedArtifactId branched id of the artifact + * @param artifactType Type of artifact in context * @param isFileLock if the locking is required, since the status API is used in the other flows of git * Only for the direct hits from the client the locking will be added - * @param artifactType Type of artifact in context * @param gitType Type of the service * @return Map of json file names which are added, modified, conflicting, removed and the working tree if this is clean */ private Mono getStatus( String branchedArtifactId, + ArtifactType artifactType, boolean isFileLock, boolean compareRemote, - ArtifactType artifactType, GitType gitType) { Mono> baseAndBranchedArtifacts = @@ -1868,14 +1868,14 @@ public Mono fetchRemoteChanges( * 1. Checkout (if required) to the branch to make sure we are comparing the right branch * 2. Run a git fetch command to fetch the latest changes from the remote * - * @param refArtifactId id of the reference - * @param isFileLock whether to add file lock or not + * @param refArtifactId id of the reference * @param artifactType + * @param isFileLock whether to add file lock or not * @return Mono of {@link BranchTrackingStatus} */ @Override public Mono fetchRemoteChanges( - String refArtifactId, boolean isFileLock, ArtifactType artifactType, GitType gitType, RefType refType) { + String refArtifactId, ArtifactType artifactType, boolean isFileLock, GitType gitType, RefType refType) { GitArtifactHelper artifactGitHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); AclPermission artifactEditPermission = artifactGitHelper.getArtifactEditPermission(); @@ -2067,15 +2067,15 @@ protected Mono discardChanges(Artifact branchedArtifact, Git } public Mono> listBranchForArtifact( - String branchedArtifactId, Boolean pruneBranches, ArtifactType artifactType, GitType gitType) { - return getBranchList(branchedArtifactId, pruneBranches, true, artifactType, gitType); + String branchedArtifactId, ArtifactType artifactType, Boolean pruneBranches, GitType gitType) { + return getBranchList(branchedArtifactId, artifactType, pruneBranches, true, gitType); } protected Mono> getBranchList( String branchedArtifactId, + ArtifactType artifactType, Boolean pruneBranches, boolean syncDefaultBranchWithRemote, - ArtifactType artifactType, GitType gitType) { GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); @@ -2177,9 +2177,9 @@ private Mono syncDefaultBranchNameFromRemote( // default branch has been changed in remote return updateDefaultBranchName( metadata.getDefaultArtifactId(), + artifactType, defaultBranchNameInRemote, jsonTransformationDTO, - artifactType, gitType) .then() .thenReturn(defaultBranchNameInRemote); @@ -2192,9 +2192,9 @@ private Mono syncDefaultBranchNameFromRemote( private Flux updateDefaultBranchName( String baseArtifactId, + ArtifactType artifactType, String newDefaultBranchName, ArtifactJsonTransformationDTO jsonTransformationDTO, - ArtifactType artifactType, GitType gitType) { // Get the artifact from DB by new defaultBranchName GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); @@ -2392,7 +2392,7 @@ private Mono> getBranchListWithDefaultBranchName( @Override public Mono> updateProtectedBranches( - String baseArtifactId, List branchNames, ArtifactType artifactType) { + String baseArtifactId, ArtifactType artifactType, List branchNames) { GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); AclPermission artifactManageProtectedBranchPermission = @@ -2509,7 +2509,7 @@ public Mono toggleAutoCommitEnabled(String baseArtifactId, ArtifactType @Override public Mono getAutoCommitProgress( - String artifactId, String branchName, ArtifactType artifactType) { + String artifactId, ArtifactType artifactType, String branchName) { return gitAutoCommitHelper.getAutoCommitProgress(artifactId, branchName); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java index e08e5716fb3..aefef9970fe 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/controllers/GitApplicationControllerCE.java @@ -68,7 +68,7 @@ public Mono> connectApplicationToRemoteRepo( @RequestBody GitConnectDTO gitConnectDTO, @RequestHeader("Origin") String originHeader) { return centralGitService - .connectArtifactToGit(applicationId, gitConnectDTO, originHeader, ARTIFACT_TYPE, GIT_TYPE) + .connectArtifactToGit(applicationId, ARTIFACT_TYPE, gitConnectDTO, originHeader, GIT_TYPE) .map(application -> new ResponseDTO<>(HttpStatus.OK.value(), application, null)); } @@ -95,7 +95,7 @@ public Mono> createReference( referencedApplicationId, srcBranch); return centralGitService - .createReference(referencedApplicationId, gitRefDTO, ArtifactType.APPLICATION, GIT_TYPE) + .createReference(referencedApplicationId, ArtifactType.APPLICATION, gitRefDTO, GIT_TYPE) .map(result -> new ResponseDTO<>(HttpStatus.CREATED.value(), result, null)); } @@ -104,7 +104,7 @@ public Mono> createReference( public Mono> checkoutReference( @PathVariable String referencedApplicationId, @RequestBody GitRefDTO gitRefDTO) { return centralGitService - .checkoutReference(referencedApplicationId, gitRefDTO, true, ARTIFACT_TYPE, GIT_TYPE) + .checkoutReference(referencedApplicationId, ARTIFACT_TYPE, gitRefDTO, true, GIT_TYPE) .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); } @@ -133,7 +133,7 @@ public Mono> getStatus( @RequestParam(required = false, defaultValue = "true") Boolean compareRemote) { log.info("Going to get status for branchedApplicationId {}", branchedApplicationId); return centralGitService - .getStatus(branchedApplicationId, compareRemote, ARTIFACT_TYPE, GIT_TYPE) + .getStatus(branchedApplicationId, ARTIFACT_TYPE, compareRemote, GIT_TYPE) .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); } @@ -144,7 +144,7 @@ public Mono> fetchRemoteChanges( @RequestHeader(required = false, defaultValue = "branch") RefType refType) { log.info("Going to compare with remote for default referencedApplicationId {}", referencedApplicationId); return centralGitService - .fetchRemoteChanges(referencedApplicationId, true, ARTIFACT_TYPE, GIT_TYPE, refType) + .fetchRemoteChanges(referencedApplicationId, ARTIFACT_TYPE, true, GIT_TYPE, refType) .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); } @@ -154,7 +154,7 @@ public Mono> deleteBranch( @PathVariable String baseArtifactId, @RequestBody GitRefDTO gitRefDTO) { log.info("Going to delete ref {} for baseApplicationId {}", gitRefDTO.getRefName(), baseArtifactId); return centralGitService - .deleteGitReference(baseArtifactId, gitRefDTO, ARTIFACT_TYPE, GIT_TYPE) + .deleteGitReference(baseArtifactId, ARTIFACT_TYPE, gitRefDTO, GIT_TYPE) .map(application -> new ResponseDTO<>(HttpStatus.OK.value(), application, null)); } @@ -173,7 +173,7 @@ public Mono>> updateProtectedBranches( @PathVariable String baseArtifactId, @RequestBody @Valid BranchProtectionRequestDTO branchProtectionRequestDTO) { return centralGitService - .updateProtectedBranches(baseArtifactId, branchProtectionRequestDTO.getBranchNames(), ARTIFACT_TYPE) + .updateProtectedBranches(baseArtifactId, ARTIFACT_TYPE, branchProtectionRequestDTO.getBranchNames()) .map(data -> new ResponseDTO<>(HttpStatus.OK.value(), data, null)); } @@ -199,7 +199,7 @@ public Mono> getAutoCommitProgress( @PathVariable String baseApplicationId, @RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) { return centralGitService - .getAutoCommitProgress(baseApplicationId, branchName, ARTIFACT_TYPE) + .getAutoCommitProgress(baseApplicationId, ARTIFACT_TYPE, branchName) .map(data -> new ResponseDTO<>(HttpStatus.OK.value(), data, null)); } @@ -219,7 +219,7 @@ public Mono>> branch( log.debug("Going to get branch list for application {}", branchedApplicationId); return centralGitService .listBranchForArtifact( - branchedApplicationId, BooleanUtils.isTrue(pruneBranches), ARTIFACT_TYPE, GIT_TYPE) + branchedApplicationId, ARTIFACT_TYPE, BooleanUtils.isTrue(pruneBranches), GIT_TYPE) .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); } } 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 adbd9b2c83f..c5cb0f0843f 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 @@ -1,5 +1,6 @@ package com.appsmith.server.migrations; +import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.server.constants.ArtifactType; import com.appsmith.server.dtos.ApplicationJson; import com.appsmith.server.dtos.ArtifactExchangeJson; @@ -41,23 +42,23 @@ private Integer getCorrectSchemaVersion(Integer schemaVersion) { * @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, + * @param refName The ref name of the artifact being imported, * if it's a Git-connected application; otherwise, null. + * @param refType Type of the reference i.e. branch, tag. */ - // TODO: add refType support public Mono migrateArtifactExchangeJsonToLatestSchema( - ArtifactExchangeJson artifactExchangeJson, String baseArtifactId, String branchName) { + ArtifactExchangeJson artifactExchangeJson, String baseArtifactId, String refName, RefType refType) { if (ArtifactType.APPLICATION.equals(artifactExchangeJson.getArtifactJsonType())) { return migrateApplicationJsonToLatestSchema( - (ApplicationJson) artifactExchangeJson, baseArtifactId, branchName); + (ApplicationJson) artifactExchangeJson, baseArtifactId, refName, refType); } return Mono.fromCallable(() -> artifactExchangeJson); } public Mono migrateApplicationJsonToLatestSchema( - ApplicationJson applicationJson, String baseApplicationId, String branchName) { + ApplicationJson applicationJson, String baseApplicationId, String refName, RefType refType) { return Mono.fromCallable(() -> { setSchemaVersions(applicationJson); return applicationJson; @@ -67,7 +68,7 @@ public Mono migrateApplicationJsonToLatestSchema( return Mono.empty(); } - return migrateServerSchema(applicationJson, baseApplicationId, branchName); + return migrateServerSchema(applicationJson, baseApplicationId, refName); }) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.INCOMPATIBLE_IMPORTED_JSON))); } 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 da73e86a08b..8f8bb0357f4 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 @@ -251,7 +251,7 @@ public Mono createPageFromDBTable( }) .subscribeOn(Schedulers.boundedElastic()) .flatMap(applicationJson -> - jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null)); + jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null, null)); return datasourceStorageMono .zipWhen(datasourceStorage -> Mono.zip( 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 8963aba9e62..8ce36a1fc29 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 @@ -292,8 +292,8 @@ private Mono createAppJson(String filePath) { return stringifiedFile .map(data -> gson.fromJson(data, ApplicationJson.class)) - .flatMap(applicationJson -> - jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null)) + .flatMap(applicationJson -> jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + applicationJson, null, null, null)) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } 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 1afa9d79a01..c437281adc4 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 @@ -3,6 +3,7 @@ import com.appsmith.external.dtos.GitLogDTO; import com.appsmith.external.git.FileInterface; import com.appsmith.external.git.GitExecutor; +import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.helpers.AppsmithBeanUtils; import com.appsmith.external.models.ApplicationGitReference; import com.appsmith.server.configurations.ProjectProperties; @@ -435,7 +436,7 @@ public void autoCommitServerMigration_WhenServerHasNoChanges_NoCommitMade() thro doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) .migrateApplicationJsonToLatestSchema( - Mockito.eq(applicationJson), Mockito.anyString(), Mockito.anyString()); + Mockito.eq(applicationJson), Mockito.anyString(), Mockito.anyString(), any(RefType.class)); doReturn(Mono.just("success")) .when(gitExecutor) @@ -514,7 +515,8 @@ public void autocommitServerMigration_WhenJsonSchemaMigrationPresent_CommitSucce doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) - .migrateApplicationJsonToLatestSchema(any(), Mockito.anyString(), Mockito.anyString()); + .migrateApplicationJsonToLatestSchema( + any(), Mockito.anyString(), Mockito.anyString(), any(RefType.class)); gitFileSystemTestHelper.setupGitRepository(autoCommitEvent, applicationJson); 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 39a4287537c..77bf3e4a083 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 @@ -2,6 +2,7 @@ import com.appsmith.external.dtos.GitLogDTO; import com.appsmith.external.git.GitExecutor; +import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.helpers.AppsmithBeanUtils; import com.appsmith.server.acl.AclPermission; import com.appsmith.server.applications.base.ApplicationService; @@ -255,7 +256,7 @@ public void testAutoCommit_whenOnlyServerIsEligibleForMigration_commitSuccess() doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) .migrateApplicationJsonToLatestSchema( - any(ApplicationJson.class), Mockito.anyString(), Mockito.anyString()); + any(ApplicationJson.class), Mockito.anyString(), Mockito.anyString(), any(RefType.class)); gitFileSystemTestHelper.setupGitRepository( WORKSPACE_ID, DEFAULT_APP_ID, BRANCH_NAME, REPO_NAME, applicationJson); @@ -544,7 +545,7 @@ public void testAutoCommit_whenAutoCommitEligibleButPrerequisiteNotComplete_retu doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) .migrateApplicationJsonToLatestSchema( - any(ApplicationJson.class), Mockito.anyString(), Mockito.anyString()); + any(ApplicationJson.class), Mockito.anyString(), Mockito.anyString(), any(RefType.class)); gitFileSystemTestHelper.setupGitRepository( WORKSPACE_ID, DEFAULT_APP_ID, BRANCH_NAME, REPO_NAME, applicationJson); @@ -618,7 +619,7 @@ public void testAutoCommit_whenServerIsRunningMigrationCallsAutocommitAgainOnDif doReturn(Mono.just(applicationJson1)) .when(jsonSchemaMigration) .migrateApplicationJsonToLatestSchema( - any(ApplicationJson.class), Mockito.anyString(), Mockito.anyString()); + any(ApplicationJson.class), Mockito.anyString(), Mockito.anyString(), any(RefType.class)); gitFileSystemTestHelper.setupGitRepository( WORKSPACE_ID, DEFAULT_APP_ID, BRANCH_NAME, REPO_NAME, applicationJson); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java index 7b8b377c642..6342eaf3b91 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java @@ -167,7 +167,7 @@ private Application createApplicationConnectedToGit(String name, String branchNa gitConnectDTO.setGitProfile(gitProfile); return centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact) .block(); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java index 9d848250e35..541ef59eb6f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java @@ -84,7 +84,7 @@ public void connectArtifactToGit_withEmptyRemoteUrl_throwsInvalidParameterExcept gitConnectDTO.setRemoteUrl(null); gitConnectDTO.setGitProfile(new GitProfile()); Mono applicationMono = centralGitService - .connectArtifactToGit("testID", gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + .connectArtifactToGit("testID", ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -108,7 +108,7 @@ public void connectArtifactToGit_withEmptyOriginHeader_throwsInvalidParameterExc gitConnectDTO.setGitProfile(new GitProfile()); Mono applicationMono = centralGitService - .connectArtifactToGit("testID", gitConnectDTO, null, ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + .connectArtifactToGit("testID", ArtifactType.APPLICATION, gitConnectDTO, null, GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -151,7 +151,7 @@ public void connectArtifactToGit_whenConnectingMorePrivateReposThanSupported_thr gitConnectDTO.setGitProfile(gitProfile); Mono applicationMono = centralGitService .connectArtifactToGit( - application.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -171,7 +171,7 @@ public void connectArtifactToGit_whenUserDoesNotHaveRequiredPermission_operation gitConnectDTO.setGitProfile(new GitProfile()); Mono applicationMono = centralGitService .connectArtifactToGit( - application.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -251,7 +251,7 @@ public void connectArtifactToGit_whenCloneOperationFails_throwsGitException() { Mono applicationMono = centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -325,7 +325,7 @@ public void connectArtifactToGit_whenUsingGlobalProfile_completesSuccessfully() gitConnectDTO.setGitProfile(gitProfile); Mono applicationMono = centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -375,7 +375,7 @@ public void connectArtifactToGit_whenUsingIncompleteLocalProfile_throwsAuthorNam gitConnectDTO.setGitProfile(gitProfile); Mono applicationMono = centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -421,7 +421,7 @@ public void connectArtifactToGit_whenClonedRepoIsNotEmpty_throwsException() thro gitConnectDTO.setGitProfile(gitProfile); Mono applicationMono = centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) @@ -470,7 +470,7 @@ public void connectArtifactToGit_whenDefaultCommitFails_throwsException() throws gitConnectDTO.setGitProfile(gitProfile); Mono applicationMono = centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact); StepVerifier.create(applicationMono) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java index 7ca39f4bcb5..daa65959339 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java @@ -151,7 +151,7 @@ private Application createApplicationConnectedToGit(String name, String branchNa gitConnectDTO.setGitProfile(gitProfile); return centralGitService .connectArtifactToGit( - application1.getId(), gitConnectDTO, "baseUrl", ArtifactType.APPLICATION, GitType.FILE_SYSTEM) + application1.getId(), ArtifactType.APPLICATION, gitConnectDTO, "baseUrl", GitType.FILE_SYSTEM) .map(artifact -> (Application) artifact) .block(); } @@ -167,7 +167,7 @@ private Mono createArtifactJson(String filePath) ArtifactExchangeJson artifactExchangeJson = objectMapper.copy().disable(MapperFeature.USE_ANNOTATIONS).readValue(artifactJson, exchangeJsonType); - return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null, null); } @Test diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/resourcemap/ExchangeJsonConversionTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/resourcemap/ExchangeJsonConversionTests.java index 56de587dcb8..9dfe3997401 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/resourcemap/ExchangeJsonConversionTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/resourcemap/ExchangeJsonConversionTests.java @@ -104,7 +104,7 @@ private Mono createArtifactJson(ExchangeJsonCont ArtifactExchangeJson artifactExchangeJson = objectMapper.copy().disable(MapperFeature.USE_ANNOTATIONS).readValue(artifactJson, exchangeJsonType); - return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null, null); } @TestTemplate 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 c9486d45314..819d4e06de4 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 @@ -84,8 +84,8 @@ private Mono createAppJson(String filePath) { .map(data -> { return gson.fromJson(data, ApplicationJson.class); }) - .flatMap(applicationJson -> - jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null)) + .flatMap(applicationJson -> jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + applicationJson, null, null, null)) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } 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 e6fe0159535..37fd07110d3 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 @@ -361,8 +361,8 @@ private Mono createAppJson(String filePath) { .map(data -> { return gson.fromJson(data, ApplicationJson.class); }) - .flatMap(applicationJson -> - jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null)) + .flatMap(applicationJson -> jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + applicationJson, null, null, null)) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } @@ -2724,7 +2724,8 @@ public void applySchemaMigration_jsonFileWithFirstVersion_migratedToLatestVersio .flatMap(applicationJson -> { ApplicationJson applicationJson1 = new ApplicationJson(); AppsmithBeanUtils.copyNestedNonNullProperties(applicationJson, applicationJson1); - return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson1, null, null); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + applicationJson1, null, null, null); }) .map(applicationJson -> (ApplicationJson) applicationJson); 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 index 1a08d854560..ad9a79fd4b4 100644 --- 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 @@ -39,7 +39,7 @@ public void migrateArtifactToLatestSchema_whenFeatureFlagIsOn_returnsIncremented gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); ArtifactExchangeJson artifactExchangeJson = jsonSchemaMigration - .migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null) + .migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null, null) .block(); assertThat(artifactExchangeJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); assertThat(artifactExchangeJson.getClientSchemaVersion()).isEqualTo(jsonSchemaVersions.getClientVersion()); @@ -55,7 +55,7 @@ public void migrateApplicationJsonToLatestSchema_whenFeatureFlagIsOn_returnsIncr gitFileSystemTestHelper.getApplicationJson(this.getClass().getResource("application.json")); Mono applicationJsonMono = - jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null); + jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null, null); StepVerifier.create(applicationJsonMono) .assertNext(appJson -> { assertThat(appJson.getServerSchemaVersion()).isEqualTo(jsonSchemaVersions.getServerVersion()); 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 f5d0c483540..ffc8dabbe12 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 @@ -130,8 +130,8 @@ private Mono createAppJson(String filePath) { .map(data -> { return gson.fromJson(data, ApplicationJson.class); }) - .flatMap(applicationJson -> - jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(applicationJson, null, null)) + .flatMap(applicationJson -> jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + applicationJson, null, null, null)) .map(artifactExchangeJson -> (ApplicationJson) artifactExchangeJson); } diff --git a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ArtifactBuilderExtension.java b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ArtifactBuilderExtension.java index 941265dbb43..123664de18e 100644 --- a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ArtifactBuilderExtension.java +++ b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ArtifactBuilderExtension.java @@ -112,6 +112,6 @@ private Mono createArtifactJson(String filePath, ArtifactExchangeJson artifactExchangeJson = objectMapper.copy().disable(MapperFeature.USE_ANNOTATIONS).readValue(artifactJson, exchangeJsonType); - return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null, null); } } From 7a3406e8b7d9b822d2b4db8ebd4f67dee6e8d788 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Fri, 3 Jan 2025 19:17:51 +0530 Subject: [PATCH 4/6] review comments --- .../applications/git/ApplicationGitFileUtilsCEImpl.java | 3 ++- .../server/solutions/ce/CreateDBTablePageSolutionCEImpl.java | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java index f4b2f7ee9af..79aef2cb351 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/applications/git/ApplicationGitFileUtilsCEImpl.java @@ -478,8 +478,9 @@ public Mono performJsonMigration( ArtifactJsonTransformationDTO jsonTransformationDTO, ArtifactExchangeJson artifactExchangeJson) { String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); String refName = jsonTransformationDTO.getRefName(); + RefType refType = jsonTransformationDTO.getRefType(); return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( - artifactExchangeJson, baseArtifactId, refName, null); + artifactExchangeJson, baseArtifactId, refName, refType); } protected List getApplicationResource(Map resources, Type type) { 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 8f8bb0357f4..1b9d602f5d2 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 @@ -4,6 +4,7 @@ import com.appsmith.external.constants.AnalyticsEvents; import com.appsmith.external.converters.HttpMethodConverter; import com.appsmith.external.converters.ISOStringToInstantConverter; +import com.appsmith.external.git.constants.ce.RefType; import com.appsmith.external.helpers.AppsmithBeanUtils; import com.appsmith.external.models.ActionConfiguration; import com.appsmith.external.models.ActionDTO; @@ -250,8 +251,8 @@ public Mono createPageFromDBTable( return applicationJson; }) .subscribeOn(Schedulers.boundedElastic()) - .flatMap(applicationJson -> - jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null, null)); + .flatMap(applicationJson -> jsonSchemaMigration.migrateApplicationJsonToLatestSchema( + applicationJson, null, null, RefType.branch)); return datasourceStorageMono .zipWhen(datasourceStorage -> Mono.zip( From 70ad2a103d2b316998e918eb09d2c9233c832be1 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Fri, 3 Jan 2025 20:09:40 +0530 Subject: [PATCH 5/6] modified mocking for test failures --- .../java/com/appsmith/server/git/ops/GitCommitTests.java | 6 +++--- .../java/com/appsmith/server/git/ops/GitDiscardTests.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java index 6342eaf3b91..39106cb937a 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitCommitTests.java @@ -87,7 +87,7 @@ public void commitArtifact_whenNoChangesInLocal_returnsWithEmptyCommitMessage() Mockito.doReturn(Mono.just(Paths.get(""))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); Mockito.doReturn(Mono.error(new EmptyCommitException("nothing to commit"))) .when(fsGitHandler) .commitArtifact( @@ -136,7 +136,7 @@ private Application createApplicationConnectedToGit(String name, String branchNa .initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString()); Mockito.doReturn(Mono.just(Paths.get("path"))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); Application testApplication = new Application(); testApplication.setName(name); @@ -225,7 +225,7 @@ public void commitArtifact_whenLocalRepoNotAvailable_throwsRepoNotFoundException Mockito.doReturn(Mono.error(new RepositoryNotFoundException(AppsmithError.REPOSITORY_NOT_FOUND.getMessage()))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); StepVerifier.create(commitMono) .expectErrorMatches(throwable -> throwable instanceof AppsmithException diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java index daa65959339..30e0e35deda 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java @@ -120,7 +120,7 @@ private Application createApplicationConnectedToGit(String name, String branchNa .initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString()); Mockito.doReturn(Mono.just(Paths.get("path"))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); Application testApplication = new Application(); testApplication.setName(name); From 8877a5b92ae5bcb25b428ed50fe09a8d0b767e35 Mon Sep 17 00:00:00 2001 From: sondermanish Date: Fri, 3 Jan 2025 20:39:58 +0530 Subject: [PATCH 6/6] more mocking --- .../java/com/appsmith/server/git/ops/GitConnectTests.java | 2 +- .../java/com/appsmith/server/git/ops/GitDiscardTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java index 541ef59eb6f..21a2c17164e 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java @@ -289,7 +289,7 @@ public void connectArtifactToGit_whenUsingGlobalProfile_completesSuccessfully() Mockito.anyString()); Mockito.doReturn(Mono.just(Paths.get(""))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); Mockito.doReturn(Mono.just(true)).when(commonGitFileUtils).checkIfDirectoryIsEmpty(any(Path.class)); Mockito.doReturn(Mono.just(Paths.get("textPath"))) .when(commonGitFileUtils) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java index 30e0e35deda..d62ff5fc6a5 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitDiscardTests.java @@ -198,7 +198,7 @@ public void discardChanges_whenUpstreamChangesAvailable_discardsSuccessfully() t Mockito.doReturn(Mono.just(Paths.get("path"))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); Mockito.doReturn(Mono.just(artifactExchangeJson)) .when(gitHandlingService) .recreateArtifactJsonFromLastCommit(Mockito.any()); @@ -243,7 +243,7 @@ public void discardChanges_whenCancelledMidway_discardsSuccessfully() throws IOE Mockito.doReturn(Mono.just(Paths.get("path"))) .when(commonGitFileUtils) - .saveArtifactToLocalRepoWithAnalytics(any(Path.class), any(), Mockito.anyString()); + .saveArtifactToLocalRepoNew(any(Path.class), any(), Mockito.anyString()); Mockito.doReturn(Mono.just(artifactExchangeJson)) .when(gitHandlingService) .recreateArtifactJsonFromLastCommit(Mockito.any());