From 649338d18850299833bf029c929fb66720565919 Mon Sep 17 00:00:00 2001 From: Manish Kumar <107841575+sondermanish@users.noreply.github.com> Date: Sun, 5 Jan 2025 21:34:36 +0530 Subject: [PATCH] chore: added git resource map consumption (#38470) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description - Added git resource map consumption Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Git" it=true ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 8877a5b92ae5bcb25b428ed50fe09a8d0b767e35 > Cypress dashboard. > Tags: `@tag.Git` > Spec: >
Fri, 03 Jan 2025 16:35:41 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit Based on the comprehensive summary of changes, here are the release notes: ## Release Notes - **Git Integration Enhancements** - Improved Git reference handling across multiple service methods - Enhanced support for artifact migration and JSON schema transformations - Refined parameter management for Git-related operations - **Method Signature Updates** - Standardized method signatures across Git-related services - Added support for more flexible reference type handling - Improved consistency in method parameter ordering - **Backend Improvements** - Updated JSON migration processes - Enhanced error handling in Git file system operations - Expanded support for different artifact types in Git workflows - **Testing and Validation** - Updated test cases to reflect new method signatures - Improved test coverage for Git-related functionality These changes primarily focus on backend improvements to the Git integration system, providing more robust and flexible handling of artifacts and references. --- .../appsmith/git/files/FileUtilsCEImpl.java | 7 ++ .../appsmith/external/git/FileInterface.java | 2 + .../git/ApplicationGitFileUtilsCEImpl.java | 14 ++- .../ApplicationImportServiceCEImpl.java | 8 +- .../git/central/CentralGitServiceCE.java | 18 +-- .../git/central/CentralGitServiceCEImpl.java | 51 ++++----- .../GitApplicationControllerCE.java | 18 +-- .../server/git/fs/GitFSServiceCEImpl.java | 14 +-- .../helpers/ce/ArtifactGitFileUtilsCE.java | 4 + .../helpers/ce/CommonGitFileUtilsCE.java | 104 +++++++++++++++++- .../migrations/JsonSchemaMigration.java | 12 +- .../ce/CreateDBTablePageSolutionCEImpl.java | 5 +- .../server/git/CommonGitServiceCETest.java | 4 +- .../AutoCommitEventHandlerImplTest.java | 6 +- .../git/autocommit/AutoCommitServiceTest.java | 7 +- .../server/git/ops/GitCommitTests.java | 8 +- .../server/git/ops/GitConnectTests.java | 20 ++-- .../server/git/ops/GitDiscardTests.java | 10 +- .../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 +- 24 files changed, 231 insertions(+), 104 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 b7f3950221..7d68aaf19e 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 class FileUtilsCEImpl implements FileInterface { .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 d5422a24ef..c655ef2bfb 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 @@ public interface FileInterface { 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 a5628db2df..79aef2cb35 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; @@ -29,6 +30,7 @@ import com.appsmith.server.dtos.ArtifactExchangeJson; 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; @@ -467,10 +469,20 @@ public class ApplicationGitFileUtilsCEImpl implements ArtifactGitFileUtilsCE performJsonMigration( + ArtifactJsonTransformationDTO jsonTransformationDTO, ArtifactExchangeJson artifactExchangeJson) { + String baseArtifactId = jsonTransformationDTO.getBaseArtifactId(); + String refName = jsonTransformationDTO.getRefName(); + RefType refType = jsonTransformationDTO.getRefType(); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema( + artifactExchangeJson, baseArtifactId, refName, refType); + } + protected List getApplicationResource(Map resources, Type type) { List deserializedResources = new ArrayList<>(); 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 1ab22bc3d8..6d876dd96c 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 class ApplicationImportServiceCEImpl 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 a9fc22f6a0..ccadec5b3c 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 @@ public interface CentralGitServiceCE { Mono connectArtifactToGit( String baseArtifactId, + ArtifactType artifactType, GitConnectDTO gitConnectDTO, String originHeader, - ArtifactType artifactType, GitType gitType); Mono commitArtifact( @@ -36,44 +36,44 @@ public interface CentralGitServiceCE { 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 bc6c38ebab..db895a42bb 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 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { @Override public Mono checkoutReference( String referenceArtifactId, + ArtifactType artifactType, GitRefDTO gitRefDTO, boolean addFileLock, - ArtifactType artifactType, GitType gitType) { if (gitRefDTO == null || !hasText(gitRefDTO.getRefName())) { @@ -423,6 +423,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { 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()); @@ -474,7 +475,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { } 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(); @@ -559,7 +560,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { @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 @@ -689,7 +690,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { }) // 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( @@ -729,7 +730,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { @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(); @@ -867,19 +868,19 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { * 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 @@ -1473,31 +1474,31 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { } 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 = @@ -1867,14 +1868,14 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { * 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(); @@ -2066,15 +2067,15 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { } 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); @@ -2176,9 +2177,9 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { // default branch has been changed in remote return updateDefaultBranchName( metadata.getDefaultArtifactId(), + artifactType, defaultBranchNameInRemote, jsonTransformationDTO, - artifactType, gitType) .then() .thenReturn(defaultBranchNameInRemote); @@ -2191,9 +2192,9 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { 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); @@ -2391,7 +2392,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { @Override public Mono> updateProtectedBranches( - String baseArtifactId, List branchNames, ArtifactType artifactType) { + String baseArtifactId, ArtifactType artifactType, List branchNames) { GitArtifactHelper gitArtifactHelper = gitArtifactHelperResolver.getArtifactHelper(artifactType); AclPermission artifactManageProtectedBranchPermission = @@ -2508,7 +2509,7 @@ public class CentralGitServiceCEImpl implements CentralGitServiceCE { @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 e08e5716fb..aefef9970f 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 class GitApplicationControllerCE { @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 class GitApplicationControllerCE { 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 class GitApplicationControllerCE { 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 class GitApplicationControllerCE { @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 class GitApplicationControllerCE { @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 class GitApplicationControllerCE { @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 class GitApplicationControllerCE { @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 class GitApplicationControllerCE { @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 class GitApplicationControllerCE { 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/git/fs/GitFSServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/git/fs/GitFSServiceCEImpl.java index eafd070e04..598147b8f8 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 @@ -209,12 +209,8 @@ public class GitFSServiceCEImpl implements GitHandlingServiceCE { @Override public Mono reconstructArtifactJsonFromGitRepository( ArtifactJsonTransformationDTO artifactJsonTransformationDTO) { - return commonGitFileUtils.reconstructArtifactExchangeJsonFromGitRepoWithAnalytics( - artifactJsonTransformationDTO.getWorkspaceId(), - artifactJsonTransformationDTO.getBaseArtifactId(), - artifactJsonTransformationDTO.getRepoName(), - artifactJsonTransformationDTO.getRefName(), - artifactJsonTransformationDTO.getArtifactType()); + return commonGitFileUtils.constructArtifactExchangeJsonFromGitRepositoryWithAnalytics( + artifactJsonTransformationDTO); } @Override @@ -367,7 +363,7 @@ public class GitFSServiceCEImpl implements GitHandlingServiceCE { Path repoSuffix = gitArtifactHelper.getRepoSuffixPath(workspaceId, baseArtifactId, repoName); return commonGitFileUtils - .saveArtifactToLocalRepoWithAnalytics(repoSuffix, artifactExchangeJson, branchName) + .saveArtifactToLocalRepoNew(repoSuffix, artifactExchangeJson, branchName) .map(ignore -> Boolean.TRUE) .onErrorResume(e -> { log.error("Error in commit flow: ", e); @@ -376,6 +372,7 @@ public class GitFSServiceCEImpl implements GitHandlingServiceCE { } else if (e instanceof AppsmithException) { return Mono.error(e); } + return Mono.error(new AppsmithException(AppsmithError.GIT_FILE_SYSTEM_ERROR, e.getMessage())); }); } @@ -617,8 +614,7 @@ public class GitFSServiceCEImpl implements GitHandlingServiceCE { 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 f92820c047..f20fe5f878 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 @@ package com.appsmith.server.helpers.ce; 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 @@ public interface ArtifactGitFileUtilsCE { 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 5349f788df..4ce31654b0 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.ArtifactExchangeJson; 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; @@ -159,16 +160,19 @@ public class CommonGitFileUtilsCE { } 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( @@ -553,6 +557,96 @@ public class CommonGitFileUtilsCE { 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 df6caf59bb..c5cb0f0843 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,22 +42,23 @@ public class JsonSchemaMigration { * @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. */ 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; @@ -66,7 +68,7 @@ public class JsonSchemaMigration { 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 da73e86a08..1b9d602f5d 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.ActionCreationSourceTypeEnum; 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 class CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolutio return applicationJson; }) .subscribeOn(Schedulers.boundedElastic()) - .flatMap(applicationJson -> - jsonSchemaMigration.migrateApplicationJsonToLatestSchema(applicationJson, null, null)); + .flatMap(applicationJson -> jsonSchemaMigration.migrateApplicationJsonToLatestSchema( + applicationJson, null, null, RefType.branch)); 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 8963aba9e6..8ce36a1fc2 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 @@ public class CommonGitServiceCETest { 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 1afa9d79a0..c437281adc 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 @@ package com.appsmith.server.git.autocommit; 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 class AutoCommitEventHandlerImplTest { 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 class AutoCommitEventHandlerImplTest { 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 39a4287537..77bf3e4a08 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 @@ package com.appsmith.server.git.autocommit; 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 class AutoCommitServiceTest { 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 class AutoCommitServiceTest { 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 class AutoCommitServiceTest { 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 7b8b377c64..39106cb937 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 class GitCommitTests { 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 @@ public class GitCommitTests { .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); @@ -167,7 +167,7 @@ public class GitCommitTests { 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(); } @@ -225,7 +225,7 @@ public class GitCommitTests { 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/GitConnectTests.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/ops/GitConnectTests.java index 9d848250e3..21a2c17164 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 class GitConnectTests { 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 class GitConnectTests { 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 class GitConnectTests { 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 class GitConnectTests { 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 class GitConnectTests { 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) @@ -289,7 +289,7 @@ public class GitConnectTests { 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) @@ -325,7 +325,7 @@ public class GitConnectTests { 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 class GitConnectTests { 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 class GitConnectTests { 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 class GitConnectTests { 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 7ca39f4bcb..d62ff5fc6a 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 @@ public class GitDiscardTests { .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); @@ -151,7 +151,7 @@ public class GitDiscardTests { 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 @@ public class GitDiscardTests { 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 @@ -198,7 +198,7 @@ public class GitDiscardTests { 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 class GitDiscardTests { 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()); 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 56de587dcb..9dfe399740 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 @@ public class ExchangeJsonConversionTests { 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 c9486d4531..819d4e06de 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 @@ public class GitFileUtilsTest { .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 e6fe015953..37fd07110d 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 @@ public class ImportServiceTests { .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 class ImportServiceTests { .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 1a08d85456..ad9a79fd4b 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 class JsonSchemaMigrationTest { 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 class JsonSchemaMigrationTest { 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 f5d0c48354..ffc8dabbe1 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 @@ public class ImportApplicationTransactionServiceTest { .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 941265dbb4..123664de18 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 @@ public class ArtifactBuilderExtension implements AfterEachCallback, BeforeEachCa ArtifactExchangeJson artifactExchangeJson = objectMapper.copy().disable(MapperFeature.USE_ANNOTATIONS).readValue(artifactJson, exchangeJsonType); - return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null); + return jsonSchemaMigration.migrateArtifactExchangeJsonToLatestSchema(artifactExchangeJson, null, null, null); } }