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 a4c5052f3caa..d4165d1c4d49 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 @@ -2259,7 +2259,7 @@ protected Mono discardChanges(Artifact branchedArtifact, Git .flatMap(artifactExchangeJson -> importService.importArtifactInWorkspaceFromGit( workspaceId, branchedArtifact.getId(), artifactExchangeJson, branchName)) .flatMap(artifactFromLastCommit -> - gitArtifactHelper.publishArtifact(artifactFromLastCommit, true)) + gitArtifactHelper.validateAndPublishArtifact(artifactFromLastCommit, true)) .flatMap(publishedArtifact -> gitAnalyticsUtils.addAnalyticsForGitOperation( AnalyticsEvents.GIT_DISCARD_CHANGES, publishedArtifact, null)) .onErrorResume(exception -> { diff --git a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitApplicationTestUtils.java b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitApplicationTestUtils.java new file mode 100644 index 000000000000..b2a488257892 --- /dev/null +++ b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitApplicationTestUtils.java @@ -0,0 +1,53 @@ +package com.appsmith.server.git; + +import com.appsmith.external.constants.PluginConstants; +import com.appsmith.external.models.ActionConfiguration; +import com.appsmith.external.models.ActionDTO; +import com.appsmith.external.models.Datasource; +import com.appsmith.external.models.PluginType; +import com.appsmith.server.domains.Application; +import com.appsmith.server.domains.Artifact; +import com.appsmith.server.domains.Plugin; +import com.appsmith.server.plugins.base.PluginService; +import com.appsmith.server.services.LayoutActionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +import java.util.UUID; + +@Component +public class GitApplicationTestUtils implements GitArtifactTestUtils { + + @Autowired + LayoutActionService layoutActionService; + @Autowired + PluginService pluginService; + + + @Override + public Mono createADiff(Artifact artifact) { + + Application application = (Application) artifact; + String pageId = application.getPages().get(0).getId(); + Plugin plugin = pluginService.findByPackageName("restapi-plugin").block(); + + Datasource datasource = new Datasource(); + datasource.setName(PluginConstants.DEFAULT_REST_DATASOURCE); + datasource.setWorkspaceId(application.getWorkspaceId()); + datasource.setPluginId(plugin.getId()); + + ActionDTO action = new ActionDTO(); + action.setPluginType(PluginType.API); + action.setName("aGetAction_" + UUID.randomUUID()); + action.setDatasource(datasource); + action.setActionConfiguration(new ActionConfiguration()); + action.getActionConfiguration().setHttpMethod(HttpMethod.GET); + action.setPageId(pageId); + + return layoutActionService + .createSingleAction(action, Boolean.FALSE) + .then(); + } +} diff --git a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitArtifactTestUtils.java b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitArtifactTestUtils.java index b8c76ce38fd4..34584a339219 100644 --- a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitArtifactTestUtils.java +++ b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitArtifactTestUtils.java @@ -1,52 +1,8 @@ package com.appsmith.server.git; -import com.appsmith.external.constants.PluginConstants; -import com.appsmith.external.models.ActionConfiguration; -import com.appsmith.external.models.ActionDTO; -import com.appsmith.external.models.Datasource; -import com.appsmith.external.models.PluginType; -import com.appsmith.server.domains.Application; import com.appsmith.server.domains.Artifact; -import com.appsmith.server.domains.Plugin; -import com.appsmith.server.plugins.base.PluginService; -import com.appsmith.server.services.LayoutActionService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpMethod; -import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; -import java.util.UUID; - -@Component -public class GitArtifactTestUtils { - - @Autowired - LayoutActionService layoutActionService; - @Autowired - PluginService pluginService; - - Mono createADiff(Artifact artifact) { - - Application application = (Application) artifact; - - String pageId = application.getPages().get(0).getId(); - Plugin plugin = pluginService.findByPackageName("restapi-plugin").block(); - - Datasource datasource = new Datasource(); - datasource.setName(PluginConstants.DEFAULT_REST_DATASOURCE); - datasource.setWorkspaceId(application.getWorkspaceId()); - datasource.setPluginId(plugin.getId()); - - ActionDTO action = new ActionDTO(); - action.setPluginType(PluginType.API); - action.setName("aGetAction_" + UUID.randomUUID()); - action.setDatasource(datasource); - action.setActionConfiguration(new ActionConfiguration()); - action.getActionConfiguration().setHttpMethod(HttpMethod.GET); - action.setPageId(pageId); - - return layoutActionService - .createSingleAction(action, Boolean.FALSE) - .then(); - } +public interface GitArtifactTestUtils { + Mono createADiff(Artifact artifact); } diff --git a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitTestUtils.java b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitTestUtils.java index 34780cec9e72..cab41d79a6eb 100644 --- a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitTestUtils.java +++ b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/GitTestUtils.java @@ -1,27 +1,13 @@ package com.appsmith.server.git; -import com.appsmith.server.constants.ArtifactType; + import com.appsmith.server.domains.Application; -import com.appsmith.server.domains.Artifact; -import lombok.RequiredArgsConstructor; +import com.appsmith.server.git.ce.GitTestUtilsCE; import org.springframework.stereotype.Component; -import reactor.core.publisher.Mono; -@RequiredArgsConstructor @Component -public class GitTestUtils { - - private final GitArtifactTestUtils gitApplicationTestUtils; - - private GitArtifactTestUtils getArtifactSpecificUtils(ArtifactType artifactType) { - // TODO For now just work with apps - return gitApplicationTestUtils; - } - - - public Mono createADiffInArtifact(Artifact artifact) { - GitArtifactTestUtils artifactSpecificUtils = getArtifactSpecificUtils(artifact.getArtifactType()); - - return artifactSpecificUtils.createADiff(artifact); +public class GitTestUtils extends GitTestUtilsCE { + public GitTestUtils(GitArtifactTestUtils gitApplicationTestUtils) { + super(gitApplicationTestUtils); } } diff --git a/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ce/GitTestUtilsCE.java b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ce/GitTestUtilsCE.java new file mode 100644 index 000000000000..5e8c031d1398 --- /dev/null +++ b/app/server/appsmith-server/src/test/utils/com/appsmith/server/git/ce/GitTestUtilsCE.java @@ -0,0 +1,26 @@ +package com.appsmith.server.git.ce; + +import com.appsmith.server.constants.ArtifactType; +import com.appsmith.server.domains.Application; +import com.appsmith.server.domains.Artifact; +import com.appsmith.server.git.GitArtifactTestUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Component +public class GitTestUtilsCE { + + private final GitArtifactTestUtils gitApplicationTestUtils; + protected GitArtifactTestUtils getArtifactSpecificUtils(ArtifactType artifactType) { + return gitApplicationTestUtils; + } + + + public Mono createADiffInArtifact(Artifact artifact) { + GitArtifactTestUtils artifactSpecificUtils = getArtifactSpecificUtils(artifact.getArtifactType()); + + return artifactSpecificUtils.createADiff(artifact); + } +}