From 3206dddf918b63bcd9d6f8a8ff8d48c7c160dffd Mon Sep 17 00:00:00 2001 From: Kevin Knight Date: Tue, 27 Jun 2023 16:52:38 -0400 Subject: [PATCH 1/2] Clean up CachingFileAccessContext and delete CachingProjectFileAccessProvider --- .../project/CachingFileAccessContext.java | 49 ++- .../CachingProjectFileAccessProvider.java | 278 ------------------ 2 files changed, 21 insertions(+), 306 deletions(-) delete mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingProjectFileAccessProvider.java diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingFileAccessContext.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingFileAccessContext.java index 4910cf115e..b83d032edc 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingFileAccessContext.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingFileAccessContext.java @@ -27,7 +27,7 @@ public class CachingFileAccessContext extends AbstractFileAccessContext { private final FileAccessContext delegate; private final MutableMap cache = Maps.mutable.empty(); - private volatile boolean isCacheFull = false; + private boolean isCacheFull = false; private CachingFileAccessContext(FileAccessContext delegate) { @@ -62,41 +62,34 @@ protected Stream getFilesInCanonicalDirectories(MutableList public ProjectFile getFile(String path) { String canonicalPath = canonicalizePath(path); - byte[] bytes; - if (this.isCacheFull) + byte[] bytes = getFileBytes(canonicalPath); + return (bytes == null) ? null : ProjectFiles.newByteArrayProjectFile(canonicalPath, bytes); + } + + private byte[] getFileBytes(String canonicalPath) + { + synchronized (this.cache) { - bytes = this.cache.get(canonicalPath); + return this.isCacheFull ? + this.cache.get(canonicalPath) : + this.cache.getIfAbsentPutWithKey(canonicalPath, this::getFileBytesFromDelegate); } - else - { - synchronized (this.cache) - { - bytes = this.cache.get(canonicalPath); - if ((bytes == null) && !this.isCacheFull) - { - ProjectFile file = this.delegate.getFile(canonicalPath); - if (file != null) - { - bytes = file.getContentAsBytes(); - this.cache.put(canonicalPath, bytes); - } - } - } - } - return (bytes == null) ? null : ProjectFiles.newByteArrayProjectFile(canonicalPath, bytes); + } + + private byte[] getFileBytesFromDelegate(String canonicalPath) + { + ProjectFile file = this.delegate.getFile(canonicalPath); + return (file == null) ? null : file.getContentAsBytes(); } public void fillCache() { - if (!this.isCacheFull) + synchronized (this.cache) { - synchronized (this.cache) + if (!this.isCacheFull) { - if (!this.isCacheFull) - { - this.delegate.getFiles().forEach(pf -> this.cache.getIfAbsentPut(pf.getPath(), pf::getContentAsBytes)); - this.isCacheFull = true; - } + this.delegate.getFiles().forEach(pf -> this.cache.getIfAbsentPut(pf.getPath(), pf::getContentAsBytes)); + this.isCacheFull = true; } } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingProjectFileAccessProvider.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingProjectFileAccessProvider.java deleted file mode 100644 index 3a3d7ee587..0000000000 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/CachingProjectFileAccessProvider.java +++ /dev/null @@ -1,278 +0,0 @@ -// Copyright 2020 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.sdlc.server.project; - -import org.eclipse.collections.api.factory.Maps; -import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; - -import java.util.Map; -import java.util.Objects; - -class CachingProjectFileAccessProvider implements ProjectFileAccessProvider -{ - private final ProjectFileAccessProvider delegate; - private final Map cache = Maps.mutable.empty(); - - private CachingProjectFileAccessProvider(ProjectFileAccessProvider delegate) - { - this.delegate = delegate; - } - - // File Access Context - - @Override - public FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - if (revisionId == null) - { - return this.delegate.getFileAccessContext(projectId, sourceSpecification, null); - } - - CacheKey cacheKey = getCacheKey(projectId, sourceSpecification.getWorkspaceId(), revisionId); - synchronized (this.cache) - { - CachingFileAccessContext fileAccessContext = this.cache.get(cacheKey); - if (fileAccessContext == null) - { - fileAccessContext = CachingFileAccessContext.wrap(this.delegate.getFileAccessContext(projectId, sourceSpecification, revisionId)); - if (fileAccessContext != null) - { - this.cache.put(cacheKey, fileAccessContext); - } - } - return fileAccessContext; - } - } - - @Override - public FileAccessContext getFileAccessContext(String projectId, VersionId versionId) - { - CacheKey cacheKey = getCacheKey(projectId, versionId); - synchronized (this.cache) - { - CachingFileAccessContext fileAccessContext = this.cache.get(cacheKey); - if (fileAccessContext == null) - { - fileAccessContext = CachingFileAccessContext.wrap(this.delegate.getFileAccessContext(projectId, versionId)); - if (fileAccessContext != null) - { - this.cache.put(cacheKey, fileAccessContext); - } - } - return fileAccessContext; - } - } - - // Revision Access Context - - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String path) - { - return this.delegate.getRevisionAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, path); - } - - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification, Iterable paths) - { - return this.delegate.getRevisionAccessContext(projectId, sourceSpecification, paths); - } - - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, String path) - { - return this.delegate.getRevisionAccessContext(projectId, versionId, path); - } - - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, Iterable paths) - { - return this.delegate.getRevisionAccessContext(projectId, versionId, paths); - } - - // File Modification Access Context - - @Override - public FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.delegate.getFileModificationContext(projectId, sourceSpecification, revisionId); - } - - public void clearCache() - { - synchronized (this.cache) - { - this.cache.clear(); - } - } - - public void clearCache(String projectId, String workspaceId, String revisionId) - { - if (revisionId != null) - { - CacheKey cacheKey = getCacheKey(projectId, workspaceId, revisionId); - synchronized (this.cache) - { - this.cache.remove(cacheKey); - } - } - } - - public void clearCache(String projectId, VersionId versionId) - { - CacheKey cacheKey = getCacheKey(projectId, versionId); - synchronized (this.cache) - { - this.cache.remove(cacheKey); - } - } - - private CacheKey getCacheKey(String projectId, String workspaceId, String revisionId) - { - return (workspaceId == null) ? new ProjectRevisionCacheKey(projectId, revisionId) : new ProjectWorkspaceRevisionCacheKey(projectId, workspaceId, revisionId); - } - - private CacheKey getCacheKey(String projectId, VersionId versionId) - { - return new ProjectVersionCacheKey(projectId, versionId); - } - - static CachingProjectFileAccessProvider wrap(ProjectFileAccessProvider projectFileAccessProvider) - { - if (projectFileAccessProvider == null) - { - return null; - } - if (projectFileAccessProvider instanceof CachingProjectFileAccessProvider) - { - return (CachingProjectFileAccessProvider)projectFileAccessProvider; - } - return new CachingProjectFileAccessProvider(projectFileAccessProvider); - } - - private interface CacheKey - { - } - - private static class ProjectRevisionCacheKey implements CacheKey - { - private final String projectId; - private final String revisionId; - - private ProjectRevisionCacheKey(String projectId, String revisionId) - { - this.projectId = projectId; - this.revisionId = revisionId; - } - - @Override - public boolean equals(Object other) - { - if (this == other) - { - return true; - } - - if ((other == null) || (this.getClass() != other.getClass())) - { - return false; - } - - ProjectRevisionCacheKey that = (ProjectRevisionCacheKey)other; - return Objects.equals(this.projectId, that.projectId) && Objects.equals(this.revisionId, that.revisionId); - } - - @Override - public int hashCode() - { - return Objects.hashCode(this.projectId) + 43 * Objects.hashCode(this.revisionId); - } - } - - private static class ProjectWorkspaceRevisionCacheKey implements CacheKey - { - private final String projectId; - private final String workspaceId; - private final String revisionId; - - private ProjectWorkspaceRevisionCacheKey(String projectId, String workspaceId, String revisionId) - { - this.projectId = projectId; - this.workspaceId = workspaceId; - this.revisionId = revisionId; - } - - @Override - public boolean equals(Object other) - { - if (this == other) - { - return true; - } - - if ((other == null) || (this.getClass() != other.getClass())) - { - return false; - } - - ProjectWorkspaceRevisionCacheKey that = (ProjectWorkspaceRevisionCacheKey)other; - return Objects.equals(this.projectId, that.projectId) && - Objects.equals(this.workspaceId, that.workspaceId) && - Objects.equals(this.revisionId, that.revisionId); - } - - @Override - public int hashCode() - { - return Objects.hashCode(this.projectId) + 17 * (Objects.hashCode(this.workspaceId) + 17 * Objects.hashCode(this.revisionId)); - } - } - - private static class ProjectVersionCacheKey implements CacheKey - { - private final String projectId; - private final VersionId versionId; - - private ProjectVersionCacheKey(String projectId, VersionId versionId) - { - this.projectId = projectId; - this.versionId = versionId; - } - - @Override - public boolean equals(Object other) - { - if (this == other) - { - return true; - } - - if ((other == null) || (this.getClass() != other.getClass())) - { - return false; - } - - ProjectVersionCacheKey that = (ProjectVersionCacheKey)other; - return Objects.equals(this.projectId, that.projectId) && Objects.equals(this.versionId, that.versionId); - } - - @Override - public int hashCode() - { - return Objects.hashCode(this.projectId) + 41 * Objects.hashCode(this.versionId); - } - } -} From 7a3488556a6cd97b828d400006b46abd8317a0ce Mon Sep 17 00:00:00 2001 From: Kevin Knight Date: Wed, 28 Jun 2023 17:24:22 -0400 Subject: [PATCH 2/2] Clean up SourceSpecification --- .../domain/model/revision/RevisionStatus.java | 3 + .../server/domain/api/backup/BackupApi.java | 80 ++- .../domain/api/comparison/ComparisonApi.java | 167 +++-- .../ConflictResolutionApi.java | 91 ++- .../api/dependency/DependenciesApi.java | 2 +- .../api/dependency/DependenciesApiImpl.java | 10 +- .../server/domain/api/entity/EntityApi.java | 194 ++++-- .../api/project/ProjectConfigurationApi.java | 254 ++++++-- .../api/project/SourceSpecification.java | 162 ----- .../source/PatchSourceSpecification.java | 59 ++ .../source/ProjectSourceSpecification.java | 36 + .../project/source/SourceSpecification.java | 173 +++++ .../source/SourceSpecificationConsumer.java | 74 +++ .../source/SourceSpecificationVisitor.java | 46 ++ .../source/VersionSourceSpecification.java | 59 ++ .../source/WorkspaceSourceSpecification.java | 59 ++ .../server/domain/api/review/ReviewApi.java | 331 +++++----- .../domain/api/revision/RevisionApi.java | 138 +++- .../domain/api/test/TestModelBuilder.java | 4 +- .../domain/api/workflow/WorkflowApi.java | 62 +- .../domain/api/workflow/WorkflowJobApi.java | 62 +- .../api/workspace/PatchWorkspaceSource.java | 66 ++ .../api/workspace/ProjectWorkspaceSource.java | 44 ++ .../domain/api/workspace/WorkspaceApi.java | 348 +++++++--- .../domain/api/workspace/WorkspaceSource.java | 57 ++ .../workspace/WorkspaceSourceConsumer.java | 50 ++ .../api/workspace/WorkspaceSourceVisitor.java | 36 + .../api/workspace/WorkspaceSpecification.java | 162 +++++ .../sdlc/server/gitlab/api/BaseGitLabApi.java | 526 ++++++++++----- .../gitlab/api/GitLabApiWithFileAccess.java | 549 +++++++--------- .../server/gitlab/api/GitLabBackupApi.java | 109 ++-- .../server/gitlab/api/GitLabBuildApi.java | 2 +- .../gitlab/api/GitLabComparisonApi.java | 160 +++-- .../api/GitLabConflictResolutionApi.java | 250 ++++--- .../server/gitlab/api/GitLabEntityApi.java | 439 ++++--------- .../server/gitlab/api/GitLabPatchApi.java | 54 +- .../server/gitlab/api/GitLabProjectApi.java | 32 +- .../api/GitLabProjectConfigurationApi.java | 275 ++------ .../server/gitlab/api/GitLabReviewApi.java | 200 +++--- .../server/gitlab/api/GitLabRevisionApi.java | 170 ++--- .../server/gitlab/api/GitLabWorkspaceApi.java | 615 +++++++++--------- .../server/gitlab/api/GitlabWorkflowApi.java | 72 +- .../gitlab/api/GitlabWorkflowJobApi.java | 68 +- .../server/gitlab/tools/GitLabApiTools.java | 32 +- .../project/ProjectFileAccessProvider.java | 379 ++++++----- .../sdlc/server/project/ProjectStructure.java | 30 +- ...PatchesGroupWorkspaceEntitiesResource.java | 2 +- ...chesGroupWorkspaceEntityPathsResource.java | 2 +- ...WorkspaceProjectConfigurationResource.java | 2 +- .../BackupPatchesGroupWorkspaceResource.java | 2 +- ...roupWorkspaceRevisionEntitiesResource.java | 2 +- ...pWorkspaceRevisionEntityPathsResource.java | 2 +- ...eRevisionProjectConfigurationResource.java | 2 +- ...atchesGroupWorkspaceRevisionsResource.java | 2 +- ...ackupPatchesWorkspaceEntitiesResource.java | 2 +- ...upPatchesWorkspaceEntityPathsResource.java | 2 +- ...WorkspaceProjectConfigurationResource.java | 2 +- .../user/BackupPatchesWorkspaceResource.java | 2 +- ...chesWorkspaceRevisionEntitiesResource.java | 2 +- ...sWorkspaceRevisionEntityPathsResource.java | 2 +- ...eRevisionProjectConfigurationResource.java | 2 +- ...ckupPatchesWorkspaceRevisionsResource.java | 2 +- ...tchesGroupComparisonWorkspaceResource.java | 2 +- .../ComparisonPatchesWorkspaceResource.java | 2 +- ...PatchesGroupWorkspaceEntitiesResource.java | 2 +- ...chesGroupWorkspaceEntityPathsResource.java | 2 +- ...WorkspaceProjectConfigurationResource.java | 2 +- ...solutionPatchesGroupWorkspaceResource.java | 2 +- ...roupWorkspaceRevisionEntitiesResource.java | 2 +- ...pWorkspaceRevisionEntityPathsResource.java | 2 +- ...eRevisionProjectConfigurationResource.java | 2 +- ...atchesGroupWorkspaceRevisionsResource.java | 2 +- ...utionPatchesWorkspaceEntitiesResource.java | 2 +- ...onPatchesWorkspaceEntityPathsResource.java | 2 +- ...WorkspaceProjectConfigurationResource.java | 2 +- ...ictResolutionPatchesWorkspaceResource.java | 2 +- ...chesWorkspaceRevisionEntitiesResource.java | 2 +- ...sWorkspaceRevisionEntityPathsResource.java | 2 +- ...eRevisionProjectConfigurationResource.java | 2 +- ...tionPatchesWorkspaceRevisionsResource.java | 2 +- ...WorkspaceRevisionDependenciesResource.java | 2 +- ...WorkspaceRevisionDependenciesResource.java | 2 +- ...PatchesGroupWorkspaceEntitiesResource.java | 2 +- ...esGroupWorkspaceEntityChangesResource.java | 2 +- ...chesGroupWorkspaceEntityPathsResource.java | 2 +- ...roupWorkspaceRevisionEntitiesResource.java | 2 +- ...pWorkspaceRevisionEntityPathsResource.java | 2 +- .../PatchesWorkspaceEntitiesResource.java | 2 +- ...PatchesWorkspaceEntityChangesResource.java | 2 +- .../PatchesWorkspaceEntityPathsResource.java | 2 +- ...chesWorkspaceRevisionEntitiesResource.java | 2 +- ...sWorkspaceRevisionEntityPathsResource.java | 2 +- ...WorkspacePureModelContextDataResource.java | 2 +- ...eRevisionPureModelContextDataResource.java | 2 +- ...WorkspacePureModelContextDataResource.java | 2 +- ...eRevisionPureModelContextDataResource.java | 2 +- .../PatchProjectConfigurationResource.java | 11 +- ...WorkspaceProjectConfigurationResource.java | 2 +- ...eRevisionProjectConfigurationResource.java | 2 +- ...WorkspaceProjectConfigurationResource.java | 2 +- ...eRevisionProjectConfigurationResource.java | 2 +- .../project/ProjectConfigurationResource.java | 7 +- ...tRevisionProjectConfigurationResource.java | 7 +- .../review/patch/PatchReviewsResource.java | 2 +- ...GroupWorkspaceEntityRevisionsResource.java | 2 +- ...roupWorkspacePackageRevisionsResource.java | 2 +- ...atchesGroupWorkspaceRevisionsResource.java | 2 +- ...tchesWorkspaceEntityRevisionsResource.java | 2 +- ...chesWorkspacePackageRevisionsResource.java | 2 +- .../PatchesWorkspaceRevisionsResource.java | 2 +- .../resources/version/VersionsResource.java | 7 +- ...hesGroupWorkspaceWorkflowJobsResource.java | 2 +- ...atchesGroupWorkspaceWorkflowsResource.java | 2 +- .../PatchesWorkspaceWorkflowJobsResource.java | 2 +- .../PatchesWorkspaceWorkflowsResource.java | 2 +- .../group/PatchesGroupWorkspacesResource.java | 2 +- .../patch/user/PatchesWorkspacesResource.java | 2 +- .../api/GitLabComparisonApiTestResource.java | 2 +- .../api/GitLabEntityApiTestResource.java | 278 ++++---- .../api/GitLabProjectApiTestResource.java | 48 +- ...abProjectConfigurationApiTestResource.java | 55 +- .../api/GitLabRevisionApiTestResource.java | 2 +- .../api/GitLabWorkspaceApiTestResource.java | 2 +- .../server/gitlab/api/TestBaseGitLabApi.java | 128 ++++ .../IntegrationTestGitLabComparisonApis.java | 2 +- .../TestGitLabServerComparisonApis.java | 2 +- .../backend/api/InMemoryBackupApi.java | 6 +- .../backend/api/InMemoryComparisonApi.java | 11 +- .../api/InMemoryConflictResolutionApi.java | 8 +- .../backend/api/InMemoryEntityApi.java | 207 +++--- .../api/InMemoryProjectConfigurationApi.java | 169 ++--- .../backend/api/InMemoryReviewApi.java | 36 +- .../backend/api/InMemoryRevisionApi.java | 209 ++++-- .../backend/api/InMemoryWorkflowApi.java | 19 +- .../backend/api/InMemoryWorkflowJobApi.java | 19 +- .../backend/api/InMemoryWorkspaceApi.java | 159 +++-- .../inmemory/domain/api/InMemoryProject.java | 24 +- .../inmemory/domain/api/InMemoryRevision.java | 8 +- .../InMemoryProjectFileAccessProvider.java | 208 +++--- .../TestMultiGenerationProjectStructure.java | 2 +- .../server/project/TestProjectStructure.java | 235 ++++--- .../resources/TestDependenciesResource.java | 2 +- .../server/resources/TestPatchesResource.java | 4 +- .../server/resources/TestReviewsResource.java | 33 +- .../server/utils/TestModelBuilderTest.java | 13 +- 145 files changed, 5036 insertions(+), 3812 deletions(-) delete mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/SourceSpecification.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/PatchSourceSpecification.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/ProjectSourceSpecification.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecification.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationConsumer.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationVisitor.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/VersionSourceSpecification.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/WorkspaceSourceSpecification.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/PatchWorkspaceSource.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/ProjectWorkspaceSource.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSource.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceConsumer.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceVisitor.java create mode 100644 legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSpecification.java diff --git a/legend-sdlc-model/src/main/java/org/finos/legend/sdlc/domain/model/revision/RevisionStatus.java b/legend-sdlc-model/src/main/java/org/finos/legend/sdlc/domain/model/revision/RevisionStatus.java index fd2306e209..22976673bf 100644 --- a/legend-sdlc-model/src/main/java/org/finos/legend/sdlc/domain/model/revision/RevisionStatus.java +++ b/legend-sdlc-model/src/main/java/org/finos/legend/sdlc/domain/model/revision/RevisionStatus.java @@ -14,6 +14,7 @@ package org.finos.legend.sdlc.domain.model.revision; +import org.finos.legend.sdlc.domain.model.patch.Patch; import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; import org.finos.legend.sdlc.domain.model.version.Version; @@ -28,4 +29,6 @@ public interface RevisionStatus List getWorkspaces(); List getVersions(); + + List getPatches(); } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/backup/BackupApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/backup/BackupApi.java index 71c89e657a..c8fc3c5cf1 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/backup/BackupApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/backup/BackupApi.java @@ -14,30 +14,54 @@ package org.finos.legend.sdlc.server.domain.api.backup; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; public interface BackupApi { + /** + * Discard the backup workspace + * + * @param projectId project id + * @param workspaceSpecification workspace specification + */ + void discardBackupWorkspace(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Recover the backup workspace + * + * @param projectId project id + * @param workspaceSpecification workspace specification + * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup + */ + void recoverBackupWorkspace(String projectId, WorkspaceSpecification workspaceSpecification, boolean forceRecovery); + + // Deprecated APIs + /** * Discard the backup user workspace * - * @param projectId project id - * @param workspaceId id of backup workspace + * @param projectId project id + * @param workspaceId id of backup workspace */ + @Deprecated default void discardBackupUserWorkspace(String projectId, String workspaceId) { - this.discardBackupWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + discardBackupWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** * Discard the backup group workspace * - * @param projectId project id - * @param workspaceId id of backup workspace + * @param projectId project id + * @param workspaceId id of backup workspace */ + @Deprecated default void discardBackupGroupWorkspace(String projectId, String workspaceId) { - this.discardBackupWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + discardBackupWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** @@ -46,38 +70,56 @@ default void discardBackupGroupWorkspace(String projectId, String workspaceId) * @param projectId project id * @param sourceSpecification source specification */ - void discardBackupWorkspace(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default void discardBackupWorkspace(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + discardBackupWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Recover the backup user workspace * - * @param projectId project id - * @param workspaceId workspace id - * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup + * @param projectId project id + * @param workspaceId workspace id + * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup */ + @Deprecated default void recoverBackupUserWorkspace(String projectId, String workspaceId, boolean forceRecovery) { - this.recoverBackupWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), forceRecovery); + recoverBackupWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER), forceRecovery); } /** * Recover the backup group workspace * - * @param projectId project id - * @param workspaceId workspace id - * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup + * @param projectId project id + * @param workspaceId workspace id + * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup */ + @Deprecated default void recoverBackupGroupWorkspace(String projectId, String workspaceId, boolean forceRecovery) { - this.recoverBackupWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), forceRecovery); + recoverBackupWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP), forceRecovery); } /** * Recover the backup workspace * - * @param projectId project id + * @param projectId project id * @param sourceSpecification source specification - * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup + * @param forceRecovery flag indicating that if the workspace and its backup both exist, we will override the workspace by its backup */ - void recoverBackupWorkspace(String projectId, SourceSpecification sourceSpecification, boolean forceRecovery); + @Deprecated + default void recoverBackupWorkspace(String projectId, SourceSpecification sourceSpecification, boolean forceRecovery) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + recoverBackupWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification(), forceRecovery); + } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/comparison/ComparisonApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/comparison/ComparisonApi.java index c6e4184954..3fc97e794a 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/comparison/ComparisonApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/comparison/ComparisonApi.java @@ -17,135 +17,122 @@ import org.finos.legend.sdlc.domain.model.comparison.Comparison; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; public interface ComparisonApi { /** - * Get the comparison between user workspace HEAD and BASE - *

- * Given a user workspace, returns the comparison from the creation of the workspace - * to the current revision of the workspace + * Get the comparison between workspace HEAD (current revision) and workspace BASE (creation revision). * - * @param projectId project id - * @param workspaceId workspace id - * @return comparison between user workspace HEAD and BASE + * @param projectId project id + * @param workspaceSpecification workspace specification + * @return comparison between workspace HEAD and BASE */ - default Comparison getUserWorkspaceCreationComparison(String projectId, String workspaceId) - { - return this.getWorkspaceCreationComparison(projectId, workspaceId, WorkspaceType.USER); - } + Comparison getWorkspaceCreationComparison(String projectId, WorkspaceSpecification workspaceSpecification); /** - * Get the comparison between group workspace HEAD and BASE - *

- * Given a group workspace, returns the comparison from the creation of the workspace - * to the current revision of the workspace + * Get the comparison between the HEAD (current revision) of a workspace and its source. * - * @param projectId project id - * @param workspaceId workspace id - * @return comparison between group workspace HEAD and BASE + * @param projectId project id + * @param workspaceSpecification workspace specification + * @return comparison between user workspace HEAD and workspace source HEAD */ + Comparison getWorkspaceSourceComparison(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Get the comparison for a given review between the HEAD (current revision) of its source (workspace) and target. + * This is equivalent to calling {@link #getWorkspaceSourceComparison} for the source workspace of the review. + * + * @param projectId project id + * @param reviewId review id + * @return comparison between review source HEAD and target HEAD + */ + Comparison getReviewComparison(String projectId, String reviewId); + + /** + * Get the comparison for a given review between the HEAD (current revision) and BASE (creation revision) of its + * source workspace. This is equivalent to calling {@link #getWorkspaceCreationComparison} for the source workspace + * of the reivew. + * + * @param projectId project id + * @param reviewId review id + * @return comparison between review workspace HEAD and BASE + */ + Comparison getReviewWorkspaceCreationComparison(String projectId, String reviewId); + + + // Deprecated APIs + + @Deprecated + default Comparison getUserWorkspaceCreationComparison(String projectId, String workspaceId) + { + return getWorkspaceCreationComparison(projectId, workspaceId, WorkspaceType.USER); + } + + @Deprecated default Comparison getGroupWorkspaceCreationComparison(String projectId, String workspaceId) { return this.getWorkspaceCreationComparison(projectId, workspaceId, WorkspaceType.GROUP); } - /** - * Get the comparison between workspace HEAD and workspace BASE - *

- * Given a workspace, returns the comparison from the creation of the workspace - * to the current revision of the workspace - * - * @param projectId project id - * @param sourceSpecification source specification - * @return comparison between workspace HEAD and BASE - */ - Comparison getWorkspaceCreationComparison(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default Comparison getWorkspaceCreationComparison(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getWorkspaceCreationComparison(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } + @Deprecated default Comparison getWorkspaceCreationComparison(String projectId, String workspaceId, WorkspaceType workspaceType) { - return this.getWorkspaceCreationComparison(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType)); + return getWorkspaceCreationComparison(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType)); } - /** - * Get the comparison between user workspace HEAD and project HEAD - *

- * Given a user workspace, returns the comparison from the current revision of the - * project to the current revision of the workspace - * - * @param projectId project id - * @param workspaceId workspace id - * @return comparison between user workspace HEAD and project HEAD - */ + @Deprecated default Comparison getUserWorkspaceProjectComparison(String projectId, String workspaceId) { return this.getWorkspaceProjectComparison(projectId, workspaceId, WorkspaceType.USER); } - /** - * Get the comparison between group workspace HEAD and project HEAD - *

- * Given a group workspace, returns the comparison from the current revision of the - * project to the current revision of the workspace - * - * @param projectId project id - * @param workspaceId workspace id - * @return comparison between group workspace HEAD and project HEAD - */ + @Deprecated default Comparison getGroupWorkspaceProjectComparison(String projectId, String workspaceId) { return this.getWorkspaceProjectComparison(projectId, workspaceId, WorkspaceType.GROUP); } - /** - * Get the comparison between workspace HEAD and project HEAD - *

- * Given a workspace, returns the comparison from the current revision of the - * project to the current revision of the workspace - * - * @param projectId project id - * @param sourceSpecification source specification - * @return comparison between workspace HEAD and project HEAD - */ - Comparison getWorkspaceProjectComparison(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default Comparison getWorkspaceProjectComparison(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getWorkspaceSourceComparison(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } + @Deprecated default Comparison getWorkspaceProjectComparison(String projectId, String workspaceId, WorkspaceType workspaceType) { - return this.getWorkspaceProjectComparison(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType)); + return getWorkspaceSourceComparison(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, WorkspaceSource.projectWorkspaceSource())); } - /** - * Get the comparison for a given review (between review workspace HEAD and project HEAD) - *

- * Given a review, returns the comparison for that review - * Uses the diff ref (start and end revision id for review) to get revisions ids for comparison - * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id - * @return comparison between review workspace HEAD and project HEAD - */ - Comparison getReviewComparison(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Comparison getReviewComparison(String projectId, String reviewId) + @Deprecated + default Comparison getReviewComparison(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewComparison(projectId, null, reviewId); + return getReviewComparison(projectId, reviewId); } - /** - * Get the comparison for a given review (between review workspace HEAD and workspace BASE) - * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id - * @return comparison between review workspace HEAD and BASE - */ - Comparison getReviewWorkspaceCreationComparison(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Comparison getReviewWorkspaceCreationComparison(String projectId, String reviewId) + @Deprecated + default Comparison getReviewWorkspaceCreationComparison(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewWorkspaceCreationComparison(projectId, null, reviewId); + return getReviewWorkspaceCreationComparison(projectId, reviewId); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/conflictResolution/ConflictResolutionApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/conflictResolution/ConflictResolutionApi.java index c0c343672a..7007c4e511 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/conflictResolution/ConflictResolutionApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/conflictResolution/ConflictResolutionApi.java @@ -14,11 +14,44 @@ package org.finos.legend.sdlc.server.domain.api.conflictResolution; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; public interface ConflictResolutionApi { + /** + * Discard/Abandon conflict resolution, as a result, we will delete the workspace with conflict resolution that + * we created when we started conflict resolution. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + */ + void discardConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Discard all conflict resolution changes, effectively delete the workspace with conflict resolution and the original + * workspace and create a new workspace from the current revision of the project. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + */ + void discardChangesConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Accept the conflict resolution. This will apply the entity changes (to resolve conflicts) and + * replace the original workspace by the workspace with conflict resolution. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + * @param command entity changes to resolve any conflicts + */ + void acceptConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification, PerformChangesCommand command); + + // Deprecated APIs + /** * Discard/Abandon conflict resolution in a user workspace, as a result, we will delete the workspace with conflict resolution that * we created when we started conflict resolution. @@ -26,9 +59,10 @@ public interface ConflictResolutionApi * @param projectId project id * @param workspaceId id of workspace with conflict resolution to delete */ + @Deprecated default void discardConflictResolutionInGroupWorkspace(String projectId, String workspaceId) { - this.discardConflictResolution(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + discardConflictResolution(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** @@ -38,19 +72,28 @@ default void discardConflictResolutionInGroupWorkspace(String projectId, String * @param projectId project id * @param workspaceId id of workspace with conflict resolution to delete */ + @Deprecated default void discardConflictResolutionInUserWorkspace(String projectId, String workspaceId) { - this.discardConflictResolution(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + discardConflictResolution(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** * Discard/Abandon conflict resolution, as a result, we will delete the workspace with conflict resolution that * we created when we started conflict resolution. * - * @param projectId project id + * @param projectId project id * @param sourceSpecification source specification */ - void discardConflictResolution(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default void discardConflictResolution(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + discardConflictResolution(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Discard all conflict resolution changes in a user workspace, effectively delete the workspace with conflict resolution and the original @@ -59,9 +102,10 @@ default void discardConflictResolutionInUserWorkspace(String projectId, String w * @param projectId project id * @param workspaceId workspace id */ + @Deprecated default void discardChangesConflictResolutionInUserWorkspace(String projectId, String workspaceId) { - this.discardConflictResolution(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + discardChangesConflictResolution(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** @@ -71,19 +115,28 @@ default void discardChangesConflictResolutionInUserWorkspace(String projectId, S * @param projectId project id * @param workspaceId workspace id */ + @Deprecated default void discardChangesConflictResolutionInGroupWorkspace(String projectId, String workspaceId) { - this.discardConflictResolution(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + discardChangesConflictResolution(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** * Discard all conflict resolution changes, effectively delete the workspace with conflict resolution and the original * workspace and create a new workspace from the current revision of the project. * - * @param projectId project id + * @param projectId project id * @param sourceSpecification source specification */ - void discardChangesConflictResolution(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default void discardChangesConflictResolution(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + discardChangesConflictResolution(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Accept the conflict resolution in a user workspace. This will apply the entity changes (to resolve conflicts) and @@ -93,9 +146,10 @@ default void discardChangesConflictResolutionInGroupWorkspace(String projectId, * @param workspaceId workspace id * @param command entity changes to resolve any conflicts */ + @Deprecated default void acceptConflictResolutionInUserWorkspace(String projectId, String workspaceId, PerformChangesCommand command) { - this.acceptConflictResolution(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), command); + acceptConflictResolution(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER), command); } /** @@ -106,18 +160,27 @@ default void acceptConflictResolutionInUserWorkspace(String projectId, String wo * @param workspaceId workspace id * @param command entity changes to resolve any conflicts */ + @Deprecated default void acceptConflictResolutionInGroupWorkspace(String projectId, String workspaceId, PerformChangesCommand command) { - this.acceptConflictResolution(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), command); + acceptConflictResolution(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP), command); } /** * Accept the conflict resolution. This will apply the entity changes (to resolve conflicts) and * replace the original workspace by the workspace with conflict resolution. * - * @param projectId project id + * @param projectId project id * @param sourceSpecification source specification - * @param command entity changes to resolve any conflicts + * @param command entity changes to resolve any conflicts */ - void acceptConflictResolution(String projectId, SourceSpecification sourceSpecification, PerformChangesCommand command); + @Deprecated + default void acceptConflictResolution(String projectId, SourceSpecification sourceSpecification, PerformChangesCommand command) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + acceptConflictResolution(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification(), command); + } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApi.java index 29041dcd57..3267d403c8 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApi.java @@ -17,7 +17,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import java.util.Set; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApiImpl.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApiImpl.java index fbda57c3fc..591d590d1d 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApiImpl.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/dependency/DependenciesApiImpl.java @@ -25,7 +25,7 @@ import org.finos.legend.sdlc.server.domain.api.project.ProjectApi; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import java.util.ArrayDeque; import java.util.Deque; @@ -64,7 +64,7 @@ public Set getProjectRevisionUpstreamProjects(String projectI @Override public Set getProjectVersionUpstreamProjects(String projectId, String versionId, boolean transitive) { - ProjectConfiguration projectConfiguration = this.projectConfigurationApi.getVersionProjectConfiguration(projectId, versionId); + ProjectConfiguration projectConfiguration = this.projectConfigurationApi.getProjectConfiguration(projectId, SourceSpecification.versionSourceSpecification(versionId), versionId); return searchUpstream(projectConfiguration, transitive); } @@ -83,8 +83,8 @@ public Set getDownstreamProjects(String projectId) String otherProjectId = otherProject.getProjectId(); if (!projectId.equals(otherProjectId)) { - Revision otherProjectRevision = this.revisionApi.getProjectRevisionContext(otherProjectId).getCurrentRevision(); - ProjectConfiguration projectConfiguration = this.projectConfigurationApi.getProjectRevisionProjectConfiguration(otherProjectId, otherProjectRevision.getId()); + Revision otherProjectRevision = this.revisionApi.getRevisionContext(otherProjectId, SourceSpecification.projectSourceSpecification()).getCurrentRevision(); + ProjectConfiguration projectConfiguration = this.projectConfigurationApi.getProjectConfiguration(otherProjectId, SourceSpecification.projectSourceSpecification(), otherProjectRevision.getId()); if (Iterate.anySatisfy(projectConfiguration.getProjectDependencies(), d -> projectId.equals(d.getProjectId()))) { results.add(new ProjectRevision(otherProject.getProjectId(), otherProjectRevision.getId())); @@ -108,7 +108,7 @@ private Set searchUpstream(ProjectConfiguration rootProjectCo ProjectDependency dependency = deque.pollFirst(); if (results.add(dependency)) { - ProjectConfiguration dependencyProjectConfig = this.projectConfigurationApi.getVersionProjectConfiguration(dependency.getProjectId(), dependency.getVersionId()); + ProjectConfiguration dependencyProjectConfig = this.projectConfigurationApi.getProjectConfiguration(dependency.getProjectId(), SourceSpecification.versionSourceSpecification(dependency.getVersionId())); deque.addAll(dependencyProjectConfig.getProjectDependencies()); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/entity/EntityApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/entity/EntityApi.java index e97a99e0c7..c65996ec53 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/entity/EntityApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/entity/EntityApi.java @@ -16,163 +16,247 @@ import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; -import org.finos.legend.sdlc.server.error.LegendSDLCServerException; - -import javax.ws.rs.core.Response.Status; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; public interface EntityApi { // Entity access - EntityAccessContext getProjectEntityAccessContext(String projectId, VersionId patchReleaseVersionId); + EntityAccessContext getEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId); + + default EntityAccessContext getEntityAccessContext(String projectId, SourceSpecification sourceSpecification) + { + return getEntityAccessContext(projectId, sourceSpecification, null); + } + + EntityAccessContext getReviewFromEntityAccessContext(String projectId, String reviewId); + + EntityAccessContext getReviewToEntityAccessContext(String projectId, String reviewId); + + // Entity modification + + EntityModificationContext getEntityModificationContext(String projectId, WorkspaceSourceSpecification sourceSpecification); + + // Deprecated APIs + @Deprecated + default EntityAccessContext getProjectEntityAccessContext(String projectId, VersionId patchReleaseVersionId) + { + return getEntityAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId)); + } + + @Deprecated default EntityAccessContext getProjectEntityAccessContext(String projectId) { - return this.getProjectEntityAccessContext(projectId, null); + return getEntityAccessContext(projectId, SourceSpecification.projectSourceSpecification()); } - EntityAccessContext getProjectRevisionEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String revisionId); + @Deprecated + default EntityAccessContext getProjectRevisionEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String revisionId) + { + return getEntityAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), revisionId); + } + @Deprecated default EntityAccessContext getProjectRevisionEntityAccessContext(String projectId, String revisionId) { - return this.getProjectRevisionEntityAccessContext(projectId, null, revisionId); + return getEntityAccessContext(projectId, SourceSpecification.projectSourceSpecification(), revisionId); } + @Deprecated default EntityAccessContext getUserWorkspaceEntityAccessContext(String projectId, String workspaceId) { - return this.getWorkspaceEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getUserWorkspaceRevisionEntityAccessContext(projectId, workspaceId, null); } + @Deprecated default EntityAccessContext getGroupWorkspaceEntityAccessContext(String projectId, String workspaceId) { - return this.getWorkspaceEntityAccessContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getGroupWorkspaceRevisionEntityAccessContext(projectId, workspaceId, null); } - // for backward compatibility @Deprecated default EntityAccessContext getWorkspaceEntityAccessContext(String projectId, String workspaceId) { - return getWorkspaceEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getWorkspaceRevisionEntityAccessContext(projectId, workspaceId, null); } - EntityAccessContext getWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default EntityAccessContext getWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification) + { + return getWorkspaceRevisionEntityAccessContext(projectId, sourceSpecification, null); + } + @Deprecated default EntityAccessContext getBackupUserWorkspaceEntityAccessContext(String projectId, String workspaceId) { - return this.getBackupWorkspaceEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getBackupUserWorkspaceRevisionEntityAccessContext(projectId, workspaceId, null); } + @Deprecated default EntityAccessContext getBackupGroupWorkspaceEntityAccessContext(String projectId, String workspaceId) { - return this.getBackupWorkspaceEntityAccessContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getBackupGroupWorkspaceRevisionEntityAccessContext(projectId, workspaceId, null); } - EntityAccessContext getBackupWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default EntityAccessContext getBackupWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification) + { + return getBackupWorkspaceRevisionEntityAccessContext(projectId, sourceSpecification, null); + } + @Deprecated default EntityAccessContext getUserWorkspaceWithConflictResolutionEntityAccessContext(String projectId, String workspaceId) { - return this.getWorkspaceWithConflictResolutionEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getUserWorkspaceWithConflictResolutionRevisionEntityAccessContext(projectId, workspaceId, null); } + @Deprecated default EntityAccessContext getGroupWorkspaceWithConflictResolutionEntityAccessContext(String projectId, String workspaceId) { - return this.getWorkspaceWithConflictResolutionEntityAccessContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getGroupWorkspaceWithConflictResolutionRevisionEntityAccessContext(projectId, workspaceId, null); } - EntityAccessContext getWorkspaceWithConflictResolutionEntityAccessContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default EntityAccessContext getWorkspaceWithConflictResolutionEntityAccessContext(String projectId, SourceSpecification sourceSpecification) + { + return getWorkspaceWithConflictResolutionRevisionEntityAccessContext(projectId, sourceSpecification, null); + } + @Deprecated default EntityAccessContext getUserWorkspaceRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceRevisionEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); + return getWorkspaceRevisionEntityAccessContext(projectId, workspaceId, WorkspaceType.USER, revisionId); } + @Deprecated default EntityAccessContext getGroupWorkspaceRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceRevisionEntityAccessContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), revisionId); + return getWorkspaceRevisionEntityAccessContext(projectId, workspaceId, WorkspaceType.GROUP, revisionId); } - // for backward compatibility @Deprecated default EntityAccessContext getWorkspaceRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return getWorkspaceRevisionEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); + return getWorkspaceRevisionEntityAccessContext(projectId, workspaceId, WorkspaceType.USER, revisionId); } + @Deprecated default EntityAccessContext getWorkspaceRevisionEntityAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, String revisionId) { - return getWorkspaceRevisionEntityAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType), revisionId); + return getEntityAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType)), revisionId); } - EntityAccessContext getWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecificationo, String revisionId); + @Deprecated + default EntityAccessContext getWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getEntityAccessContext(projectId, sourceSpecification, revisionId); + } + @Deprecated default EntityAccessContext getBackupUserWorkspaceRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return this.getBackupWorkspaceRevisionEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); + return getEntityAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.BACKUP)), revisionId); } + @Deprecated default EntityAccessContext getBackupGroupWorkspaceRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return this.getBackupWorkspaceRevisionEntityAccessContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), revisionId); + return getEntityAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.BACKUP)), revisionId); } - EntityAccessContext getBackupWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId); + @Deprecated + default EntityAccessContext getBackupWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.BACKUP)) + { + throw new IllegalArgumentException("Not a backup workspace source specification: " + sourceSpecification); + } + return getEntityAccessContext(projectId, sourceSpecification, revisionId); + } + @Deprecated default EntityAccessContext getUserWorkspaceWithConflictResolutionRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceWithConflictResolutionRevisionEntityAccessContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); + return getEntityAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.CONFLICT_RESOLUTION)), revisionId); } + @Deprecated default EntityAccessContext getGroupWorkspaceWithConflictResolutionRevisionEntityAccessContext(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceWithConflictResolutionRevisionEntityAccessContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), revisionId); + return getEntityAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.CONFLICT_RESOLUTION)), revisionId); } - EntityAccessContext getWorkspaceWithConflictResolutionRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId); - - default EntityAccessContext getVersionEntityAccessContext(String projectId, String versionIdString) + @Deprecated + default EntityAccessContext getWorkspaceWithConflictResolutionRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) { - VersionId versionId; - try - { - versionId = VersionId.parseVersionId(versionIdString); - } - catch (IllegalArgumentException e) + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.CONFLICT_RESOLUTION)) { - throw new LegendSDLCServerException(e.getMessage(), Status.BAD_REQUEST, e); + throw new IllegalArgumentException("Not a conflict resolution workspace source specification: " + sourceSpecification); } - return getVersionEntityAccessContext(projectId, versionId); + return getEntityAccessContext(projectId, sourceSpecification, revisionId); } - EntityAccessContext getReviewFromEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default EntityAccessContext getReviewFromEntityAccessContext(String projectId, String reviewId) + @Deprecated + default EntityAccessContext getReviewFromEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewFromEntityAccessContext(projectId, null, reviewId); + return getReviewFromEntityAccessContext(projectId, reviewId); } - EntityAccessContext getReviewToEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default EntityAccessContext getReviewToEntityAccessContext(String projectId, String reviewId) + @Deprecated + default EntityAccessContext getReviewToEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewToEntityAccessContext(projectId, null, reviewId); + return getReviewToEntityAccessContext(projectId, reviewId); } - EntityAccessContext getVersionEntityAccessContext(String projectId, VersionId versionId); + @Deprecated + default EntityAccessContext getVersionEntityAccessContext(String projectId, String versionIdString) + { + return getEntityAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionIdString)); + } - // Entity modification + @Deprecated + default EntityAccessContext getVersionEntityAccessContext(String projectId, VersionId versionId) + { + return getEntityAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId)); + } + @Deprecated default EntityModificationContext getUserWorkspaceEntityModificationContext(String projectId, String workspaceId) { - return this.getWorkspaceEntityModificationContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getEntityModificationContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE))); } + @Deprecated default EntityModificationContext getGroupWorkspaceEntityModificationContext(String projectId, String workspaceId) { - return this.getWorkspaceEntityModificationContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getEntityModificationContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.WORKSPACE))); } - EntityModificationContext getWorkspaceEntityModificationContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default EntityModificationContext getWorkspaceEntityModificationContext(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getEntityModificationContext(projectId, (WorkspaceSourceSpecification) sourceSpecification); + } - EntityModificationContext getWorkspaceWithConflictResolutionEntityModificationContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default EntityModificationContext getWorkspaceWithConflictResolutionEntityModificationContext(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.CONFLICT_RESOLUTION)) + { + throw new IllegalArgumentException("Not a conflict resolution workspace source specification: " + sourceSpecification); + } + return getEntityModificationContext(projectId, (WorkspaceSourceSpecification) sourceSpecification); + } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/ProjectConfigurationApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/ProjectConfigurationApi.java index 915f55aeec..eb6c6bf3cf 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/ProjectConfigurationApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/ProjectConfigurationApi.java @@ -20,192 +20,308 @@ import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.error.LegendSDLCServerException; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.project.ProjectConfigurationStatusReport; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import java.util.Collections; import java.util.List; -import javax.ws.rs.core.Response; public interface ProjectConfigurationApi { - ProjectConfiguration getProjectProjectConfiguration(String projectId, VersionId patchReleaseVersionId); + ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId); + default ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification) + { + return getProjectConfiguration(projectId, sourceSpecification, null); + } + + ProjectConfiguration getReviewFromProjectConfiguration(String projectId, String reviewId); + + ProjectConfiguration getReviewToProjectConfiguration(String projectId, String reviewId); + + Revision updateProjectConfiguration(String projectId, WorkspaceSourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater); + + List getAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId); + + default List getAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification) + { + return getAvailableArtifactGenerations(projectId, sourceSpecification, null); + } + + ProjectConfigurationStatusReport getProjectConfigurationStatus(String projectId); + + ProjectStructureVersion getLatestProjectStructureVersion(); + + // Deprecated APIs + + @Deprecated + default ProjectConfiguration getProjectProjectConfiguration(String projectId, VersionId patchReleaseVersionId) + { + return getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId)); + } + + @Deprecated default ProjectConfiguration getProjectProjectConfiguration(String projectId) { - return this.getProjectProjectConfiguration(projectId, null); + return getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()); } + @Deprecated default ProjectConfiguration getProjectRevisionProjectConfiguration(String projectId, String revisionId) { - return this.getProjectRevisionProjectConfiguration(projectId, null, revisionId); + return getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification(), revisionId); } - ProjectConfiguration getProjectRevisionProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String revisionId); // support revision ID alias + @Deprecated + default ProjectConfiguration getProjectRevisionProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String revisionId) + { + return getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), revisionId); + } + @Deprecated default ProjectConfiguration getUserWorkspaceProjectConfiguration(String projectId, String workspaceId) { - return this.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getUserWorkspaceRevisionProjectConfiguration(projectId, workspaceId, null); } + @Deprecated default ProjectConfiguration getGroupWorkspaceProjectConfiguration(String projectId, String workspaceId) { - return this.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getGroupWorkspaceRevisionProjectConfiguration(projectId, workspaceId, null); } - ProjectConfiguration getWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default ProjectConfiguration getWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification) + { + return getWorkspaceRevisionProjectConfiguration(projectId, sourceSpecification, null); + } + @Deprecated default ProjectConfiguration getBackupUserWorkspaceProjectConfiguration(String projectId, String workspaceId) { - return this.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getBackupUserWorkspaceRevisionProjectConfiguration(projectId, workspaceId, null); } + @Deprecated default ProjectConfiguration getBackupGroupWorkspaceProjectConfiguration(String projectId, String workspaceId) { - return this.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getBackupGroupWorkspaceRevisionProjectConfiguration(projectId, workspaceId, null); } - ProjectConfiguration getBackupWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default ProjectConfiguration getBackupWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification) + { + return getBackupWorkspaceRevisionProjectConfiguration(projectId, sourceSpecification, null); + } + @Deprecated default ProjectConfiguration getUserWorkspaceWithConflictResolutionProjectConfiguration(String projectId, String workspaceId) { - return this.getWorkspaceWithConflictResolutionProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getUserWorkspaceWithConflictResolutionRevisionProjectConfiguration(projectId, workspaceId, null); } + @Deprecated default ProjectConfiguration getGroupWorkspaceWithConflictResolutionProjectConfiguration(String projectId, String workspaceId) { - return this.getWorkspaceWithConflictResolutionProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getGroupWorkspaceWithConflictResolutionRevisionProjectConfiguration(projectId, workspaceId, null); } - ProjectConfiguration getWorkspaceWithConflictResolutionProjectConfiguration(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default ProjectConfiguration getWorkspaceWithConflictResolutionProjectConfiguration(String projectId, SourceSpecification sourceSpecification) + { + return getWorkspaceWithConflictResolutionRevisionProjectConfiguration(projectId, sourceSpecification, null); + } - default ProjectConfiguration getUserWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) // support revision ID alias + @Deprecated + default ProjectConfiguration getUserWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceRevisionProjectConfiguration(projectId, workspaceId, WorkspaceType.USER, revisionId); + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE)), revisionId); } - default ProjectConfiguration getGroupWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) // support revision ID alias + @Deprecated + default ProjectConfiguration getGroupWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceRevisionProjectConfiguration(projectId, workspaceId, WorkspaceType.GROUP, revisionId); + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.WORKSPACE)), revisionId); } - ProjectConfiguration getWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId); // support revision ID alias + @Deprecated + default ProjectConfiguration getWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getProjectConfiguration(projectId, sourceSpecification, revisionId); + } + @Deprecated default ProjectConfiguration getWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, WorkspaceType workspaceType, String revisionId) { - return this.getWorkspaceRevisionProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType), revisionId); + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, WorkspaceAccessType.WORKSPACE)), revisionId); } - default ProjectConfiguration getBackupUserWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) // support revision ID alias + @Deprecated + default ProjectConfiguration getBackupUserWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) { - return this.getBackupWorkspaceRevisionProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.BACKUP)), revisionId); } - default ProjectConfiguration getBackupGroupWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) // support revision ID alias + @Deprecated + default ProjectConfiguration getBackupGroupWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) { - return this.getBackupWorkspaceRevisionProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), revisionId); + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.BACKUP)), revisionId); } - ProjectConfiguration getBackupWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId); // support revision ID alias - - default ProjectConfiguration getUserWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) // support revision ID alias + @Deprecated + default ProjectConfiguration getBackupWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) { - return this.getWorkspaceWithConflictResolutionRevisionProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.BACKUP)) + { + throw new IllegalArgumentException("Not a backup workspace source specification: " + sourceSpecification); + } + return getProjectConfiguration(projectId, sourceSpecification, revisionId); } - default ProjectConfiguration getGroupWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) // support revision ID alias + @Deprecated + default ProjectConfiguration getUserWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceWithConflictResolutionRevisionProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), revisionId); + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.CONFLICT_RESOLUTION)), revisionId); } - ProjectConfiguration getWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId); // support revision ID alias + @Deprecated + default ProjectConfiguration getGroupWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) + { + return getProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.CONFLICT_RESOLUTION)), revisionId); + } - default ProjectConfiguration getVersionProjectConfiguration(String projectId, String versionIdString) + @Deprecated + default ProjectConfiguration getWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) { - VersionId versionId; - try + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.CONFLICT_RESOLUTION)) { - versionId = VersionId.parseVersionId(versionIdString); + throw new IllegalArgumentException("Not a conflict resolution workspace source specification: " + sourceSpecification); } - catch (IllegalArgumentException e) - { - throw new LegendSDLCServerException(e.getMessage(), Response.Status.BAD_REQUEST, e); - } - return getVersionProjectConfiguration(projectId, versionId); + return getProjectConfiguration(projectId, sourceSpecification, revisionId); } - ProjectConfiguration getVersionProjectConfiguration(String projectId, VersionId versionId); - - ProjectConfiguration getReviewFromProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId); + @Deprecated + default ProjectConfiguration getVersionProjectConfiguration(String projectId, String versionId) + { + return getProjectConfiguration(projectId, SourceSpecification.versionSourceSpecification(versionId)); + } - default ProjectConfiguration getReviewFromProjectConfiguration(String projectId, String reviewId) + @Deprecated + default ProjectConfiguration getVersionProjectConfiguration(String projectId, VersionId versionId) { - return this.getReviewFromProjectConfiguration(projectId, null, reviewId); + return getProjectConfiguration(projectId, SourceSpecification.versionSourceSpecification(versionId)); } - ProjectConfiguration getReviewToProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId); + @Deprecated + default ProjectConfiguration getReviewFromProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return getReviewFromProjectConfiguration(projectId, reviewId); + } - default ProjectConfiguration getReviewToProjectConfiguration(String projectId, String reviewId) + @Deprecated + default ProjectConfiguration getReviewToProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewToProjectConfiguration(projectId, null, reviewId); + return getReviewToProjectConfiguration(projectId, reviewId); } - Revision updateProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater); + @Deprecated + default Revision updateProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater) + { + return updateProjectConfiguration(projectId, (WorkspaceSourceSpecification) sourceSpecification, message, updater); + } + @Deprecated default Revision updateProjectConfiguration(String projectId, String workspaceId, WorkspaceType workspaceType, String message, ProjectConfigurationUpdater updater) { - return this.updateProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType), message, updater); + return updateProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType)), message, updater); } - Revision updateProjectConfigurationForWorkspaceWithConflictResolution(String projectId, String workspaceId, String message, ProjectConfigurationUpdater updater); + @Deprecated + default Revision updateProjectConfigurationForWorkspaceWithConflictResolution(String projectId, String workspaceId, String message, ProjectConfigurationUpdater updater) + { + return updateProjectConfiguration(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.CONFLICT_RESOLUTION)), message, updater); + } - List getProjectAvailableArtifactGenerations(String projectId, VersionId patchReleaseVersionId); + @Deprecated + default List getProjectAvailableArtifactGenerations(String projectId, VersionId patchReleaseVersionId) + { + return getAvailableArtifactGenerations(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId)); + } + @Deprecated default List getProjectAvailableArtifactGenerations(String projectId) { - return this.getProjectAvailableArtifactGenerations(projectId, null); + return getAvailableArtifactGenerations(projectId, SourceSpecification.projectSourceSpecification()); } - List getRevisionAvailableArtifactGenerations(String projectId, String revisionId); + @Deprecated + default List getRevisionAvailableArtifactGenerations(String projectId, String revisionId) + { + return getAvailableArtifactGenerations(projectId, SourceSpecification.projectSourceSpecification(), revisionId); + } + + @Deprecated + default List getWorkspaceRevisionAvailableArtifactGenerations(String projectId, String workspaceId, WorkspaceType workspaceType, String revisionId) + { + return getAvailableArtifactGenerations(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, WorkspaceAccessType.WORKSPACE)), revisionId); + } + @Deprecated default List getUserWorkspaceRevisionAvailableArtifactGenerations(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceRevisionAvailableArtifactGenerations(projectId, workspaceId, WorkspaceType.USER, revisionId); + return getWorkspaceRevisionAvailableArtifactGenerations(projectId, workspaceId, WorkspaceType.USER, revisionId); } + @Deprecated default List getGroupWorkspaceRevisionAvailableArtifactGenerations(String projectId, String workspaceId, String revisionId) { - return this.getWorkspaceRevisionAvailableArtifactGenerations(projectId, workspaceId, WorkspaceType.GROUP, revisionId); + return getWorkspaceRevisionAvailableArtifactGenerations(projectId, workspaceId, WorkspaceType.GROUP, revisionId); } - List getWorkspaceRevisionAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId); - - default List getWorkspaceRevisionAvailableArtifactGenerations(String projectId, String workspaceId, WorkspaceType workspaceType, String revisionId) + @Deprecated + default List getWorkspaceRevisionAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId) { - return this.getWorkspaceRevisionAvailableArtifactGenerations(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType), revisionId); + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getAvailableArtifactGenerations(projectId, sourceSpecification, revisionId); } + @Deprecated default List getUserWorkspaceAvailableArtifactGenerations(String projectId, String workspaceId) { - return this.getWorkspaceAvailableArtifactGenerations(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getUserWorkspaceRevisionAvailableArtifactGenerations(projectId, workspaceId, null); } + @Deprecated default List getGroupWorkspaceAvailableArtifactGenerations(String projectId, String workspaceId) { - return this.getWorkspaceAvailableArtifactGenerations(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getGroupWorkspaceRevisionAvailableArtifactGenerations(projectId, workspaceId, null); } - List getWorkspaceAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification); - - List getVersionAvailableArtifactGenerations(String projectId, String versionId); + @Deprecated + default List getWorkspaceAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification) + { + return getWorkspaceRevisionAvailableArtifactGenerations(projectId, sourceSpecification, null); + } - ProjectStructureVersion getLatestProjectStructureVersion(); + @Deprecated + default List getVersionAvailableArtifactGenerations(String projectId, String versionId) + { + return getAvailableArtifactGenerations(projectId, SourceSpecification.versionSourceSpecification(versionId)); + } @Deprecated default List getLatestAvailableArtifactGenerations() { return Collections.emptyList(); } - - ProjectConfigurationStatusReport getProjectConfigurationStatus(String projectId); } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/SourceSpecification.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/SourceSpecification.java deleted file mode 100644 index 55c7cc863e..0000000000 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/SourceSpecification.java +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.sdlc.server.domain.api.project; - -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; - -import java.util.Objects; - -public class SourceSpecification -{ - private final String workspaceId; - - private final WorkspaceType workspaceType; - - private final ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType; - - private final VersionId patchReleaseVersionId; - - private SourceSpecification(String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) - { - this.workspaceId = workspaceId; - this.workspaceType = workspaceType; - this.workspaceAccessType = workspaceAccessType == null ? ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE : workspaceAccessType; - this.patchReleaseVersionId = patchReleaseVersionId; - if ((this.workspaceId != null) && ((this.workspaceType == null) || (this.workspaceAccessType == null))) - { - throw new RuntimeException("workspace type and access type are required when workspace id is specified"); - } - } - - public static SourceSpecification newGroupWorkspaceSourceSpecification(String workspaceId) - { - return new SourceSpecification(workspaceId, WorkspaceType.GROUP, null, null); - } - - public static SourceSpecification newUserWorkspaceSourceSpecification(String workspaceId) - { - return new SourceSpecification(workspaceId, WorkspaceType.USER, null, null); - } - - public static SourceSpecification newGroupWorkspaceSourceSpecification(String workspaceId, VersionId patchReleaseVersionId) - { - return new SourceSpecification(workspaceId, WorkspaceType.GROUP, null, patchReleaseVersionId); - } - - public static SourceSpecification newUserWorkspaceSourceSpecification(String workspaceId, VersionId patchReleaseVersionId) - { - return new SourceSpecification(workspaceId, WorkspaceType.USER, null, patchReleaseVersionId); - } - - public static SourceSpecification newGroupWorkspaceSourceSpecification(String workspaceId, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) - { - return new SourceSpecification(workspaceId, WorkspaceType.GROUP, workspaceAccessType, patchReleaseVersionId); - } - - public static SourceSpecification newUserWorkspaceSourceSpecification(String workspaceId, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) - { - return new SourceSpecification(workspaceId, WorkspaceType.USER, workspaceAccessType, patchReleaseVersionId); - } - - public static SourceSpecification newSourceSpecification(String workspaceId, WorkspaceType workspaceType) - { - return new SourceSpecification(workspaceId, workspaceType, null, null); - } - - public static SourceSpecification newSourceSpecification(VersionId patchReleaseVersionId) - { - return new SourceSpecification(null, null, null, patchReleaseVersionId); - } - - public static SourceSpecification newSourceSpecification(String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) - { - return new SourceSpecification(workspaceId, workspaceType, workspaceAccessType, patchReleaseVersionId); - } - - public static SourceSpecification newSourceSpecification(String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) - { - return new SourceSpecification(workspaceId, workspaceType, workspaceAccessType, null); - } - - public String getWorkspaceId() - { - return this.workspaceId; - } - - public WorkspaceType getWorkspaceType() - { - return this.workspaceType; - } - - public ProjectFileAccessProvider.WorkspaceAccessType getWorkspaceAccessType() - { - return this.workspaceAccessType; - } - - public VersionId getPatchReleaseVersionId() - { - return this.patchReleaseVersionId; - } - - @Override - public int hashCode() - { - return Objects.hash(getWorkspaceId(), getWorkspaceType(), getWorkspaceAccessType(), getPatchReleaseVersionId()); - } - - @Override - public boolean equals(Object other) - { - if (this == other) - { - return true; - } - if (!(other instanceof SourceSpecification)) - { - return false; - } - - SourceSpecification that = (SourceSpecification) other; - return Objects.equals(this.getWorkspaceId(), that.getWorkspaceId()) && - this.getWorkspaceType() == that.getWorkspaceType() && - this.getWorkspaceAccessType() == that.getWorkspaceAccessType() && - Objects.equals(this.getPatchReleaseVersionId(), that.getPatchReleaseVersionId()); - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(" T visit(SourceSpecificationVisitor visitor) + { + return visitor.visit(this); + } + + public VersionId getVersionId() + { + return this.versionId; + } + + @Override + public boolean equals(Object other) + { + return (this == other) || + ((other instanceof PatchSourceSpecification) && this.versionId.equals(((PatchSourceSpecification) other).versionId)); + } + + @Override + public int hashCode() + { + return this.versionId.hashCode(); + } + + @Override + protected StringBuilder appendAdditionalInfo(StringBuilder builder) + { + return this.versionId.appendVersionIdString(builder.append(" patch=")); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/ProjectSourceSpecification.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/ProjectSourceSpecification.java new file mode 100644 index 0000000000..7c71931cc7 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/ProjectSourceSpecification.java @@ -0,0 +1,36 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.project.source; + +public class ProjectSourceSpecification extends SourceSpecification +{ + static final ProjectSourceSpecification INSTANCE = new ProjectSourceSpecification(); + + private ProjectSourceSpecification() + { + } + + @Override + public T visit(SourceSpecificationVisitor visitor) + { + return visitor.visit(this); + } + + @Override + protected StringBuilder appendAdditionalInfo(StringBuilder builder) + { + return builder; + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecification.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecification.java new file mode 100644 index 0000000000..bc21f3dd6a --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecification.java @@ -0,0 +1,173 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.project.source; + +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; +import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; + +public abstract class SourceSpecification +{ + SourceSpecification() + { + } + + public abstract T visit(SourceSpecificationVisitor visitor); + + @Deprecated + public String getWorkspaceId() + { + if (this instanceof WorkspaceSourceSpecification) + { + return ((WorkspaceSourceSpecification) this).getWorkspaceSpecification().getId(); + } + return null; + } + + @Deprecated + public final WorkspaceType getWorkspaceType() + { + if (this instanceof WorkspaceSourceSpecification) + { + return ((WorkspaceSourceSpecification) this).getWorkspaceSpecification().getType(); + } + return null; + } + + @Deprecated + public final ProjectFileAccessProvider.WorkspaceAccessType getWorkspaceAccessType() + { + if (this instanceof WorkspaceSourceSpecification) + { + return ((WorkspaceSourceSpecification) this).getWorkspaceSpecification().getAccessType(); + } + return null; + } + + @Deprecated + public final VersionId getPatchReleaseVersionId() + { + if (this instanceof PatchSourceSpecification) + { + return ((PatchSourceSpecification) this).getVersionId(); + } + return null; + } + + @Override + public final String toString() + { + return appendAdditionalInfo(new StringBuilder("<").append(getClass().getSimpleName())).append('>').toString(); + } + + protected abstract StringBuilder appendAdditionalInfo(StringBuilder builder); + + public static ProjectSourceSpecification projectSourceSpecification() + { + return ProjectSourceSpecification.INSTANCE; + } + + public static VersionSourceSpecification versionSourceSpecification(String versionId) + { + return versionSourceSpecification(VersionId.parseVersionId(versionId)); + } + + public static VersionSourceSpecification versionSourceSpecification(VersionId versionId) + { + return new VersionSourceSpecification(versionId); + } + + public static PatchSourceSpecification patchSourceSpecification(VersionId versionId) + { + return new PatchSourceSpecification(versionId); + } + + public static WorkspaceSourceSpecification workspaceSourceSpecification(WorkspaceSpecification workspaceSpec) + { + return new WorkspaceSourceSpecification(workspaceSpec); + } + + @Deprecated + public static SourceSpecification newSourceSpecification(String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) + { + if (workspaceId != null) + { + WorkspaceSource workspaceSource = (patchReleaseVersionId == null) ? WorkspaceSource.projectWorkspaceSource() : WorkspaceSource.patchWorkspaceSource(patchReleaseVersionId); + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType, workspaceSource); + return workspaceSourceSpecification(workspaceSpec); + } + if (patchReleaseVersionId != null) + { + return patchSourceSpecification(patchReleaseVersionId); + } + return projectSourceSpecification(); + } + + @Deprecated + public static SourceSpecification newSourceSpecification(String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) + { + return newSourceSpecification(workspaceId, workspaceType, workspaceAccessType, null); + } + + @Deprecated + public static SourceSpecification newSourceSpecification(String workspaceId, WorkspaceType workspaceType) + { + return newSourceSpecification(workspaceId, workspaceType, null, null); + } + + @Deprecated + public static SourceSpecification newSourceSpecification(VersionId patchReleaseVersionId) + { + return newSourceSpecification(null, null, null, patchReleaseVersionId); + } + + @Deprecated + public static SourceSpecification newGroupWorkspaceSourceSpecification(String workspaceId, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) + { + return newSourceSpecification(workspaceId, WorkspaceType.GROUP, workspaceAccessType, patchReleaseVersionId); + } + + @Deprecated + public static SourceSpecification newGroupWorkspaceSourceSpecification(String workspaceId, VersionId patchReleaseVersionId) + { + return newGroupWorkspaceSourceSpecification(workspaceId, null, patchReleaseVersionId); + } + + @Deprecated + public static SourceSpecification newGroupWorkspaceSourceSpecification(String workspaceId) + { + return newGroupWorkspaceSourceSpecification(workspaceId, null); + } + + @Deprecated + public static SourceSpecification newUserWorkspaceSourceSpecification(String workspaceId, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType, VersionId patchReleaseVersionId) + { + return newSourceSpecification(workspaceId, WorkspaceType.USER, workspaceAccessType, patchReleaseVersionId); + } + + @Deprecated + public static SourceSpecification newUserWorkspaceSourceSpecification(String workspaceId, VersionId patchReleaseVersionId) + { + return newUserWorkspaceSourceSpecification(workspaceId, null, patchReleaseVersionId); + } + + @Deprecated + public static SourceSpecification newUserWorkspaceSourceSpecification(String workspaceId) + { + return newUserWorkspaceSourceSpecification(workspaceId, null); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationConsumer.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationConsumer.java new file mode 100644 index 0000000000..6fcb65b196 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationConsumer.java @@ -0,0 +1,74 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.project.source; + +import java.util.function.Consumer; + +public abstract class SourceSpecificationConsumer implements SourceSpecificationVisitor, Consumer +{ + @Override + public final Void visit(ProjectSourceSpecification sourceSpec) + { + accept(sourceSpec); + return null; + } + + @Override + public final Void visit(VersionSourceSpecification sourceSpec) + { + accept(sourceSpec); + return null; + } + + @Override + public final Void visit(PatchSourceSpecification sourceSpec) + { + accept(sourceSpec); + return null; + } + + @Override + public final Void visit(WorkspaceSourceSpecification sourceSpec) + { + accept(sourceSpec); + return null; + } + + @Override + public void accept(SourceSpecification sourceSpec) + { + sourceSpec.visit(this); + } + + protected void accept(ProjectSourceSpecification sourceSpec) + { + // nothing by default + } + + protected void accept(VersionSourceSpecification sourceSpec) + { + // nothing by default + } + + protected void accept(PatchSourceSpecification sourceSpec) + { + // nothing by default + } + + protected void accept(WorkspaceSourceSpecification sourceSpec) + { + // nothing by default + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationVisitor.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationVisitor.java new file mode 100644 index 0000000000..59c75172aa --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/SourceSpecificationVisitor.java @@ -0,0 +1,46 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.project.source; + +import java.util.function.Function; + +public interface SourceSpecificationVisitor extends Function +{ + default T visit(ProjectSourceSpecification sourceSpec) + { + throw new UnsupportedOperationException("Unsupported source specification: " + sourceSpec); + } + + default T visit(VersionSourceSpecification sourceSpec) + { + throw new UnsupportedOperationException("Unsupported source specification: " + sourceSpec); + } + + default T visit(PatchSourceSpecification sourceSpec) + { + throw new UnsupportedOperationException("Unsupported source specification: " + sourceSpec); + } + + default T visit(WorkspaceSourceSpecification sourceSpec) + { + throw new UnsupportedOperationException("Unsupported source specification: " + sourceSpec); + } + + @Override + default T apply(SourceSpecification sourceSpec) + { + return sourceSpec.visit(this); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/VersionSourceSpecification.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/VersionSourceSpecification.java new file mode 100644 index 0000000000..72e7c6c4a3 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/VersionSourceSpecification.java @@ -0,0 +1,59 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.project.source; + +import org.finos.legend.sdlc.domain.model.version.VersionId; + +import java.util.Objects; + +public class VersionSourceSpecification extends SourceSpecification +{ + private final VersionId versionId; + + VersionSourceSpecification(VersionId versionId) + { + this.versionId = Objects.requireNonNull(versionId, "version id is required"); + } + + @Override + public T visit(SourceSpecificationVisitor visitor) + { + return visitor.visit(this); + } + + public VersionId getVersionId() + { + return this.versionId; + } + + @Override + public boolean equals(Object other) + { + return (this == other) || + ((other instanceof VersionSourceSpecification) && this.versionId.equals(((VersionSourceSpecification) other).versionId)); + } + + @Override + public int hashCode() + { + return this.versionId.hashCode(); + } + + @Override + protected StringBuilder appendAdditionalInfo(StringBuilder builder) + { + return this.versionId.appendVersionIdString(builder.append(" version=")); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/WorkspaceSourceSpecification.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/WorkspaceSourceSpecification.java new file mode 100644 index 0000000000..8d6e9683a0 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/project/source/WorkspaceSourceSpecification.java @@ -0,0 +1,59 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.project.source; + +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; + +import java.util.Objects; + +public class WorkspaceSourceSpecification extends SourceSpecification +{ + private final WorkspaceSpecification workspaceSpec; + + WorkspaceSourceSpecification(WorkspaceSpecification workspaceSpec) + { + this.workspaceSpec = Objects.requireNonNull(workspaceSpec, "workspace specification is required"); + } + + @Override + public T visit(SourceSpecificationVisitor visitor) + { + return visitor.visit(this); + } + + public WorkspaceSpecification getWorkspaceSpecification() + { + return this.workspaceSpec; + } + + @Override + public boolean equals(Object other) + { + return (this == other) || + ((other instanceof WorkspaceSourceSpecification) && this.workspaceSpec.equals(((WorkspaceSourceSpecification) other).workspaceSpec)); + } + + @Override + public int hashCode() + { + return this.workspaceSpec.hashCode(); + } + + @Override + protected StringBuilder appendAdditionalInfo(StringBuilder builder) + { + return builder.append(" workspace=").append(this.workspaceSpec); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/review/ReviewApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/review/ReviewApi.java index a05e1b5585..46d547b9f2 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/review/ReviewApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/review/ReviewApi.java @@ -20,7 +20,9 @@ import org.finos.legend.sdlc.domain.model.review.Review; import org.finos.legend.sdlc.domain.model.review.ReviewState; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import java.time.Instant; import java.util.List; @@ -32,17 +34,11 @@ public interface ReviewApi /** * Get a particular review for the given project. * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id + * @param projectId project id + * @param reviewId review id * @return review */ - Review getReview(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Review getReview(String projectId, String reviewId) - { - return this.getReview(projectId, null, reviewId); - } + Review getReview(String projectId, String reviewId); /** * Get all reviews for the given project with the given state. @@ -52,28 +48,16 @@ default Review getReview(String projectId, String reviewId) * Time filter range (since/until) is inclusive. * If the limit equals to 0, effectively no limit is applied. * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param state review state - * @param revisionIds a set of revision IDs, with each we will get the reviews are associated + * @param projectId project id + * @param state review state + * @param revisionIds a set of revision IDs, with each we will get the reviews are associated * @param workspaceIdAndTypePredicate workspace Id and type predicate with which review is associated - * @param since this time limit is interpreted based on the chosen state, for example: if only committed reviews are fetched, 'since' will concern the committed time - * @param until this time limit is interpreted based on the chosen state, for example: if only committed reviews are fetched, 'since' will concern the committed time - * @param limit maximum number of reviews to get + * @param since this time limit is interpreted based on the chosen state, for example: if only committed reviews are fetched, 'since' will concern the committed time + * @param until this time limit is interpreted based on the chosen state, for example: if only committed reviews are fetched, 'since' will concern the committed time + * @param limit maximum number of reviews to get * @return reviews */ - List getReviews(String projectId, VersionId patchReleaseVersionId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit); - - default List getReviews(String projectId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit) - { - return this.getReviews(projectId, null, state, revisionIds, workspaceIdAndTypePredicate, since, until, limit); - } - - @Deprecated - default List getReviews(String projectId, ReviewState state, Iterable revisionIds, Instant since, Instant until, Integer limit) - { - return this.getReviews(projectId, state, revisionIds, null, since, until, limit); - } + List getReviews(String projectId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit); /** * Get reviews across all projects with the given state and labels. @@ -85,211 +69,134 @@ default List getReviews(String projectId, ReviewState state, Iterable getReviews(boolean assignedToMe, boolean authoredByMe, List labels, BiPredicate workspaceIdAndTypePredicate, ReviewState state, Instant since, Instant until, Integer limit); - @Deprecated - default List getReviews(Set projectTypes, boolean assignedToMe, boolean authoredByMe, List labels, ReviewState state, Instant since, Instant until, Integer limit) - { - return this.getReviews(assignedToMe, authoredByMe, labels, null, state, since, until, limit); - } - /** * Create a review for changes from the given workspace. * - * @param projectId project id - * @param sourceSpecification source specification - * @param title review title - * @param description review description - * @param labels review labels + * @param projectId project id + * @param workspaceSpecification source specification + * @param title review title + * @param description review description + * @param labels review labels * @return new review */ - Review createReview(String projectId, SourceSpecification sourceSpecification, String title, String description, List labels); + Review createReview(String projectId, WorkspaceSpecification workspaceSpecification, String title, String description, List labels); - default Review createReview(String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, List labels) - { - return this.createReview(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType), title, description, labels); - } + /** + * Edit review. Update the title, description, or labels. + * + * @param projectId project id + * @param reviewId review id + * @param title updated Title + * @param description description + * @param labels review labels + * @return edited review + */ + Review editReview(String projectId, String reviewId, String title, String description, List labels); /** * Close a review. This is only valid if the review is open. * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id - * @return updated review + * @param projectId project id + * @param reviewId review id + * @return updated review */ - Review closeReview(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Review closeReview(String projectId, String reviewId) - { - return this.closeReview(projectId, null, reviewId); - } + Review closeReview(String projectId, String reviewId); /** * Reopen a review. This is only valid if the review is closed. * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id - * @return updated review + * @param projectId project id + * @param reviewId review id + * @return updated review */ - Review reopenReview(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Review reopenReview(String projectId, String reviewId) - { - return this.reopenReview(projectId, null, reviewId); - } + Review reopenReview(String projectId, String reviewId); /** * Approve a review. This is only valid if the review is open. * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id - * @return updated review + * @param projectId project id + * @param reviewId review id + * @return updated review */ - Review approveReview(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Review approveReview(String projectId, String reviewId) - { - return this.approveReview(projectId, null, reviewId); - } + Review approveReview(String projectId, String reviewId); /** - * Revoke approval of a review. This is only valid if the review - * is open and the user has previously approved it. + * Revoke approval of a review. This is only valid if the review is open and the user has previously approved it. * * @param projectId project id - * @param patchReleaseVersionId patch release version * @param reviewId review id * @return updated review */ - Review revokeReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Review revokeReviewApproval(String projectId, String reviewId) - { - return this.revokeReviewApproval(projectId, null, reviewId); - } + Review revokeReviewApproval(String projectId, String reviewId); /** - * Reject a review. This is only valid if the review is open. It - * may cause the review to be closed. + * Reject a review. This is only valid if the review is open. It may cause the review to be closed. * * @param projectId project id - * @param patchReleaseVersionId patch release version * @param reviewId review id * @return updated review */ - Review rejectReview(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Review rejectReview(String projectId, String reviewId) - { - return this.rejectReview(projectId, null, reviewId); - } + Review rejectReview(String projectId, String reviewId); /** * Get the approval information for a particular review in the given project. * * @param projectId project id - * @param patchReleaseVersionId patch release version * @param reviewId review id * @return approval */ - Approval getReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default Approval getReviewApproval(String projectId, String reviewId) - { - return this.getReviewApproval(projectId, null, reviewId); - } + Approval getReviewApproval(String projectId, String reviewId); /** - * Commit changes from a review. This is only valid if the - * review is open and has sufficient approvals. + * Commit changes from a review. This is only valid if the review is open and has sufficient approvals. * * @param projectId project id - * @param patchReleaseVersionId patch release version * @param reviewId review id * @param message commit message * @return committed review */ - Review commitReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String message); - - default Review commitReview(String projectId, String reviewId, String message) - { - return this.commitReview(projectId, null, reviewId, message); - } + Review commitReview(String projectId, String reviewId, String message); /** - * Get the current update status of an open review. See {@link ReviewUpdateStatus} - * for more information on the meaning of the return value. If the review is not - * open, this method will throw an exception. + * Get the current update status of an open review. See {@link ReviewUpdateStatus} for more information on the + * meaning of the return value. If the review is not open, this method will throw an exception. * * @param projectId project id - * @param patchReleaseVersionId patch release version * @param reviewId review id * @return update status */ - ReviewUpdateStatus getReviewUpdateStatus(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default ReviewUpdateStatus getReviewUpdateStatus(String projectId, String reviewId) - { - return this.getReviewUpdateStatus(projectId, null, reviewId); - } + ReviewUpdateStatus getReviewUpdateStatus(String projectId, String reviewId); /** - * Try to update an open review. That is, try to bring the review up to date - * with the latest revision of the project. If the review is not open, this - * method will throw an exception. + * Try to update an open review. That is, try to bring the review up to date with the latest revision of the + * source of the workspace. If the review is not open, this method will throw an exception. *

- * This method does not wait for the update to complete. It starts the update - * and returns an initial status. Use {@link #getReviewUpdateStatus} for - * subsequent status checks. + * This method does not wait for the update to complete. It starts the update and returns an initial status. Use + * {@link #getReviewUpdateStatus} for subsequent status checks. *

- * If an update is already in progress or if the review is already up to - * date, this returns the current update status but is otherwise a no-op. + * If an update is already in progress or if the review is already up to date, this returns the current update + * status but is otherwise a no-op. *

- * It is not always possible to update a review. In case the update fails, - * the review will be left in the pre-update state. + * It is not always possible to update a review. In case the update fails, the review will be left in the pre-update + * state. * * @param projectId project id - * @param patchReleaseVersionId patch release version * @param reviewId review id * @return update status */ - ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseVersionId, String reviewId); - - default ReviewUpdateStatus updateReview(String projectId, String reviewId) - { - return this.updateReview(projectId, null, reviewId); - } - - /** - * Edit review, update the review title, description and labels - * - * @param projectId project id - * @param patchReleaseVersionId patch release version - * @param reviewId review id - * @param title updated Title - * @param description description - * @param labels review labels - * @return edited review - */ - Review editReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String title, String description, List labels); - - default Review editReview(String projectId, String reviewId, String title, String description, List labels) - { - return this.editReview(projectId, null, reviewId, title, description, labels); - } + ReviewUpdateStatus updateReview(String projectId, String reviewId); interface ReviewUpdateStatus { @@ -317,4 +224,106 @@ interface ReviewUpdateStatus */ String getTargetRevisionId(); } + + // Deprecated APIs + + @Deprecated + default Review getReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return getReview(projectId, reviewId); + } + + @Deprecated + default List getReviews(String projectId, VersionId patchReleaseVersionId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit) + { + return getReviews(projectId, state, revisionIds, workspaceIdAndTypePredicate, since, until, limit); + } + + @Deprecated + default List getReviews(String projectId, ReviewState state, Iterable revisionIds, Instant since, Instant until, Integer limit) + { + return getReviews(projectId, state, revisionIds, null, since, until, limit); + } + + @Deprecated + default List getReviews(Set projectTypes, boolean assignedToMe, boolean authoredByMe, List labels, ReviewState state, Instant since, Instant until, Integer limit) + { + return getReviews(assignedToMe, authoredByMe, labels, null, state, since, until, limit); + } + + @Deprecated + default Review createReview(String projectId, SourceSpecification sourceSpecification, String title, String description, List labels) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return createReview(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification(), title, description, labels); + } + + @Deprecated + default Review createReview(String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, List labels) + { + return createReview(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType), title, description, labels); + } + + @Deprecated + default Review closeReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return closeReview(projectId, reviewId); + } + + @Deprecated + default Review reopenReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return reopenReview(projectId, reviewId); + } + + @Deprecated + default Review approveReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return approveReview(projectId, reviewId); + } + + @Deprecated + default Review revokeReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return revokeReviewApproval(projectId, reviewId); + } + + @Deprecated + default Review rejectReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return rejectReview(projectId, reviewId); + } + + @Deprecated + default Approval getReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return getReviewApproval(projectId, reviewId); + } + + @Deprecated + default Review commitReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String message) + { + return commitReview(projectId, reviewId, message); + } + + @Deprecated + default ReviewUpdateStatus getReviewUpdateStatus(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return getReviewUpdateStatus(projectId, reviewId); + } + + @Deprecated + default ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + { + return updateReview(projectId, reviewId); + } + + @Deprecated + default Review editReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String title, String description, List labels) + { + return editReview(projectId, reviewId, title, description, labels); + } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/revision/RevisionApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/revision/RevisionApi.java index 44003b39a3..ab4a5c1e83 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/revision/RevisionApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/revision/RevisionApi.java @@ -14,9 +14,13 @@ package org.finos.legend.sdlc.server.domain.api.revision; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.RevisionStatus; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; /** * Note that all of these APIs support revision ID alias as they all essentially calls getRevision() from RevisionAccessContext @@ -24,98 +28,176 @@ */ public interface RevisionApi { - RevisionAccessContext getProjectRevisionContext(String projectId, VersionId patchReleaseVersionId); + RevisionAccessContext getRevisionContext(String projectId, SourceSpecification sourceSpec); + RevisionAccessContext getPackageRevisionContext(String projectId, SourceSpecification sourceSpec, String packagePath); + + RevisionAccessContext getEntityRevisionContext(String projectId, SourceSpecification sourceSpec, String entityPath); + + RevisionStatus getRevisionStatus(String projectId, String revisionId); + + // Deprecated APIs + + @Deprecated + default RevisionAccessContext getProjectRevisionContext(String projectId, VersionId patchReleaseVersionId) + { + return getRevisionContext(projectId, (patchReleaseVersionId == null) ? SourceSpecification.projectSourceSpecification() : SourceSpecification.patchSourceSpecification(patchReleaseVersionId)); + } + + @Deprecated default RevisionAccessContext getProjectRevisionContext(String projectId) { - return this.getProjectRevisionContext(projectId, null); + return getRevisionContext(projectId, SourceSpecification.projectSourceSpecification()); } - RevisionAccessContext getProjectEntityRevisionContext(String projectId, VersionId patchReleaseVersionId, String entityPath); + @Deprecated + default RevisionAccessContext getProjectEntityRevisionContext(String projectId, VersionId patchReleaseVersionId, String entityPath) + { + return getEntityRevisionContext(projectId, (patchReleaseVersionId == null) ? SourceSpecification.projectSourceSpecification() : SourceSpecification.patchSourceSpecification(patchReleaseVersionId), entityPath); + } + @Deprecated default RevisionAccessContext getProjectEntityRevisionContext(String projectId, String entityPath) { - return this.getProjectEntityRevisionContext(projectId, null, entityPath); + return getEntityRevisionContext(projectId, SourceSpecification.projectSourceSpecification(), entityPath); } - RevisionAccessContext getProjectPackageRevisionContext(String projectId, VersionId patchReleaseVersionId, String packagePath); + @Deprecated + default RevisionAccessContext getProjectPackageRevisionContext(String projectId, VersionId patchReleaseVersionId, String packagePath) + { + return getPackageRevisionContext(projectId, (patchReleaseVersionId == null) ? SourceSpecification.projectSourceSpecification() : SourceSpecification.patchSourceSpecification(patchReleaseVersionId), packagePath); + } + @Deprecated default RevisionAccessContext getProjectPackageRevisionContext(String projectId, String packagePath) { - return this.getProjectPackageRevisionContext(projectId, null, packagePath); + return getPackageRevisionContext(projectId, SourceSpecification.projectSourceSpecification(), packagePath); } + @Deprecated default RevisionAccessContext getUserWorkspaceRevisionContext(String projectId, String workspaceId) { - return this.getWorkspaceRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); } + @Deprecated default RevisionAccessContext getGroupWorkspaceRevisionContext(String projectId, String workspaceId) { - return this.getWorkspaceRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); } - // for backward compatibility @Deprecated default RevisionAccessContext getWorkspaceRevisionContext(String projectId, String workspaceId) { - return getWorkspaceRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); } - RevisionAccessContext getWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default RevisionAccessContext getWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpec) + { + if (!(sourceSpec instanceof WorkspaceSourceSpecification) || + (((WorkspaceSourceSpecification) sourceSpec).getWorkspaceSpecification().getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + { + throw new IllegalArgumentException("Invalid source specification (must be workspace specification): " + sourceSpec); + } + return getRevisionContext(projectId, sourceSpec); + } + @Deprecated default RevisionAccessContext getBackupUserWorkspaceRevisionContext(String projectId, String workspaceId) { - return this.getBackupWorkspaceRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP))); } + @Deprecated default RevisionAccessContext getBackupGroupWorkspaceRevisionContext(String projectId, String workspaceId) { - return this.getBackupWorkspaceRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP))); } - RevisionAccessContext getBackupWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default RevisionAccessContext getBackupWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpec) + { + if (!(sourceSpec instanceof WorkspaceSourceSpecification) || + (((WorkspaceSourceSpecification) sourceSpec).getWorkspaceSpecification().getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.BACKUP)) + { + throw new IllegalArgumentException("Invalid source specification (must be backup workspace specification): " + sourceSpec); + } + return getRevisionContext(projectId, sourceSpec); + } + @Deprecated default RevisionAccessContext getUserWorkspaceWithConflictResolutionRevisionContext(String projectId, String workspaceId) { - return this.getWorkspaceWithConflictResolutionRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION))); } + @Deprecated default RevisionAccessContext getGroupWorkspaceWithConflictResolutionRevisionContext(String projectId, String workspaceId) { - return this.getWorkspaceWithConflictResolutionRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getRevisionContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION))); } - RevisionAccessContext getWorkspaceWithConflictResolutionRevisionContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default RevisionAccessContext getWorkspaceWithConflictResolutionRevisionContext(String projectId, SourceSpecification sourceSpec) + { + if (!(sourceSpec instanceof WorkspaceSourceSpecification) || + (((WorkspaceSourceSpecification) sourceSpec).getWorkspaceSpecification().getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION)) + { + throw new IllegalArgumentException("Invalid source specification (must be conflict resolution workspace specification): " + sourceSpec); + } + return getRevisionContext(projectId, sourceSpec); + } + @Deprecated default RevisionAccessContext getUserWorkspaceEntityRevisionContext(String projectId, String workspaceId, String entityPath) { - return this.getWorkspaceEntityRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), entityPath); + return getEntityRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), entityPath); } + @Deprecated default RevisionAccessContext getGroupWorkspaceEntityRevisionContext(String projectId, String workspaceId, String entityPath) { - return this.getWorkspaceEntityRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), entityPath); + return getEntityRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), entityPath); } - RevisionAccessContext getWorkspaceEntityRevisionContext(String projectId, SourceSpecification sourceSpecification, String entityPath); + @Deprecated + default RevisionAccessContext getWorkspaceEntityRevisionContext(String projectId, SourceSpecification sourceSpec, String entityPath) + { + if (!(sourceSpec instanceof WorkspaceSourceSpecification) || + (((WorkspaceSourceSpecification) sourceSpec).getWorkspaceSpecification().getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + { + throw new IllegalArgumentException("Invalid source specification (must be workspace specification): " + sourceSpec); + } + return getEntityRevisionContext(projectId, sourceSpec, entityPath); + } + @Deprecated default RevisionAccessContext getUserWorkspacePackageRevisionContext(String projectId, String workspaceId, String packagePath) { - return this.getWorkspacePackageRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), packagePath); + return getPackageRevisionContext(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), packagePath); } + @Deprecated default RevisionAccessContext getGroupWorkspacePackageRevisionContext(String projectId, String workspaceId, String packagePath) { - return this.getWorkspacePackageRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), packagePath); + return getPackageRevisionContext(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), packagePath); } - RevisionAccessContext getWorkspacePackageRevisionContext(String projectId, SourceSpecification sourceSpecification, String packagePath); - - RevisionStatus getRevisionStatus(String projectId, VersionId patchReleaseVersionId, String revisionId); + @Deprecated + default RevisionAccessContext getWorkspacePackageRevisionContext(String projectId, SourceSpecification sourceSpec, String packagePath) + { + if (!(sourceSpec instanceof WorkspaceSourceSpecification) || + (((WorkspaceSourceSpecification) sourceSpec).getWorkspaceSpecification().getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + { + throw new IllegalArgumentException("Invalid source specification (must be workspace specification): " + sourceSpec); + } + return getPackageRevisionContext(projectId, sourceSpec, packagePath); + } - default RevisionStatus getRevisionStatus(String projectId, String revisionId) + @Deprecated + default RevisionStatus getRevisionStatus(String projectId, VersionId patchReleaseVersionId, String revisionId) { - return this.getRevisionStatus(projectId, null, revisionId); + return getRevisionStatus(projectId, revisionId); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/test/TestModelBuilder.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/test/TestModelBuilder.java index 5f1e6f01db..5e9ece640d 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/test/TestModelBuilder.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/test/TestModelBuilder.java @@ -32,7 +32,7 @@ import org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApi; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.tools.StringTools; @@ -181,7 +181,7 @@ private List getEntities(DepotProjectVersion depotProjectVersion) private DepotProjectId getDepotProjectId(String gitLabProjectId) { - ProjectConfiguration projectConfiguration = this.projectConfigurationApi.getProjectProjectConfiguration(gitLabProjectId); + ProjectConfiguration projectConfiguration = this.projectConfigurationApi.getProjectConfiguration(gitLabProjectId, SourceSpecification.projectSourceSpecification()); return DepotProjectId.newDepotProjectId(projectConfiguration.getGroupId(), projectConfiguration.getArtifactId()); } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowApi.java index 754515138e..b55e3dcc53 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowApi.java @@ -14,50 +14,64 @@ package org.finos.legend.sdlc.server.domain.api.workflow; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; -import org.finos.legend.sdlc.server.error.LegendSDLCServerException; +import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; -import javax.ws.rs.core.Response; - public interface WorkflowApi { - WorkflowAccessContext getProjectWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId); + WorkflowAccessContext getWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification); + + WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, String reviewId); + + // Deprecated APIs + @Deprecated + default WorkflowAccessContext getProjectWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId) + { + return getWorkflowAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId)); + } + + @Deprecated default WorkflowAccessContext getProjectWorkflowAccessContext(String projectId) { - return this.getProjectWorkflowAccessContext(projectId, null); + return getWorkflowAccessContext(projectId, SourceSpecification.projectSourceSpecification()); } - WorkflowAccessContext getWorkspaceWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default WorkflowAccessContext getWorkspaceWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getWorkflowAccessContext(projectId, sourceSpecification); + } + @Deprecated default WorkflowAccessContext getWorkspaceWorkflowAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) { - return this.getWorkspaceWorkflowAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType)); + return getWorkflowAccessContext(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType).getSourceSpecification()); } + @Deprecated default WorkflowAccessContext getVersionWorkflowAccessContext(String projectId, String versionIdString) { - VersionId versionId; - try - { - versionId = VersionId.parseVersionId(versionIdString); - } - catch (IllegalArgumentException e) - { - throw new LegendSDLCServerException(e.getMessage(), Response.Status.BAD_REQUEST, e); - } - return getVersionWorkflowAccessContext(projectId, versionId); + return getWorkflowAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionIdString)); } - WorkflowAccessContext getVersionWorkflowAccessContext(String projectId, VersionId versionId); - - WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId); + @Deprecated + default WorkflowAccessContext getVersionWorkflowAccessContext(String projectId, VersionId versionId) + { + return getWorkflowAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId)); + } - default WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, String reviewId) + @Deprecated + default WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewWorkflowAccessContext(projectId, null, reviewId); + return getReviewWorkflowAccessContext(projectId, reviewId); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowJobApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowJobApi.java index 32a4a213e1..ce50990445 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowJobApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workflow/WorkflowJobApi.java @@ -14,50 +14,64 @@ package org.finos.legend.sdlc.server.domain.api.workflow; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; -import org.finos.legend.sdlc.server.error.LegendSDLCServerException; +import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; -import javax.ws.rs.core.Response; - public interface WorkflowJobApi { - WorkflowJobAccessContext getProjectWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId); + WorkflowJobAccessContext getWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification); + + WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, String reviewId); + + // Deprecated APIs + @Deprecated + default WorkflowJobAccessContext getProjectWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId) + { + return getWorkflowJobAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId)); + } + + @Deprecated default WorkflowJobAccessContext getProjectWorkflowJobAccessContext(String projectId) { - return this.getProjectWorkflowJobAccessContext(projectId, null); + return getWorkflowJobAccessContext(projectId, SourceSpecification.projectSourceSpecification()); } - WorkflowJobAccessContext getWorkspaceWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default WorkflowJobAccessContext getWorkspaceWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getWorkflowJobAccessContext(projectId, sourceSpecification); + } + @Deprecated default WorkflowJobAccessContext getWorkspaceWorkflowJobAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) { - return this.getWorkspaceWorkflowJobAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType)); + return this.getWorkspaceWorkflowJobAccessContext(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType).getSourceSpecification()); } + @Deprecated default WorkflowJobAccessContext getVersionWorkflowJobAccessContext(String projectId, String versionIdString) { - VersionId versionId; - try - { - versionId = VersionId.parseVersionId(versionIdString); - } - catch (IllegalArgumentException e) - { - throw new LegendSDLCServerException(e.getMessage(), Response.Status.BAD_REQUEST, e); - } - return getVersionWorkflowJobAccessContext(projectId, versionId); + return getWorkflowJobAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionIdString)); } - WorkflowJobAccessContext getVersionWorkflowJobAccessContext(String projectId, VersionId versionId); - - WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId); + @Deprecated + default WorkflowJobAccessContext getVersionWorkflowJobAccessContext(String projectId, VersionId versionId) + { + return getWorkflowJobAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId)); + } - default WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, String reviewId) + @Deprecated + default WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) { - return this.getReviewWorkflowJobAccessContext(projectId, null, reviewId); + return getReviewWorkflowJobAccessContext(projectId, reviewId); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/PatchWorkspaceSource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/PatchWorkspaceSource.java new file mode 100644 index 0000000000..49887fdeef --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/PatchWorkspaceSource.java @@ -0,0 +1,66 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.workspace; + +import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; + +import java.util.Objects; + +public class PatchWorkspaceSource extends WorkspaceSource +{ + private final VersionId patchVersion; + + PatchWorkspaceSource(VersionId patchVersion) + { + this.patchVersion = Objects.requireNonNull(patchVersion, "patch version may not be null"); + } + + public VersionId getPatchVersionId() + { + return this.patchVersion; + } + + @Override + public SourceSpecification getSourceSpecification() + { + return SourceSpecification.patchSourceSpecification(this.patchVersion); + } + + @Override + public T visit(WorkspaceSourceVisitor visitor) + { + return visitor.visit(this); + } + + @Override + public boolean equals(Object other) + { + return (this == other) || + ((other instanceof PatchWorkspaceSource) && this.patchVersion.equals(((PatchWorkspaceSource) other).patchVersion)); + } + + @Override + public int hashCode() + { + return this.patchVersion.hashCode(); + } + + @Override + protected StringBuilder appendAdditionalInfo(StringBuilder builder) + { + return this.patchVersion.appendVersionIdString(builder.append(" patchVersion=")); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/ProjectWorkspaceSource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/ProjectWorkspaceSource.java new file mode 100644 index 0000000000..9f6e48ffd2 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/ProjectWorkspaceSource.java @@ -0,0 +1,44 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.workspace; + +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; + +public class ProjectWorkspaceSource extends WorkspaceSource +{ + static final ProjectWorkspaceSource INSTANCE = new ProjectWorkspaceSource(); + + private ProjectWorkspaceSource() + { + } + + @Override + public SourceSpecification getSourceSpecification() + { + return SourceSpecification.projectSourceSpecification(); + } + + @Override + public T visit(WorkspaceSourceVisitor visitor) + { + return visitor.visit(this); + } + + @Override + protected StringBuilder appendAdditionalInfo(StringBuilder builder) + { + return builder; + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceApi.java index 53d66f2a64..1b6306c9cd 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceApi.java @@ -17,21 +17,127 @@ import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import java.util.Collections; -import java.util.EnumSet; import java.util.List; import java.util.Set; public interface WorkspaceApi { + /** + * Get a workspace in the given project. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + * @return workspace + */ + Workspace getWorkspace(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Get all workspaces in the given project for the current user subject to the given filters. + * + * @param projectId project id + * @param types set of workspace types in scope; null means all types + * @param accessTypes set of workspace access types in scope; null means all access types + * @param sources set of workspace sources in scope; null means all sources + * @return workspaces + */ + List getWorkspaces(String projectId, Set types, Set accessTypes, Set sources); + + /** + * Get all workspaces in the given project for all users subject to the given filters. + * + * @param projectId project id + * @param types set of workspace types in scope + * @param accessTypes set of workspace access types in scope; null means all types + * @param sources set of workspace sources in scope + * @return workspaces + */ + List getAllWorkspaces(String projectId, Set types, Set accessTypes, Set sources); + + /** + * Create a new workspace in the given project. If the workspace is a user workspace, then it will be for the + * current user. + * + * @param projectId project id + * @param workspaceId workspace id + * @param type workspace type + * @param source workspace source + * @return new workspace + */ + Workspace newWorkspace(String projectId, String workspaceId, WorkspaceType type, WorkspaceSource source); + + /** + * Delete the given workspace. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + */ + void deleteWorkspace(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Check if a workspace is outdated. i.e. if the workspace base revision is the latest revision in project. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + * @return flag indicating if a workspace is outdated + */ + boolean isWorkspaceOutdated(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Check if a workspace is in conflict resolution mode + * + * @param projectId project id + * @param workspaceSpecification workspace specification + * @return flag indicating if a workspace is in conflict resolution mode + */ + boolean isWorkspaceInConflictResolutionMode(String projectId, WorkspaceSpecification workspaceSpecification); + + /** + * Update the workspace with the latest committed changes. Potentially, this needs to handle conflict resolution. + * + * @param projectId project id + * @param workspaceSpecification workspace specification + * @return a workspace update report + */ + WorkspaceUpdateReport updateWorkspace(String projectId, WorkspaceSpecification workspaceSpecification); + + interface WorkspaceUpdateReport + { + WorkspaceUpdateReportStatus getStatus(); + + /** + * Get the project revision id where the updated or conflict resolution workspace stems from. + * + * @return merge base revision id of the workspace + */ + String getWorkspaceMergeBaseRevisionId(); + + /** + * Get the current revision id of the updated or conflict resolution workspace. + * + * @return current workspace revision id + */ + String getWorkspaceRevisionId(); + } + + enum WorkspaceUpdateReportStatus + { + NO_OP, UPDATED, CONFLICT + } + + // Deprecated APIs + /** * Get all user workspaces in the given project for the current user. * * @param projectId project id * @return user workspaces in the current project */ + @Deprecated default List getUserWorkspaces(String projectId) { return getWorkspaces(projectId, null, Collections.singleton(WorkspaceType.USER)); @@ -43,6 +149,7 @@ default List getUserWorkspaces(String projectId) * @param projectId project id * @return group workspaces in the current project */ + @Deprecated default List getGroupWorkspaces(String projectId) { return getWorkspaces(projectId, null, Collections.singleton(WorkspaceType.GROUP)); @@ -51,25 +158,39 @@ default List getGroupWorkspaces(String projectId) /** * Get all workspaces of desired type(s) in the given project for the current user. * - * @param projectId project id - * @param workspaceTypes set of workspace types in scope + * @param projectId project id + * @param workspaceTypes set of workspace types in scope * @param patchReleaseVersionId patch release version branch the workspace has to be created from * @return all workspaces of desired type(s) in the current project for the current user */ - List getWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes); + @Deprecated + default List getWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes) + { + return getWorkspaces(projectId, workspaceTypes, Collections.singleton(WorkspaceAccessType.WORKSPACE), Collections.singleton((patchReleaseVersionId == null) ? WorkspaceSource.projectWorkspaceSource() : WorkspaceSource.patchWorkspaceSource(patchReleaseVersionId))); + } - List getWorkspacesWithConflictResolution(String projectId, VersionId patchReleaseVersionId); + @Deprecated + default List getWorkspacesWithConflictResolution(String projectId, VersionId patchReleaseVersionId) + { + return getWorkspaces(projectId, Collections.singleton(WorkspaceType.USER), Collections.singleton(WorkspaceAccessType.CONFLICT_RESOLUTION), Collections.singleton((patchReleaseVersionId == null) ? WorkspaceSource.projectWorkspaceSource() : WorkspaceSource.patchWorkspaceSource(patchReleaseVersionId))); + } + @Deprecated default List getWorkspacesWithConflictResolution(String projectId) { - return this.getWorkspacesWithConflictResolution(projectId, null); + return getWorkspacesWithConflictResolution(projectId, null); } - List getBackupWorkspaces(String projectId, VersionId patchReleaseVersionId); + @Deprecated + default List getBackupWorkspaces(String projectId, VersionId patchReleaseVersionId) + { + return getWorkspaces(projectId, Collections.singleton(WorkspaceType.USER), Collections.singleton(WorkspaceAccessType.BACKUP), Collections.singleton((patchReleaseVersionId == null) ? WorkspaceSource.projectWorkspaceSource() : WorkspaceSource.patchWorkspaceSource(patchReleaseVersionId))); + } + @Deprecated default List getBackupWorkspaces(String projectId) { - return this.getBackupWorkspaces(projectId, null); + return getBackupWorkspaces(projectId, null); } /** @@ -78,9 +199,10 @@ default List getBackupWorkspaces(String projectId) * @param projectId project id * @return all user workspaces in the current project */ + @Deprecated default List getAllUserWorkspaces(String projectId) { - return getAllWorkspaces(projectId, null, Collections.singleton(WorkspaceType.USER)); + return getAllWorkspaces(projectId, Collections.singleton(WorkspaceType.USER), null, Collections.singleton(WorkspaceSource.projectWorkspaceSource())); } /** @@ -89,20 +211,25 @@ default List getAllUserWorkspaces(String projectId) * @param projectId project id * @return all workspaces in the current project */ + @Deprecated default List getAllWorkspaces(String projectId) { - return getAllWorkspaces(projectId, null, EnumSet.allOf(WorkspaceType.class)); + return getAllWorkspaces(projectId, null, null, Collections.singleton(WorkspaceSource.projectWorkspaceSource())); } /** * Get all workspaces of desired type(s) in the given project for all users. * - * @param projectId project id + * @param projectId project id * @param patchReleaseVersionId patch release version - * @param workspaceTypes set of workspace types in scope + * @param workspaceTypes set of workspace types in scope * @return all workspaces of desired type(s) in the current project */ - List getAllWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes); + @Deprecated + default List getAllWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes) + { + return getAllWorkspaces(projectId, workspaceTypes, Collections.singleton(WorkspaceAccessType.WORKSPACE), Collections.singleton((patchReleaseVersionId == null) ? WorkspaceSource.projectWorkspaceSource() : WorkspaceSource.patchWorkspaceSource(patchReleaseVersionId))); + } /** * Get a workspace in the given project for the current user. @@ -111,9 +238,10 @@ default List getAllWorkspaces(String projectId) * @param workspaceId workspace id * @return user workspace */ + @Deprecated default Workspace getUserWorkspace(String projectId, String workspaceId) { - return getWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** @@ -123,43 +251,72 @@ default Workspace getUserWorkspace(String projectId, String workspaceId) * @param workspaceId workspace id * @return user workspace */ + @Deprecated default Workspace getGroupWorkspace(String projectId, String workspaceId) { - return getWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** * Get a workspace in the given project for the current user. * - * @param projectId project id - * @param sourceSpecification source specification + * @param projectId project id + * @param sourceSpecification source specification * @return user workspace */ - Workspace getWorkspace(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default Workspace getWorkspace(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return getWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } + @Deprecated default Workspace getUserWorkspaceWithConflictResolution(String projectId, String workspaceId) { - return getWorkspaceWithConflictResolution(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.CONFLICT_RESOLUTION)); } + @Deprecated default Workspace getGroupWorkspaceWithConflictResolution(String projectId, String workspaceId) { - return getWorkspaceWithConflictResolution(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.CONFLICT_RESOLUTION)); } - Workspace getWorkspaceWithConflictResolution(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default Workspace getWorkspaceWithConflictResolution(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.CONFLICT_RESOLUTION)) + { + throw new IllegalArgumentException("Not a conflict resolution workspace source specification: " + sourceSpecification); + } + return getWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } + @Deprecated default Workspace getBackupUserWorkspace(String projectId, String workspaceId) { - return getBackupWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return getWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.BACKUP)); } + @Deprecated default Workspace getBackupGroupWorkspace(String projectId, String workspaceId) { - return getBackupWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return getWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.BACKUP)); } - Workspace getBackupWorkspace(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default Workspace getBackupWorkspace(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.BACKUP)) + { + throw new IllegalArgumentException("Not a backup workspace source specification: " + sourceSpecification); + } + return getWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Check if a user workspace is outdated. i.e. if the workspace base revision is the latest revision in project. @@ -168,9 +325,10 @@ default Workspace getBackupGroupWorkspace(String projectId, String workspaceId) * @param workspaceId workspace id * @return flag indicating if a user workspace is outdated */ + @Deprecated default boolean isUserWorkspaceOutdated(String projectId, String workspaceId) { - return isWorkspaceOutdated(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceOutdated(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** @@ -180,43 +338,72 @@ default boolean isUserWorkspaceOutdated(String projectId, String workspaceId) * @param workspaceId workspace id * @return flag indicating if a group workspace is outdated */ + @Deprecated default boolean isGroupWorkspaceOutdated(String projectId, String workspaceId) { - return isWorkspaceOutdated(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceOutdated(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** * Check if a workspace is outdated. i.e. if the workspace base revision is the latest revision in project. * - * @param projectId project id - * @param sourceSpecification source specification + * @param projectId project id + * @param sourceSpecification source specification * @return flag indicating if a workspace is outdated */ - boolean isWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default boolean isWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return isWorkspaceOutdated(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } + @Deprecated default boolean isUserWorkspaceWithConflictResolutionOutdated(String projectId, String workspaceId) { - return isWorkspaceWithConflictResolutionOutdated(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceOutdated(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.CONFLICT_RESOLUTION)); } + @Deprecated default boolean isGroupWorkspaceWithConflictResolutionOutdated(String projectId, String workspaceId) { - return isWorkspaceWithConflictResolutionOutdated(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceOutdated(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.CONFLICT_RESOLUTION)); } - boolean isWorkspaceWithConflictResolutionOutdated(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default boolean isWorkspaceWithConflictResolutionOutdated(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.CONFLICT_RESOLUTION)) + { + throw new IllegalArgumentException("Not a conflict resolution workspace source specification: " + sourceSpecification); + } + return isWorkspaceOutdated(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } + @Deprecated default boolean isBackupUserWorkspaceOutdated(String projectId, String workspaceId) { - return isBackupWorkspaceOutdated(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceOutdated(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.BACKUP)); } + @Deprecated default boolean isBackupGroupWorkspaceOutdated(String projectId, String workspaceId) { - return isBackupWorkspaceOutdated(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceOutdated(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP, WorkspaceAccessType.BACKUP)); } - boolean isBackupWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default boolean isBackupWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification) || (((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification().getAccessType() != WorkspaceAccessType.BACKUP)) + { + throw new IllegalArgumentException("Not a backup workspace source specification: " + sourceSpecification); + } + return isWorkspaceOutdated(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Check if a user workspace is in conflict resolution mode @@ -225,9 +412,10 @@ default boolean isBackupGroupWorkspaceOutdated(String projectId, String workspac * @param workspaceId workspace id * @return flag indicating if a user workspace is in conflict resolution mode */ + @Deprecated default boolean isUserWorkspaceInConflictResolutionMode(String projectId, String workspaceId) { - return isWorkspaceInConflictResolutionMode(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceInConflictResolutionMode(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** @@ -237,19 +425,28 @@ default boolean isUserWorkspaceInConflictResolutionMode(String projectId, String * @param workspaceId workspace id * @return flag indicating if a group workspace is in conflict resolution mode */ + @Deprecated default boolean isGroupWorkspaceInConflictResolutionMode(String projectId, String workspaceId) { - return isWorkspaceInConflictResolutionMode(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return isWorkspaceInConflictResolutionMode(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** * Check if a workspace is in conflict resolution mode * - * @param projectId project id - * @param sourceSpecification source specification + * @param projectId project id + * @param sourceSpecification source specification * @return flag indicating if a workspace is in conflict resolution mode */ - boolean isWorkspaceInConflictResolutionMode(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default boolean isWorkspaceInConflictResolutionMode(String projectId, SourceSpecification sourceSpecification) + { + if (!(sourceSpecification instanceof WorkspaceSourceSpecification)) + { + throw new IllegalArgumentException("Not a workspace source specification: " + sourceSpecification); + } + return isWorkspaceInConflictResolutionMode(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Create a new user workspace in the given project for the current user. @@ -258,9 +455,10 @@ default boolean isGroupWorkspaceInConflictResolutionMode(String projectId, Strin * @param workspaceId new workspace id * @return new workspace */ + @Deprecated default Workspace newUserWorkspace(String projectId, String workspaceId) { - return newWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return newWorkspace(projectId, workspaceId, WorkspaceType.USER, WorkspaceSource.projectWorkspaceSource()); } /** @@ -270,19 +468,25 @@ default Workspace newUserWorkspace(String projectId, String workspaceId) * @param workspaceId new workspace id * @return new workspace */ + @Deprecated default Workspace newGroupWorkspace(String projectId, String workspaceId) { - return newWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return newWorkspace(projectId, workspaceId, WorkspaceType.GROUP, WorkspaceSource.projectWorkspaceSource()); } /** * Create a new workspace in the given project for the current user. * - * @param projectId project id - * @param sourceSpecification source specification + * @param projectId project id + * @param sourceSpecification source specification * @return new workspace */ - Workspace newWorkspace(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default Workspace newWorkspace(String projectId, SourceSpecification sourceSpecification) + { + WorkspaceSpecification workspaceSpec = ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification(); + return newWorkspace(projectId, workspaceSpec.getId(), workspaceSpec.getType(), workspaceSpec.getSource()); + } /** * Delete the given user workspace. @@ -290,9 +494,10 @@ default Workspace newGroupWorkspace(String projectId, String workspaceId) * @param projectId project id * @param workspaceId id of workspace to delete */ + @Deprecated default void deleteUserWorkspace(String projectId, String workspaceId) { - deleteWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + deleteWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** @@ -301,18 +506,23 @@ default void deleteUserWorkspace(String projectId, String workspaceId) * @param projectId project id * @param workspaceId id of workspace to delete */ + @Deprecated default void deleteGroupWorkspace(String projectId, String workspaceId) { - deleteWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + deleteWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** * Delete the given workspace. * - * @param projectId project id - * @param sourceSpecification source specification + * @param projectId project id + * @param sourceSpecification source specification */ - void deleteWorkspace(String projectId, SourceSpecification sourceSpecification); + @Deprecated + default void deleteWorkspace(String projectId, SourceSpecification sourceSpecification) + { + deleteWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); + } /** * Update the user workspace with the latest committed changes. Potentially, this needs to handle conflict resolution. @@ -321,9 +531,10 @@ default void deleteGroupWorkspace(String projectId, String workspaceId) * @param workspaceId id of workspace to update * @return a workspace update report */ + @Deprecated default WorkspaceUpdateReport updateUserWorkspace(String projectId, String workspaceId) { - return updateWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId)); + return updateWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)); } /** @@ -333,41 +544,22 @@ default WorkspaceUpdateReport updateUserWorkspace(String projectId, String works * @param workspaceId id of workspace to update * @return a workspace update report */ + @Deprecated default WorkspaceUpdateReport updateGroupWorkspace(String projectId, String workspaceId) { - return updateWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId)); + return updateWorkspace(projectId, WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.GROUP)); } /** * Update the workspace with the latest committed changes. Potentially, this needs to handle conflict resolution. * - * @param projectId project id - * @param sourceSpecification source specification + * @param projectId project id + * @param sourceSpecification source specification * @return a workspace update report */ - WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecification sourceSpecification); - - interface WorkspaceUpdateReport + @Deprecated + default WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecification sourceSpecification) { - WorkspaceUpdateReportStatus getStatus(); - - /** - * Get the project revision id where the updated or conflict resolution workspace stems from. - * - * @return merge base revision id of the workspace - */ - String getWorkspaceMergeBaseRevisionId(); - - /** - * Get the current revision id of the updated or conflict resolution workspace. - * - * @return current workspace revision id - */ - String getWorkspaceRevisionId(); - } - - enum WorkspaceUpdateReportStatus - { - NO_OP, UPDATED, CONFLICT + return updateWorkspace(projectId, ((WorkspaceSourceSpecification) sourceSpecification).getWorkspaceSpecification()); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSource.java new file mode 100644 index 0000000000..2b558706c9 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSource.java @@ -0,0 +1,57 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.workspace; + +import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; + +public abstract class WorkspaceSource +{ + WorkspaceSource() + { + } + + public abstract SourceSpecification getSourceSpecification(); + + public abstract T visit(WorkspaceSourceVisitor visitor); + + @Override + public String toString() + { + return appendString(new StringBuilder()).toString(); + } + + StringBuilder appendString(StringBuilder builder) + { + return appendAdditionalInfo(builder.append("<").append(getClass().getSimpleName())).append('>'); + } + + protected abstract StringBuilder appendAdditionalInfo(StringBuilder builder); + + public static ProjectWorkspaceSource projectWorkspaceSource() + { + return ProjectWorkspaceSource.INSTANCE; + } + + public static PatchWorkspaceSource patchWorkspaceSource(String patch) + { + return patchWorkspaceSource(VersionId.parseVersionId(patch)); + } + + public static PatchWorkspaceSource patchWorkspaceSource(VersionId patch) + { + return new PatchWorkspaceSource(patch); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceConsumer.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceConsumer.java new file mode 100644 index 0000000000..d6024c95ce --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceConsumer.java @@ -0,0 +1,50 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.workspace; + +import java.util.function.Consumer; + +public abstract class WorkspaceSourceConsumer implements WorkspaceSourceVisitor, Consumer +{ + @Override + public final Void visit(ProjectWorkspaceSource source) + { + accept(source); + return null; + } + + @Override + public final Void visit(PatchWorkspaceSource source) + { + accept(source); + return null; + } + + @Override + public final void accept(WorkspaceSource source) + { + source.visit(this); + } + + protected void accept(ProjectWorkspaceSource source) + { + // nothing by default + } + + protected void accept(PatchWorkspaceSource source) + { + // nothing by default + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceVisitor.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceVisitor.java new file mode 100644 index 0000000000..d1014c3bc3 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSourceVisitor.java @@ -0,0 +1,36 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.workspace; + +import java.util.function.Function; + +public interface WorkspaceSourceVisitor extends Function +{ + default T visit(ProjectWorkspaceSource source) + { + throw new UnsupportedOperationException("Unsupported workspace source specification: " + source); + } + + default T visit(PatchWorkspaceSource source) + { + throw new UnsupportedOperationException("Unsupported workspace source specification: " + source); + } + + @Override + default T apply(WorkspaceSource source) + { + return source.visit(this); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSpecification.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSpecification.java new file mode 100644 index 0000000000..5bfe1959f9 --- /dev/null +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/domain/api/workspace/WorkspaceSpecification.java @@ -0,0 +1,162 @@ +// Copyright 2023 Goldman Sachs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.finos.legend.sdlc.server.domain.api.workspace; + +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; + +import java.util.Objects; + +public class WorkspaceSpecification +{ + private final String id; + private final WorkspaceType type; + private final WorkspaceAccessType accessType; + private final WorkspaceSource source; + private final String userId; + + private WorkspaceSpecification(String id, WorkspaceType type, WorkspaceAccessType accessType, WorkspaceSource source, String userId) + { + if ((userId != null) && (type != WorkspaceType.USER)) + { + throw new IllegalArgumentException("User id may only be specified for user workspaces"); + } + this.id = Objects.requireNonNull(id, "id may not be null"); + this.type = Objects.requireNonNull(type, "type may not be null"); + this.accessType = Objects.requireNonNull(accessType, "access type may not be null"); + this.source = Objects.requireNonNull(source, "source may not be null"); + this.userId = userId; + } + + @Override + public boolean equals(Object other) + { + if (this == other) + { + return true; + } + + if (!(other instanceof WorkspaceSpecification)) + { + return false; + } + + WorkspaceSpecification that = (WorkspaceSpecification) other; + return (this.type == that.type) && + (this.accessType == that.accessType) && + this.id.equals(that.id) && + this.source.equals(that.source) && + Objects.equals(this.userId, that.userId); + } + + @Override + public int hashCode() + { + return Objects.hash(this.id, this.type, this.accessType, this.source, this.userId); + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder("').toString(); + } + + public String getId() + { + return this.id; + } + + public WorkspaceType getType() + { + return this.type; + } + + public WorkspaceAccessType getAccessType() + { + return this.accessType; + } + + public WorkspaceSource getSource() + { + return this.source; + } + + /** + * The user id, if specified; otherwise, null. The user id may only be specified if the workspace type is + * {@link WorkspaceType#USER}. Even then, it is optional. + * + * @return user id or null + */ + public String getUserId() + { + return this.userId; + } + + public WorkspaceSourceSpecification getSourceSpecification() + { + return SourceSpecification.workspaceSourceSpecification(this); + } + + /** + * Create a new workspace specification. If the workspace type is {@link WorkspaceType#USER}, then a user id may be + * specified. If it is not specified, then it is assumed to be the current user. + * + * @param id workspace id + * @param type workspace type + * @param accessType workspace access type + * @param source workspace source + * @param userId optional user id + * @return workspace specification + */ + public static WorkspaceSpecification newWorkspaceSpecification(String id, WorkspaceType type, WorkspaceAccessType accessType, WorkspaceSource source, String userId) + { + return new WorkspaceSpecification(id, type, (accessType == null) ? WorkspaceAccessType.WORKSPACE : accessType, (source == null) ? WorkspaceSource.projectWorkspaceSource() : source, userId); + } + + public static WorkspaceSpecification newWorkspaceSpecification(String id, WorkspaceType type, WorkspaceAccessType accessType, WorkspaceSource source) + { + return newWorkspaceSpecification(id, type, accessType, source, null); + } + + public static WorkspaceSpecification newWorkspaceSpecification(String id, WorkspaceType type, WorkspaceAccessType accessType) + { + return newWorkspaceSpecification(id, type, accessType, null); + } + + public static WorkspaceSpecification newWorkspaceSpecification(String id, WorkspaceType type, WorkspaceSource source) + { + return newWorkspaceSpecification(id, type, null, source); + } + + public static WorkspaceSpecification newWorkspaceSpecification(String id, WorkspaceType type) + { + return newWorkspaceSpecification(id, type, null, null); + } +} diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/BaseGitLabApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/BaseGitLabApi.java index fbf27f78a6..f9b5dc13f8 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/BaseGitLabApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/BaseGitLabApi.java @@ -14,6 +14,7 @@ package org.finos.legend.sdlc.server.gitlab.api; +import org.finos.legend.sdlc.domain.model.patch.Patch; import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.review.ReviewState; @@ -22,7 +23,19 @@ import org.finos.legend.sdlc.domain.model.user.User; import org.finos.legend.sdlc.domain.model.version.Version; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.PatchSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.ProjectSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationConsumer; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationVisitor; +import org.finos.legend.sdlc.server.domain.api.project.source.VersionSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.ProjectWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceConsumer; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceVisitor; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -64,6 +77,8 @@ import java.util.function.Function; import java.util.function.LongUnaryOperator; import java.util.function.Supplier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -82,12 +97,15 @@ abstract class BaseGitLabApi private static final String WORKSPACE_BRANCH_PREFIX = "workspace"; private static final String CONFLICT_RESOLUTION_BRANCH_PREFIX = "resolution"; private static final String BACKUP_BRANCH_PREFIX = "backup"; - private static final String TEMPORARY_BRANCH_PREFIX = "tmp"; - private static final String GROUP_BRANCH_PREFIX = "group"; + private static final String GROUP_WORKSPACE_BRANCH_PREFIX = "group"; private static final String GROUP_CONFLICT_RESOLUTION_BRANCH_PREFIX = "group-resolution"; private static final String GROUP_BACKUP_BRANCH_PREFIX = "group-backup"; - private static final String PATCH_RELEASE_BRANCH_PREFIX = "patch/main"; - protected static final String PATCH_RELEASE_WORKSPACE_BRANCH_PREFIX = "patch"; + private static final String PATCH_WORKSPACE_BRANCH_PREFIX = "patch"; + + private static final String TEMPORARY_BRANCH_PREFIX = "tmp"; + private static final String PATCH_BRANCH_PREFIX = "patch/main"; + + private static final Pattern WORKSPACE_BRANCH_PATTERN = Pattern.compile("(" + PATCH_WORKSPACE_BRANCH_PREFIX + "/(?\\d++\\.\\d++\\.\\d++)/)?(?" + WORKSPACE_BRANCH_PREFIX + "|" + GROUP_WORKSPACE_BRANCH_PREFIX + "|" + CONFLICT_RESOLUTION_BRANCH_PREFIX + "|" + GROUP_CONFLICT_RESOLUTION_BRANCH_PREFIX + "|" + BACKUP_BRANCH_PREFIX + "|" + GROUP_BACKUP_BRANCH_PREFIX + ")/((?[^/]++)/)?(?[^/]++)"); private static final String MR_STATE_OPENED = "opened"; private static final String MR_STATE_CLOSED = "closed"; @@ -98,9 +116,6 @@ abstract class BaseGitLabApi protected static final int ITEMS_PER_PAGE = 100; - @Deprecated - protected static final String PACKAGE_SEPARATOR = EntityPaths.PACKAGE_SEPARATOR; - protected static final char BRANCH_DELIMITER = '/'; protected static final String RELEASE_TAG_PREFIX = "release-"; @@ -194,6 +209,27 @@ protected static boolean isValidPackageableElementPath(String string) return (string != null) && string.matches("^\\w++(::\\w++)*+[\\w$]*+$"); } + protected static String getWorkspaceBranchNamePrefix(WorkspaceSpecification workspaceSpec) + { + String basePrefix = getWorkspaceBranchNamePrefix(workspaceSpec.getType(), workspaceSpec.getAccessType()); + return workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public String visit(ProjectWorkspaceSource source) + { + return basePrefix; + } + + @Override + public String visit(PatchWorkspaceSource source) + { + StringBuilder builder = new StringBuilder(getPatchWorkspaceBranchPrefix()).append(BRANCH_DELIMITER); + source.getPatchVersionId().appendVersionIdString(builder).append(BRANCH_DELIMITER); + return builder.append(basePrefix).toString(); + } + }); + } + protected static String getWorkspaceBranchNamePrefix(WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) { assert workspaceAccessType != null : "Workspace access type has been used but it is null, which should not be the case"; @@ -206,7 +242,7 @@ protected static String getWorkspaceBranchNamePrefix(WorkspaceType workspaceType { case WORKSPACE: { - return GROUP_BRANCH_PREFIX; + return GROUP_WORKSPACE_BRANCH_PREFIX; } case CONFLICT_RESOLUTION: { @@ -218,7 +254,7 @@ protected static String getWorkspaceBranchNamePrefix(WorkspaceType workspaceType } default: { - throw new RuntimeException("Unknown workspace access type " + workspaceAccessType); + throw new RuntimeException("Unknown workspace access type: " + workspaceAccessType); } } } @@ -240,51 +276,63 @@ protected static String getWorkspaceBranchNamePrefix(WorkspaceType workspaceType } default: { - throw new RuntimeException("Unknown workspace access type " + workspaceAccessType); + throw new RuntimeException("Unknown workspace access type: " + workspaceAccessType); } } } default: { - throw new RuntimeException("Unknown workspace type " + workspaceType); + throw new RuntimeException("Unknown workspace type: " + workspaceType); } } } - protected static WorkspaceInfo parseWorkspaceBranchName(String branchName) + protected static String getPatchWorkspaceBranchPrefix() { - String branchType; - int branchInfoDelimiter; - int firstDelimiter = branchName.indexOf(BRANCH_DELIMITER); - if (firstDelimiter == -1) + return PATCH_WORKSPACE_BRANCH_PREFIX; + } + + protected static WorkspaceSpecification parseWorkspaceBranchName(String branchName) + { + if (branchName == null) { return null; } - int secondDelimiter = branchName.indexOf(BRANCH_DELIMITER, firstDelimiter + 1); - if (secondDelimiter == -1) + + Matcher matcher = WORKSPACE_BRANCH_PATTERN.matcher(branchName); + if (!matcher.matches()) { - branchInfoDelimiter = firstDelimiter; - branchType = branchName.substring(0, firstDelimiter); + return null; + } + + String patchVersionString = matcher.group("patchVersion"); + String typeString = matcher.group("type"); + String userId = matcher.group("user"); + String workspaceId = matcher.group("id"); + + WorkspaceSource source; + if (patchVersionString == null) + { + source = WorkspaceSource.projectWorkspaceSource(); } else { - int thirdDelimter = branchName.indexOf(BRANCH_DELIMITER, secondDelimiter + 1); - if (thirdDelimter == -1) + VersionId versionId; + try { - branchInfoDelimiter = firstDelimiter; - branchType = branchName.substring(0, firstDelimiter); + versionId = VersionId.parseVersionId(patchVersionString); } - else + catch (Exception ignore) { - branchInfoDelimiter = thirdDelimter; - branchType = branchName.substring(firstDelimiter + 1, secondDelimiter); + // not a valid version string + return null; } + source = WorkspaceSource.patchWorkspaceSource(versionId); } WorkspaceType type; WorkspaceAccessType accessType; - - switch (branchType) + switch (typeString) { case WORKSPACE_BRANCH_PREFIX: { @@ -304,7 +352,7 @@ protected static WorkspaceInfo parseWorkspaceBranchName(String branchName) accessType = WorkspaceAccessType.BACKUP; break; } - case GROUP_BRANCH_PREFIX: + case GROUP_WORKSPACE_BRANCH_PREFIX: { type = WorkspaceType.GROUP; accessType = WorkspaceAccessType.WORKSPACE; @@ -324,40 +372,56 @@ protected static WorkspaceInfo parseWorkspaceBranchName(String branchName) } default: { + // This should never happen return null; } } - switch (type) + // For user workspaces, userId must be non-null; for others, userId must be null + if ((type == WorkspaceType.USER) == (userId == null)) { - case USER: + return null; + } + return WorkspaceSpecification.newWorkspaceSpecification(workspaceId, type, accessType, source, userId); + } + + protected String getBranchName(GitLabProjectId projectId, SourceSpecification sourceSpec) + { + return getBranchName(sourceSpec, () -> getDefaultBranch(projectId)); + } + + protected String getBranchName(SourceSpecification sourceSpec, Project gitLabProject) + { + return getBranchName(sourceSpec, () -> getDefaultBranch(gitLabProject)); + } + + protected String getBranchName(SourceSpecification sourceSpec, String defaultBranch) + { + return getBranchName(sourceSpec, () -> defaultBranch); + } + + protected String getBranchName(SourceSpecification sourceSpec, Supplier defaultBranchSupplier) + { + return sourceSpec.visit(new SourceSpecificationVisitor() + { + @Override + public String visit(ProjectSourceSpecification sourceSpec) { - // // - int nextDelimiter = branchName.indexOf(BRANCH_DELIMITER, branchInfoDelimiter + 1); - if (nextDelimiter == -1) - { - return null; - } - String workspaceId = branchName.substring(nextDelimiter + 1); - String userId = branchName.substring(branchInfoDelimiter + 1, nextDelimiter); - return new WorkspaceInfo(workspaceId, type, accessType, userId); + return defaultBranchSupplier.get(); } - case GROUP: + + @Override + public String visit(PatchSourceSpecification sourceSpec) { - // / - String workspaceId = branchName.substring(branchInfoDelimiter + 1); - return new WorkspaceInfo(workspaceId, type, accessType, null); + return getPatchReleaseBranchName(sourceSpec); } - default: + + @Override + public String visit(WorkspaceSourceSpecification sourceSpec) { - throw new IllegalStateException("Unknown workspace type: " + type); + return getWorkspaceBranchName(sourceSpec); } - } - } - - protected String getBranchName(GitLabProjectId projectId, SourceSpecification sourceSpecification) - { - return (sourceSpecification.getWorkspaceId() == null) ? getSourceBranch(projectId, sourceSpecification.getPatchReleaseVersionId()) : getWorkspaceBranchName(sourceSpecification); + }); } protected String getDefaultBranch(GitLabProjectId projectId) @@ -373,96 +437,138 @@ protected String getDefaultBranch(GitLabProjectId projectId) } } + protected String getDefaultBranch(Project project) + { + String defaultBranch = project.getDefaultBranch(); + return (defaultBranch == null) ? MASTER_BRANCH : defaultBranch; + } + + @Deprecated protected String getSourceBranch(GitLabProjectId projectId, VersionId patchReleaseVersionId) { - if (patchReleaseVersionId == null) - { - return getDefaultBranch(projectId); - } - else - { - return getPatchReleaseBranchName(patchReleaseVersionId); - } + return (patchReleaseVersionId == null) ? getDefaultBranch(projectId) : getPatchReleaseBranchName(patchReleaseVersionId); } - protected String getDefaultBranch(Project project) + protected String getSourceBranch(GitLabProjectId projectId, WorkspaceSourceSpecification sourceSpec) { - String defaultBranch = project.getDefaultBranch(); - return (defaultBranch == null) ? MASTER_BRANCH : defaultBranch; + return getSourceBranch(projectId, sourceSpec.getWorkspaceSpecification()); } - protected String getWorkspaceBranchName(SourceSpecification sourceSpecification) + protected String getSourceBranch(GitLabProjectId projectId, WorkspaceSpecification workspaceSpec) + { + return getSourceBranch(projectId, workspaceSpec.getSource()); + } + + protected String getSourceBranch(GitLabProjectId projectId, WorkspaceSource workspaceSource) + { + return getSourceBranch(workspaceSource, () -> getDefaultBranch(projectId)); + } + + protected static String getSourceBranch(WorkspaceSourceSpecification sourceSpec, Supplier defaultBranchSupplier) + { + return getSourceBranch(sourceSpec.getWorkspaceSpecification(), defaultBranchSupplier); + } + + protected static String getSourceBranch(WorkspaceSpecification workspaceSpec, Supplier defaultBranchSupplier) { - String prefix = getWorkspaceBranchNamePrefix(sourceSpecification.getWorkspaceType(), sourceSpecification.getWorkspaceAccessType()); - switch (sourceSpecification.getWorkspaceType()) + return getSourceBranch(workspaceSpec.getSource(), defaultBranchSupplier); + } + + protected static String getSourceBranch(WorkspaceSource workspaceSource, Supplier defaultBranchSupplier) + { + return workspaceSource.visit(new WorkspaceSourceVisitor() { - case USER: - { - return sourceSpecification.getPatchReleaseVersionId() == null ? createBranchName(prefix, getCurrentUser(), sourceSpecification.getWorkspaceId()) : createBranchName(PATCH_RELEASE_WORKSPACE_BRANCH_PREFIX, prefix, sourceSpecification.getPatchReleaseVersionId().toVersionIdString(), getCurrentUser(), sourceSpecification.getWorkspaceId()); - } - case GROUP: + @Override + public String visit(ProjectWorkspaceSource source) { - return sourceSpecification.getPatchReleaseVersionId() == null ? createBranchName(prefix, sourceSpecification.getWorkspaceId()) : createBranchName(PATCH_RELEASE_WORKSPACE_BRANCH_PREFIX, prefix, sourceSpecification.getPatchReleaseVersionId().toVersionIdString(), sourceSpecification.getWorkspaceId()); + return defaultBranchSupplier.get(); } - default: + + @Override + public String visit(PatchWorkspaceSource source) { - throw new IllegalStateException("Unknown workspace type: " + sourceSpecification.getWorkspaceType()); + return getPatchReleaseBranchName(source.getPatchVersionId()); } - } + }); } - protected String getPatchReleaseBranchPrefix() + protected String getWorkspaceBranchName(WorkspaceSourceSpecification sourceSpec) { - return PATCH_RELEASE_BRANCH_PREFIX + BRANCH_DELIMITER; + return getWorkspaceBranchName(sourceSpec.getWorkspaceSpecification()); } - protected String getPatchReleaseBranchName(VersionId patchRelaseVersionId) + protected String getWorkspaceBranchName(WorkspaceSpecification workspaceSpec) { - return patchRelaseVersionId.appendVersionIdString(new StringBuilder(PATCH_RELEASE_BRANCH_PREFIX).append(BRANCH_DELIMITER)).toString(); + return getWorkspaceBranchName(workspaceSpec, this::getCurrentUser); } - protected String newUserTemporaryBranchName() + protected static String getWorkspaceBranchName(WorkspaceSpecification workspaceSpec, Supplier currentUser) { - return createBranchName(TEMPORARY_BRANCH_PREFIX, getCurrentUser(), newTemporaryBranchId()); + StringBuilder builder = new StringBuilder(); + WorkspaceSource source = workspaceSpec.getSource(); + if (source instanceof PatchWorkspaceSource) + { + builder.append(PATCH_WORKSPACE_BRANCH_PREFIX).append(BRANCH_DELIMITER); + ((PatchWorkspaceSource) source).getPatchVersionId().appendVersionIdString(builder).append(BRANCH_DELIMITER); + } + builder.append(getWorkspaceBranchNamePrefix(workspaceSpec.getType(), workspaceSpec.getAccessType())).append(BRANCH_DELIMITER); + if (workspaceSpec.getType() == WorkspaceType.USER) + { + String userId = workspaceSpec.getUserId(); + builder.append((userId == null) ? currentUser.get() : userId).append(BRANCH_DELIMITER); + } + return builder.append(workspaceSpec.getId()).toString(); } - protected String newUserTemporaryBranchName(String workspaceId) + @Deprecated + protected String getWorkspaceBranchName(SourceSpecification sourceSpecification) { - return createBranchName(TEMPORARY_BRANCH_PREFIX, getCurrentUser(), workspaceId, newTemporaryBranchId()); + return getWorkspaceBranchName((WorkspaceSourceSpecification) sourceSpecification); } - protected static String getRandomIdString() + protected static String getPatchReleaseBranchPrefix() { - byte[] tempIdBytes = new byte[12]; - ByteBuffer buffer = ByteBuffer.wrap(tempIdBytes); - buffer.putInt(RANDOM.nextInt()); - buffer.putLong(System.currentTimeMillis()); - return new String(RANDOM_ID_ENCODER.encode(tempIdBytes), StandardCharsets.ISO_8859_1); + return PATCH_BRANCH_PREFIX + BRANCH_DELIMITER; } - private static String newTemporaryBranchId() + protected static String getPatchReleaseBranchName(PatchSourceSpecification sourceSpec) { - return getRandomIdString(); + return getPatchReleaseBranchName(sourceSpec.getVersionId()); } - private static String createBranchName(String first, String second) + protected static String getPatchReleaseBranchName(VersionId patchRelaseVersionId) { - return first + BRANCH_DELIMITER + second; + return patchRelaseVersionId.appendVersionIdString(new StringBuilder(PATCH_BRANCH_PREFIX).append(BRANCH_DELIMITER)).toString(); } - private static String createBranchName(String first, String second, String third) + protected String newUserTemporaryBranchName() { - return first + BRANCH_DELIMITER + second + BRANCH_DELIMITER + third; + return newUserTemporaryBranchName(null); } - private static String createBranchName(String first, String second, String third, String fourth) + protected String newUserTemporaryBranchName(SourceSpecification sourceSpec) { - return first + BRANCH_DELIMITER + second + BRANCH_DELIMITER + third + BRANCH_DELIMITER + fourth; + StringBuilder builder = new StringBuilder(TEMPORARY_BRANCH_PREFIX).append(BRANCH_DELIMITER) + .append(getCurrentUser()).append(BRANCH_DELIMITER); + if (sourceSpec instanceof WorkspaceSourceSpecification) + { + builder.append(((WorkspaceSourceSpecification) sourceSpec).getWorkspaceSpecification().getId()).append(BRANCH_DELIMITER); + } + return builder.append(newTemporaryBranchId()).toString(); } - private static String createBranchName(String first, String second, String third, String fourth, String fifth) + protected static String getRandomIdString() { - return first + BRANCH_DELIMITER + second + BRANCH_DELIMITER + third + BRANCH_DELIMITER + fourth + BRANCH_DELIMITER + fifth; + byte[] tempIdBytes = new byte[12]; + ByteBuffer buffer = ByteBuffer.wrap(tempIdBytes); + buffer.putInt(RANDOM.nextInt()); + buffer.putLong(System.currentTimeMillis()); + return new String(RANDOM_ID_ENCODER.encode(tempIdBytes), StandardCharsets.ISO_8859_1); + } + + private static String newTemporaryBranchId() + { + return getRandomIdString(); } protected static boolean isWorkspaceBranchName(String branchName, WorkspaceAccessType workspaceAccessType) @@ -545,11 +651,13 @@ protected static boolean isVersionTag(Tag tag) return isVersionTagName(tag.getName()); } + @Deprecated protected static String getReferenceInfo(GitLabProjectId projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) { return getReferenceInfo(projectId.toString(), workspaceId, workspaceType, workspaceAccessType, revisionId); } + @Deprecated protected static String getReferenceInfo(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) { int messageLength = projectId.length() + 8; @@ -564,6 +672,7 @@ protected static String getReferenceInfo(String projectId, String workspaceId, W return appendReferenceInfo(new StringBuilder(messageLength), projectId, workspaceId, workspaceType, workspaceAccessType, revisionId).toString(); } + @Deprecated protected static StringBuilder appendReferenceInfo(StringBuilder builder, String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) { if (revisionId != null) @@ -578,6 +687,81 @@ protected static StringBuilder appendReferenceInfo(StringBuilder builder, String return builder; } + protected static String getReferenceInfo(GitLabProjectId projectId, SourceSpecification sourceSpec) + { + return getReferenceInfo(projectId, sourceSpec, null); + } + + protected static String getReferenceInfo(GitLabProjectId projectId, SourceSpecification sourceSpec, String revisionId) + { + return getReferenceInfo(projectId.toString(), sourceSpec, revisionId); + } + + protected static String getReferenceInfo(String projectId, WorkspaceSpecification workspaceSpec) + { + return getReferenceInfo(projectId, workspaceSpec.getSourceSpecification()); + } + + protected static String getReferenceInfo(String projectId, WorkspaceSource workspaceSource) + { + return getReferenceInfo(projectId, workspaceSource.getSourceSpecification()); + } + + protected static String getReferenceInfo(String projectId, SourceSpecification sourceSpec) + { + return getReferenceInfo(projectId, sourceSpec, null); + } + + protected static String getReferenceInfo(String projectId, SourceSpecification sourceSpec, String revisionId) + { + return appendReferenceInfo(new StringBuilder(), projectId, sourceSpec, revisionId).toString(); + } + + protected static StringBuilder appendReferenceInfo(StringBuilder builder, String projectId, SourceSpecification sourceSpec) + { + return appendReferenceInfo(builder, projectId, sourceSpec, null); + } + + protected static StringBuilder appendReferenceInfo(StringBuilder builder, String projectId, SourceSpecification sourceSpec, String revisionId) + { + if (revisionId != null) + { + builder.append("revision ").append(revisionId).append(" of "); + } + sourceSpec.visit(new SourceSpecificationConsumer() + { + @Override + protected void accept(VersionSourceSpecification sourceSpec) + { + sourceSpec.getVersionId().appendVersionIdString(builder.append("version ")); + } + + @Override + protected void accept(PatchSourceSpecification sourceSpec) + { + sourceSpec.getVersionId().appendVersionIdString(builder.append("patch ")); + } + + @Override + protected void accept(WorkspaceSourceSpecification sourceSpec) + { + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + builder.append(workspaceSpec.getType().getLabel()).append(" ") + .append(workspaceSpec.getAccessType().getLabel()).append(" ") + .append(workspaceSpec.getId()).append(" of "); + workspaceSpec.getSource().visit(new WorkspaceSourceConsumer() + { + @Override + protected void accept(PatchWorkspaceSource source) + { + source.getPatchVersionId().appendVersionIdString(builder.append("patch ")).append(" of "); + } + }); + } + }); + return builder.append("project ").append(projectId); + } + protected static R applyIfNotNull(Function function, T value) { return (value == null) ? null : function.apply(value); @@ -835,12 +1019,20 @@ public String getName() }; } - protected static Workspace fromWorkspaceBranchName(String projectId, VersionId patchReleaseVersionId, String branchName, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) + protected static Workspace fromWorkspaceBranchName(String projectId, String branchName) + { + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(branchName); + return (workspaceSpec == null) ? null : fromWorkspaceSpecification(projectId, workspaceSpec); + } + + protected static Workspace fromWorkspaceSpecification(String projectId, WorkspaceSpecification workspaceSpec) { - int userIdStartIndex = patchReleaseVersionId == null ? getWorkspaceBranchNamePrefix(workspaceType, workspaceAccessType).length() + 1 : PATCH_RELEASE_WORKSPACE_BRANCH_PREFIX.length() + getWorkspaceBranchNamePrefix(workspaceType, workspaceAccessType).length() + 8; - int userIdEndIndex = branchName.indexOf(BRANCH_DELIMITER, workspaceType == WorkspaceType.GROUP ? userIdStartIndex - 1 : userIdStartIndex); - String userId = workspaceType == WorkspaceType.GROUP ? null : branchName.substring(userIdStartIndex, userIdEndIndex); - String workspaceId = branchName.substring(userIdEndIndex + 1); + String workspaceId = workspaceSpec.getId(); + String userId = workspaceSpec.getUserId(); + if ((userId == null) && (workspaceSpec.getType() == WorkspaceType.USER)) + { + throw new RuntimeException("Cannot create workspace from specification " + workspaceSpec + ": user workspace must have user id"); + } return new Workspace() { @Override @@ -863,12 +1055,42 @@ public String getWorkspaceId() }; } - protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, VersionId patchReleaseVersionId, String reviewId) + protected static Patch fromPatchBranchName(String projectId, String branchName) + { + int index = branchName.lastIndexOf(BRANCH_DELIMITER); + VersionId patchReleaseVersionId = parseVersionIdString(branchName.substring(index + 1)); + return new Patch() + { + @Override + public String getProjectId() + { + return projectId; + } + + @Override + public VersionId getPatchReleaseVersionId() + { + return patchReleaseVersionId; + } + }; + } + + protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId) + { + return getReviewMergeRequest(mergeRequestApi, projectId, reviewId, false); + } + + protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId, boolean includeRebaseInProgress) { - return getReviewMergeRequest(mergeRequestApi, projectId, patchReleaseVersionId, reviewId, false); + return getReviewMergeRequest(mergeRequestApi, projectId, reviewId, includeRebaseInProgress, () -> getDefaultBranch(projectId)); } - protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, VersionId patchReleaseVersionId, String reviewId, boolean includeRebaseInProgress) + protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId, Supplier defaultBranchSupplier) + { + return getReviewMergeRequest(mergeRequestApi, projectId, reviewId, false, defaultBranchSupplier); + } + + protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId, boolean includeRebaseInProgress, Supplier defaultBranchSupplier) { int mergeRequestId = parseIntegerId(reviewId); MergeRequest mergeRequest; @@ -884,21 +1106,25 @@ protected MergeRequest getReviewMergeRequest(MergeRequestApi mergeRequestApi, Gi () -> "Error accessing review " + reviewId + " in project " + projectId); } - if (!isReviewMergeRequest(mergeRequest, getSourceBranch(projectId, patchReleaseVersionId))) + if (!isReviewMergeRequest(mergeRequest, defaultBranchSupplier)) { throw new LegendSDLCServerException("Unknown review in project " + projectId + ": " + reviewId, Status.NOT_FOUND); } return mergeRequest; } - protected static boolean isReviewMergeRequest(MergeRequest mergeRequest, String targetBranch) + protected static boolean isReviewMergeRequest(MergeRequest mergeRequest, Supplier defaultBranchSupplier) { - if ((mergeRequest == null) || !targetBranch.equals(mergeRequest.getTargetBranch())) + if (mergeRequest != null) { - return false; + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + if ((workspaceSpec != null) && (workspaceSpec.getAccessType() == WorkspaceAccessType.WORKSPACE)) + { + String expectedTargetBranch = getSourceBranch(workspaceSpec, defaultBranchSupplier); + return expectedTargetBranch.equals(mergeRequest.getTargetBranch()); + } } - WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); - return (workspaceInfo != null) && (workspaceInfo.getWorkspaceAccessType() == WorkspaceAccessType.WORKSPACE); + return false; } protected MergeRequest getReviewMergeRequestApprovals(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, String reviewId) @@ -986,7 +1212,6 @@ private static boolean isLocked(String mergeState) protected static String resolveRevisionId(String revisionId, ProjectFileAccessProvider.RevisionAccessContext revisionAccessContext) { - Revision revision; if (revisionId == null) { throw new IllegalArgumentException("Resolving revision alias does not work with null revisionId, null handling must be done before using this method"); @@ -996,13 +1221,13 @@ protected static String resolveRevisionId(String revisionId, ProjectFileAccessPr { case BASE: { - revision = revisionAccessContext.getBaseRevision(); - return revision == null ? null : revision.getId(); + Revision revision = revisionAccessContext.getBaseRevision(); + return (revision == null) ? null : revision.getId(); } case HEAD: { - revision = revisionAccessContext.getCurrentRevision(); - return revision == null ? null : revision.getId(); + Revision revision = revisionAccessContext.getCurrentRevision(); + return (revision == null) ? null : revision.getId(); } case REVISION_ID: { @@ -1010,62 +1235,26 @@ protected static String resolveRevisionId(String revisionId, ProjectFileAccessPr } default: { - throw new IllegalArgumentException("Unknown revision alias type " + revisionAlias); + throw new IllegalArgumentException("Unknown revision alias type: " + revisionAlias); } } } protected static RevisionAlias getRevisionAlias(String revisionId) { - if (revisionId != null) - { - if (RevisionAlias.BASE.getValue().equalsIgnoreCase(revisionId)) - { - return RevisionAlias.BASE; - } - if (RevisionAlias.HEAD.getValue().equalsIgnoreCase(revisionId) || RevisionAlias.CURRENT.getValue().equalsIgnoreCase(revisionId) || RevisionAlias.LATEST.getValue().equalsIgnoreCase(revisionId)) - { - return RevisionAlias.HEAD; - } - return RevisionAlias.REVISION_ID; - } - return null; - } - - protected static final class WorkspaceInfo - { - private final String workspaceId; - private final WorkspaceType workspaceType; - private final WorkspaceAccessType workspaceAccessType; - private final String userId; - - private WorkspaceInfo(String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String userId) - { - this.workspaceId = workspaceId; - this.workspaceType = workspaceType; - this.workspaceAccessType = workspaceAccessType; - this.userId = userId; - } - - public String getWorkspaceId() - { - return this.workspaceId; - } - - public WorkspaceType getWorkspaceType() + if (revisionId == null) { - return this.workspaceType; + return null; } - - public WorkspaceAccessType getWorkspaceAccessType() + if (RevisionAlias.BASE.getValue().equalsIgnoreCase(revisionId)) { - return this.workspaceAccessType; + return RevisionAlias.BASE; } - - public String getUserId() + if (RevisionAlias.HEAD.getValue().equalsIgnoreCase(revisionId) || RevisionAlias.CURRENT.getValue().equalsIgnoreCase(revisionId) || RevisionAlias.LATEST.getValue().equalsIgnoreCase(revisionId)) { - return this.userId; + return RevisionAlias.HEAD; } + return RevisionAlias.REVISION_ID; } protected static Version fromGitLabTag(String projectId, Tag tag) @@ -1190,15 +1379,16 @@ protected Version newVersion(GitLabProjectId projectId, VersionId patchReleaseVe protected boolean isPatchReleaseBranchPresent(GitLabProjectId projectId, VersionId patchReleaseVersionId) { - boolean branchExists = false; try { - branchExists = GitLabApiTools.branchExists(getGitLabApi().getRepositoryApi(), projectId.getGitLabId(), getPatchReleaseBranchName(patchReleaseVersionId)); + return GitLabApiTools.branchExists(getGitLabApi().getRepositoryApi(), projectId.getGitLabId(), getPatchReleaseBranchName(patchReleaseVersionId)); } catch (Exception e) { - throw new LegendSDLCServerException("Error in fetching the patch release branch" + patchReleaseVersionId.toVersionIdString(), e); + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to access patch " + patchReleaseVersionId.toVersionIdString(), + () -> "Unknown patch: " + patchReleaseVersionId.toVersionIdString(), // this case should never happen + () -> "Error in fetching the patch release branch " + patchReleaseVersionId.toVersionIdString()); } - return branchExists; } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabApiWithFileAccess.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabApiWithFileAccess.java index d38c29535b..a282caf21d 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabApiWithFileAccess.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabApiWithFileAccess.java @@ -24,11 +24,19 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.api.set.MutableSet; import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.revision.RevisionAlias; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.PatchSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.ProjectSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationConsumer; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationVisitor; +import org.finos.legend.sdlc.server.domain.api.project.source.VersionSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceConsumer; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -39,7 +47,6 @@ import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.FileModificationContext; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.RevisionAccessContext; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import org.finos.legend.sdlc.server.project.ProjectFileOperation; import org.finos.legend.sdlc.server.project.ProjectFiles; import org.finos.legend.sdlc.server.project.ProjectPaths; @@ -64,7 +71,6 @@ import org.gitlab4j.api.models.Pipeline; import org.gitlab4j.api.models.PipelineStatus; import org.gitlab4j.api.models.RepositoryFile; -import org.gitlab4j.api.models.Tag; import org.gitlab4j.api.models.TreeItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,34 +110,31 @@ protected GitLabApiWithFileAccess(GitLabConfiguration gitLabConfiguration, GitLa this.backgroundTaskProcessor = backgroundTaskProcessor; } - protected ProjectConfiguration getProjectConfiguration(String projectId, WorkspaceInfo workspaceInfo, String revisionId) + @Deprecated + protected ProjectConfiguration getProjectConfiguration(String projectId, VersionId patchReleaseVersionId) { - return getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType()), revisionId); + return getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId)); + } + + protected ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification) + { + return getProjectConfiguration(projectId, sourceSpecification, null); } protected ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) { - ProjectConfiguration config = ProjectStructure.getProjectConfiguration(projectId, sourceSpecification, revisionId, getProjectFileAccessProvider()); - if (config == null) - { - config = ProjectStructure.getDefaultProjectConfiguration(projectId); - } - return config; + ProjectConfiguration config = ProjectStructure.getProjectConfiguration(projectId, sourceSpecification, revisionId, getProjectFileAccessProvider()); + return (config == null) ? ProjectStructure.getDefaultProjectConfiguration(projectId) : config; } - protected ProjectConfiguration getProjectConfiguration(String projectId, VersionId patchReleaseVersionId) + protected boolean hasProjectConfiguration(String projectId, SourceSpecification sourceSpecification) { - return ProjectStructure.getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null, getProjectFileAccessProvider()); + return hasProjectConfiguration(projectId, sourceSpecification, null); } - protected ProjectConfiguration getProjectVersionProjectConfiguration(String projectId, VersionId versionId) + protected boolean hasProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) { - ProjectConfiguration config = ProjectStructure.getProjectConfiguration(projectId, versionId, getProjectFileAccessProvider()); - if (config == null) - { - config = ProjectStructure.getDefaultProjectConfiguration(projectId); - } - return config; + return ProjectStructure.getProjectConfiguration(projectId, sourceSpecification, revisionId, getProjectFileAccessProvider()) != null; } protected ProjectStructure getProjectStructure(String projectId, SourceSpecification sourceSpecification, String revisionId) @@ -141,67 +144,101 @@ protected ProjectStructure getProjectStructure(String projectId, SourceSpecifica protected ProjectFileAccessProvider getProjectFileAccessProvider() { - return new GitLabProjectFileAccessProvider(); - } + return new ProjectFileAccessProvider() + { + @Override + public FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) + { + return new GitLabFileAccessContext(parseProjectId(projectId), sourceSpecification, revisionId); + } - private String getCurrentRevisionId(GitLabProjectId projectId, SourceSpecification sourceSpecification) - { - Revision revision = new GitLabRevisionAccessContext(projectId, sourceSpecification, null).getCurrentRevision(); - return (revision == null) ? null : revision.getId(); + @Override + public RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification, Iterable paths) + { + return new GitLabRevisionAccessContext(parseProjectId(projectId), sourceSpecification, paths); + } + + @Override + public FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification, String revisionId) + { + return new GitLabFileFileModificationContext(parseProjectId(projectId), sourceSpecification, revisionId); + } + }; } - private class GitLabProjectFileAccessProvider implements ProjectFileAccessProvider + protected String resolveRevisionId(String projectId, SourceSpecification sourceSpecification, String revisionId) { - // File Access Access Context - - @Override - public FileAccessContext getFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) + if (revisionId == null) { - return new GitLabProjectFileAccessContext(parseProjectId(projectId), SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), revisionId); + return null; } - @Override - public FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) + String resolvedRevisionId; + try { - return new GitLabProjectFileAccessContext(parseProjectId(projectId), sourceSpecification, revisionId); + resolvedRevisionId = resolveRevisionId(revisionId, getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, null)); } - - @Override - public FileAccessContext getFileAccessContext(String projectId, VersionId versionId) + catch (Exception e) { - return new GitLabProjectVersionFileAccessContext(parseProjectId(projectId), versionId); + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to get " + getReferenceInfo(projectId, sourceSpecification, revisionId), + () -> "Unknown revision " + getReferenceInfo(projectId, sourceSpecification, revisionId), + () -> "Failed to get " + getReferenceInfo(projectId, sourceSpecification, revisionId)); } - - // Revision Access Context - - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification, Iterable paths) + if (resolvedRevisionId == null) { - return new GitLabRevisionAccessContext(parseProjectId(projectId), sourceSpecification, paths); + throw new LegendSDLCServerException("Failed to resolve " + getReferenceInfo(projectId, sourceSpecification, revisionId), Status.NOT_FOUND); } + return resolvedRevisionId; + } - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, Iterable paths) + private String getCurrentRevisionId(GitLabProjectId projectId, SourceSpecification sourceSpecification) + { + Revision revision = new GitLabRevisionAccessContext(projectId, sourceSpecification, null).getCurrentRevision(); + return (revision == null) ? null : revision.getId(); + } + + private String getReferenceForSourceSpec(GitLabProjectId projectId, SourceSpecification sourceSpec) + { + return sourceSpec.visit(new SourceSpecificationVisitor() { - return new GitLabProjectVersionRevisionAccessContext(parseProjectId(projectId), versionId, paths); - } + @Override + public String visit(ProjectSourceSpecification sourceSpec) + { + return getDefaultBranch(projectId); + } + + @Override + public String visit(VersionSourceSpecification sourceSpec) + { + return buildVersionTagName(sourceSpec.getVersionId()); + } - // File Modification Context + @Override + public String visit(PatchSourceSpecification sourceSpec) + { + return getPatchReleaseBranchName(sourceSpec); + } - @Override - public FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return new GitLabProjectFileFileModificationContext(parseProjectId(projectId), sourceSpecification, revisionId); - } + @Override + public String visit(WorkspaceSourceSpecification sourceSpec) + { + return getWorkspaceBranchName(sourceSpec); + } + }); } - private abstract class AbstractGitLabFileAccessContext extends AbstractFileAccessContext + private class GitLabFileAccessContext extends AbstractFileAccessContext { - protected final GitLabProjectId projectId; + private final GitLabProjectId projectId; + private final SourceSpecification sourceSpecification; + private final String revisionId; - AbstractGitLabFileAccessContext(GitLabProjectId projectId) + GitLabFileAccessContext(GitLabProjectId projectId, SourceSpecification sourceSpecification, String revisionId) { - this.projectId = projectId; + this.projectId = Objects.requireNonNull(projectId, "project id may not be null"); + this.sourceSpecification = Objects.requireNonNull(sourceSpecification, "source specification may not be null"); + this.revisionId = revisionId; } @Override @@ -419,87 +456,28 @@ public boolean fileExists(String path) } } - protected abstract String getReference(); - - protected abstract String getDescriptionForExceptionMessage(); - } - - // NOTE: this file access context takes both workspaceId, and revisionId, which can make it look like when both - // are provided, we will find revision in a particular workspace, but that's not the case. - // - // In case revisionId is provided, the final reference to be used will be the revisionId, and Gitlab API allows us to - // access files of this commit regardless of the branch it belongs to. In particular, it can find commits whose branch - // has been squashed, merged into master and deleted after a merge request. In this case the commit surely won;t appear - // on master but Gitlab still got a hold of it. - // - // This is important because here we are leaving the semantic layer of the app and entering file access level in gitlab, - // where we just need the reference, SHA to get files and underneath, we use a really powerful API to get the files via repository archive, - // so we are allowed to access files of a commit that belongs to a deleted branch (in merge request for example) - private class GitLabProjectFileAccessContext extends AbstractGitLabFileAccessContext - { - private final String revisionId; - private final SourceSpecification sourceSpecification; - - private GitLabProjectFileAccessContext(GitLabProjectId projectId, SourceSpecification sourceSpecification, String revisionId) - { - super(projectId); - this.sourceSpecification = sourceSpecification; - this.revisionId = revisionId; - if (sourceSpecification == null) - { - throw new RuntimeException("source specification may not be null"); - } - if ((this.sourceSpecification.getWorkspaceId() != null) && ((this.sourceSpecification.getWorkspaceType() == null) || (this.sourceSpecification.getWorkspaceAccessType() == null))) - { - throw new RuntimeException("workspace type and access type are required when workspace id is specified"); - } - } - - @Override protected String getReference() { - return this.revisionId == null ? getBranchName(projectId, sourceSpecification) : this.revisionId; + return (this.revisionId == null) ? getReferenceForSourceSpec(this.projectId, this.sourceSpecification) : this.revisionId; } - @Override protected String getDescriptionForExceptionMessage() { - return BaseGitLabApi.getReferenceInfo(this.projectId, this.sourceSpecification.getWorkspaceId(), this.sourceSpecification.getWorkspaceType(), this.sourceSpecification.getWorkspaceAccessType(), this.revisionId); + return getReferenceInfo(this.projectId, this.sourceSpecification, this.revisionId); } } - private class GitLabProjectVersionFileAccessContext extends AbstractGitLabFileAccessContext + private class GitLabRevisionAccessContext implements RevisionAccessContext { - private final VersionId versionId; - - private GitLabProjectVersionFileAccessContext(GitLabProjectId projectId, VersionId versionId) - { - super(projectId); - this.versionId = versionId; - } - - @Override - protected String getReference() - { - return buildVersionTagName(this.versionId); - } - - @Override - protected String getDescriptionForExceptionMessage() - { - return this.versionId.appendVersionIdString(new StringBuilder("version ")).append(" of project ").append(this.projectId).toString(); - } - } - - private abstract class AbstractGitLabRevisionAccessContext implements RevisionAccessContext - { - protected final GitLabProjectId projectId; - protected final MutableList paths; + private final GitLabProjectId projectId; + private final SourceSpecification sourceSpecification; + private final MutableList paths; // Either file or directory paths should already have been canonicalized at this point. - AbstractGitLabRevisionAccessContext(GitLabProjectId projectId, Iterable canonicalPaths) + GitLabRevisionAccessContext(GitLabProjectId projectId, SourceSpecification sourceSpecification, Iterable canonicalPaths) { this.projectId = projectId; + this.sourceSpecification = Objects.requireNonNull(sourceSpecification, "source specification may not be null"); if (canonicalPaths == null) { this.paths = null; @@ -596,17 +574,22 @@ private Commit getCurrentCommit(CommitsApi commitsApi, String referenceId, Strin @Override public Revision getBaseRevision() + { + String reference = getReference(); + return (this.sourceSpecification instanceof WorkspaceSourceSpecification) ? getWorkspaceBaseRevision(reference) : getBaseRevision(reference); + } + + private Revision getBaseRevision(String reference) { try { CommitsApi commitsApi = getGitLabApi().getCommitsApi(); - String referenceId = getReference(); // Search for base commit Commit baseCommit; if (this.paths == null) { - baseCommit = getBaseCommit(commitsApi, referenceId, null); + baseCommit = getBaseCommit(commitsApi, reference, null); } else { @@ -614,7 +597,7 @@ public Revision getBaseRevision() baseCommit = null; for (String path : this.paths) { - Commit basePathCommit = getBaseCommit(commitsApi, referenceId, path); + Commit basePathCommit = getBaseCommit(commitsApi, reference, path); if (comparator.compare(basePathCommit, baseCommit) < 0) { baseCommit = basePathCommit; @@ -647,6 +630,45 @@ public Revision getBaseRevision() } } + private Revision getWorkspaceBaseRevision(String reference) + { + try + { + RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); + String sourceBranch = getSourceBranch(this.projectId, (WorkspaceSourceSpecification) this.sourceSpecification); + Revision workspaceBaseRevision = fromGitLabCommit(withRetries(() -> repositoryApi.getMergeBase(this.projectId.getGitLabId(), Lists.fixedSize.with(sourceBranch, reference)))); + if (this.paths == null) + { + return workspaceBaseRevision; + } + + Revision pathsBaseRevision = getBaseRevision(reference); + if (workspaceBaseRevision == null) + { + return pathsBaseRevision; + } + if (pathsBaseRevision == null) + { + return workspaceBaseRevision; + } + if (Objects.equals(workspaceBaseRevision.getId(), pathsBaseRevision.getId())) + { + return workspaceBaseRevision; + } + + Instant workspaceCommitted = workspaceBaseRevision.getCommittedTimestamp(); + Instant pathCommitted = pathsBaseRevision.getCommittedTimestamp(); + return ((pathCommitted != null) && (workspaceCommitted != null) && pathCommitted.isAfter(workspaceCommitted)) ? pathsBaseRevision : workspaceBaseRevision; + } + catch (Exception e) + { + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to get base revision for " + getDescriptionForExceptionMessage(), + () -> "Unknown: " + getDescriptionForExceptionMessage(), + () -> "Error getting base revision for " + getDescriptionForExceptionMessage()); + } + } + private Commit getBaseCommit(CommitsApi commitsApi, String referenceId, String filePath) throws GitLabApiException { Pager pager = withRetries(() -> commitsApi.getCommits(this.projectId.getGitLabId(), referenceId, null, null, filePath, 1)); @@ -808,9 +830,23 @@ private Stream getAllCommits(CommitsApi commitsApi, String branchName, D return commitStream; } - protected abstract String getReference(); + protected String getReference() + { + return getReferenceForSourceSpec(this.projectId, this.sourceSpecification); + } - protected abstract boolean referenceExists() throws GitLabApiException; + protected boolean referenceExists() throws GitLabApiException + { + if (this.sourceSpecification instanceof ProjectSourceSpecification) + { + return true; + } + if (this.sourceSpecification instanceof VersionSourceSpecification) + { + return GitLabApiTools.tagExists(getGitLabApi(), this.projectId.getGitLabId(), getReference()); + } + return GitLabApiTools.branchExists(getGitLabApi(), this.projectId.getGitLabId(), getReference()); + } protected String getDescriptionForExceptionMessage() { @@ -828,181 +864,55 @@ protected String getDescriptionForExceptionMessage() builder.append(" in "); } int lengthBefore = builder.length(); - appendReferenceDescription(builder); - if (builder.length() != lengthBefore) + this.sourceSpecification.visit(new SourceSpecificationConsumer() { - builder.append(" in "); - } - builder.append("project ").append(this.projectId); - return builder.toString(); - - } - - protected abstract void appendReferenceDescription(StringBuilder builder); - } - - private class GitLabRevisionAccessContext extends AbstractGitLabRevisionAccessContext - { - private final SourceSpecification sourceSpecification; - - private GitLabRevisionAccessContext(GitLabProjectId projectId, SourceSpecification sourceSpecification, Iterable paths) - { - super(projectId, paths); - this.sourceSpecification = sourceSpecification; - if (sourceSpecification == null) - { - throw new RuntimeException("source specification may not be null"); - } - if ((this.sourceSpecification.getWorkspaceId() != null) && ((this.sourceSpecification.getWorkspaceType() == null) || (this.sourceSpecification.getWorkspaceAccessType() == null))) - { - throw new RuntimeException("workspace type and access type are required when workspace id is specified"); - } - } - - @Override - protected String getReference() - { - return getBranchName(this.projectId, this.sourceSpecification); - } - - @Override - protected boolean referenceExists() throws GitLabApiException - { - if (this.sourceSpecification.getWorkspaceId() == null) - { - return true; - } - - try - { - RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - Branch branch = withRetries(() -> repositoryApi.getBranch(this.projectId.getGitLabId(), getReference())); - return branch != null; - } - catch (GitLabApiException e) - { - if (GitLabApiTools.isNotFoundGitLabApiException(e)) + @Override + protected void accept(VersionSourceSpecification sourceSpec) { - return false; + sourceSpec.getVersionId().appendVersionIdString(builder.append("version ")); } - throw e; - } - } - - @Override - protected void appendReferenceDescription(StringBuilder builder) - { - if (this.sourceSpecification.getWorkspaceId() != null) - { - builder.append(this.sourceSpecification.getWorkspaceType().getLabel()).append(" ").append(this.sourceSpecification.getWorkspaceAccessType().getLabel()).append(" ").append(this.sourceSpecification.getWorkspaceId()); - } - } - - @Override - public Revision getBaseRevision() - { - if (this.sourceSpecification.getWorkspaceId() == null) - { - return super.getBaseRevision(); - } - try - { - RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - Revision workspaceBaseRevision = fromGitLabCommit(withRetries(() -> repositoryApi.getMergeBase(this.projectId.getGitLabId(), Lists.fixedSize.with(getSourceBranch(projectId, sourceSpecification.getPatchReleaseVersionId()), getReference())))); - if (this.paths == null) + @Override + protected void accept(PatchSourceSpecification sourceSpec) { - return workspaceBaseRevision; + sourceSpec.getVersionId().appendVersionIdString(builder.append("patch ")); } - Revision pathsBaseRevision = super.getBaseRevision(); - if (workspaceBaseRevision == null) + @Override + protected void accept(WorkspaceSourceSpecification sourceSpec) { - return pathsBaseRevision; - } - if (pathsBaseRevision == null) - { - return workspaceBaseRevision; - } - if (Objects.equals(workspaceBaseRevision.getId(), pathsBaseRevision.getId())) - { - return workspaceBaseRevision; + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + builder.append(workspaceSpec.getType().getLabel()).append(" ").append(workspaceSpec.getAccessType().getLabel()).append(" ").append(workspaceSpec.getId()); + workspaceSpec.getSource().visit(new WorkspaceSourceConsumer() + { + @Override + protected void accept(PatchWorkspaceSource source) + { + source.getPatchVersionId().appendVersionIdString(builder.append(" of patch ")); + } + }); } - - Instant workspaceCommitted = workspaceBaseRevision.getCommittedTimestamp(); - Instant pathCommitted = pathsBaseRevision.getCommittedTimestamp(); - return ((pathCommitted != null) && (workspaceCommitted != null) && pathCommitted.isAfter(workspaceCommitted)) ? pathsBaseRevision : workspaceBaseRevision; - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get base revision for " + getDescriptionForExceptionMessage(), - () -> "Unknown: " + getDescriptionForExceptionMessage(), - () -> "Error getting base revision for " + getDescriptionForExceptionMessage()); - } - } - } - - private class GitLabProjectVersionRevisionAccessContext extends AbstractGitLabRevisionAccessContext - { - private final VersionId versionId; - - private GitLabProjectVersionRevisionAccessContext(GitLabProjectId projectId, VersionId versionId, Iterable paths) - { - super(projectId, paths); - this.versionId = versionId; - } - - @Override - protected String getReference() - { - return buildVersionTagName(this.versionId); - } - - @Override - protected boolean referenceExists() throws GitLabApiException - { - try - { - Tag tag = getGitLabApi().getTagsApi().getTag(this.projectId.getGitLabId(), getReference()); - return tag != null; - } - catch (GitLabApiException e) + }); + if (builder.length() != lengthBefore) { - if (GitLabApiTools.isNotFoundGitLabApiException(e)) - { - return false; - } - throw e; + builder.append(" in "); } - } - - @Override - protected void appendReferenceDescription(StringBuilder builder) - { - this.versionId.appendVersionIdString(builder.append("version ")); + builder.append("project ").append(this.projectId); + return builder.toString(); } } - private class GitLabProjectFileFileModificationContext implements FileModificationContext + private class GitLabFileFileModificationContext implements FileModificationContext { private final GitLabProjectId projectId; private final String revisionId; private final SourceSpecification sourceSpecification; - private GitLabProjectFileFileModificationContext(GitLabProjectId projectId, SourceSpecification sourceSpecification, String revisionId) + private GitLabFileFileModificationContext(GitLabProjectId projectId, SourceSpecification sourceSpecification, String revisionId) { this.projectId = projectId; + this.sourceSpecification = Objects.requireNonNull(sourceSpecification, "source specification may not be null"); this.revisionId = revisionId; - this.sourceSpecification = sourceSpecification; - if (sourceSpecification == null) - { - throw new RuntimeException("source specification may not be null"); - } - if ((this.sourceSpecification.getWorkspaceId() != null) && ((this.sourceSpecification.getWorkspaceType() == null) || (this.sourceSpecification.getWorkspaceAccessType() == null))) - { - throw new RuntimeException("workspace type and access type are required when workspace id is specified"); - } } @Override @@ -1052,9 +962,8 @@ public Revision submit(String message, List oper } catch (Exception e) { - // TODO improve exception handling throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to perform changes on " + this.sourceSpecification.getWorkspaceType().getLabel() + " " + this.sourceSpecification.getWorkspaceAccessType().getLabel() + " " + this.sourceSpecification.getWorkspaceId() + " in project " + this.projectId, + () -> "User " + getCurrentUser() + " is not allowed to perform changes on " + getDescription(), () -> "Unknown " + getDescription(), () -> "Failed to perform changes on " + getDescription() + " (message: " + message + ")"); } @@ -1189,7 +1098,7 @@ private Commit commitWithTemporaryBranch(String message, List comm private String getDescription() { - return BaseGitLabApi.getReferenceInfo(this.projectId, this.sourceSpecification.getWorkspaceId(), this.sourceSpecification.getWorkspaceType(), this.sourceSpecification.getWorkspaceAccessType(), null); + return getReferenceInfo(this.projectId, this.sourceSpecification, this.revisionId); } } @@ -1236,7 +1145,7 @@ private String toGitLabFilePath(String path) private TemporaryBranch newTemporaryBranch(GitLabProjectId projectId, SourceSpecification sourceSpecification, String referenceRevisionId) { String initialRevisionId = (referenceRevisionId == null) ? getCurrentRevisionId(projectId, sourceSpecification) : referenceRevisionId; - return new TemporaryBranch(projectId, sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), sourceSpecification.getWorkspaceAccessType(), initialRevisionId); + return new TemporaryBranch(projectId, sourceSpecification, initialRevisionId); } private static boolean shouldRetryOnException(Exception e) @@ -1328,20 +1237,16 @@ protected static boolean waitForPipelinesDeleteBranchAndVerify(GitLabApi gitLabA private class TemporaryBranch implements AutoCloseable { private final GitLabProjectId projectId; - private final String workspaceId; - private final WorkspaceType workspaceType; - private final WorkspaceAccessType workspaceAccessType; + private final SourceSpecification sourceSpec; private final String referenceCommitId; private String tempBranchName; private String lastSuccessfulCommitId; private boolean closed = false; - private TemporaryBranch(GitLabProjectId projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String referenceCommitId) + private TemporaryBranch(GitLabProjectId projectId, SourceSpecification sourceSpec, String referenceCommitId) { this.projectId = projectId; - this.workspaceId = workspaceId; - this.workspaceType = workspaceType; - this.workspaceAccessType = workspaceAccessType; + this.sourceSpec = sourceSpec; this.referenceCommitId = referenceCommitId; } @@ -1381,11 +1286,7 @@ synchronized Commit commit(String message, List commitActions) int statusCode = glae.getHttpStatus(); if (Family.familyOf(statusCode) == Family.CLIENT_ERROR) { - StringBuilder builder = new StringBuilder("Error committing to temporary branch ").append(this.tempBranchName) - .append("for ").append(this.workspaceType.getLabel()).append(" ").append(this.workspaceAccessType.getLabel()).append(" ").append(this.workspaceId) - .append(" in project ").append(this.projectId); - StringTools.appendThrowableMessageIfPresent(builder, e); - String msg = builder.toString(); + String msg = StringTools.appendThrowableMessageIfPresent(appendReferenceInfo(new StringBuilder("Error committing to temporary branch ").append(this.tempBranchName).append(" for "), this.projectId.toString(), this.sourceSpec), e).toString(); LOGGER.error(msg, e); if (LOGGER.isDebugEnabled()) { @@ -1411,12 +1312,8 @@ synchronized Commit commit(String message, List commitActions) } // Reached the max number of retries, give up - StringBuilder builder = new StringBuilder("Failed to commit to temporary branch for ") - .append(this.workspaceType.getLabel()).append(" ").append(this.workspaceAccessType.getLabel()).append(" ").append(this.workspaceId) - .append(" in project ").append(this.projectId) - .append(" after ").append(MAX_COMMIT_RETRIES).append(" tries"); - StringTools.appendThrowableMessageIfPresent(builder, lastException); - String msg = builder.toString(); + StringBuilder builder = appendReferenceInfo(new StringBuilder("Failed to commit to temporary branch for "), this.projectId.toString(), this.sourceSpec).append(" after ").append(MAX_COMMIT_RETRIES).append(" tries"); + String msg = StringTools.appendThrowableMessageIfPresent(builder, lastException).toString(); LOGGER.error(msg, lastException); throw new LegendSDLCServerException(msg, lastException); } @@ -1434,7 +1331,7 @@ synchronized Branch replaceTargetAndDelete() throw new IllegalStateException("No commits on temporary branch " + this.tempBranchName + " in project " + this.projectId); } - String targetBranchName = GitLabApiWithFileAccess.this.getBranchName(this.projectId, SourceSpecification.newSourceSpecification(this.workspaceId, this.workspaceType, this.workspaceAccessType)); + String targetBranchName = GitLabApiWithFileAccess.this.getBranchName(this.projectId, this.sourceSpec); LOGGER.debug("Replacing target branch {} with temporary branch {} in project {}", targetBranchName, this.tempBranchName, this.projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); @@ -1447,9 +1344,9 @@ synchronized Branch replaceTargetAndDelete() catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId, - () -> "Unknown " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " (" + this.workspaceId + ") or project (" + this.projectId + ")", - () -> "Failed to get " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId); + () -> "User " + getCurrentUser() + " is not allowed to get " + getReferenceInfo(this.projectId, this.sourceSpec), + () -> "Unknown " + getReferenceInfo(this.projectId, this.sourceSpec), + () -> "Failed to get " + getReferenceInfo(this.projectId, this.sourceSpec)); } if (targetBranch != null) @@ -1458,7 +1355,7 @@ synchronized Branch replaceTargetAndDelete() String targetBranchCommitId = (targetBranchCommit == null) ? null : targetBranchCommit.getId(); if (!this.referenceCommitId.equals(targetBranchCommitId)) { - throw new LegendSDLCServerException("Expected " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " to be at revision " + this.referenceCommitId + ", found " + targetBranchCommitId); + throw new LegendSDLCServerException("Expected " + getReferenceInfo(this.projectId, this.sourceSpec) + " to be at revision " + this.referenceCommitId + ", found " + targetBranchCommitId); } boolean oldDeleted; @@ -1469,13 +1366,13 @@ synchronized Branch replaceTargetAndDelete() catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId, - () -> "Unknown " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " (" + this.workspaceId + ") or project (" + this.projectId + ")", - () -> "Failed to delete " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(this.projectId, this.sourceSpec), + () -> "Unknown " + getReferenceInfo(this.projectId, this.sourceSpec), + () -> "Failed to delete " + getReferenceInfo(this.projectId, this.sourceSpec)); } if (!oldDeleted) { - throw new LegendSDLCServerException("Failed to delete " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(this.projectId, this.sourceSpec)); } } @@ -1487,13 +1384,13 @@ synchronized Branch replaceTargetAndDelete() catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId + " from revision " + this.lastSuccessfulCommitId, - () -> "Unknown revision (" + this.lastSuccessfulCommitId + "), " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " (" + this.workspaceId + ") or project (" + this.projectId + ")", - () -> "Failed to create " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId + " from revision " + this.lastSuccessfulCommitId); + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(this.projectId, this.sourceSpec) + " from revision " + this.lastSuccessfulCommitId, + () -> "Unknown revision (" + this.lastSuccessfulCommitId + ") or " + getReferenceInfo(this.projectId, this.sourceSpec), + () -> "Failed to create " + getReferenceInfo(this.projectId, this.sourceSpec) + " from revision " + this.lastSuccessfulCommitId); } if (newBranch == null) { - throw new LegendSDLCServerException("Failed to create " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId + " from revision " + this.lastSuccessfulCommitId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(this.projectId, this.sourceSpec) + " from revision " + this.lastSuccessfulCommitId); } deleteTempBranch(this.tempBranchName); @@ -1506,7 +1403,7 @@ public synchronized void delete() checkOpen(); if (this.tempBranchName == null) { - LOGGER.debug("No temporary branch to delete for {} {} in project {}", this.workspaceType.getLabel(), this.workspaceAccessType.getLabel(), this.projectId); + LOGGER.debug("No temporary branch to delete for {} in project {}", this.sourceSpec, this.projectId); } else { @@ -1526,24 +1423,24 @@ public synchronized void close() private synchronized void createNewTempBranch() { - String newTempBranchName = newUserTemporaryBranchName(this.workspaceId); + String newTempBranchName = newUserTemporaryBranchName(this.sourceSpec); String branchCreationRef = (this.lastSuccessfulCommitId == null) ? this.referenceCommitId : this.lastSuccessfulCommitId; - LOGGER.debug("Creating temporary branch for {} {} {} in project {} from {}: {}", this.workspaceType.getLabel(), this.workspaceAccessType.getLabel(), this.workspaceId, this.projectId, branchCreationRef, newTempBranchName); + LOGGER.debug("Creating temporary branch for {} in project {} from {}: {}", this.sourceSpec, this.projectId, branchCreationRef, newTempBranchName); // Create new temp branch RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); Branch tempBranch; try { tempBranch = GitLabApiTools.createBranchAndVerify(repositoryApi, this.projectId.getGitLabId(), newTempBranchName, branchCreationRef, 30, 1_000); - LOGGER.debug("Created temporary branch for {} {} {} in project {} from {}: {}", this.workspaceType.getLabel(), this.workspaceAccessType.getLabel(), this.workspaceId, this.projectId, branchCreationRef, newTempBranchName); + LOGGER.debug("Created temporary branch for {} in project {} from {}: {}", this.sourceSpec, this.projectId, branchCreationRef, newTempBranchName); } catch (Exception e) { - LOGGER.debug("Failed to create temporary branch for {} {} {} in project {} from {}: {}", this.workspaceType.getLabel(), this.workspaceAccessType.getLabel(), this.workspaceId, this.projectId, branchCreationRef, newTempBranchName); + LOGGER.debug("Failed to create temporary branch for {} in project {} from {}: {}", this.sourceSpec, this.projectId, branchCreationRef, newTempBranchName); throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to create temporary branch " + newTempBranchName + " in project " + this.projectId + " from revision " + branchCreationRef, () -> "Unknown project " + this.projectId + " or revision " + branchCreationRef, - () -> "Error creating temporary branch " + newTempBranchName + " for " + this.workspaceType.getLabel() + " " + this.workspaceAccessType.getLabel() + " " + this.workspaceId + " in project " + this.projectId + " from revision " + branchCreationRef); + () -> "Error creating temporary branch " + newTempBranchName + " for " + getReferenceInfo(this.projectId, this.sourceSpec) + " from revision " + branchCreationRef); } if (tempBranch == null) { diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBackupApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBackupApi.java index 3e22407be9..4bcf8a0ef3 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBackupApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBackupApi.java @@ -15,13 +15,13 @@ package org.finos.legend.sdlc.server.gitlab.api; import org.finos.legend.sdlc.server.domain.api.backup.BackupApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; import org.finos.legend.sdlc.server.gitlab.tools.GitLabApiTools; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import org.finos.legend.sdlc.server.tools.BackgroundTaskProcessor; import org.gitlab4j.api.RepositoryApi; import org.gitlab4j.api.models.Branch; @@ -42,28 +42,30 @@ public GitLabBackupApi(GitLabConfiguration gitLabConfiguration, GitLabUserContex } @Override - public void discardBackupWorkspace(String projectId, SourceSpecification sourceSpecification) + public void discardBackupWorkspace(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); + WorkspaceSpecification backupWorkspaceSpec = (workspaceSpecification.getAccessType() == WorkspaceAccessType.BACKUP) ? + workspaceSpecification : + WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.BACKUP, workspaceSpecification.getSource(), workspaceSpecification.getUserId()); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - boolean backupWorkspaceDeleted; - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; try { - backupWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + boolean success = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(backupWorkspaceSpec), 20, 1_000); + if (!success) + { + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, backupWorkspaceSpec)); + } } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); - } - if (!backupWorkspaceDeleted) - { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, backupWorkspaceSpec)); } } @@ -74,97 +76,112 @@ public void discardBackupWorkspace(String projectId, SourceSpecification sourceS * 3. Create */ @Override - public void recoverBackupWorkspace(String projectId, SourceSpecification sourceSpecification, boolean forceRecovery) + public void recoverBackupWorkspace(String projectId, WorkspaceSpecification workspaceSpecification, boolean forceRecovery) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); + + WorkspaceSpecification mainWorkspaceSpec = (workspaceSpecification.getAccessType() == WorkspaceAccessType.WORKSPACE) ? + workspaceSpecification : + WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.WORKSPACE, workspaceSpecification.getSource(), workspaceSpecification.getUserId()); + WorkspaceSpecification backupWorkspaceSpec = (workspaceSpecification.getAccessType() == WorkspaceAccessType.BACKUP) ? + workspaceSpecification : + WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.BACKUP, workspaceSpecification.getSource(), workspaceSpecification.getUserId()); + + String mainWorkspaceBranchName = getWorkspaceBranchName(mainWorkspaceSpec); + String backupWorkspaceBranchName = getWorkspaceBranchName(backupWorkspaceSpec); + RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; + // Verify the backup exists try { - withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())))); + withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), backupWorkspaceBranchName)); } catch (Exception e) { - if (GitLabApiTools.isNotFoundGitLabApiException(e)) - { - LOGGER.error("No backup for workspace {} in project {}, so recovery is not possible", sourceSpecification.getWorkspaceId(), projectId); - } throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " with (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + "). " + "This implies that a backup does not exist for the specified workspace, hence recovery is not possible", - () -> "Error getting " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "A backup cannot be found for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ", so recovery is not possible", + () -> "Error getting " + getReferenceInfo(projectId, backupWorkspaceSpec)); } - Branch existingBranch = null; - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; + // Check if branch exists + Branch existingBranch = null; try { - existingBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())))); + existingBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), mainWorkspaceBranchName)); } catch (Exception e) { if (!GitLabApiTools.isNotFoundGitLabApiException(e)) { - LOGGER.error("Error getting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, mainWorkspaceSpec), + null, + () -> "Error getting " + getReferenceInfo(projectId, mainWorkspaceSpec)); } } if (existingBranch != null) { if (!forceRecovery) { - throw new LegendSDLCServerException("Workspace " + sourceSpecification.getWorkspaceId() + " of project " + projectId + " already existed and the recovery is not forced, so recovery from backup is not possible", Response.Status.METHOD_NOT_ALLOWED); + throw new LegendSDLCServerException(getReferenceInfo(projectId, mainWorkspaceSpec) + " already exists and the recovery is not forced, so recovery from backup is not possible", Response.Status.CONFLICT); } // Delete the existing branch boolean workspaceDeleted; try { - workspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + workspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), mainWorkspaceBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "Error while attempting to recover backup for " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": User " + getCurrentUser() + " is not allowed to delete workspace", - () -> "Error while attempting to recover backup for " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": Unknown project: " + projectId, - () -> "Error while attempting to recover backup for " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": Error deleting workspace"); + () -> "Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": user " + getCurrentUser() + " is not allowed to delete workspace", + () -> "Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": Unknown project: " + projectId, + () -> "Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": Error deleting workspace"); } if (!workspaceDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, mainWorkspaceSpec)); } } // Create new workspace branch off the backup branch head Branch workspaceBranch; try { - workspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 30, 1_000); + workspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), mainWorkspaceBranchName, backupWorkspaceBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": user " + getCurrentUser() + " is not allowed to create workspace", + () -> "Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": unknown project: " + projectId, + () -> "Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": error creating workspace"); } if (workspaceBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + " from " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId()); + throw new LegendSDLCServerException("Error while attempting to recover backup for " + getReferenceInfo(projectId, mainWorkspaceSpec) + ": failed to create workspace"); } + // Delete backup branch + boolean deleted; try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); - if (!deleted) - { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); - } + deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupWorkspaceBranchName, 20, 1_000); } catch (Exception e) { // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {} after recovery is completed", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); + LOGGER.error("Error deleting {} in project {} after recovery is completed", backupWorkspaceBranchName, projectId, e); + deleted = false; + } + if (!deleted) + { + LOGGER.warn("Failed to delete {} in project {}, submitting background task", backupWorkspaceBranchName, projectId); + submitBackgroundRetryableTask(() -> GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupWorkspaceBranchName, 5, 1_000), 5000L, "delete " + backupWorkspaceBranchName); } } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBuildApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBuildApi.java index 89eadfd44f..45961cd8fd 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBuildApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabBuildApi.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.build.BuildAccessContext; import org.finos.legend.sdlc.server.domain.api.build.BuildApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApi.java index ce60713c82..a662513f52 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApi.java @@ -18,97 +18,155 @@ import org.finos.legend.sdlc.domain.model.comparison.Comparison; import org.finos.legend.sdlc.domain.model.comparison.EntityDiff; import org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.comparison.ComparisonApi; -import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; +import org.finos.legend.sdlc.server.project.ProjectPaths; import org.finos.legend.sdlc.server.project.ProjectStructure; import org.finos.legend.sdlc.server.tools.BackgroundTaskProcessor; +import org.gitlab4j.api.GitLabApi; import org.gitlab4j.api.RepositoryApi; +import org.gitlab4j.api.models.Branch; import org.gitlab4j.api.models.Commit; import org.gitlab4j.api.models.CompareResults; import org.gitlab4j.api.models.Diff; import org.gitlab4j.api.models.DiffRef; import org.gitlab4j.api.models.MergeRequest; -import javax.inject.Inject; -import javax.ws.rs.core.Response; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import javax.inject.Inject; +import javax.ws.rs.core.Response; public class GitLabComparisonApi extends GitLabApiWithFileAccess implements ComparisonApi { - private final RevisionApi revisionApi; - protected static final String FILE_PATH_DELIMITER = "/"; - @Inject - public GitLabComparisonApi(GitLabConfiguration gitLabConfiguration, GitLabUserContext userContext, RevisionApi revisionApi, BackgroundTaskProcessor backgroundTaskProcessor) + public GitLabComparisonApi(GitLabConfiguration gitLabConfiguration, GitLabUserContext userContext, BackgroundTaskProcessor backgroundTaskProcessor) { super(gitLabConfiguration, userContext, backgroundTaskProcessor); - this.revisionApi = revisionApi; } @Override - public Comparison getWorkspaceCreationComparison(String projectId, SourceSpecification sourceSpecification) + public Comparison getWorkspaceCreationComparison(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - String currentWorkspaceRevisionId = this.revisionApi.getWorkspaceRevisionContext(projectId, sourceSpecification).getCurrentRevision().getId(); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; - ProjectStructure toProjectStructure = getProjectStructure(gitLabProjectId.toString(), SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId()), currentWorkspaceRevisionId); - String workspaceCreationRevisionId; - String sourceBranch = getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()); + + Commit currentCommit; + try + { + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); + Branch workspaceBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), workspaceBranchName)); + currentCommit = workspaceBranch.getCommit(); + } + catch (Exception e) + { + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to access the current revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Could not find current revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Failed to find current revision for " + getReferenceInfo(projectId, workspaceSpecification)); + } + if (currentCommit == null) + { + throw new LegendSDLCServerException("Could not access current revision for " + getReferenceInfo(projectId, workspaceSpecification)); + } + + Commit creationCommit; try { - Commit commit = repositoryApi.getMergeBase(gitLabProjectId.getGitLabId(), Arrays.asList(sourceBranch, currentWorkspaceRevisionId)); - workspaceCreationRevisionId = commit.getId(); + String sourceBranchName = getSourceBranch(gitLabProjectId, workspaceSpecification); + creationCommit = repositoryApi.getMergeBase(gitLabProjectId.getGitLabId(), Arrays.asList(sourceBranchName, currentCommit.getId())); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get merged based revision for revisions " + sourceBranch + ", " + currentWorkspaceRevisionId + " from project " + gitLabProjectId, - () -> "Could not find revisions " + sourceBranch + ", " + currentWorkspaceRevisionId + " from project " + gitLabProjectId, - () -> "Failed to fetch Merged Base Information for revisions " + sourceBranch + ", " + currentWorkspaceRevisionId + " from project " + gitLabProjectId); + () -> "User " + getCurrentUser() + " is not allowed to access the creation revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Could not find creation revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Failed to find creation revision for " + getReferenceInfo(projectId, workspaceSpecification)); + } + if (creationCommit == null) + { + throw new LegendSDLCServerException("Could not access creation revision for " + getReferenceInfo(projectId, workspaceSpecification)); } - ProjectStructure fromProjectStructure = getProjectStructure(gitLabProjectId.toString(), SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId()), workspaceCreationRevisionId); - return getComparisonResult(gitLabProjectId, repositoryApi, workspaceCreationRevisionId, currentWorkspaceRevisionId, fromProjectStructure, toProjectStructure); + + ProjectStructure currentProjectStructure = getProjectStructure(projectId, workspaceSpecification.getSourceSpecification(), currentCommit.getId()); + ProjectStructure creationProjectStructure = getProjectStructure(projectId, workspaceSpecification.getSourceSpecification(), creationCommit.getId()); + return getComparisonResult(gitLabProjectId, repositoryApi, creationCommit.getId(), currentCommit.getId(), creationProjectStructure, currentProjectStructure); } @Override - public Comparison getWorkspaceProjectComparison(String projectId, SourceSpecification sourceSpecification) + public Comparison getWorkspaceSourceComparison(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - String currentProjectRevisionId = this.revisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; - ProjectStructure fromProjectStructure = getProjectStructure(gitLabProjectId.toString(), SourceSpecification.newSourceSpecification(getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId()), currentProjectRevisionId); - String currentWorkspaceRevisionId = this.revisionApi.getWorkspaceRevisionContext(projectId, sourceSpecification).getCurrentRevision().getId(); - ProjectStructure toProjectStructure = getProjectStructure(gitLabProjectId.toString(), SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId()), currentWorkspaceRevisionId); - return getComparisonResult(gitLabProjectId, repositoryApi, currentProjectRevisionId, currentWorkspaceRevisionId, fromProjectStructure, toProjectStructure); + Commit workspaceCommit; + try + { + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); + Branch workspaceBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), workspaceBranchName)); + workspaceCommit = workspaceBranch.getCommit(); + } + catch (Exception e) + { + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to access the current revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Could not find current revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Failed to find current revision for " + getReferenceInfo(projectId, workspaceSpecification)); + } + if (workspaceCommit == null) + { + throw new LegendSDLCServerException("Could not access current revision for " + getReferenceInfo(projectId, workspaceSpecification)); + } + + Commit sourceCommit; + try + { + String sourceBranchName = getSourceBranch(gitLabProjectId, workspaceSpecification); + Branch sourceBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), sourceBranchName)); + sourceCommit = sourceBranch.getCommit(); + } + catch (Exception e) + { + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to access the current revision for " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Could not find current revision for " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Failed to find current revision for " + getReferenceInfo(projectId, workspaceSpecification.getSource())); + } + if (sourceCommit == null) + { + throw new LegendSDLCServerException("Could not access current revision for " + getReferenceInfo(projectId, workspaceSpecification.getSource())); + } + + ProjectStructure workspaceProjectStructure = getProjectStructure(projectId, workspaceSpecification.getSourceSpecification(), workspaceCommit.getId()); + ProjectStructure sourceProjectStructure = getProjectStructure(projectId, workspaceSpecification.getSource().getSourceSpecification(), sourceCommit.getId()); + return getComparisonResult(gitLabProjectId, repositoryApi, sourceCommit.getId(), workspaceCommit.getId(), sourceProjectStructure, workspaceProjectStructure); } @Override - public Comparison getReviewComparison(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Comparison getReviewComparison(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); - RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); + GitLabApi gitLabApi = getGitLabApi(); + RepositoryApi repositoryApi = gitLabApi.getRepositoryApi(); + + MergeRequest mergeRequest = getReviewMergeRequest(gitLabApi.getMergeRequestApi(), gitLabProjectId, reviewId); - WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); - if (workspaceInfo == null) + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + if (workspaceSpec == null) { throw new LegendSDLCServerException("Unknown review in project " + projectId + ": " + reviewId, Response.Status.NOT_FOUND); } @@ -121,36 +179,38 @@ public Comparison getReviewComparison(String projectId, VersionId patchReleaseVe String fromRevisionId = diffRef.getStartSha(); String toRevisionId = diffRef.getHeadSha(); - ProjectStructure fromProjectStructure = getProjectStructure(projectId, SourceSpecification.newSourceSpecification(workspaceInfo.getWorkspaceId(),workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType(), patchReleaseVersionId), fromRevisionId); - ProjectStructure toProjectStructure = getProjectStructure(gitLabProjectId.toString(), SourceSpecification.newSourceSpecification(patchReleaseVersionId), toRevisionId); + ProjectStructure fromProjectStructure = getProjectStructure(projectId, workspaceSpec.getSourceSpecification(), fromRevisionId); + ProjectStructure toProjectStructure = getProjectStructure(projectId, workspaceSpec.getSource().getSourceSpecification(), toRevisionId); return getComparisonResult(gitLabProjectId, repositoryApi, fromRevisionId, toRevisionId, fromProjectStructure, toProjectStructure); } @Override - public Comparison getReviewWorkspaceCreationComparison(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Comparison getReviewWorkspaceCreationComparison(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); - RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); + GitLabApi gitLabApi = getGitLabApi(); + RepositoryApi repositoryApi = gitLabApi.getRepositoryApi(); + MergeRequest mergeRequest = getReviewMergeRequest(gitLabApi.getMergeRequestApi(), gitLabProjectId, reviewId); - WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); - if (workspaceInfo == null) + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + if (workspaceSpec == null) { throw new LegendSDLCServerException("Unknown review in project " + projectId + ": " + reviewId, Response.Status.NOT_FOUND); } DiffRef diffRef = mergeRequest.getDiffRefs(); - if ((diffRef == null) || (diffRef.getStartSha() == null) || (diffRef.getHeadSha() == null)) + if ((diffRef == null) || (diffRef.getBaseSha() == null) || (diffRef.getHeadSha() == null)) { throw new LegendSDLCServerException("Unable to get revision info for review " + reviewId + " in project " + projectId); } String fromRevisionId = diffRef.getBaseSha(); String toRevisionId = diffRef.getHeadSha(); - ProjectStructure fromProjectStructure = getProjectStructure(projectId, SourceSpecification.newSourceSpecification(workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType(), patchReleaseVersionId), fromRevisionId); - ProjectStructure toProjectStructure = getProjectStructure(projectId, SourceSpecification.newSourceSpecification(workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType(), patchReleaseVersionId), toRevisionId); + ProjectStructure fromProjectStructure = getProjectStructure(projectId, workspaceSpec.getSourceSpecification(), fromRevisionId); + ProjectStructure toProjectStructure = getProjectStructure(projectId, workspaceSpec.getSourceSpecification(), toRevisionId); return getComparisonResult(gitLabProjectId, repositoryApi, fromRevisionId, toRevisionId, fromProjectStructure, toProjectStructure); } @@ -198,8 +258,8 @@ private static Comparison newComparison(String fromRevisionId, String toRevision // 1. entity file changes - which we should handle without any problem // 2. project configuration changes - which we will just capture by a boolean flag to indicate if there are any changes // 3. other files: e.g. users can go in and modify pom.xml, add some non-entity files, etc. we DO NOT keep track of these - String oldPath = diff.getOldPath().startsWith(FILE_PATH_DELIMITER) ? diff.getOldPath() : FILE_PATH_DELIMITER + diff.getOldPath(); - String newPath = diff.getNewPath().startsWith(FILE_PATH_DELIMITER) ? diff.getNewPath() : FILE_PATH_DELIMITER + diff.getNewPath(); + String oldPath = ProjectPaths.canonicalizeFile(diff.getOldPath()); + String newPath = ProjectPaths.canonicalizeFile(diff.getNewPath()); // project configuration change if (ProjectStructure.PROJECT_CONFIG_PATH.equals(oldPath) || ProjectStructure.PROJECT_CONFIG_PATH.equals(newPath)) diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabConflictResolutionApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabConflictResolutionApi.java index 4a94b2b544..62c1cc175b 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabConflictResolutionApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabConflictResolutionApi.java @@ -17,15 +17,14 @@ import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; import org.finos.legend.sdlc.server.domain.api.conflictResolution.ConflictResolutionApi; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; import org.finos.legend.sdlc.server.gitlab.tools.GitLabApiTools; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import org.finos.legend.sdlc.server.tools.BackgroundTaskProcessor; -import org.gitlab4j.api.GitLabApiException; import org.gitlab4j.api.RepositoryApi; import org.gitlab4j.api.models.Branch; import org.slf4j.Logger; @@ -47,28 +46,29 @@ public GitLabConflictResolutionApi(GitLabConfiguration gitLabConfiguration, GitL } @Override - public void discardConflictResolution(String projectId, SourceSpecification sourceSpecification) + public void discardConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); + + WorkspaceSpecification conflictResWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.CONFLICT_RESOLUTION); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - boolean conflictResolutionBranchDeleted; - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; try { - conflictResolutionBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + boolean success = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(conflictResWorkspaceSpec), 20, 1_000); + if (!success) + { + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); + } } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); - } - if (!conflictResolutionBranchDeleted) - { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Unknown: " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } } @@ -81,130 +81,146 @@ public void discardConflictResolution(String projectId, SourceSpecification sour * 5. Remove backup branch for `w1` */ @Override - public void discardChangesConflictResolution(String projectId, SourceSpecification sourceSpecification) + public void discardChangesConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; + + WorkspaceSpecification workspaceWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.WORKSPACE); + WorkspaceSpecification conflictResWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.CONFLICT_RESOLUTION); + WorkspaceSpecification backupWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.BACKUP); + + String workspaceBranchName = getWorkspaceBranchName(workspaceWorkspaceSpec); + String conflictResBranchName = getWorkspaceBranchName(conflictResWorkspaceSpec); + String backupBranchName = getWorkspaceBranchName(backupWorkspaceSpec); + // Verify conflict resolution is happening try { - withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())))); + withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), conflictResBranchName)); } catch (Exception e) { if (GitLabApiTools.isNotFoundGitLabApiException(e)) { - LOGGER.error("Conflict resolution is not happening on {} {} in project {}, so discard changes is not actionable", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.debug("Could not find branch {} in project {}: conflict resolution is not happening, so discard changes is not actionable", conflictResBranchName, projectId); } throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + "). " + "This implies that conflict resolution is not taking place, hence discard changes is not actionable", - () -> "Error getting " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, conflictResWorkspaceSpec) + ": conflict resolution is not taking place, hence discard changes is not actionable", + () -> "Error getting " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } + // Delete backup branch if already exists boolean backupWorkspaceDeleted; - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; try { - backupWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + backupWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); } catch (Exception e) { // If we fail to delete the residual backup workspace, we cannot proceed anyway, so we will throw the error here throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, backupWorkspaceSpec)); } if (!backupWorkspaceDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, backupWorkspaceSpec)); } + // Create backup branch Branch workspaceBranch; - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; try { - workspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 30, 1_000); + workspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, workspaceBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Error creating " + getReferenceInfo(projectId, backupWorkspaceSpec)); } if (workspaceBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, backupWorkspaceSpec)); } + // Delete original branch boolean originalBranchDeleted; try { - originalBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + originalBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } if (!originalBranchDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } + // Create new workspace branch off the project HEAD Branch newWorkspaceBranch; try { - newWorkspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()), 30, 1_000); + newWorkspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, getSourceBranch(gitLabProjectId, workspaceWorkspaceSpec), 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, workspaceWorkspaceSpec.getSource()), + () -> "Error creating " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } if (newWorkspaceBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } + // Delete conflict resolution branch boolean conflictResolutionWorkspaceDeleted; try { - conflictResolutionWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + conflictResolutionWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), conflictResBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } if (!conflictResolutionWorkspaceDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } + // Delete backup branch + boolean backupBranchDeleted; try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); - if (!deleted) - { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); - } + backupBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); } catch (Exception e) { // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); + LOGGER.error("Error deleting backup branch {} in project {}", backupBranchName, projectId, e); + backupBranchDeleted = false; + } + if (!backupBranchDeleted) + { + LOGGER.error("Failed to delete backup branch {} in project {}, submitting background task", backupBranchName, projectId); + submitBackgroundRetryableTask(() -> GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 5, 1_000), 5000L, "delete " + backupBranchName); } } @@ -220,106 +236,117 @@ public void discardChangesConflictResolution(String projectId, SourceSpecificati * 7. Remove backup branch `w1` */ @Override - public void acceptConflictResolution(String projectId, SourceSpecification sourceSpecification, PerformChangesCommand command) + public void acceptConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification, PerformChangesCommand command) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; + + WorkspaceSpecification workspaceWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.WORKSPACE); + WorkspaceSpecification conflictResWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.CONFLICT_RESOLUTION); + WorkspaceSpecification backupWorkspaceSpec = getWorkspaceSpecWithAccessType(workspaceSpecification, WorkspaceAccessType.BACKUP); + + String workspaceBranchName = getWorkspaceBranchName(workspaceWorkspaceSpec); + String conflictResBranchName = getWorkspaceBranchName(conflictResWorkspaceSpec); + String backupBranchName = getWorkspaceBranchName(backupWorkspaceSpec); + // Verify conflict resolution is happening try { - withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())))); + withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), conflictResBranchName)); } catch (Exception e) { - if (e instanceof GitLabApiException && GitLabApiTools.isNotFoundGitLabApiException((GitLabApiException) e)) + if (GitLabApiTools.isNotFoundGitLabApiException(e)) { - LOGGER.error("Conflict resolution is not happening on workspace {} in project {}, so accepting conflict resolution is not actionable", sourceSpecification.getWorkspaceId(), projectId); + LOGGER.debug("Could not find branch {} in project {}: conflict resolution is not happening, so accepting conflict resolution is not actionable", conflictResBranchName, projectId); } throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + "). " + "This implies that conflict resolution is not taking place, hence accepting conflict resolution is not actionable", - () -> "Error getting " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to get " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, conflictResWorkspaceSpec) + ": conflict resolution is not taking place, hence accepting conflict resolution is not actionable", + () -> "Error getting " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } + // Perform entity changes to resolve conflicts try { - this.entityApi.getWorkspaceWithConflictResolutionEntityModificationContext(projectId, sourceSpecification).performChanges(command.getEntityChanges(), command.getRevisionId(), command.getMessage()); + this.entityApi.getEntityModificationContext(projectId, conflictResWorkspaceSpec.getSourceSpecification()).performChanges(command.getEntityChanges(), command.getRevisionId(), command.getMessage()); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to apply conflict resolution changes in " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + "). " + "This implies that conflict resolution is not taking place, hence accept is not actionable", - () -> "Error applying conflict resolution changes in " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to apply conflict resolution changes in " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, conflictResWorkspaceSpec) + ": conflict resolution is not taking place, hence accepting conflict resolution is not actionable", + () -> "Error applying conflict resolution changes in " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } + // Delete backup branch if already exists boolean backupWorkspaceDeleted; - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; try { - backupWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + backupWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); } catch (Exception e) { // If we fail to delete the residual backup workspace, we cannot proceed anyway, so we will throw the error here throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, backupWorkspaceSpec)); } if (!backupWorkspaceDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, backupWorkspaceSpec)); } + // Create backup branch from original branch - Branch newBackupBranch; - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; try { Thread.sleep(1000); // Wait to allow nodes to synchronize that backup branch is already deleted } catch (InterruptedException e) { - LOGGER.warn("Interrupted while waiting for nodes to synchronize that backup branch was deleted.", e); + LOGGER.warn("Interrupted while waiting for nodes to synchronize that backup branch was deleted", e); Thread.currentThread().interrupt(); } + Branch newBackupBranch; try { - newBackupBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 30, 1_000); + newBackupBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, workspaceBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, backupWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Error creating " + getReferenceInfo(projectId, backupWorkspaceSpec)); } if (newBackupBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " from " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, backupWorkspaceSpec)); } + // Delete original branch boolean originalBranchDeleted; try { - originalBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + originalBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } if (!originalBranchDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } + // Create new workspace branch off the conflict workspace head - Branch newWorkspaceBranch; try { Thread.sleep(1000); // Wait to allow nodes to synchronize that original branch is already deleted. @@ -329,39 +356,42 @@ public void acceptConflictResolution(String projectId, SourceSpecification sourc LOGGER.warn("Interrupted while waiting for nodes to synchronize that original branch was deleted.", e); Thread.currentThread().interrupt(); } + Branch newWorkspaceBranch; try { - newWorkspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 30, 1_000); + newWorkspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, conflictResBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, workspaceWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Error creating " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } if (newWorkspaceBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " from " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, workspaceWorkspaceSpec)); } + // Delete conflict resolution branch boolean conflictResolutionWorkspaceDeleted; try { // No need to waste wait time here since conflict resolution branch was long created during update - conflictResolutionWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + conflictResolutionWorkspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), conflictResBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Unknown " + getReferenceInfo(projectId, conflictResWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } if (!conflictResolutionWorkspaceDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, conflictResWorkspaceSpec)); } + // Delete backup branch try { @@ -372,18 +402,28 @@ public void acceptConflictResolution(String projectId, SourceSpecification sourc LOGGER.warn("Interrupted while waiting for nodes to synchronize that backup branch was recreated.", e); Thread.currentThread().interrupt(); } + boolean backupBranchDeleted; try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); - if (!deleted) - { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); - } + backupBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); } catch (Exception e) { // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); + LOGGER.error("Error deleting backup branch {} in project {}", backupBranchName, projectId, e); + backupBranchDeleted = false; } + if (!backupBranchDeleted) + { + LOGGER.error("Failed to delete backup branch {} in project {}, submitting background task", backupBranchName, projectId); + submitBackgroundRetryableTask(() -> GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 5, 1_000), 5000L, "delete " + backupBranchName); + } + } + + private static WorkspaceSpecification getWorkspaceSpecWithAccessType(WorkspaceSpecification workspaceSpec, WorkspaceAccessType accessType) + { + return (workspaceSpec.getAccessType() == accessType) ? + workspaceSpec : + WorkspaceSpecification.newWorkspaceSpecification(workspaceSpec.getId(), workspaceSpec.getType(), accessType, workspaceSpec.getSource(), workspaceSpec.getUserId()); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApi.java index 329d3dec12..b0f3161164 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApi.java @@ -23,18 +23,18 @@ import org.finos.legend.sdlc.domain.model.entity.change.EntityChange; import org.finos.legend.sdlc.domain.model.entity.change.EntityChangeType; import org.finos.legend.sdlc.domain.model.revision.Revision; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityAccessContext; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; import org.finos.legend.sdlc.server.domain.api.entity.EntityModificationContext; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; import org.finos.legend.sdlc.server.project.CachingFileAccessContext; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import org.finos.legend.sdlc.server.project.ProjectFileOperation; import org.finos.legend.sdlc.server.project.ProjectStructure; import org.finos.legend.sdlc.server.tools.BackgroundTaskProcessor; @@ -67,296 +67,95 @@ public GitLabEntityApi(GitLabConfiguration gitLabConfiguration, GitLabUserContex } @Override - public EntityAccessContext getProjectEntityAccessContext(String projectId, VersionId patchReleaseVersionId) + public EntityAccessContext getEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - return new GitLabEntityAccessContext() - { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - return projectFileAccessProvider.getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null); - } - - @Override - protected String getInfoForException() - { - return "project " + projectId; - } - }; + LegendSDLCServerException.validateNonNull(sourceSpecification, "sourceSpecification may not be null"); + return new GitLabEntityAccessContext(projectId, sourceSpecification, revisionId); } @Override - public EntityAccessContext getProjectRevisionEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String revisionId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - validateRevision(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), revisionId); - return new GitLabEntityAccessContext() - { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - String resolvedRevisionId; - try - { - resolvedRevisionId = resolveRevisionId(revisionId, getProjectFileAccessProvider().getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null)); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + getInfoForException(), - () -> "Unknown " + getInfoForException(), - () -> "Failed to get " + getInfoForException()); - } - if (resolvedRevisionId == null) - { - throw new LegendSDLCServerException("Failed to resolve " + getInfoForException()); - } - return projectFileAccessProvider.getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), resolvedRevisionId); - } - - @Override - protected String getInfoForException() - { - return "revision " + revisionId + " of project " + projectId; - } - }; - } - - public EntityAccessContext getReviewFromEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public EntityAccessContext getReviewFromEntityAccessContext(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId); validateMergeRequestForComparison(mergeRequest); DiffRef diffRef = mergeRequest.getDiffRefs(); - - if (diffRef != null && diffRef.getStartSha() != null && diffRef.getHeadSha() != null) - { - String revisionId = diffRef.getStartSha(); - return new GitLabEntityAccessContext() - { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - return projectFileAccessProvider.getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), revisionId); - } - - @Override - protected String getInfoForException() - { - return "review " + reviewId + " of project " + projectId; - } - }; - } - else + if ((diffRef == null) || (diffRef.getStartSha() == null)) { throw new LegendSDLCServerException("Unable to get [from] revision info in project " + projectId + " for review " + reviewId); } - } - - public EntityAccessContext getReviewToEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); - - GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); - validateMergeRequestForComparison(mergeRequest); - DiffRef diffRef = mergeRequest.getDiffRefs(); - - if (diffRef != null && diffRef.getStartSha() != null && diffRef.getHeadSha() != null) - { - String revisionId = diffRef.getHeadSha(); - return new GitLabEntityAccessContext() - { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - return projectFileAccessProvider.getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), revisionId); - } - - @Override - protected String getInfoForException() - { - return "review " + reviewId + " of project " + projectId; - } - }; - } - else - { - throw new LegendSDLCServerException("Unable to get [to] revision info in project " + projectId + " for review " + reviewId); - } - } - - private void validateMergeRequestForComparison(MergeRequest mergeRequest) - { - // We only allow review in OPEN and COMMITTED state. Note that this is the only control point for this restriction - if (!isOpen(mergeRequest) && !isCommitted(mergeRequest)) - { - throw new LegendSDLCServerException("Current operation not supported for review state " + getReviewState(mergeRequest) + " on review " + mergeRequest.getIid()); - } - } - - @Override - public EntityAccessContext getWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceEntityAccessContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public EntityAccessContext getBackupWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceEntityAccessContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public EntityAccessContext getWorkspaceWithConflictResolutionEntityAccessContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceEntityAccessContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId())); - } - private EntityAccessContext getWorkspaceEntityAccessContextByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification, "source specification may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - return new GitLabEntityAccessContext() + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + return new GitLabEntityAccessContext(projectId, workspaceSpec.getSourceSpecification(), diffRef.getStartSha()) { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - return projectFileAccessProvider.getFileAccessContext(projectId, sourceSpecification, null); - } - @Override protected String getInfoForException() { - return sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId; + return "review " + reviewId + " of project " + projectId; } }; } @Override - public EntityAccessContext getWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.getWorkspaceRevisionEntityAccessContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId()), revisionId); - } - - @Override - public EntityAccessContext getBackupWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.getWorkspaceRevisionEntityAccessContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId()), revisionId); - } - - @Override - public EntityAccessContext getWorkspaceWithConflictResolutionRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.getWorkspaceRevisionEntityAccessContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId()), revisionId); - } - - private EntityAccessContext getWorkspaceRevisionEntityAccessContextByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification, String revisionId) + public EntityAccessContext getReviewToEntityAccessContext(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification, "source specification may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - validateRevision(projectId, sourceSpecification, revisionId); - return new GitLabEntityAccessContext() - { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - String resolvedRevisionId; - try - { - resolvedRevisionId = resolveRevisionId(revisionId, getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, null)); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + getInfoForException(), - () -> "Unknown " + getInfoForException(), - () -> "Failed to get " + getInfoForException()); - } - if (resolvedRevisionId == null) - { - throw new LegendSDLCServerException("Failed to resolve " + getInfoForException()); - } - return projectFileAccessProvider.getFileAccessContext(projectId, sourceSpecification, resolvedRevisionId); - } - - @Override - protected String getInfoForException() - { - return "revision " + revisionId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId; - } - }; - } + LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); - @Override - public EntityAccessContext getVersionEntityAccessContext(String projectId, VersionId versionId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(versionId, "versionId may not be null"); - return new GitLabEntityAccessContext() + GitLabProjectId gitLabProjectId = parseProjectId(projectId); + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId); + validateMergeRequestForComparison(mergeRequest); + DiffRef diffRef = mergeRequest.getDiffRefs(); + if ((diffRef == null) || (diffRef.getHeadSha() == null)) { - @Override - protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) - { - return projectFileAccessProvider.getFileAccessContext(projectId, versionId); - } + throw new LegendSDLCServerException("Unable to get [from] revision info in project " + projectId + " for review " + reviewId); + } + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + return new GitLabEntityAccessContext(projectId, workspaceSpec.getSourceSpecification(), diffRef.getHeadSha()) + { @Override protected String getInfoForException() { - return "version " + versionId.toVersionIdString() + " of project " + projectId; + return "review " + reviewId + " of project " + projectId; } }; } @Override - public EntityModificationContext getWorkspaceEntityModificationContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceEntityModificationContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public EntityModificationContext getWorkspaceWithConflictResolutionEntityModificationContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceEntityModificationContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId())); - } - - private EntityModificationContext getWorkspaceEntityModificationContextByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification) + public EntityModificationContext getEntityModificationContext(String projectId, WorkspaceSourceSpecification sourceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(sourceSpecification, "source specification may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); return new GitLabEntityModificationContext(projectId, sourceSpecification); } - private void validateRevision(String projectId, SourceSpecification sourceSpecification, String revisionId) + private void validateMergeRequestForComparison(MergeRequest mergeRequest) { - Revision revision = getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, null).getRevision(revisionId); - if (revision == null) + // We only allow review in OPEN and COMMITTED state. Note that this is the only control point for this restriction + if (!isOpen(mergeRequest) && !isCommitted(mergeRequest)) { - StringBuilder builder = new StringBuilder("Revision ").append(revisionId).append(" is unknown for "); - appendReferenceInfo(builder, projectId, sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), sourceSpecification.getWorkspaceAccessType(), null); - throw new LegendSDLCServerException(builder.toString(), Status.NOT_FOUND); + throw new LegendSDLCServerException("Current operation not supported for review state " + getReviewState(mergeRequest) + " on review " + mergeRequest.getIid()); } } - private abstract class GitLabEntityAccessContext implements EntityAccessContext + private class GitLabEntityAccessContext implements EntityAccessContext { + private final String projectId; + private final SourceSpecification sourceSpecification; + private final String revisionId; + + private GitLabEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) + { + this.projectId = projectId; + this.sourceSpecification = sourceSpecification; + this.revisionId = revisionId; + } + @Override public Entity getEntity(String path) { @@ -440,28 +239,26 @@ public List getEntityPaths(Predicate entityPathPredicate, Predic } } - protected abstract ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider); + protected ProjectFileAccessProvider.FileAccessContext getFileAccessContext(ProjectFileAccessProvider projectFileAccessProvider) + { + return projectFileAccessProvider.getFileAccessContext(this.projectId, this.sourceSpecification, resolveRevisionId(this.projectId, this.sourceSpecification, this.revisionId)); + } - protected abstract String getInfoForException(); + protected String getInfoForException() + { + return getReferenceInfo(this.projectId, this.sourceSpecification, this.revisionId); + } } private class GitLabEntityModificationContext implements EntityModificationContext { private final String projectId; - private final SourceSpecification sourceSpecification; + private final WorkspaceSourceSpecification sourceSpecification; - private GitLabEntityModificationContext(String projectId, SourceSpecification sourceSpecification) + private GitLabEntityModificationContext(String projectId, WorkspaceSourceSpecification sourceSpecification) { this.projectId = projectId; - this.sourceSpecification = sourceSpecification; - if (sourceSpecification == null) - { - throw new RuntimeException("source specification may not be null"); - } - if ((this.sourceSpecification.getWorkspaceId() != null) && ((this.sourceSpecification.getWorkspaceType() == null) || (this.sourceSpecification.getWorkspaceAccessType() == null))) - { - throw new RuntimeException("workspace type and access type are required when workspace id is specified"); - } + this.sourceSpecification = Objects.requireNonNull(sourceSpecification, "source specification may not be null"); } @Override @@ -482,7 +279,58 @@ public Revision performChanges(List changes, String revi } } - private Revision updateEntities(String projectId, SourceSpecification sourceSpecification, Iterable newEntities, boolean replace, String message) + private Revision updateEntities(String projectId, WorkspaceSourceSpecification sourceSpecification, Iterable newEntities, boolean replace, String message) + { + MutableMap newEntityDefinitions = indexAndValidateEntitiesForUpdate(newEntities); + + ProjectFileAccessProvider fileProvider = getProjectFileAccessProvider(); + + Revision currentWorkspaceRevision = fileProvider.getRevisionAccessContext(projectId, sourceSpecification, null).getCurrentRevision(); + if (currentWorkspaceRevision == null) + { + throw new LegendSDLCServerException("Could not find current revision for " + getReferenceInfo(projectId, sourceSpecification) + ": it may be corrupt"); + } + String revisionId = currentWorkspaceRevision.getId(); + LOGGER.debug("Using revision {} for reference in entity update in {} in project {}", revisionId, sourceSpecification, projectId); + List entityChanges = Lists.mutable.ofInitialCapacity(newEntityDefinitions.size()); + if (newEntityDefinitions.notEmpty()) + { + try (Stream stream = getEntityProjectFiles(fileProvider.getFileAccessContext(projectId, sourceSpecification, revisionId))) + { + stream.forEach(epf -> + { + String path = epf.getEntityPath(); + Entity newDefinition = newEntityDefinitions.remove(path); + if (newDefinition != null) + { + Entity entity = epf.getEntity(); + String newClassifierPath = newDefinition.getClassifierPath(); + Map newContent = newDefinition.getContent(); + if (!newClassifierPath.equals(entity.getClassifierPath()) || !newContent.equals(entity.getContent())) + { + entityChanges.add(EntityChange.newModifyEntity(path, newClassifierPath, newContent)); + } + } + else if (replace) + { + entityChanges.add(EntityChange.newDeleteEntity(path)); + } + }); + } + newEntityDefinitions.forEachValue(definition -> entityChanges.add(EntityChange.newCreateEntity(definition.getPath(), definition.getClassifierPath(), definition.getContent()))); + } + else if (replace) + { + try (Stream stream = getEntityProjectFiles(fileProvider.getFileAccessContext(projectId, sourceSpecification, revisionId))) + { + stream.map(EntityProjectFile::getEntityPath).map(EntityChange::newDeleteEntity).forEach(entityChanges::add); + } + } + + return performChanges(projectId, sourceSpecification, revisionId, message, entityChanges); + } + + private MutableMap indexAndValidateEntitiesForUpdate(Iterable newEntities) { MutableMap newEntityDefinitions = Maps.mutable.empty(); MutableList errorMessages = Lists.mutable.empty(); @@ -512,7 +360,7 @@ private Revision updateEntities(String projectId, SourceSpecification sourceSpec { errorMessages.add("Entity: " + path + "; error: missing content"); } - else if (path != null) + else { Object pkg = content.get("package"); Object name = content.get("name"); @@ -536,8 +384,7 @@ else if (path != null) { builder.append(name); } - builder.append(") properties"); - errorMessages.add(builder.toString()); + errorMessages.add(builder.append(") properties").toString()); } } @@ -549,69 +396,20 @@ else if (path != null) }); if (errorMessages.notEmpty()) { - throw new LegendSDLCServerException((errorMessages.size() == 1) ? errorMessages.get(0) : "There are errors with entity definitions:\n\t" + String.join("\n\t", errorMessages), Status.BAD_REQUEST); - } - - Revision currentWorkspaceRevision = getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, null).getCurrentRevision(); - if (currentWorkspaceRevision == null) - { - throw new LegendSDLCServerException("Could not find current revision for " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " may be corrupt"); - } - String revisionId = currentWorkspaceRevision.getId(); - LOGGER.debug("Using revision {} for reference in entity update in {} {} {} in project {}", revisionId, sourceSpecification.getWorkspaceType().getLabel(), sourceSpecification.getWorkspaceAccessType().getLabel(), sourceSpecification.getWorkspaceId(), projectId); - List entityChanges = Lists.mutable.ofInitialCapacity(newEntityDefinitions.size()); - if (newEntityDefinitions.isEmpty()) - { - if (replace) - { - try (Stream stream = getEntityProjectFiles(projectId, sourceSpecification, revisionId)) - { - stream.map(EntityProjectFile::getEntityPath).map(EntityChange::newDeleteEntity).forEach(entityChanges::add); - } - } + throw new LegendSDLCServerException((errorMessages.size() == 1) ? errorMessages.get(0) : errorMessages.makeString("There are errors with entity definitions:\n\t", "\n\t", ""), Status.BAD_REQUEST); } - else - { - try (Stream stream = getEntityProjectFiles(projectId, sourceSpecification, revisionId)) - { - stream.forEach(epf -> - { - String path = epf.getEntityPath(); - Entity newDefinition = newEntityDefinitions.remove(path); - if (newDefinition == null) - { - if (replace) - { - entityChanges.add(EntityChange.newDeleteEntity(path)); - } - } - else - { - Entity entity = epf.getEntity(); - String newClassifierPath = newDefinition.getClassifierPath(); - Map newContent = newDefinition.getContent(); - if (!newClassifierPath.equals(entity.getClassifierPath()) || !newContent.equals(entity.getContent())) - { - entityChanges.add(EntityChange.newModifyEntity(path, newClassifierPath, newContent)); - } - } - }); - } - newEntityDefinitions.forEachValue(definition -> entityChanges.add(EntityChange.newCreateEntity(definition.getPath(), definition.getClassifierPath(), definition.getContent()))); - } - - return performChanges(projectId, sourceSpecification, revisionId, message, entityChanges); + return newEntityDefinitions; } - private Revision performChanges(String projectId, SourceSpecification sourceSpecification, String referenceRevisionId, String message, List changes) + private Revision performChanges(String projectId, WorkspaceSourceSpecification sourceSpecification, String referenceRevisionId, String message, List changes) { int changeCount = changes.size(); if (changeCount == 0) { - LOGGER.debug("No changes for {} {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel(), sourceSpecification.getWorkspaceAccessType().getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.debug("No changes for {} in project {}", sourceSpecification, projectId); return null; } - LOGGER.debug("Committing {} changes to {} {} {} in project {}: {}", changeCount, sourceSpecification.getWorkspaceType().getLabel(), sourceSpecification.getWorkspaceAccessType().getLabel(), sourceSpecification.getWorkspaceId(), projectId, message); + LOGGER.debug("Committing {} changes to {} in project {}: {}", changeCount, sourceSpecification, projectId, message); try { ProjectFileAccessProvider.FileAccessContext fileAccessContext = getProjectFileAccessProvider().getFileAccessContext(projectId, sourceSpecification, referenceRevisionId); @@ -620,7 +418,7 @@ private Revision performChanges(String projectId, SourceSpecification sourceSpec fileOperations.removeIf(Objects::isNull); if (fileOperations.isEmpty()) { - LOGGER.debug("No changes for {} {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel(), sourceSpecification.getWorkspaceAccessType().getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.debug("No changes for {} in project {}", sourceSpecification, projectId); return null; } return getProjectFileAccessProvider().getFileModificationContext(projectId, sourceSpecification, referenceRevisionId).submit(message, fileOperations); @@ -628,9 +426,9 @@ private Revision performChanges(String projectId, SourceSpecification sourceSpec catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to perform changes on " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Failed to perform changes on " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + " (message: " + message + ")"); + () -> "User " + getCurrentUser() + " is not allowed to perform changes on " + getReferenceInfo(projectId, sourceSpecification), + () -> "Unknown " + getReferenceInfo(projectId, sourceSpecification), + () -> "Failed to perform changes on " + getReferenceInfo(projectId, sourceSpecification) + " (message: " + message + ")"); } } @@ -719,11 +517,6 @@ private ProjectFileOperation entityChangeToFileOperation(EntityChange change, Pr } } - private Stream getEntityProjectFiles(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return getEntityProjectFiles(getProjectFileAccessProvider().getFileAccessContext(projectId, sourceSpecification, revisionId)); - } - private Stream getEntityProjectFiles(ProjectFileAccessProvider.FileAccessContext accessContext, Predicate entityPathPredicate, Predicate classifierPathPredicate, Predicate> contentPredicate) { return getEntityProjectFiles(accessContext, entityPathPredicate, classifierPathPredicate, contentPredicate, false); diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabPatchApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabPatchApi.java index 79b47b15f7..61b616d3bc 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabPatchApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabPatchApi.java @@ -34,12 +34,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.ws.rs.core.Response; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.inject.Inject; +import javax.ws.rs.core.Response; public class GitLabPatchApi extends GitLabApiWithFileAccess implements PatchApi { @@ -51,15 +50,6 @@ public GitLabPatchApi(GitLabConfiguration gitLabConfiguration, GitLabUserContext super(gitLabConfiguration, userContext, backgroundTaskProcessor); } - private Patch patchBranchToPatch(String projectId, Branch patchBranch) - { - if (patchBranch != null) - { - return fromPatchBranchName(projectId, patchBranch.getName()); - } - return null; - } - @Override public Patch newPatch(String projectId, VersionId sourceVersionId) { @@ -71,11 +61,11 @@ public Patch newPatch(String projectId, VersionId sourceVersionId) boolean sourceTagExists; try { - sourceTagExists = GitLabApiTools.tagExists(getGitLabApi(), gitLabProjectId, buildVersionTagName(sourceVersionId)); + sourceTagExists = GitLabApiTools.tagExists(getGitLabApi(), gitLabProjectId.getGitLabId(), buildVersionTagName(sourceVersionId)); } catch (Exception e) { - throw new LegendSDLCServerException("Error in fetching version " + sourceVersionId.toVersionIdString() + " for project " + projectId, Response.Status.BAD_REQUEST, e); + throw new LegendSDLCServerException("Error in fetching version " + sourceVersionId.toVersionIdString() + " for project " + projectId, e); } if (!sourceTagExists) { @@ -86,11 +76,11 @@ public Patch newPatch(String projectId, VersionId sourceVersionId) boolean targetTagExists; try { - targetTagExists = GitLabApiTools.tagExists(getGitLabApi(), gitLabProjectId, buildVersionTagName(targetVersionId)); + targetTagExists = GitLabApiTools.tagExists(getGitLabApi(), gitLabProjectId.getGitLabId(), buildVersionTagName(targetVersionId)); } catch (Exception e) { - throw new LegendSDLCServerException("Error in fetching version " + targetVersionId.toVersionIdString() + " for project " + projectId, Response.Status.BAD_REQUEST, e); + throw new LegendSDLCServerException("Error in fetching version " + targetVersionId.toVersionIdString() + " for project " + projectId, e); } if (targetTagExists) { @@ -107,7 +97,7 @@ public Patch newPatch(String projectId, VersionId sourceVersionId) Branch branch; try { - branch = GitLabApiTools.createProtectedBranchFromSourceTagAndVerify(getGitLabApi(), gitLabProjectId, getPatchReleaseBranchName(targetVersionId), buildVersionTagName(sourceVersionId), 30, 1_000); + branch = GitLabApiTools.createProtectedBranchFromSourceTagAndVerify(getGitLabApi(), gitLabProjectId.getGitLabId(), getPatchReleaseBranchName(targetVersionId), buildVersionTagName(sourceVersionId), 30, 1_000); } catch (Exception e) { @@ -121,7 +111,7 @@ public Patch newPatch(String projectId, VersionId sourceVersionId) throw new LegendSDLCServerException("Failed to create patch " + targetVersionId.toVersionIdString() + " in project " + projectId); } - return patchBranchToPatch(projectId, branch); + return fromPatchBranchName(projectId, branch.getName()); } @Override @@ -135,7 +125,7 @@ public List getPatches(String projectId, Integer minMajorVersion, Integer Pager pager = getGitLabApi().getRepositoryApi().getBranches(gitLabProjectId.getGitLabId(), "^" + branchPrefix, ITEMS_PER_PAGE); Stream stream = PagerTools.stream(pager) .filter(branch -> (branch != null) && (branch.getName() != null) && branch.getName().startsWith(branchPrefix)) - .map(branch -> patchBranchToPatch(projectId, branch)); + .map(branch -> fromPatchBranchName(projectId, branch.getName())); // major version constraint if ((minMajorVersion != null) && (maxMajorVersion != null)) { @@ -234,26 +224,6 @@ else if (maxPatchVersion != null) } } - private Patch fromPatchBranchName(String projectId, String branchName) - { - int index = branchName.lastIndexOf(BRANCH_DELIMITER); - VersionId patchReleaseVersionId = parseVersionIdString(branchName.substring(index + 1, branchName.length())); - return new Patch() - { - @Override - public String getProjectId() - { - return projectId; - } - - @Override - public VersionId getPatchReleaseVersionId() - { - return patchReleaseVersionId; - } - }; - } - @Override public void deletePatch(String projectId, VersionId patchReleaseVersionId) { @@ -296,7 +266,7 @@ public Version releasePatch(String projectId, VersionId patchReleaseVersionId) boolean targetTagExists; try { - targetTagExists = GitLabApiTools.tagExists(getGitLabApi(), gitLabProjectId, buildVersionTagName(patchReleaseVersionId)); + targetTagExists = GitLabApiTools.tagExists(getGitLabApi(), gitLabProjectId.getGitLabId(), buildVersionTagName(patchReleaseVersionId)); } catch (Exception e) { @@ -331,8 +301,8 @@ public Version releasePatch(String projectId, VersionId patchReleaseVersionId) private boolean closeMergeRequestsCreatedForPatchReleaseBranch(GitLabProjectId projectId, VersionId patchReleaseVersionId) { + String branchName = getPatchReleaseBranchName(patchReleaseVersionId); List mergeRequests; - String branchName = getSourceBranch(projectId, patchReleaseVersionId); try { MergeRequestFilter mergeRequestFilter = new MergeRequestFilter().withTargetBranch(branchName).withState(Constants.MergeRequestState.OPENED); @@ -344,8 +314,8 @@ private boolean closeMergeRequestsCreatedForPatchReleaseBranch(GitLabProjectId p { return false; } - mergeRequests = Collections.emptyList(); LOGGER.warn("Unable to fetch merge requests for target branch {} of project {}", branchName, projectId, e); + return true; } boolean shouldRetry = false; for (MergeRequest mergeRequest : mergeRequests) diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApi.java index f5683bb93a..e2f4fb93a2 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApi.java @@ -30,7 +30,8 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.server.domain.api.project.ProjectApi; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationUpdater; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -372,13 +373,12 @@ public ImportReport importProject(String id, ProjectType type, String groupId, S // Create a workspace for project configuration RepositoryApi repositoryApi = gitLabApi.getRepositoryApi(); String workspaceId = PROJECT_CONFIGURATION_WORKSPACE_ID_PREFIX + getRandomIdString(); - WorkspaceType workspaceType = WorkspaceType.USER; - WorkspaceAccessType workspaceAccessType = WorkspaceAccessType.WORKSPACE; + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE); Branch workspaceBranch; String defaultBranch = getDefaultBranch(projectId); try { - workspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, projectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType)), defaultBranch, 30, 1_000); + workspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, projectId.getGitLabId(), getWorkspaceBranchName(workspaceSpec), defaultBranch, 30, 1_000); } catch (Exception e) { @@ -397,13 +397,13 @@ public ImportReport importProject(String id, ProjectType type, String groupId, S Revision configRevision; try { - ProjectConfiguration currentConfig = ProjectStructure.getProjectConfiguration(projectId.toString(), SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE), null, projectFileAccessProvider); + ProjectConfiguration currentConfig = ProjectStructure.getProjectConfiguration(projectId.toString(), SourceSpecification.projectSourceSpecification(), null, projectFileAccessProvider); ProjectConfigurationUpdater configUpdater = ProjectConfigurationUpdater.newUpdater() .withProjectType(type) .withGroupId(groupId) .withArtifactId(artifactId); ProjectStructure.UpdateBuilder builder = ProjectStructure.newUpdateBuilder(projectFileAccessProvider, projectId.toString(), configUpdater) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType)) + .withWorkspace(workspaceSpec) .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions); int defaultProjectStructureVersion = getDefaultProjectStructureVersion(); @@ -434,7 +434,7 @@ public ImportReport importProject(String id, ProjectType type, String groupId, S catch (Exception e) { // Try to delete the branch in case of exception - deleteWorkspace(projectId, repositoryApi, workspaceId, workspaceType, workspaceAccessType); + deleteWorkspace(projectId, repositoryApi, workspaceSpec); throw e; } @@ -446,22 +446,22 @@ public ImportReport importProject(String id, ProjectType type, String groupId, S reviewId = null; // Try to delete the branch - deleteWorkspace(projectId, repositoryApi, workspaceId, workspaceType, workspaceAccessType); + deleteWorkspace(projectId, repositoryApi, workspaceSpec); } else { MergeRequest mergeRequest; try { - mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(projectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType)), defaultBranch, "Project structure", "Set up project structure", null, null, null, null, true, false); + mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(projectId.getGitLabId(), getWorkspaceBranchName(workspaceSpec), defaultBranch, "Project structure", "Set up project structure", null, null, null, null, true, false); } catch (Exception e) { // Try to delete the branch in case of exception - deleteWorkspace(projectId, repositoryApi, workspaceId, workspaceType, workspaceAccessType); + deleteWorkspace(projectId, repositoryApi, workspaceSpec); throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to submit project configuration changes create a workspace for initial configuration of project " + id, - () -> "Could not find " + workspaceType.getLabel() + " " + workspaceAccessType.getLabel() + " " + workspaceId + " in project " + id, + () -> "Could not find " + getReferenceInfo(id, workspaceSpec), () -> "Failed to create a review for configuration of project " + id); } reviewId = toStringIfNotNull(mergeRequest.getIid()); @@ -491,7 +491,7 @@ public ImportReport importProject(String id, ProjectType type, String groupId, S catch (Exception e) { // Try to delete the branch in case of exception - deleteWorkspace(projectId, repositoryApi, workspaceId, workspaceType, workspaceAccessType); + deleteWorkspace(projectId, repositoryApi, workspaceSpec); throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to import project " + id, () -> "Could not find project " + id, @@ -515,20 +515,20 @@ public String getReviewId() }; } - private void deleteWorkspace(GitLabProjectId projectId, RepositoryApi repositoryApi, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) + private void deleteWorkspace(GitLabProjectId projectId, RepositoryApi repositoryApi, WorkspaceSpecification workspaceSpec) { try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, projectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType)), 30, 1_000); + boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, projectId.getGitLabId(), getWorkspaceBranchName(workspaceSpec), 30, 1_000); if (!deleted) { - LOGGER.error("Failed to delete {} {} {} in project {}", workspaceType.getLabel(), workspaceAccessType.getLabel(), workspaceId, projectId); + LOGGER.error("Failed to delete {} {} {} in project {}", workspaceSpec.getType().getLabel(), workspaceSpec.getAccessType().getLabel(), workspaceSpec.getId(), projectId); } } catch (Exception e) { // Possibly failed to delete branch - unfortunate, but ignore it - LOGGER.error("Error deleting {} {} {} in project {}", workspaceType.getLabel(), workspaceAccessType.getLabel(), workspaceId, projectId, e); + LOGGER.error("Error deleting {} {} {} in project {}", workspaceSpec.getType().getLabel(), workspaceSpec.getAccessType().getLabel(), workspaceSpec.getId(), projectId, e); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApi.java index 762f7315d4..f494b8db3e 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApi.java @@ -20,12 +20,12 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency; import org.finos.legend.sdlc.domain.model.project.configuration.ProjectStructureVersion; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationUpdater; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -33,7 +33,6 @@ import org.finos.legend.sdlc.server.gitlab.tools.PagerTools; import org.finos.legend.sdlc.server.project.ProjectConfigurationStatusReport; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; -import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import org.finos.legend.sdlc.server.project.ProjectStructure; import org.finos.legend.sdlc.server.project.ProjectStructurePlatformExtensions; import org.finos.legend.sdlc.server.project.extension.ProjectStructureExtensionProvider; @@ -46,7 +45,6 @@ import java.util.List; import java.util.stream.Stream; import javax.inject.Inject; -import javax.ws.rs.core.Response.Status; public class GitLabProjectConfigurationApi extends GitLabApiWithFileAccess implements ProjectConfigurationApi { @@ -62,252 +60,96 @@ public GitLabProjectConfigurationApi(GitLabConfiguration gitLabConfiguration, Gi } @Override - public ProjectConfiguration getProjectProjectConfiguration(String projectId, VersionId patchReleaseVersionId) + public ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - try - { - return getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access project configuration for project " + projectId, - () -> "Unknown project (" + projectId + ")", - () -> "Failed to access project configuration for project " + projectId); - } - } - - @Override - public ProjectConfiguration getProjectRevisionProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String revisionId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - String resolvedRevisionId; - try - { - resolvedRevisionId = resolveRevisionId(revisionId, getProjectFileAccessProvider().getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null)); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get revision " + revisionId + " of project " + projectId, - () -> "Unknown revision " + revisionId + " of project " + projectId, - () -> "Failed to get revision " + revisionId + " of project " + projectId); - } - if (resolvedRevisionId == null) - { - throw new LegendSDLCServerException("Failed to resolve revision " + revisionId + " of project " + projectId, Status.NOT_FOUND); - } - try - { - return getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, patchReleaseVersionId), resolvedRevisionId); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access project configuration for project " + projectId + " at revision " + revisionId, - () -> "Unknown project (" + projectId + ") or revision (" + revisionId + ")", - () -> "Failed to access project configuration for project " + projectId + " at revision " + revisionId); - } - } - - @Override - public ProjectConfiguration getWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceProjectConfigurationByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public ProjectConfiguration getBackupWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceProjectConfigurationByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public ProjectConfiguration getWorkspaceWithConflictResolutionProjectConfiguration(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceProjectConfigurationByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId())); - } - - private ProjectConfiguration getWorkspaceProjectConfigurationByAccessType(String projectId, SourceSpecification sourceSpecification) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - try - { - return getProjectConfiguration(projectId, sourceSpecification, null); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access project configuration for project " + projectId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId(), - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Failed to access project configuration for project " + projectId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId()); - } - } - - @Override - public ProjectConfiguration getWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.getWorkspaceRevisionProjectConfigurationByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId()), revisionId); - } - - @Override - public ProjectConfiguration getBackupUserWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) - { - return this.getBackupWorkspaceRevisionProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceId), revisionId); - } - - @Override - public ProjectConfiguration getBackupGroupWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) - { - return this.getBackupWorkspaceRevisionProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceId), revisionId); - } - - @Override - public ProjectConfiguration getBackupWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.getWorkspaceRevisionProjectConfigurationByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId()), revisionId); - } - - @Override - public ProjectConfiguration getWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return this.getWorkspaceRevisionProjectConfigurationByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId()), revisionId); - } + LegendSDLCServerException.validateNonNull(sourceSpecification, "sourceSpecification may not be null"); - private ProjectConfiguration getWorkspaceRevisionProjectConfigurationByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - String resolvedRevisionId; + String resolvedRevisionId = resolveRevisionId(projectId, sourceSpecification, revisionId); try { - resolvedRevisionId = resolveRevisionId(revisionId, getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, null)); + return super.getProjectConfiguration(projectId, sourceSpecification, resolvedRevisionId); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get revision " + revisionId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId, - () -> "Unknown revision " + revisionId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId, - () -> "Failed to get revision " + revisionId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId); - } - if (resolvedRevisionId == null) - { - throw new LegendSDLCServerException("Failed to resolve revision " + revisionId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId, Status.NOT_FOUND); - } - try - { - return getProjectConfiguration(projectId, sourceSpecification, resolvedRevisionId); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access project configuration for project " + projectId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " at revision " + revisionId, - () -> "Unknown project (" + projectId + "), " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " (" + sourceSpecification.getWorkspaceId() + "), or revision (" + revisionId + ")", - () -> "Failed to access project configuration for project " + projectId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " at revision " + revisionId); + () -> "User " + getCurrentUser() + " is not allowed to access project configuration for " + getReferenceInfo(projectId, sourceSpecification, revisionId), + () -> "Unknown " + getReferenceInfo(projectId, sourceSpecification, revisionId), + () -> "Failed to access project configuration for " + getReferenceInfo(projectId, sourceSpecification, revisionId)); } } @Override - public ProjectConfiguration getVersionProjectConfiguration(String projectId, VersionId versionId) + public ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification) { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(versionId, "versionId may not be null"); - try - { - return getProjectVersionProjectConfiguration(projectId, versionId); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access project configuration for version " + versionId.toVersionIdString() + " of project " + projectId, - () -> "Unknown project (" + projectId + ") or version (" + versionId.toVersionIdString() + ")", - () -> "Failed to access project configuration for version " + versionId.toVersionIdString() + " of project " + projectId); - } + return getProjectConfiguration(projectId, sourceSpecification, null); } @Override - public ProjectConfiguration getReviewFromProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId) + public ProjectConfiguration getReviewFromProjectConfiguration(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId); validateMergeRequestForComparison(mergeRequest); DiffRef diffRef = mergeRequest.getDiffRefs(); - - if (diffRef != null && diffRef.getStartSha() != null && diffRef.getHeadSha() != null) - { - String revisionId = diffRef.getStartSha(); - return getProjectRevisionProjectConfiguration(projectId, patchReleaseVersionId, revisionId); - } - else + if ((diffRef == null) || (diffRef.getStartSha() == null)) { throw new LegendSDLCServerException("Unable to get [from] revision info in project " + projectId + " for review " + reviewId); } + + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + return super.getProjectConfiguration(projectId, workspaceSpec.getSourceSpecification(), diffRef.getStartSha()); } @Override - public ProjectConfiguration getReviewToProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId) + public ProjectConfiguration getReviewToProjectConfiguration(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId); validateMergeRequestForComparison(mergeRequest); DiffRef diffRef = mergeRequest.getDiffRefs(); - - if (diffRef != null && diffRef.getStartSha() != null && diffRef.getHeadSha() != null) - { - String revisionId = diffRef.getHeadSha(); - return getProjectRevisionProjectConfiguration(projectId, patchReleaseVersionId, revisionId); - } - else + if ((diffRef == null) || (diffRef.getHeadSha() == null)) { throw new LegendSDLCServerException("Unable to get [to] revision info in project " + projectId + " for review " + reviewId); } - } - @Override - public Revision updateProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater) - { - return updateProjectConfigurationByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId()), message, updater); + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + return super.getProjectConfiguration(projectId, workspaceSpec.getSourceSpecification(), diffRef.getHeadSha()); } - @Override - public Revision updateProjectConfigurationForWorkspaceWithConflictResolution(String projectId, String workspaceId, String message, ProjectConfigurationUpdater updater) + private void validateMergeRequestForComparison(MergeRequest mergeRequest) { - return updateProjectConfigurationByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, WorkspaceAccessType.CONFLICT_RESOLUTION), message, updater); + // We only allow review in OPEN and COMMITTED state. Note that this is the only control point for this restriction + if (!isOpen(mergeRequest) && !isCommitted(mergeRequest)) + { + throw new LegendSDLCServerException("Current operation not supported for review state " + getReviewState(mergeRequest) + " on review " + mergeRequest.getIid()); + } } - private Revision updateProjectConfigurationByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater) + @Override + public Revision updateProjectConfiguration(String projectId, WorkspaceSourceSpecification sourceSpec, String message, ProjectConfigurationUpdater updater) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); + LegendSDLCServerException.validateNonNull(sourceSpec, "sourceSpec may not be null"); LegendSDLCServerException.validateNonNull(message, "message may not be null"); try { ProjectFileAccessProvider fileAccessProvider = getProjectFileAccessProvider(); - Revision currentRevision = fileAccessProvider.getRevisionAccessContext(projectId, sourceSpecification, null).getCurrentRevision(); + Revision currentRevision = fileAccessProvider.getRevisionAccessContext(projectId, sourceSpec, null).getCurrentRevision(); if (currentRevision == null) { - throw new LegendSDLCServerException("Could not find current revision for " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " may be corrupt"); + throw new LegendSDLCServerException("Could not find current revision for " + getReferenceInfo(projectId, sourceSpec) + ": it may be corrupt"); } return ProjectStructure.newUpdateBuilder(fileAccessProvider, projectId) .withProjectConfigurationUpdater(updater) - .withWorkspace(sourceSpecification) + .withSourceSpecification(sourceSpec) .withRevisionId(currentRevision.getId()) .withMessage(message) .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) @@ -317,43 +159,18 @@ private Revision updateProjectConfigurationByWorkspaceAccessType(String projectI catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to update project configuration for project " + projectId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId(), - () -> "Unknown project (" + projectId + ") or " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " (" + sourceSpecification.getWorkspaceId() + ")", - () -> "Failed to update project configuration for project " + projectId + " in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId()); - } - } - - private void validateMergeRequestForComparison(MergeRequest mergeRequest) - { - // We only allow review in OPEN and COMMITTED state. Note that this is the only control point for this restriction - if (!isOpen(mergeRequest) && !isCommitted(mergeRequest)) - { - throw new LegendSDLCServerException("Current operation not supported for review state " + getReviewState(mergeRequest) + " on review " + mergeRequest.getIid()); + () -> "User " + getCurrentUser() + " is not allowed to update project configuration for " + getReferenceInfo(projectId, sourceSpec), + () -> "Unknown: " + getReferenceInfo(projectId, sourceSpec), + () -> "Failed to update project configuration for " + getReferenceInfo(projectId, sourceSpec)); } } @Override - public List getProjectAvailableArtifactGenerations(String projectId, VersionId patchReleaseVersionId) + public List getAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId) { - return ProjectStructure.getProjectStructure(getProjectProjectConfiguration(projectId, patchReleaseVersionId)).getAvailableGenerationConfigurations(); - } - - @Override - public List getRevisionAvailableArtifactGenerations(String projectId, String revisionId) - { - return ProjectStructure.getProjectStructure(getProjectRevisionProjectConfiguration(projectId, revisionId)).getAvailableGenerationConfigurations(); - } - - @Override - public List getWorkspaceRevisionAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - return ProjectStructure.getProjectStructure(getWorkspaceRevisionProjectConfiguration(projectId, sourceSpecification, revisionId)).getAvailableGenerationConfigurations(); - } - - @Override - public List getVersionAvailableArtifactGenerations(String projectId, String versionId) - { - return ProjectStructure.getProjectStructure(getVersionProjectConfiguration(projectId, versionId)).getAvailableGenerationConfigurations(); + ProjectConfiguration config = getProjectConfiguration(projectId, sourceSpecification, revisionId); + ProjectStructure structure = ProjectStructure.getProjectStructure(config); + return structure.getAvailableGenerationConfigurations(); } @Override @@ -410,7 +227,7 @@ public List getMetamodelDependencies() @Override public ProjectConfigurationStatusReport getProjectConfigurationStatus(String projectId) { - Boolean isProjectConfigured = getProjectConfiguration(projectId, null) != null; + boolean isProjectConfigured = hasProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()); List reviewIds = Lists.mutable.empty(); if (!isProjectConfigured) { @@ -446,10 +263,4 @@ public List getReviewIds() } }; } - - @Override - public List getWorkspaceAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification) - { - return ProjectStructure.getProjectStructure(getWorkspaceProjectConfiguration(projectId, sourceSpecification)).getAvailableGenerationConfigurations(); - } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabReviewApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabReviewApi.java index 61f218de95..d0d83eae23 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabReviewApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabReviewApi.java @@ -28,13 +28,14 @@ import org.finos.legend.sdlc.domain.model.review.Approval; import org.finos.legend.sdlc.domain.model.review.Review; import org.finos.legend.sdlc.domain.model.review.ReviewState; -import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.domain.model.user.User; import org.finos.legend.sdlc.server.domain.api.review.ReviewApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; +import org.finos.legend.sdlc.server.gitlab.tools.GitLabApiTools; import org.finos.legend.sdlc.server.gitlab.tools.PagerTools; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.finos.legend.sdlc.server.project.ProjectStructure; @@ -56,7 +57,6 @@ import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequestFilter; import org.gitlab4j.api.models.MergeRequestParams; -import org.finos.legend.sdlc.domain.model.user.User; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,6 +69,7 @@ import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.inject.Inject; @@ -85,7 +86,7 @@ public GitLabReviewApi(GitLabConfiguration gitLabConfiguration, GitLabUserContex } @Override - public List getReviews(String projectId, VersionId patchReleaseVersionId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit) + public List getReviews(String projectId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); Set revisionIdSet; @@ -140,8 +141,9 @@ else if (revisionIds instanceof Set) MergeRequestFilter mergeRequestFilter = withMergeRequestFilters(new MergeRequestFilter(), state, since, until).withProjectId(gitLabProjectId.getGitLabId()); mergeRequestStream = PagerTools.stream(withRetries(() -> getGitLabApi().getMergeRequestApi().getMergeRequests(mergeRequestFilter, ITEMS_PER_PAGE))); } - String targetBranch = getSourceBranch(gitLabProjectId, patchReleaseVersionId); - Stream stream = mergeRequestStream.filter(mr -> isReviewMergeRequest(mr, targetBranch)).map(mr -> fromGitLabMergeRequest(projectId, patchReleaseVersionId, mr)); + String defaultBranch = getDefaultBranch(gitLabProjectId); + Supplier defaultBranchSupplier = () -> defaultBranch; + Stream stream = mergeRequestStream.filter(mr -> isReviewMergeRequest(mr, defaultBranchSupplier)).map(mr -> fromGitLabMergeRequest(projectId, mr)); return addReviewFilters(stream, state, workspaceIdAndTypePredicate, since, until, limit).collect(Collectors.toList()); } catch (Exception e) @@ -168,24 +170,20 @@ public List getReviews(boolean assignedToMe, boolean authoredByMe, List< private Stream getReviewStream(MergeRequestFilter mergeRequestFilter) { - MutableIntObjectMap pIdTodefaultBranch = IntObjectMaps.mutable.empty(); - + MutableIntObjectMap defaultBranchByProject = IntObjectMaps.mutable.empty(); + String idPrefix = getGitLabConfiguration().getProjectIdPrefix(); try { return PagerTools.stream(withRetries(() -> getGitLabApi().getMergeRequestApi().getMergeRequests(mergeRequestFilter, ITEMS_PER_PAGE))) - .filter(mr -> - { - String defaultBranch = pIdTodefaultBranch.getIfAbsentPutWithKey(mr.getProjectId(), pid -> getDefaultBranch(GitLabProjectId.newProjectId(this.getGitLabConfiguration().getProjectIdPrefix(), pid))); - return isReviewMergeRequest(mr, defaultBranch); - }) - .map(mr -> fromGitLabMergeRequest(GitLabProjectId.newProjectId(this.getGitLabConfiguration().getProjectIdPrefix(), mr.getProjectId()).toString(), null, mr)); + .filter(mr -> isReviewMergeRequest(mr, () -> defaultBranchByProject.getIfAbsentPut(mr.getProjectId(), () -> getDefaultBranch(GitLabProjectId.newProjectId(idPrefix, mr.getProjectId()))))) + .map(mr -> fromGitLabMergeRequest(GitLabProjectId.newProjectId(idPrefix, mr.getProjectId()).toString(), mr)); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get reviews", - null, - () -> "Error getting reviews"); + () -> "User " + getCurrentUser() + " is not allowed to get reviews", + null, + () -> "Error getting reviews"); } } @@ -318,74 +316,73 @@ private Predicate getTimePredicate(ReviewState state, Instant since, Ins } @Override - public Review getReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review getReview(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); try { GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, mergeRequest); + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId); + return fromGitLabMergeRequest(projectId, mergeRequest); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get review " + reviewId + " for project " + projectId, - () -> "Unknown review (" + reviewId + ") or project (" + projectId + ")", - () -> "Error getting review " + reviewId + " for project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to get review " + reviewId + " for project " + projectId, + () -> "Unknown review (" + reviewId + ") or project (" + projectId + ")", + () -> "Error getting review " + reviewId + " for project " + projectId); } } @Override - public Review createReview(String projectId, SourceSpecification sourceSpecification, String title, String description, List labels) + public Review createReview(String projectId, WorkspaceSpecification workspaceSpecification, String title, String description, List labels) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); LegendSDLCServerException.validateNonNull(title, "title may not be null"); LegendSDLCServerException.validateNonNull(description, "description may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - // checking if target branch exists or not - if (sourceSpecification.getPatchReleaseVersionId() != null && !isPatchReleaseBranchPresent(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId())) - { - throw new LegendSDLCServerException("Target patch release branch " + getPatchReleaseBranchName(sourceSpecification.getPatchReleaseVersionId()) + " for which you want to create review does not exist"); - } + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); + String sourceBranchName = getSourceBranch(gitLabProjectId, workspaceSpecification); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; try { - validateProjectConfigurationForCreateOrCommit(getProjectConfiguration(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId()), null)); - String workspaceBranchName = getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())); - // TODO should we check for other merge requests for this workspace? - MergeRequest mergeRequest = getGitLabApi().getMergeRequestApi().createMergeRequest(gitLabProjectId.getGitLabId(), workspaceBranchName, getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()), title, description, null, null, (labels == null || labels.isEmpty()) ? null : labels.toArray(new String[0]), null, true); - return fromGitLabMergeRequest(projectId, sourceSpecification.getPatchReleaseVersionId(), mergeRequest); + GitLabApi gitLabApi = getGitLabApi(); + boolean sourceBranchExists = withRetries(() -> GitLabApiTools.branchExists(gitLabApi, gitLabProjectId.getGitLabId(), sourceBranchName)); + if (!sourceBranchExists) + { + throw new LegendSDLCServerException("Review target does not exist: " + getReferenceInfo(projectId, workspaceSpecification.getSource()), Status.CONFLICT); + } + + MergeRequest mergeRequest = gitLabApi.getMergeRequestApi().createMergeRequest(gitLabProjectId.getGitLabId(), workspaceBranchName, sourceBranchName, title, description, null, null, (labels == null || labels.isEmpty()) ? null : labels.toArray(new String[0]), null, true); + return fromGitLabMergeRequest(projectId, mergeRequest); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to submit changes from " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + " for review", - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error submitting changes from " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + " for review"); + () -> "User " + getCurrentUser() + " is not allowed to submit changes from " + getReferenceInfo(projectId, workspaceSpecification) + " for review", + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error submitting changes from " + getReferenceInfo(projectId, workspaceSpecification) + " for review"); } } @Override - public Review closeReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review closeReview(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); validateMergeRequestReviewState(mergeRequest, ReviewState.OPEN); try { - MergeRequest closeMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, mergeRequest, Constants.StateEvent.CLOSE); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, closeMergeRequest); + MergeRequest closeMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, mergeRequest, Constants.StateEvent.CLOSE); + return fromGitLabMergeRequest(projectId, closeMergeRequest); } catch (Exception e) { @@ -397,38 +394,38 @@ public Review closeReview(String projectId, VersionId patchReleaseVersionId, Str } @Override - public Review reopenReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review reopenReview(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); validateMergeRequestReviewState(mergeRequest, ReviewState.CLOSED); try { - MergeRequest reopenMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, mergeRequest, StateEvent.REOPEN); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, reopenMergeRequest); + MergeRequest reopenMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, mergeRequest, StateEvent.REOPEN); + return fromGitLabMergeRequest(projectId, reopenMergeRequest); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to reopen review " + reviewId + " in project " + projectId, - () -> "Unknown review in project " + projectId + ": " + reviewId, - () -> "Error reopening review " + reviewId + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to reopen review " + reviewId + " in project " + projectId, + () -> "Unknown review in project " + projectId + ": " + reviewId, + () -> "Error reopening review " + reviewId + " in project " + projectId); } } @Override - public Review approveReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review approveReview(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); try { MergeRequest approvalMergeRequest = mergeRequestApi.approveMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid(), mergeRequest.getSha()); @@ -436,7 +433,7 @@ public Review approveReview(String projectId, VersionId patchReleaseVersionId, S // creating a Review, as most relevant properties are null. The only useful thing we get // from it is the last update time. mergeRequest.setUpdatedAt(approvalMergeRequest.getUpdatedAt()); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, mergeRequest); + return fromGitLabMergeRequest(projectId, mergeRequest); } catch (GitLabApiException e) { @@ -480,14 +477,14 @@ public Review approveReview(String projectId, VersionId patchReleaseVersionId, S } @Override - public Review revokeReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review revokeReviewApproval(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); try { MergeRequest revokeApprovalMergeRequest = mergeRequestApi.unapproveMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid()); @@ -495,43 +492,43 @@ public Review revokeReviewApproval(String projectId, VersionId patchReleaseVersi // for creating a Review, as most relevant properties are null. The only useful thing we // get from it is the last update time. mergeRequest.setUpdatedAt(revokeApprovalMergeRequest.getUpdatedAt()); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, mergeRequest); + return fromGitLabMergeRequest(projectId, mergeRequest); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to revoke approval of review " + reviewId + " in project " + projectId, - () -> "Unknown review in project " + projectId + ": " + reviewId, - () -> "Error revoking review approval " + reviewId + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to revoke approval of review " + reviewId + " in project " + projectId, + () -> "Unknown review in project " + projectId + ": " + reviewId, + () -> "Error revoking review approval " + reviewId + " in project " + projectId); } } @Override - public Review rejectReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review rejectReview(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); validateMergeRequestReviewState(mergeRequest, ReviewState.OPEN); try { - MergeRequest rejectMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, mergeRequest, StateEvent.CLOSE); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, rejectMergeRequest); + MergeRequest rejectMergeRequest = updateMergeRequestState(mergeRequestApi, gitLabProjectId, mergeRequest, StateEvent.CLOSE); + return fromGitLabMergeRequest(projectId, rejectMergeRequest); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to reject review " + reviewId + " in project " + projectId, - () -> "Unknown review in project " + projectId + ": " + reviewId, - () -> "Error rejecting review " + reviewId + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to reject review " + reviewId + " in project " + projectId, + () -> "Unknown review in project " + projectId + ": " + reviewId, + () -> "Error rejecting review " + reviewId + " in project " + projectId); } } @Override - public Approval getReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Approval getReviewApproval(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); @@ -544,14 +541,14 @@ public Approval getReviewApproval(String projectId, VersionId patchReleaseVersio catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get approval details for review " + reviewId + " in project " + projectId, - () -> "Unknown review (" + reviewId + ") or project (" + projectId + ")", - () -> "Error getting approval details for review " + reviewId + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to get approval details for review " + reviewId + " in project " + projectId, + () -> "Unknown review (" + reviewId + ") or project (" + projectId + ")", + () -> "Error getting approval details for review " + reviewId + " in project " + projectId); } } @Override - public Review commitReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String message) + public Review commitReview(String projectId, String reviewId, String message) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); @@ -561,7 +558,7 @@ public Review commitReview(String projectId, VersionId patchReleaseVersionId, St MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); // Find the merge request - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); // Validate that the merge request is ready to be merged @@ -576,12 +573,12 @@ public Review commitReview(String projectId, VersionId patchReleaseVersionId, St } // Validate the project configuration - WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); - if (workspaceInfo == null) + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + if (workspaceSpec == null) { throw new LegendSDLCServerException("Error committing review " + reviewId + " in project " + projectId + ": could not find workspace information"); } - ProjectConfiguration projectConfig = getProjectConfiguration(projectId, workspaceInfo, null); + ProjectConfiguration projectConfig = getProjectConfiguration(projectId, workspaceSpec.getSourceSpecification(), null); validateProjectConfigurationForCreateOrCommit(projectConfig); // TODO add more validations @@ -589,7 +586,7 @@ public Review commitReview(String projectId, VersionId patchReleaseVersionId, St // Accept try { - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, mergeRequestApi.acceptMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid(), message, true, null, null)); + return fromGitLabMergeRequest(projectId, mergeRequestApi.acceptMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid(), message, true, null, null)); } catch (GitLabApiException e) { @@ -660,14 +657,14 @@ public Review commitReview(String projectId, VersionId patchReleaseVersionId, St } @Override - public ReviewUpdateStatus getReviewUpdateStatus(String projectId, VersionId patchReleaseVersionId, String reviewId) + public ReviewUpdateStatus getReviewUpdateStatus(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); GitLabApi gitLabApi = getGitLabApi(); - MergeRequest mergeRequest = getReviewMergeRequest(gitLabApi.getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(gitLabApi.getMergeRequestApi(), gitLabProjectId, reviewId); if (!(isOpen(mergeRequest) || isLocked(mergeRequest))) { throw new LegendSDLCServerException("Cannot get update status for review " + mergeRequest.getIid() + " in project " + projectId + ": state is " + getReviewState(mergeRequest), Status.CONFLICT); @@ -676,7 +673,7 @@ public ReviewUpdateStatus getReviewUpdateStatus(String projectId, VersionId patc } @Override - public ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public ReviewUpdateStatus updateReview(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); @@ -686,7 +683,7 @@ public ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseV MergeRequestApi mergeRequestApi = gitLabApi.getMergeRequestApi(); // Check the current status of the review - MergeRequest initialMergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest initialMergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); if (!isOpen(initialMergeRequest)) { throw new LegendSDLCServerException("Only open reviews can be updated: state of review " + initialMergeRequest.getIid() + " in project " + projectId + " is " + getReviewState(initialMergeRequest), Status.CONFLICT); @@ -703,10 +700,10 @@ public ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseV try { CallUntil callUntil = CallUntil.callUntil( - () -> withRetries(() -> mergeRequestApi.rebaseMergeRequest(gitLabProjectId.getGitLabId(), initialMergeRequest.getIid())), - MergeRequest::getRebaseInProgress, - 3, - 500L); + () -> withRetries(() -> mergeRequestApi.rebaseMergeRequest(gitLabProjectId.getGitLabId(), initialMergeRequest.getIid())), + MergeRequest::getRebaseInProgress, + 3, + 500L); if (!callUntil.succeeded()) { throw new LegendSDLCServerException("Failed to start update for review " + reviewId + " in project " + projectId); @@ -716,15 +713,15 @@ public ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseV catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to update review " + reviewId + " in project " + projectId, - () -> "Unknown review in project " + projectId + ": " + reviewId, - () -> "Error updating review " + reviewId + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to update review " + reviewId + " in project " + projectId, + () -> "Unknown review in project " + projectId + ": " + reviewId, + () -> "Error updating review " + reviewId + " in project " + projectId); } return getReviewUpdateStatus(gitLabProjectId, gitLabApi, rebaseMergeRequest); } @Override - public Review editReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String title, String description, List labels) + public Review editReview(String projectId, String reviewId, String title, String description, List labels) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); @@ -735,7 +732,7 @@ public Review editReview(String projectId, VersionId patchReleaseVersionId, Stri GitLabApi gitLabApi = getGitLabApi(); MergeRequestApi mergeRequestApi = gitLabApi.getMergeRequestApi(); - MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, patchReleaseVersionId, reviewId); + MergeRequest mergeRequest = getReviewMergeRequest(mergeRequestApi, gitLabProjectId, reviewId); if (!isOpen(mergeRequest)) { throw new LegendSDLCServerException("Only open reviews can be edited: state of review " + mergeRequest.getIid() + " in project " + gitLabProjectId.toString() + " is " + getReviewState(mergeRequest)); @@ -749,14 +746,14 @@ public Review editReview(String projectId, VersionId patchReleaseVersionId, Stri } MergeRequest editedRequest = mergeRequestApi.updateMergeRequest(gitLabProjectId.getGitLabId(), mergeRequest.getIid(), mergeRequestParams); - return fromGitLabMergeRequest(projectId, patchReleaseVersionId, editedRequest); + return fromGitLabMergeRequest(projectId, editedRequest); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to edit review " + reviewId + " in project " + projectId, - () -> "Unknown review in project " + projectId + ": " + reviewId, - () -> "Error editing review " + reviewId + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to edit review " + reviewId + " in project " + projectId, + () -> "Unknown review in project " + projectId + ": " + reviewId, + () -> "Error editing review " + reviewId + " in project " + projectId); } } @@ -873,9 +870,9 @@ private void validateMergeRequestReviewState(MergeRequest mergeRequest, ReviewSt } } - protected MergeRequest updateMergeRequestState(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, VersionId patchReleaseVersionId, MergeRequest mergeRequest, Constants.StateEvent stateEvent) throws GitLabApiException + protected MergeRequest updateMergeRequestState(MergeRequestApi mergeRequestApi, GitLabProjectId projectId, MergeRequest mergeRequest, Constants.StateEvent stateEvent) throws GitLabApiException { - return mergeRequestApi.updateMergeRequest(projectId.getGitLabId(), mergeRequest.getIid(), getSourceBranch(projectId, patchReleaseVersionId), null, null, null, stateEvent, null, null, null, null, null, null); + return mergeRequestApi.updateMergeRequest(projectId.getGitLabId(), mergeRequest.getIid(), null, null, null, null, stateEvent, null, null, null, null, null, null); } private boolean isCreatedAtWithinBounds(Review review, Instant lowerBound, Instant upperBound) @@ -948,7 +945,7 @@ private static Constants.MergeRequestState getMergeRequestState(ReviewState stat } } - protected static Review fromGitLabMergeRequest(String projectId, VersionId patchReleaseVersionId, MergeRequest mergeRequest) + protected static Review fromGitLabMergeRequest(String projectId, MergeRequest mergeRequest) { if (mergeRequest == null) { @@ -956,17 +953,18 @@ protected static Review fromGitLabMergeRequest(String projectId, VersionId patch } String sourceBranchName = mergeRequest.getSourceBranch(); - WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(sourceBranchName); - if ((workspaceInfo == null) || (workspaceInfo.getWorkspaceAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + WorkspaceSpecification workspaceInfo = parseWorkspaceBranchName(sourceBranchName); + if ((workspaceInfo == null) || (workspaceInfo.getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) { return null; } + return newReview(mergeRequest.getIid(), projectId, workspaceInfo, mergeRequest.getTitle(), mergeRequest.getDescription(), mergeRequest.getCreatedAt(), mergeRequest.getUpdatedAt(), mergeRequest.getClosedAt(), mergeRequest.getMergedAt(), mergeRequest.getState(), mergeRequest.getAuthor(), mergeRequest.getMergeCommitSha(), mergeRequest.getWebUrl(), mergeRequest.getLabels()); } - private static Review newReview(Integer reviewId, String projectId, WorkspaceInfo workspaceInfo, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser author, String commitRevisionId, String webURL, List labels) + private static Review newReview(Integer reviewId, String projectId, WorkspaceSpecification workspaceSpec, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser author, String commitRevisionId, String webURL, List labels) { - return newReview(reviewId, projectId, workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), title, description, createdAt, lastUpdatedAt, closedAt, committedAt, reviewState, author, commitRevisionId, webURL, labels); + return newReview(reviewId, projectId, workspaceSpec.getId(), workspaceSpec.getType(), title, description, createdAt, lastUpdatedAt, closedAt, committedAt, reviewState, author, commitRevisionId, webURL, labels); } private static Review newReview(Integer reviewId, String projectId, String workspaceId, WorkspaceType workspaceType, String title, String description, Date createdAt, Date lastUpdatedAt, Date closedAt, Date committedAt, String reviewState, AbstractUser author, String commitRevisionId, String webURL, List labels) diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApi.java index a879679144..83063e8fa6 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApi.java @@ -19,15 +19,15 @@ import org.eclipse.collections.api.list.MutableList; import org.eclipse.collections.impl.utility.Iterate; import org.eclipse.collections.impl.utility.LazyIterate; +import org.finos.legend.sdlc.domain.model.patch.Patch; import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.revision.RevisionStatus; import org.finos.legend.sdlc.domain.model.version.Version; -import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.revision.RevisionAccessContext; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -40,7 +40,6 @@ import org.finos.legend.sdlc.tools.entity.EntityPaths; import org.gitlab4j.api.CommitsApi; import org.gitlab4j.api.GitLabApi; -import org.gitlab4j.api.Pager; import org.gitlab4j.api.TagsApi; import org.gitlab4j.api.models.CommitRef; import org.gitlab4j.api.models.CommitRef.RefType; @@ -66,131 +65,53 @@ public GitLabRevisionApi(GitLabConfiguration gitLabConfiguration, GitLabUserCont } @Override - public RevisionAccessContext getProjectRevisionContext(String projectId, VersionId patchReleaseVersionId) + public RevisionAccessContext getRevisionContext(String projectId, SourceSpecification sourceSpec) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null)); + LegendSDLCServerException.validateNonNull(sourceSpec, "sourceSpec may not be null"); + return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpec)); } @Override - public RevisionAccessContext getProjectEntityRevisionContext(String projectId, VersionId patchReleaseVersionId, String entityPath) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(entityPath, "entityPath may not be null"); - if (!EntityPaths.isValidEntityPath(entityPath)) - { - throw new LegendSDLCServerException("Invalid entity path: " + entityPath, Status.BAD_REQUEST); - } - ProjectFileAccessProvider fileAccessProvider = getProjectFileAccessProvider(); - ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null); - ProjectStructure projectStructure = ProjectStructure.getProjectStructure(fileAccessContext); - String filePath = projectStructure.findEntityFile(entityPath, fileAccessContext); - if (filePath == null) - { - throw new LegendSDLCServerException("Cannot find entity \"" + entityPath + "\" in project " + projectId, Status.NOT_FOUND); - } - String canonicalizedFilePath = ProjectPaths.canonicalizeFile(filePath); - return new ProjectFileRevisionAccessContextWrapper(fileAccessProvider.getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), Collections.singleton(canonicalizedFilePath)), new PackageablePathExceptionProcessor(entityPath, canonicalizedFilePath)); - } - - @Override - public RevisionAccessContext getProjectPackageRevisionContext(String projectId, VersionId patchReleaseVersionId, String packagePath) + public RevisionAccessContext getPackageRevisionContext(String projectId, SourceSpecification sourceSpec, String packagePath) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); + LegendSDLCServerException.validateNonNull(sourceSpec, "sourceSpec may not be null"); LegendSDLCServerException.validateNonNull(packagePath, "packagePath may not be null"); if (!EntityPaths.isValidPackagePath(packagePath)) { throw new LegendSDLCServerException("Invalid package path: " + packagePath, Status.BAD_REQUEST); } - ProjectStructure projectStructure = getProjectStructure(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), null); + ProjectStructure projectStructure = getProjectStructure(projectId, sourceSpec, null); MutableList directories = Iterate.collectWith(projectStructure.getEntitySourceDirectories(), ProjectStructure.EntitySourceDirectory::packagePathToFilePath, packagePath, Lists.mutable.empty()); MutableList canonicalizedAndReducedDirectories = ProjectPaths.canonicalizeAndReduceDirectories(directories); - return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(patchReleaseVersionId), canonicalizedAndReducedDirectories), new PackageablePathExceptionProcessor(packagePath, canonicalizedAndReducedDirectories)); - } - - @Override - public RevisionAccessContext getWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceRevisionContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId())); + return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpec, canonicalizedAndReducedDirectories), new PackageablePathExceptionProcessor(packagePath, canonicalizedAndReducedDirectories)); } @Override - public RevisionAccessContext getBackupWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceRevisionContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public RevisionAccessContext getWorkspaceWithConflictResolutionRevisionContext(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceRevisionContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId())); - } - - private RevisionAccessContext getWorkspaceRevisionContextByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, null)); - } - - @Override - public RevisionAccessContext getWorkspaceEntityRevisionContext(String projectId, SourceSpecification sourceSpecification, String entityPath) - { - return this.getWorkspaceEntityRevisionContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId()), entityPath); - } - - private RevisionAccessContext getWorkspaceEntityRevisionContextByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification, String entityPath) + public RevisionAccessContext getEntityRevisionContext(String projectId, SourceSpecification sourceSpec, String entityPath) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); + LegendSDLCServerException.validateNonNull(sourceSpec, "sourceSpec may not be null"); LegendSDLCServerException.validateNonNull(entityPath, "entityPath may not be null"); if (!EntityPaths.isValidEntityPath(entityPath)) { throw new LegendSDLCServerException("Invalid entity path: " + entityPath, Status.BAD_REQUEST); } - ProjectFileAccessProvider fileAccessProvider = getProjectFileAccessProvider(); - ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(projectId, sourceSpecification, null); + ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(projectId, sourceSpec, null); ProjectStructure projectStructure = ProjectStructure.getProjectStructure(fileAccessContext); String filePath = projectStructure.findEntityFile(entityPath, fileAccessContext); if (filePath == null) { - throw new LegendSDLCServerException("Cannot find entity \"" + entityPath + "\" in " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, Status.NOT_FOUND); + throw new LegendSDLCServerException("Cannot find entity \"" + entityPath + "\" in " + getReferenceInfo(projectId, sourceSpec), Status.NOT_FOUND); } - String canonicalizedFilePath = ProjectPaths.canonicalizeFile(filePath); - return new ProjectFileRevisionAccessContextWrapper(fileAccessProvider.getRevisionAccessContext(projectId, sourceSpecification, Collections.singleton(canonicalizedFilePath)), new PackageablePathExceptionProcessor(entityPath, canonicalizedFilePath)); - } - - @Override - public RevisionAccessContext getWorkspacePackageRevisionContext(String projectId, SourceSpecification sourceSpecification, String packagePath) - { - return this.getWorkspacePackageRevisionContextByWorkspaceAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId()), packagePath); - } - - private RevisionAccessContext getWorkspacePackageRevisionContextByWorkspaceAccessType(String projectId, SourceSpecification sourceSpecification, String packagePath) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification, "source specification may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - LegendSDLCServerException.validateNonNull(packagePath, "packagePath may not be null"); - if (!EntityPaths.isValidPackagePath(packagePath)) - { - throw new LegendSDLCServerException("Invalid package path: " + packagePath, Status.BAD_REQUEST); - } - ProjectStructure projectStructure = getProjectStructure(projectId, sourceSpecification, null); - MutableList directories = Iterate.collectWith(projectStructure.getEntitySourceDirectories(), ProjectStructure.EntitySourceDirectory::packagePathToFilePath, packagePath, Lists.mutable.empty()); - MutableList canonicalizedAndReducedDirectories = ProjectPaths.canonicalizeAndReduceDirectories(directories); - return new ProjectFileRevisionAccessContextWrapper(getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification, canonicalizedAndReducedDirectories), new PackageablePathExceptionProcessor(packagePath, canonicalizedAndReducedDirectories)); + String canonicalFilePath = ProjectPaths.canonicalizeFile(filePath); + return new ProjectFileRevisionAccessContextWrapper(fileAccessProvider.getRevisionAccessContext(projectId, sourceSpec, Collections.singleton(canonicalFilePath)), new PackageablePathExceptionProcessor(entityPath, canonicalFilePath)); } @Override - public RevisionStatus getRevisionStatus(String projectId, VersionId patchReleaseVersionId, String revisionId) + public RevisionStatus getRevisionStatus(String projectId, String revisionId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); @@ -200,18 +121,16 @@ public RevisionStatus getRevisionStatus(String projectId, VersionId patchRelease { GitLabApi gitLabApi = getGitLabApi(); CommitsApi commitsApi = gitLabApi.getCommitsApi(); - Revision revision = getProjectRevisionContext(projectId, null).getRevision(revisionId); + Revision revision = getRevisionContext(projectId, SourceSpecification.projectSourceSpecification()).getRevision(revisionId); - Pager commitRefPager = withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), revision.getId(), RefType.ALL, ITEMS_PER_PAGE)); - List commitRefs = PagerTools.stream(commitRefPager).collect(Collectors.toList()); - String sourceBranch = getSourceBranch(gitLabProjectId, patchReleaseVersionId); - boolean isCommitted = commitRefs.stream().anyMatch(cr -> sourceBranch.equals(cr.getName())); + MutableList commitRefs = PagerTools.stream(withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), revision.getId(), RefType.ALL, ITEMS_PER_PAGE))) + .collect(Collectors.toCollection(Lists.mutable::empty)); + + String defaultBranch = getDefaultBranch(gitLabProjectId); + boolean isCommitted = commitRefs.anySatisfy(cr -> defaultBranch.equals(cr.getName())); List versions; - List versionTagNames = commitRefs.stream() - .filter(cr -> (RefType.TAG == cr.getType()) && isVersionTagName(cr.getName())) - .map(CommitRef::getName) - .collect(Collectors.toList()); + MutableList versionTagNames = commitRefs.collectIf(cr -> (RefType.TAG == cr.getType()) && isVersionTagName(cr.getName()), CommitRef::getName); if (versionTagNames.isEmpty()) { versions = Collections.emptyList(); @@ -228,18 +147,33 @@ public RevisionStatus getRevisionStatus(String projectId, VersionId patchRelease versions.sort(Comparator.comparing(Version::getId)); } - List workspaces; - if (isCommitted) - { - workspaces = Collections.emptyList(); - } - else + List workspaces = Lists.mutable.empty(); + List patches = Lists.mutable.empty(); + if (!isCommitted) { // Note that here we will not account for conflict resolution or backup branch because in the model those are not real workspaces. - workspaces = commitRefs.stream() - .filter(cr -> (RefType.BRANCH == cr.getType()) && isWorkspaceBranchName(cr.getName(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) - .map(cr -> fromWorkspaceBranchName(projectId, patchReleaseVersionId, cr.getName(), WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) - .collect(Collectors.toList()); + String patchReleaseBranchPrefix = getPatchReleaseBranchPrefix(); + commitRefs.forEach(cr -> + { + if (cr.getType() != RefType.BRANCH) + { + return; + } + + // patch branch + if (branchNameStartsWith(cr.getName(), patchReleaseBranchPrefix)) + { + patches.add(fromPatchBranchName(projectId, cr.getName())); + return; + } + + // workspace branch + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(cr.getName()); + if ((workspaceSpec != null) && (workspaceSpec.getAccessType() == ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + { + workspaces.add(fromWorkspaceSpecification(projectId, workspaceSpec)); + } + }); } return new RevisionStatus() @@ -267,6 +201,12 @@ public List getVersions() { return versions; } + + @Override + public List getPatches() + { + return patches; + } }; } catch (Exception e) diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApi.java index 2b4ab0402d..a261aca21b 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApi.java @@ -15,14 +15,15 @@ package org.finos.legend.sdlc.server.gitlab.api; import org.eclipse.collections.api.factory.Lists; -import org.eclipse.collections.impl.utility.Iterate; import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceConsumer; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -30,6 +31,7 @@ import org.finos.legend.sdlc.server.gitlab.tools.GitLabApiTools; import org.finos.legend.sdlc.server.gitlab.tools.PagerTools; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.WorkspaceAccessType; import org.finos.legend.sdlc.server.tools.BackgroundTaskProcessor; import org.finos.legend.sdlc.server.tools.CallUntil; import org.gitlab4j.api.CommitsApi; @@ -51,14 +53,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.inject.Inject; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; import java.util.Arrays; +import java.util.Collections; +import java.util.EnumSet; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import javax.inject.Inject; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; public class GitLabWorkspaceApi extends GitLabApiWithFileAccess implements WorkspaceApi { @@ -74,141 +79,148 @@ public GitLabWorkspaceApi(GitLabConfiguration gitLabConfiguration, GitLabUserCon } @Override - public List getWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes) - { - return Iterate.flatCollect(workspaceTypes, type -> getWorkspacesByAccessType(projectId, patchReleaseVersionId, type, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), Lists.mutable.empty()); - } - - @Override - public List getWorkspacesWithConflictResolution(String projectId, VersionId patchReleaseVersionId) - { - return getWorkspacesByAccessType(projectId, patchReleaseVersionId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION); - } - - @Override - public List getBackupWorkspaces(String projectId, VersionId patchReleaseVersionId) - { - return getWorkspacesByAccessType(projectId, patchReleaseVersionId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP); - } - - private List getWorkspacesByAccessType(String projectId, VersionId patchReleaseVersionId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) + public Workspace getWorkspace(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + try { GitLabProjectId gitLabProjectId = parseProjectId(projectId); - String branchPrefix = getWorkspaceBranchName(SourceSpecification.newSourceSpecification("", workspaceType, workspaceAccessType, patchReleaseVersionId)); - Pager pager = getGitLabApi().getRepositoryApi().getBranches(gitLabProjectId.getGitLabId(), "^" + branchPrefix, ITEMS_PER_PAGE); - return PagerTools.stream(pager) - .filter(branch -> (branch != null) && (branch.getName() != null) && branch.getName().startsWith(branchPrefix)) - .map(branch -> workspaceBranchToWorkspace(projectId, patchReleaseVersionId, branch, workspaceType, workspaceAccessType)) - .collect(PagerTools.listCollector(pager)); + String branchName = getWorkspaceBranchName(workspaceSpecification); + RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); + Branch branch = withRetries(() -> GitLabApiTools.getBranch(repositoryApi, gitLabProjectId.getGitLabId(), branchName)); + return fromWorkspaceBranchName(projectId, branch.getName()); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + workspaceType.getLabel() + " " + workspaceAccessType.getLabelPlural() + " for project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error getting " + workspaceType.getLabel() + " " + workspaceAccessType.getLabelPlural() + " for project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to get " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error getting " + getReferenceInfo(projectId, workspaceSpecification)); } } @Override - public List getAllWorkspaces(String projectId, VersionId patchReleaseVersionId, Set WorkspaceTypes) + public List getWorkspaces(String projectId, Set types, Set accessTypes, Set sources) + { + return getWorkspaces(projectId, types, accessTypes, sources, getCurrentUser()); + } + + @Override + public List getAllWorkspaces(String projectId, Set types, Set accessTypes, Set sources) { - return Iterate.flatCollect(WorkspaceTypes, type -> getAllWorkspacesByAccessType(projectId, patchReleaseVersionId, type, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), Lists.mutable.empty()); + return getWorkspaces(projectId, types, accessTypes, sources, null); } - private List getAllWorkspacesByAccessType(String projectId, VersionId patchReleaseVersionId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) + private List getWorkspaces(String projectId, Set types, Set accessTypes, Set sources, String userId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); + + Set resolvedTypes = (types == null) ? EnumSet.allOf(WorkspaceType.class) : types; + Set resolvedAccessTypes = (accessTypes == null) ? EnumSet.allOf(WorkspaceAccessType.class) : accessTypes; + try { - GitLabProjectId gitLabProjectId = parseProjectId(projectId); - String branchPrefix = patchReleaseVersionId == null ? getWorkspaceBranchNamePrefix(workspaceType, workspaceAccessType) + BRANCH_DELIMITER : PATCH_RELEASE_WORKSPACE_BRANCH_PREFIX + BRANCH_DELIMITER + getWorkspaceBranchNamePrefix(workspaceType, workspaceAccessType) + BRANCH_DELIMITER + patchReleaseVersionId.toVersionIdString() + BRANCH_DELIMITER; - Pager pager = getGitLabApi().getRepositoryApi().getBranches(gitLabProjectId.getGitLabId(), "^" + branchPrefix, ITEMS_PER_PAGE); - return PagerTools.stream(pager) - .filter(branch -> (branch != null) && (branch.getName() != null) && branch.getName().startsWith(branchPrefix)) - .map(branch -> workspaceBranchToWorkspace(projectId, patchReleaseVersionId, branch, workspaceType, workspaceAccessType)) - .collect(PagerTools.listCollector(pager)); + Stream stream = null; + if (sources == null) + { + stream = getAllPatchWorkspaces(gitLabProjectId, types, accessTypes, userId); + } + else + { + for (WorkspaceType type : resolvedTypes) + { + for (WorkspaceAccessType accessType : resolvedAccessTypes) + { + for (WorkspaceSource source : sources) + { + Stream localStream = getWorkspaces(gitLabProjectId, type, accessType, source, userId); + stream = (stream == null) ? localStream : Stream.concat(stream, localStream); + } + } + } + } + if (stream == null) + { + // If stream is null, then types, accessTypes, or sources is empty, which means the result must be empty. + // However, we still should verify that the project exists and that the user is allowed to access branches. + // The following request should result in an error if either the project does not exist or the user is not + // allowed to access branches. + withRetries(() -> getGitLabApi().getRepositoryApi().getBranches(gitLabProjectId.getGitLabId(), 1)); + return Collections.emptyList(); + } + String prIdStr = gitLabProjectId.toString(); + return stream.map(ws -> fromWorkspaceSpecification(prIdStr, ws)).collect(Collectors.toList()); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + workspaceType.getLabel() + " " + workspaceAccessType.getLabelPlural() + " for project " + projectId, + () -> "User " + getCurrentUser() + " is not allowed to get workspaces for project " + projectId, () -> "Unknown project: " + projectId, - () -> "Error getting " + workspaceType.getLabel() + " " + workspaceAccessType.getLabelPlural() + " for project " + projectId); + () -> "Error getting workspaces for project " + projectId); } } - @Override - public Workspace getWorkspace(String projectId, SourceSpecification sourceSpecification) + private Stream getAllPatchWorkspaces(GitLabProjectId projectId, Set types, Set accessTypes, String userId) throws GitLabApiException { - return getWorkspaceByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public Workspace getWorkspaceWithConflictResolution(String projectId, SourceSpecification sourceSpecification) - { - return getWorkspaceByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId())); - } - - @Override - public Workspace getBackupWorkspace(String projectId, SourceSpecification sourceSpecification) - { - return this.getWorkspaceByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId())); - } - - private Workspace getWorkspaceByAccessType(String projectId, SourceSpecification sourceSpecification) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - try + String branchPrefix = getPatchWorkspaceBranchPrefix(); + RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); + Pager pager = withRetries(() -> repositoryApi.getBranches(projectId.getGitLabId(), "^" + branchPrefix, ITEMS_PER_PAGE)); + Stream stream = PagerTools.stream(pager) + .map(Branch::getName) + .filter(n -> (n != null) && n.startsWith(branchPrefix)) + .map(GitLabWorkspaceApi::parseWorkspaceBranchName) + .filter(Objects::nonNull); + if (types != null) { - GitLabProjectId gitLabProjectId = parseProjectId(projectId); - Branch branch = getGitLabApi().getRepositoryApi().getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(sourceSpecification)); - return workspaceBranchToWorkspace(projectId, sourceSpecification.getPatchReleaseVersionId(),branch, sourceSpecification.getWorkspaceType(), sourceSpecification.getWorkspaceAccessType()); + stream = stream.filter(ws -> types.contains(ws.getType())); } - catch (Exception e) + if (accessTypes != null) { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error getting " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + stream = stream.filter(ws -> accessTypes.contains(ws.getAccessType())); + } + if (userId != null) + { + stream = stream.filter(ws -> userId.equals(ws.getUserId())); } + return stream; } - @Override - public boolean isWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification) + private Stream getWorkspaces(GitLabProjectId projectId, WorkspaceType type, WorkspaceAccessType accessType, WorkspaceSource source, String userId) throws GitLabApiException { - return this.isWorkspaceOutdatedByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, sourceSpecification.getPatchReleaseVersionId())); - } + String branchPrefix = getBranchSearchPrefix(type, accessType, source, userId); - @Override - public boolean isWorkspaceWithConflictResolutionOutdated(String projectId, SourceSpecification sourceSpecification) - { - return this.isWorkspaceOutdatedByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, sourceSpecification.getPatchReleaseVersionId())); + RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); + Pager pager = withRetries(() -> repositoryApi.getBranches(projectId.getGitLabId(), "^" + branchPrefix, ITEMS_PER_PAGE)); + return PagerTools.stream(pager) + .map(Branch::getName) + .filter(n -> (n != null) && n.startsWith(branchPrefix)) + .map(GitLabWorkspaceApi::parseWorkspaceBranchName) + .filter(Objects::nonNull) + .filter(spec -> (spec.getType() == type) && (spec.getAccessType() == accessType) && source.equals(spec.getSource())); } - @Override - public boolean isBackupWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification) + private String getBranchSearchPrefix(WorkspaceType type, WorkspaceAccessType accessType, WorkspaceSource source, String userId) { - return this.isWorkspaceOutdatedByAccessType(projectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, sourceSpecification.getPatchReleaseVersionId())); + if (type == WorkspaceType.USER) + { + return (userId == null) ? + getWorkspaceBranchNamePrefix(WorkspaceSpecification.newWorkspaceSpecification("", type, accessType, source)) : + getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("", type, accessType, source, userId)); + } + return getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("", type, accessType, source)); } - private boolean isWorkspaceOutdatedByAccessType(String projectId, SourceSpecification sourceSpecification) + @Override + public boolean isWorkspaceOutdated(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - String workspaceBranchName = getBranchName(gitLabProjectId, sourceSpecification); + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); GitLabApi gitLabApi = getGitLabApi(); RepositoryApi repositoryApi = gitLabApi.getRepositoryApi(); @@ -221,16 +233,15 @@ private boolean isWorkspaceOutdatedByAccessType(String projectId, SourceSpecific catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " in project " + projectId + ": " + sourceSpecification.getWorkspaceId(), - () -> "Error accessing " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error accessing " + getReferenceInfo(projectId, workspaceSpecification)); } String workspaceRevisionId = workspaceBranch.getCommit().getId(); // Get source branch + String sourceBranchName = getSourceBranch(gitLabProjectId, workspaceSpecification); Branch sourceBranch; - String sourceBranchName = getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()); - try { sourceBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), sourceBranchName)); @@ -238,20 +249,21 @@ private boolean isWorkspaceOutdatedByAccessType(String projectId, SourceSpecific catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access the latest revision in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error accessing latest revision for project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access the latest revision in " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Error accessing latest revision for " + getReferenceInfo(projectId, workspaceSpecification.getSource())); } String sourceBranchRevisionId = sourceBranch.getCommit().getId(); - CommitsApi commitsApi = gitLabApi.getCommitsApi(); // Check if the workspace does not have the latest revision of the project, i.e. it is outdated + if (sourceBranchRevisionId.equals(workspaceRevisionId)) + { + return false; + } + + CommitsApi commitsApi = gitLabApi.getCommitsApi(); try { - if (sourceBranchRevisionId.equals(workspaceRevisionId)) - { - return false; - } Pager sourceCommitRefsPager = withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), sourceBranchRevisionId, RefType.BRANCH, ITEMS_PER_PAGE)); Stream sourceCommitRefs = PagerTools.stream(sourceCommitRefsPager); // This will check if the branch contains the master HEAD commit by looking up the list of references the commit is pushed to @@ -260,62 +272,65 @@ private boolean isWorkspaceOutdatedByAccessType(String projectId, SourceSpecific catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to check if " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId + " is outdated", - () -> "Unknown revision (" + sourceBranchRevisionId + "), or " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error checking if " + sourceSpecification.getWorkspaceType().getLabel() + " " + sourceSpecification.getWorkspaceAccessType().getLabel() + " " + sourceSpecification.getWorkspaceId() + " of project " + projectId + " is outdated"); + () -> "User " + getCurrentUser() + " is not allowed to check if " + getReferenceInfo(projectId, workspaceSpecification) + " is outdated", + () -> "Unknown revision (" + sourceBranchRevisionId + "), or " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error checking if " + getReferenceInfo(projectId, workspaceSpecification) + " is outdated"); } } @Override - public boolean isWorkspaceInConflictResolutionMode(String projectId, SourceSpecification sourceSpecification) + public boolean isWorkspaceInConflictResolutionMode(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); + GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; + + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); try { - withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())))); + withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), workspaceBranchName)); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error getting " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " is in conflict resolution mode for " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error accessing " + getReferenceInfo(projectId, workspaceSpecification)); + } + + if (workspaceSpecification.getAccessType() != WorkspaceAccessType.WORKSPACE) + { + return false; } - Branch conflictBranch; - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; + + WorkspaceSpecification conflictWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.CONFLICT_RESOLUTION, workspaceSpecification.getSource(), workspaceSpecification.getUserId()); + String conflictBranchName = getWorkspaceBranchName(conflictWorkspaceSpec); try { - conflictBranch = repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId()))); - return conflictBranch != null; + return GitLabApiTools.branchExists(repositoryApi, gitLabProjectId.getGitLabId(), conflictBranchName); } catch (Exception e) { - if (GitLabApiTools.isNotFoundGitLabApiException(e)) - { - return false; - } throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to check if " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " is in conflict resolution mode for " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error checking if " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " is in conflict resolution mode for " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, conflictWorkspaceSpec), + () -> "Unknown: " + getReferenceInfo(projectId, conflictWorkspaceSpec), + () -> "Error accessing " + getReferenceInfo(projectId, conflictWorkspaceSpec)); } } - /** - * When we create a new workspace, we also should clean left-over backup and conflict resolution workspaces with the same name - */ @Override - public Workspace newWorkspace(String projectId, SourceSpecification sourceSpecification) + public Workspace newWorkspace(String projectId, String workspaceId, WorkspaceType type, WorkspaceSource source) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceId, "workspace id may not be null"); + LegendSDLCServerException.validateNonNull(type, "workspace type may not be null"); + LegendSDLCServerException.validateNonNull(source, "workspace source may not be null"); - validateWorkspaceId(sourceSpecification.getWorkspaceId()); - if (this.getProjectConfiguration(projectId, sourceSpecification.getPatchReleaseVersionId()) == null) + validateWorkspaceId(workspaceId); + WorkspaceSpecification workspaceSpecification = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, type, WorkspaceAccessType.WORKSPACE, source); + if (getProjectConfiguration(projectId, workspaceSpecification.getSourceSpecification()) == null) { throw new LegendSDLCServerException("Project structure has not been set up", Status.CONFLICT); } @@ -324,152 +339,139 @@ public Workspace newWorkspace(String projectId, SourceSpecification sourceSpecif RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); // check if the source branch exists or not - if (sourceSpecification.getPatchReleaseVersionId() != null && !isPatchReleaseBranchPresent(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId())) + workspaceSpecification.getSource().visit(new WorkspaceSourceConsumer() { - throw new LegendSDLCServerException("Patch release branch for " + sourceSpecification.getPatchReleaseVersionId() + " doesn't exist", Response.Status.BAD_REQUEST); - } + @Override + protected void accept(PatchWorkspaceSource source) + { + if (!isPatchReleaseBranchPresent(gitLabProjectId, source.getPatchVersionId())) + { + throw new LegendSDLCServerException("Patch release branch for " + source.getPatchVersionId() + " doesn't exist", Response.Status.BAD_REQUEST); + } + } + }); // Delete backup workspace with the same name if exists - Branch backupBranch = null; - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; + String backupBranchName = getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, type, WorkspaceAccessType.BACKUP, source)); try { - backupBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())))); - } - catch (Exception e) - { - if (!GitLabApiTools.isNotFoundGitLabApiException(e)) + if (GitLabApiTools.branchExists(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName)) { - LOGGER.error("Error accessing {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); - } - } - if (backupBranch != null) - { - LOGGER.debug("Cleaning up left-over {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); - try - { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + LOGGER.debug("Cleaning up left-over backup branch {} in project {}", backupBranchName, projectId); + boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); if (!deleted) { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.error("Failed to delete backup branch {} in project {}", backupBranchName, projectId); } } - catch (Exception e) - { - // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); - } - } - // Delete workspace with conflict resolution with the same name if exists - Branch conflictResolutionBranch = null; - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; - try - { - conflictResolutionBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())))); } catch (Exception e) { - if (!GitLabApiTools.isNotFoundGitLabApiException(e)) - { - LOGGER.error("Error accessing {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); - } + LOGGER.error("Error cleaning up backup branch {} in project {}", backupBranchName, projectId, e); } - if (conflictResolutionBranch != null) + + // Delete workspace with conflict resolution with the same name if exists + String conflictResolutionBranchName = getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, type, WorkspaceAccessType.CONFLICT_RESOLUTION, source)); + try { - LOGGER.debug("Cleaning up left-over {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); - try + if (GitLabApiTools.branchExists(repositoryApi, gitLabProjectId.getGitLabId(), conflictResolutionBranchName)) { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + LOGGER.debug("Cleaning up left-over conflict resolution branch {} in project {}", conflictResolutionBranchName, projectId); + boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), conflictResolutionBranchName, 20, 1_000); if (!deleted) { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.error("Failed to delete conflict resolution branch {} in project {}", conflictResolutionBranchName, projectId); } } - catch (Exception e) - { - // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); - } } + catch (Exception e) + { + LOGGER.error("Error cleaning up conflict resolution branch {} in project {}", conflictResolutionBranchName, projectId, e); + } + // Create new workspace + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); + String sourceBranchName = getSourceBranch(gitLabProjectId, workspaceSpecification); Branch branch; - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; try { - branch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()), 30, 1_000); + branch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, sourceBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId, + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, workspaceSpecification), () -> "Unknown project: " + projectId, - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "Error creating " + getReferenceInfo(projectId, workspaceSpecification)); } if (branch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, workspaceSpecification)); } - return workspaceBranchToWorkspace(projectId, sourceSpecification.getPatchReleaseVersionId(), branch, sourceSpecification.getWorkspaceType(), workspaceAccessType); + return fromWorkspaceBranchName(projectId, branch.getName()); } /** * When we delete a workspace, we also need to remember to delete the conflict resolution and backup workspaces */ @Override - public void deleteWorkspace(String projectId, SourceSpecification sourceSpecification) + public void deleteWorkspace(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); + // Delete workspace + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); boolean workspaceDeleted; - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; try { - workspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + workspaceDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error deleting " + getReferenceInfo(projectId, workspaceSpecification)); } if (!workspaceDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, workspaceSpecification)); } + // Delete conflict resolution workspace - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; + String conflictResolutionBranchName = getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.CONFLICT_RESOLUTION, workspaceSpecification.getSource())); try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), conflictResolutionBranchName, 20, 1_000); if (!deleted) { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.error("Failed to delete {} in project {}", conflictResolutionBranchName, projectId); } } catch (Exception e) { // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); + LOGGER.error("Error deleting {} in project {}", conflictResolutionBranchName, projectId, e); } + // Delete backup workspace - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; + String backupBranchName = getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.BACKUP, workspaceSpecification.getSource())); try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); if (!deleted) { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.error("Failed to delete {} in project {}", backupBranchName, projectId); } } catch (Exception e) { // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, e); + LOGGER.error("Error deleting {} in project {}", backupBranchName, projectId, e); } } @@ -492,19 +494,18 @@ public void deleteWorkspace(String projectId, SourceSpecification sourceSpecific * it means the workspace in overall truly has merge conflicts while updating, so entering conflict resolution mode */ @Override - public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecification sourceSpecification) + public WorkspaceUpdateReport updateWorkspace(String projectId, WorkspaceSpecification workspaceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId() may not be null"); + LegendSDLCServerException.validateNonNull(workspaceSpecification, "workspace specification may not be null"); - LOGGER.info("Updating workspace {} in project {} to latest revision", sourceSpecification.getWorkspaceId(), projectId); + LOGGER.debug("Updating workspace {} in project {} to latest revision", workspaceSpecification, projectId); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; - String workspaceBranchName = getBranchName(gitLabProjectId, SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())); GitLabApi gitLabApi = getGitLabApi(); RepositoryApi repositoryApi = gitLabApi.getRepositoryApi(); // Get the workspace branch + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); Branch workspaceBranch; try { @@ -513,16 +514,16 @@ public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecificati catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " in project " + projectId + ": " + sourceSpecification.getWorkspaceId(), - () -> "Error accessing " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Unknown: " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Error accessing " + getReferenceInfo(projectId, workspaceSpecification)); } String currentWorkspaceRevisionId = workspaceBranch.getCommit().getId(); - LOGGER.info("Found latest revision of {} {} in project {}: {}", sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel(), sourceSpecification.getWorkspaceId(), projectId, currentWorkspaceRevisionId); + LOGGER.debug("Found latest revision of {} in project {}: {}", workspaceBranchName, projectId, currentWorkspaceRevisionId); // Determine the revision to update to + String sourceBranchName = getSourceBranch(gitLabProjectId, workspaceSpecification); Branch sourceBranch; - String sourceBranchName = getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()); try { sourceBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), sourceBranchName)); @@ -530,18 +531,18 @@ public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecificati catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access the latest revision in project " + projectId, - () -> "Unknown project: " + projectId, - () -> "Error accessing latest revision for project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access the latest revision in " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Unknown : " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Error accessing latest revision for " + getReferenceInfo(projectId, workspaceSpecification.getSource())); } String sourceRevisionId = sourceBranch.getCommit().getId(); - LOGGER.info("Found latest revision of project {}: {}", projectId, sourceRevisionId); + LOGGER.debug("Found latest revision of project {}: {}", projectId, sourceRevisionId); CommitsApi commitsApi = gitLabApi.getCommitsApi(); // Check if the workspace already has the latest revision try { - boolean isAlreadyLatest = false; + boolean isAlreadyLatest; // This will check if the branch contains the master HEAD commit by looking up the list of references the commit is pushed to if (sourceRevisionId.equals(currentWorkspaceRevisionId)) { @@ -549,26 +550,22 @@ public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecificati } else { - Pager masterHeadCommitRefPager = withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), sourceRevisionId, RefType.BRANCH, ITEMS_PER_PAGE)); - Stream sourceHeadCommitRefs = PagerTools.stream(masterHeadCommitRefPager); - if (sourceHeadCommitRefs.anyMatch(cr -> workspaceBranchName.equals(cr.getName()))) - { - isAlreadyLatest = true; - } + Pager sourceRevisionRefPager = withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), sourceRevisionId, RefType.BRANCH, ITEMS_PER_PAGE)); + isAlreadyLatest = PagerTools.stream(sourceRevisionRefPager).anyMatch(cr -> workspaceBranchName.equals(cr.getName())); } if (isAlreadyLatest) { // revision is already in the workspace, no update necessary, hence NO_OP - LOGGER.info("Workspace {} in project {} already has revision {}, no update necessary", sourceSpecification.getWorkspaceId(), projectId, sourceRevisionId); + LOGGER.debug("Workspace {} in project {} already has revision {}, no update necessary", workspaceSpecification, projectId, sourceRevisionId); return createWorkspaceUpdateReport(WorkspaceUpdateReportStatus.NO_OP, sourceRevisionId, currentWorkspaceRevisionId); } } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to access revision " + sourceRevisionId + " in project " + projectId, - () -> "Unknown revision in project " + projectId + ": " + sourceRevisionId, - () -> "Error accessing revision " + sourceRevisionId + " of project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to access revision " + sourceRevisionId + " in " + getReferenceInfo(projectId, workspaceSpecification.getSource()), + () -> "Unknown revision in " + getReferenceInfo(projectId, workspaceSpecification.getSource()) + ": " + sourceRevisionId, + () -> "Error accessing revision " + sourceRevisionId + " of " + getReferenceInfo(projectId, workspaceSpecification.getSource())); } // Temp branch for checking for merge conflicts @@ -591,7 +588,7 @@ public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecificati } // Attempt to rebase the temporary branch on top of master - boolean rebaseSucceeded = this.attemptToRebaseWorkspaceUsingTemporaryBranch(projectId, sourceSpecification, tempBranchName, sourceRevisionId); + boolean rebaseSucceeded = attemptToRebaseWorkspaceUsingTemporaryBranch(projectId, workspaceSpecification, tempBranchName, sourceRevisionId); // If fail to rebase, there could be 2 possible reasons: // 1. At least one of the intermediate commits on the workspace branch causes rebase to fail // -> we need to squash the workspace branch and try rebase again @@ -608,28 +605,28 @@ public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecificati catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to get merged base revision for workspace " + sourceSpecification.getWorkspaceId() + " from project " + projectId, - () -> "Could not find revision " + currentWorkspaceRevisionId + " from project " + projectId, - () -> "Failed to fetch merged base revision for workspace " + sourceSpecification.getWorkspaceId() + " from project " + projectId); + () -> "User " + getCurrentUser() + " is not allowed to get merged base revision for " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Could not find revision " + currentWorkspaceRevisionId + " from " + getReferenceInfo(projectId, workspaceSpecification), + () -> "Failed to fetch merged base revision for " + getReferenceInfo(projectId, workspaceSpecification)); } // Small optimization step to make sure we need squashing. // If there are less than 2 commits (not including the base commit), there is no point in squashing - List latestTwoRevisionsOnWorkspaceBranch = this.revisionApi.getWorkspaceRevisionContext(projectId, sourceSpecification).getRevisions(null, null, null, 2); + List latestTwoRevisionsOnWorkspaceBranch = this.revisionApi.getRevisionContext(projectId, workspaceSpecification.getSourceSpecification()).getRevisions(null, null, null, 2); Set latestTwoRevisionOnWorkspaceBranchIds = latestTwoRevisionsOnWorkspaceBranch.stream().map(Revision::getId).collect(Collectors.toSet()); if (latestTwoRevisionOnWorkspaceBranchIds.contains(workspaceCreationRevisionId)) { LOGGER.debug("Failed to rebase branch {}, but the branch does not have enough commits to perform squashing. Proceeding to conflict resolution...", workspaceBranchName); - return this.createConflictResolution(projectId, sourceSpecification, sourceRevisionId); + return createConflictResolution(projectId, workspaceSpecification, sourceRevisionId); } else { LOGGER.debug("Failed to rebase branch {}. Performing squashing commits and re-attempting rebase...", workspaceBranchName); } - WorkspaceUpdateReport rebaseUpdateAttemptReport = this.attemptToSquashAndRebaseWorkspace(projectId, sourceSpecification, sourceRevisionId, currentWorkspaceRevisionId, workspaceCreationRevisionId); - return WorkspaceUpdateReportStatus.UPDATED.equals(rebaseUpdateAttemptReport.getStatus()) ? rebaseUpdateAttemptReport : this.createConflictResolution(projectId, sourceSpecification, sourceRevisionId); + WorkspaceUpdateReport rebaseUpdateAttemptReport = attemptToSquashAndRebaseWorkspace(projectId, workspaceSpecification, sourceRevisionId, currentWorkspaceRevisionId, workspaceCreationRevisionId); + return WorkspaceUpdateReportStatus.UPDATED.equals(rebaseUpdateAttemptReport.getStatus()) ? rebaseUpdateAttemptReport : this.createConflictResolution(projectId, workspaceSpecification, sourceRevisionId); } - String updatedCurrentWorkspaceRevisionId = this.revisionApi.getWorkspaceRevisionContext(projectId, sourceSpecification).getCurrentRevision().getId(); + String updatedCurrentWorkspaceRevisionId = this.revisionApi.getRevisionContext(projectId, workspaceSpecification.getSourceSpecification()).getCurrentRevision().getId(); return createWorkspaceUpdateReport(WorkspaceUpdateReportStatus.UPDATED, sourceRevisionId, updatedCurrentWorkspaceRevisionId); } @@ -652,7 +649,7 @@ public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecificati * * @return a workspace update report that might have status as UPDATED or CONFLICT. */ - private WorkspaceUpdateReport attemptToSquashAndRebaseWorkspace(String projectId, SourceSpecification sourceSpecification, String masterRevisionId, String currentWorkspaceRevisionId, String workspaceCreationRevisionId) + private WorkspaceUpdateReport attemptToSquashAndRebaseWorkspace(String projectId, WorkspaceSpecification workspaceSpecification, String masterRevisionId, String currentWorkspaceRevisionId, String workspaceCreationRevisionId) { GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); @@ -688,8 +685,7 @@ private WorkspaceUpdateReport attemptToSquashAndRebaseWorkspace(String projectId } // Create a new commit on temp branch that squashes all changes on the concerned workspace branch CommitsApi commitsApi = getGitLabApi().getCommitsApi(); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; - ProjectFileAccessProvider.FileAccessContext workspaceFileAccessContext = getProjectFileAccessProvider().getWorkspaceFileAccessContext(projectId, sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType); + ProjectFileAccessProvider.FileAccessContext workspaceFileAccessContext = getProjectFileAccessProvider().getFileAccessContext(projectId, workspaceSpecification.getSourceSpecification()); Commit squashedCommit; try { @@ -753,7 +749,7 @@ else if (diff.getNewFile()) ); } }); - squashedCommit = commitsApi.createCommit(gitLabProjectId.getGitLabId(), tempBranchName, "aggregated changes for workspace " + sourceSpecification.getWorkspaceId(), null, null, getCurrentUser(), commitActions); + squashedCommit = commitsApi.createCommit(gitLabProjectId.getGitLabId(), tempBranchName, "aggregated changes for workspace " + workspaceSpecification.getId(), null, null, getCurrentUser(), commitActions); } catch (Exception e) { @@ -763,7 +759,7 @@ else if (diff.getNewFile()) () -> "Failed to create commit in temporary workspace " + tempBranchName + " of project " + projectId); } // Attempt to rebase the temporary branch on top of master - boolean attemptRebaseResult = this.attemptToRebaseWorkspaceUsingTemporaryBranch(projectId, sourceSpecification, tempBranchName, masterRevisionId); + boolean attemptRebaseResult = attemptToRebaseWorkspaceUsingTemporaryBranch(projectId, workspaceSpecification, tempBranchName, masterRevisionId); // If rebasing failed, this implies there are conflicts, otherwise, the workspace should be updated if (!attemptRebaseResult) { @@ -785,19 +781,19 @@ else if (diff.getNewFile()) * * @return a boolean flag indicating if the attempted rebase succeeded. */ - private boolean attemptToRebaseWorkspaceUsingTemporaryBranch(String projectId, SourceSpecification sourceSpecification, String tempBranchName, String masterRevisionId) + private boolean attemptToRebaseWorkspaceUsingTemporaryBranch(String projectId, WorkspaceSpecification workspaceSpecification, String tempBranchName, String masterRevisionId) { GitLabProjectId gitLabProjectId = parseProjectId(projectId); GitLabApi gitLabApi = getGitLabApi(); RepositoryApi repositoryApi = gitLabApi.getRepositoryApi(); // Create merge request to rebase MergeRequestApi mergeRequestApi = getGitLabApi().getMergeRequestApi(); - String title = "Update workspace " + sourceSpecification.getWorkspaceId(); - String message = "Update workspace " + sourceSpecification.getWorkspaceId() + " up to revision " + masterRevisionId; + String title = "Update workspace " + workspaceSpecification.getId(); + String message = "Update workspace " + workspaceSpecification.getId() + " up to revision " + masterRevisionId; MergeRequest mergeRequest; try { - mergeRequest = mergeRequestApi.createMergeRequest(gitLabProjectId.getGitLabId(), tempBranchName, getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()), title, message, null, null, null, null, false, false); + mergeRequest = mergeRequestApi.createMergeRequest(gitLabProjectId.getGitLabId(), tempBranchName, getSourceBranch(gitLabProjectId, workspaceSpecification), title, message, null, null, null, null, false, false); } catch (Exception e) { @@ -831,78 +827,76 @@ private boolean attemptToRebaseWorkspaceUsingTemporaryBranch(String projectId, S // if there are no merge conflicts, proceed with the update else { + String workspaceBranchName = getWorkspaceBranchName(workspaceSpecification); // Create backup branch Branch backupBranch; - ProjectFileAccessProvider.WorkspaceAccessType backupWorkspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.BACKUP; - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; + WorkspaceSpecification backupWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceSpecification.getId(), workspaceSpecification.getType(), WorkspaceAccessType.BACKUP, workspaceSpecification.getSource()); + String backupBranchName = getWorkspaceBranchName(backupWorkspaceSpec); try { - backupBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), - getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), - getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), - 30, 1_000); + backupBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, workspaceBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceAccessType.getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, backupWorkspaceSpec), () -> "Unknown project: " + projectId, - () -> "Error creating " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceAccessType.getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "Error creating " + getReferenceInfo(projectId, backupWorkspaceSpec)); } if (backupBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceAccessType.getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " from " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, backupWorkspaceSpec) + " from " + getReferenceInfo(projectId, workspaceSpecification)); } // Delete original branch boolean originalBranchDeleted; try { - originalBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + originalBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), workspaceBranchName, 20, 1_000); } catch (Exception e) { throw buildException(e, - () -> "Error while attempting to update the workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": user " + getCurrentUser() + " is not allowed to delete workspace", - () -> "Error while attempting to update the workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": unknown workspace or project", - () -> "Error while attempting to update the workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": error deleting workspace"); + () -> "Error while attempting to update " + getReferenceInfo(projectId, workspaceSpecification) + ": user " + getCurrentUser() + " is not allowed to delete workspace", + () -> "Error while attempting to update " + getReferenceInfo(projectId, workspaceSpecification) + ": unknown workspace or project", + () -> "Error while attempting to update " + getReferenceInfo(projectId, workspaceSpecification) + ": error deleting workspace"); } if (!originalBranchDeleted) { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, workspaceSpecification)); } // Create new workspace branch off the temp branch head Branch newWorkspaceBranch; try { newWorkspaceBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), - getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), + workspaceBranchName, tempBranchName, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "Error while attempting to update the workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": user " + getCurrentUser() + " is not allowed to create workspace", - () -> "Error while attempting to update the workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": unknown project: " + projectId, - () -> "Error while attempting to update the workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId + ": error creating workspace"); + () -> "Error while attempting to update " + getReferenceInfo(projectId, workspaceSpecification) + ": user " + getCurrentUser() + " is not allowed to create workspace", + () -> "Error while attempting to update " + getReferenceInfo(projectId, workspaceSpecification) + ": unknown project: " + projectId, + () -> "Error while attempting to update " + getReferenceInfo(projectId, workspaceSpecification) + ": error creating workspace"); } if (newWorkspaceBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + workspaceAccessType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " from temporary workspace " + tempBranchName + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, workspaceSpecification) + " from temporary workspace " + tempBranchName); } // Delete backup branch try { - boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), backupWorkspaceAccessType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); + boolean deleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), backupBranchName, 20, 1_000); if (!deleted) { - LOGGER.error("Failed to delete {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceAccessType.getLabel() + " " + workspaceAccessType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.error("Failed to delete {} in project {}", backupBranchName, projectId); } } catch (Exception e) { // unfortunate, but this should not throw error - LOGGER.error("Error deleting {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + backupWorkspaceAccessType.getLabel() + " " + workspaceAccessType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.error("Error deleting {} in project {}", backupBranchName, projectId); } } } @@ -937,66 +931,62 @@ private boolean attemptToRebaseWorkspaceUsingTemporaryBranch(String projectId, S * 2. Get all the changes of workspace branch `w1` * 3. Copy and replace those changes to resolution branch `w1` and create a new commit out of that. */ - private WorkspaceUpdateReport createConflictResolution(String projectId, SourceSpecification sourceSpecification, String masterRevisionId) + private WorkspaceUpdateReport createConflictResolution(String projectId, WorkspaceSpecification workspaceSpec, String masterRevisionId) { // Check if conflict resolution is happening, if it is, it means conflict resolution branch already existed, so we will // scrap that branch and create a new one. GitLabProjectId gitLabProjectId = parseProjectId(projectId); RepositoryApi repositoryApi = getGitLabApi().getRepositoryApi(); - Branch previousConflictResolutionBranch = null; - ProjectFileAccessProvider.WorkspaceAccessType conflictResolutionWorkspaceType = ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION; + WorkspaceSpecification conflictResolutionWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceSpec.getId(), workspaceSpec.getType(), WorkspaceAccessType.CONFLICT_RESOLUTION, workspaceSpec.getSource()); + String conflictResolutionWorkspaceBranchName = getWorkspaceBranchName(conflictResolutionWorkspaceSpec); try { - previousConflictResolutionBranch = withRetries(() -> repositoryApi.getBranch(gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())))); - } - catch (Exception e) - { - if (!GitLabApiTools.isNotFoundGitLabApiException(e)) + if (GitLabApiTools.branchExists(repositoryApi, gitLabProjectId.getGitLabId(), conflictResolutionWorkspaceBranchName)) { - LOGGER.error("Error updating {} {} in project {}", sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel(), sourceSpecification.getWorkspaceId(), projectId); + LOGGER.debug("Conflict resolution already happened in {} in project {}, but we will recreate this conflict resolution workspace to make sure it's up to date", workspaceSpec, projectId); + boolean conflictResolutionBranchDeleted; + try + { + conflictResolutionBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), conflictResolutionWorkspaceBranchName, 20, 1_000); + } + catch (Exception e) + { + throw buildException(e, + () -> "User " + getCurrentUser() + " is not allowed to delete " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec), + () -> "Unknown: " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec), + () -> "Error deleting " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec)); + } + if (!conflictResolutionBranchDeleted) + { + throw new LegendSDLCServerException("Failed to delete " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec)); + } } } - // Delete conflict resolution workspace - if (previousConflictResolutionBranch != null) + catch (Exception e) { - LOGGER.debug("Conflict resolution already happened in workspace {} in project {}, but we will recreate this conflict resolution workspace to make sure it's up to date", sourceSpecification.getWorkspaceId(), projectId); - boolean conflictResolutionBranchDeleted; - try - { - conflictResolutionBranchDeleted = GitLabApiTools.deleteBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), 20, 1_000); - } - catch (Exception e) - { - throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId, - () -> "Unknown " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " (" + sourceSpecification.getWorkspaceId() + ") or project (" + projectId + ")", - () -> "Error deleting " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); - } - if (!conflictResolutionBranchDeleted) - { - throw new LegendSDLCServerException("Failed to delete " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); - } + LOGGER.error("Error accessing {} in project {}", conflictResolutionWorkspaceBranchName, projectId, e); } + // Create conflict resolution workspace Branch conflictResolutionBranch; - String sourceBranch = getSourceBranch(gitLabProjectId, sourceSpecification.getPatchReleaseVersionId()); + String sourceBranch = getSourceBranch(gitLabProjectId, workspaceSpec); try { - conflictResolutionBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), sourceBranch, 30, 1_000); + conflictResolutionBranch = GitLabApiTools.createBranchFromSourceBranchAndVerify(repositoryApi, gitLabProjectId.getGitLabId(), conflictResolutionWorkspaceBranchName, sourceBranch, 30, 1_000); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId, + () -> "User " + getCurrentUser() + " is not allowed to create " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec), () -> "Unknown project: " + projectId, - () -> "Error creating workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + () -> "Error creating " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec)); } if (conflictResolutionBranch == null) { - throw new LegendSDLCServerException("Failed to create " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId() + " in project " + projectId); + throw new LegendSDLCServerException("Failed to create " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec)); } // Get the changes of the current workspace - String currentWorkspaceRevisionId = this.revisionApi.getWorkspaceRevisionContext(projectId, sourceSpecification).getCurrentRevision().getId(); + String currentWorkspaceRevisionId = this.revisionApi.getRevisionContext(projectId, workspaceSpec.getSourceSpecification()).getCurrentRevision().getId(); String workspaceCreationRevisionId; try @@ -1026,9 +1016,8 @@ private WorkspaceUpdateReport createConflictResolution(String projectId, SourceS // Create a new commit on conflict resolution branch CommitsApi commitsApi = getGitLabApi().getCommitsApi(); - ProjectFileAccessProvider.FileAccessContext projectFileAccessContext = getProjectFileAccessProvider().getProjectFileAccessContext(projectId); - ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType = ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE; - ProjectFileAccessProvider.FileAccessContext workspaceFileAccessContext = getProjectFileAccessProvider().getWorkspaceFileAccessContext(projectId, sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), workspaceAccessType); + ProjectFileAccessProvider.FileAccessContext projectFileAccessContext = getProjectFileAccessProvider().getFileAccessContext(projectId, workspaceSpec.getSource().getSourceSpecification()); + ProjectFileAccessProvider.FileAccessContext workspaceFileAccessContext = getProjectFileAccessProvider().getFileAccessContext(projectId, workspaceSpec.getSourceSpecification()); try { List commitActions = Lists.mutable.empty(); @@ -1097,15 +1086,14 @@ else if (diff.getNewFile()) ); } }); - commitsApi.createCommit(gitLabProjectId.getGitLabId(), this.getWorkspaceBranchName(SourceSpecification.newSourceSpecification(sourceSpecification.getWorkspaceId(), sourceSpecification.getWorkspaceType(), conflictResolutionWorkspaceType, sourceSpecification.getPatchReleaseVersionId())), - "aggregated changes for conflict resolution", null, null, getCurrentUser(), commitActions); + commitsApi.createCommit(gitLabProjectId.getGitLabId(), conflictResolutionWorkspaceBranchName, "aggregated changes for conflict resolution", null, null, getCurrentUser(), commitActions); } catch (Exception e) { throw buildException(e, - () -> "User " + getCurrentUser() + " is not allowed to create commit on " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + sourceSpecification.getWorkspaceId() + " of project " + projectId, - () -> "Unknown project: " + projectId + " or " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + " " + sourceSpecification.getWorkspaceId(), - () -> "Failed to create commit in " + sourceSpecification.getWorkspaceType().getLabel() + " " + conflictResolutionWorkspaceType.getLabel() + sourceSpecification.getWorkspaceId() + " of project" + projectId); + () -> "User " + getCurrentUser() + " is not allowed to create commit on " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec), + () -> "Unknown : " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec), + () -> "Failed to create commit in " + getReferenceInfo(projectId, conflictResolutionWorkspaceSpec)); } return createWorkspaceUpdateReport(WorkspaceUpdateReportStatus.CONFLICT, masterRevisionId, conflictResolutionBranch.getCommit().getId()); @@ -1135,11 +1123,6 @@ public String getWorkspaceRevisionId() }; } - private static Workspace workspaceBranchToWorkspace(String projectId, VersionId patchReleaseVersionId, Branch branch, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) - { - return (branch == null) ? null : fromWorkspaceBranchName(projectId, patchReleaseVersionId, branch.getName(), workspaceType, workspaceAccessType); - } - private static void validateWorkspaceId(String idString) { validateWorkspaceId(idString, null); diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowApi.java index b28bb6a05b..4e8628d807 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowApi.java @@ -19,12 +19,12 @@ import org.eclipse.collections.impl.utility.Iterate; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.revision.RevisionAlias; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.domain.model.workflow.Workflow; import org.finos.legend.sdlc.domain.model.workflow.WorkflowStatus; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowAccessContext; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -57,79 +57,38 @@ public GitlabWorkflowApi(GitLabConfiguration gitLabConfiguration, GitLabUserCont } @Override - public WorkflowAccessContext getProjectWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId) + public WorkflowAccessContext getWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - GitLabProjectId gitLabProjectId = parseProjectId(projectId); - return new RefWorkflowAccessContext(projectId, getSourceBranch(gitLabProjectId, patchReleaseVersionId)) - { - @Override - protected String getInfoForException() - { - return "project " + projectId; - } - - @Override - protected ProjectFileAccessProvider.RevisionAccessContext getRevisionAccessContext() - { - return getProjectFileAccessProvider().getProjectRevisionAccessContext(projectId); - } - }; - } + LegendSDLCServerException.validateNonNull(sourceSpecification, "source specification may not be null"); - @Override - public WorkflowAccessContext getWorkspaceWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - return new RefWorkflowAccessContext(projectId, getBranchName(gitLabProjectId, sourceSpecification)) + return new RefWorkflowAccessContext(gitLabProjectId, getBranchName(gitLabProjectId, sourceSpecification)) { @Override protected String getInfoForException() { - return sourceSpecification.getWorkspaceType().getLabel() + " workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId; + return getReferenceInfo(projectId, sourceSpecification); } @Override protected ProjectFileAccessProvider.RevisionAccessContext getRevisionAccessContext() { - return getProjectFileAccessProvider().getWorkspaceRevisionAccessContext(projectId, sourceSpecification); + return getProjectFileAccessProvider().getRevisionAccessContext(projectId, sourceSpecification); } }; } @Override - public WorkflowAccessContext getVersionWorkflowAccessContext(String projectId, VersionId versionId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(versionId, "versionId may not be null"); - return new RefWorkflowAccessContext(projectId, buildVersionTagName(versionId)) - { - @Override - protected String getInfoForException() - { - return "version " + versionId.toVersionIdString() + " of project " + projectId; - } - - @Override - protected ProjectFileAccessProvider.RevisionAccessContext getRevisionAccessContext() - { - return getProjectFileAccessProvider().getVersionRevisionAccessContext(projectId, versionId); - } - }; - } - - @Override - public WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId, true); - WorkspaceInfo workspaceInfo = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); - if (workspaceInfo == null) + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId, true); + WorkspaceSpecification workspaceSpec = parseWorkspaceBranchName(mergeRequest.getSourceBranch()); + if (workspaceSpec == null) { throw new LegendSDLCServerException("Unknown review in project " + projectId + ": " + reviewId, Response.Status.NOT_FOUND); } @@ -157,7 +116,7 @@ protected String getInfoForException() @Override protected ProjectFileAccessProvider.RevisionAccessContext getRevisionAccessContext() { - return getProjectFileAccessProvider().getWorkspaceRevisionAccessContext(projectId, workspaceInfo.getWorkspaceId(), workspaceInfo.getWorkspaceType(), workspaceInfo.getWorkspaceAccessType()); + return getProjectFileAccessProvider().getRevisionAccessContext(projectId, workspaceSpec.getSourceSpecification(), null); } }; } @@ -171,11 +130,6 @@ protected GitLabWorkflowAccessContext(GitLabProjectId projectId) this.gitLabProjectId = projectId; } - protected GitLabWorkflowAccessContext(String projectId) - { - this(parseProjectId(projectId)); - } - @Override public Workflow getWorkflow(String workflowId) { @@ -328,7 +282,7 @@ private abstract class RefWorkflowAccessContext extends GitLabWorkflowAccessCont { private final String ref; - private RefWorkflowAccessContext(String projectId, String ref) + private RefWorkflowAccessContext(GitLabProjectId projectId, String ref) { super(projectId); this.ref = ref; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowJobApi.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowJobApi.java index 5c6b55f1cf..a023c58aeb 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowJobApi.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/api/GitlabWorkflowJobApi.java @@ -18,12 +18,11 @@ import org.eclipse.collections.api.map.primitive.IntObjectMap; import org.eclipse.collections.impl.utility.Iterate; import org.eclipse.collections.impl.utility.ListIterate; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.domain.model.workflow.WorkflowJob; import org.finos.legend.sdlc.domain.model.workflow.WorkflowJobStatus; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowJobAccessContext; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowJobApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.GitLabConfiguration; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; @@ -52,59 +51,30 @@ public GitlabWorkflowJobApi(GitLabConfiguration gitLabConfiguration, GitLabUserC } @Override - public WorkflowJobAccessContext getProjectWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId) + public WorkflowJobAccessContext getWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - GitLabProjectId gitLabProjectId = parseProjectId(projectId); - return new RefWorkflowJobAccessContext(projectId, getSourceBranch(gitLabProjectId, patchReleaseVersionId)) - { - @Override - protected String getInfoForException() - { - return "project " + projectId; - } - }; - } + LegendSDLCServerException.validateNonNull(sourceSpecification, "source specification may not be null"); - @Override - public WorkflowJobAccessContext getWorkspaceWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - return new RefWorkflowJobAccessContext(projectId, getBranchName(gitLabProjectId, sourceSpecification)) - { - @Override - protected String getInfoForException() - { - return "workspace " + sourceSpecification.getWorkspaceId() + " in project " + projectId; - } - }; - } - - @Override - public WorkflowJobAccessContext getVersionWorkflowJobAccessContext(String projectId, VersionId versionId) - { - LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); - LegendSDLCServerException.validateNonNull(versionId, "versionId may not be null"); - return new RefWorkflowJobAccessContext(projectId, buildVersionTagName(versionId)) + return new RefWorkflowJobAccessContext(gitLabProjectId, getBranchName(gitLabProjectId, sourceSpecification)) { @Override protected String getInfoForException() { - return "version " + versionId.toVersionIdString() + " of project " + projectId; + return getReferenceInfo(projectId, sourceSpecification); } }; } @Override - public WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, String reviewId) { LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null"); LegendSDLCServerException.validateNonNull(reviewId, "reviewId may not be null"); GitLabProjectId gitLabProjectId = parseProjectId(projectId); - MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, patchReleaseVersionId, reviewId, true); + MergeRequest mergeRequest = getReviewMergeRequest(getGitLabApi().getMergeRequestApi(), gitLabProjectId, reviewId, true); return new GitLabWorkflowJobAccessContext(projectId) { @@ -133,7 +103,7 @@ private IntObjectMap getPipelinesById() throws GitLabApiException { if (this.pipelinesById == null) { - this.pipelinesById = indexPipelinesById(getMergeRequestPipelines(gitLabProjectId.getGitLabId(), mergeRequest.getIid()), true, false); + this.pipelinesById = indexPipelinesById(getMergeRequestPipelines(this.gitLabProjectId.getGitLabId(), mergeRequest.getIid()), true, false); } return this.pipelinesById; } @@ -142,11 +112,11 @@ private IntObjectMap getPipelinesById() throws GitLabApiException private abstract class GitLabWorkflowJobAccessContext implements WorkflowJobAccessContext { - protected final GitLabProjectId projectId; + protected final GitLabProjectId gitLabProjectId; protected GitLabWorkflowJobAccessContext(GitLabProjectId projectId) { - this.projectId = projectId; + this.gitLabProjectId = projectId; } protected GitLabWorkflowJobAccessContext(String projectId) @@ -174,7 +144,7 @@ public List getWorkflowJobs(String workflowId, Iterable jobs; try { - jobs = withRetries(() -> jobApi.getJobsForPipeline(this.projectId.getGitLabId(), pipelineId)); + jobs = withRetries(() -> jobApi.getJobsForPipeline(this.gitLabProjectId.getGitLabId(), pipelineId)); } catch (Exception e) { @@ -205,7 +175,7 @@ public String getWorkflowJobLog(String workflowId, String workflowJobId) JobApi jobApi = getGitLabApi().getJobApi(); try { - return withRetries(() -> jobApi.getTrace(this.projectId.getGitLabId(), job.getId())); + return withRetries(() -> jobApi.getTrace(this.gitLabProjectId.getGitLabId(), job.getId())); } catch (Exception e) { @@ -233,7 +203,7 @@ public WorkflowJob runWorkflowJob(String workflowId, String workflowJobId) Job result; try { - result = withRetries(() -> jobApi.playJob(this.projectId.getGitLabId(), job.getId())); + result = withRetries(() -> jobApi.playJob(this.gitLabProjectId.getGitLabId(), job.getId())); } catch (Exception e) { @@ -261,7 +231,7 @@ public WorkflowJob retryWorkflowJob(String workflowId, String workflowJobId) Job result; try { - result = withRetries(() -> jobApi.retryJob(this.projectId.getGitLabId(), job.getId())); + result = withRetries(() -> jobApi.retryJob(this.gitLabProjectId.getGitLabId(), job.getId())); } catch (Exception e) { @@ -290,7 +260,7 @@ public WorkflowJob cancelWorkflowJob(String workflowId, String workflowJobId) Job result; try { - result = withRetries(() -> jobApi.cancelJob(this.projectId.getGitLabId(), job.getId())); + result = withRetries(() -> jobApi.cancelJob(this.gitLabProjectId.getGitLabId(), job.getId())); } catch (Exception e) { @@ -352,13 +322,13 @@ protected Job getJob(String workflowId, String workflowJobId) protected Job getJob(int pipelineId, int jobId) throws GitLabApiException { JobApi jobApi = getGitLabApi().getJobApi(); - Job job = withRetries(() -> jobApi.getJob(this.projectId.getGitLabId(), jobId)); + Job job = withRetries(() -> jobApi.getJob(this.gitLabProjectId.getGitLabId(), jobId)); return ((job.getPipeline() != null) && (job.getPipeline().getId() != null) && (pipelineId == job.getPipeline().getId())) ? job : null; } protected WorkflowJob fromGitLabJob(Job job) { - return GitlabWorkflowJobApi.fromGitLabJob(this.projectId.toString(), job); + return GitlabWorkflowJobApi.fromGitLabJob(this.gitLabProjectId.toString(), job); } protected abstract String getInfoForException(); @@ -368,7 +338,7 @@ private abstract class RefWorkflowJobAccessContext extends GitLabWorkflowJobAcce { private final String ref; - private RefWorkflowJobAccessContext(String projectId, String ref) + private RefWorkflowJobAccessContext(GitLabProjectId projectId, String ref) { super(projectId); this.ref = ref; @@ -377,7 +347,7 @@ private RefWorkflowJobAccessContext(String projectId, String ref) @Override protected Pipeline getPipeline(int pipelineId) throws GitLabApiException { - return getRefPipeline(this.projectId.getGitLabId(), this.ref, pipelineId); + return getRefPipeline(this.gitLabProjectId.getGitLabId(), this.ref, pipelineId); } @Override diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/tools/GitLabApiTools.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/tools/GitLabApiTools.java index ee36273ca2..014ccb41d2 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/tools/GitLabApiTools.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/gitlab/tools/GitLabApiTools.java @@ -318,23 +318,41 @@ public static Branch createBranchFromSourceBranchAndVerify(RepositoryApi api, Ob return createBranchAndVerify(api, projectIdOrPath, branchName, sourceBranch.getCommit().getId(), maxVerificationTries, verificationWaitMillis); } + @Deprecated public static Branch createProtectedBranchFromSourceTagAndVerify(GitLabApi api, GitLabProjectId projectId, String branchName, String sourceTagName, int maxVerificationTries, long verificationWaitMillis) throws GitLabApiException { - Tag sourceTag = getTag(api, projectId, sourceTagName); + return createProtectedBranchFromSourceTagAndVerify(api, projectId.getGitLabId(), branchName, sourceTagName, maxVerificationTries, verificationWaitMillis); + } + + @Deprecated + public static Tag getTag(GitLabApi api, GitLabProjectId gitLabProjectId, String tagName) throws GitLabApiException + { + return getTag(api, gitLabProjectId.getGitLabId(), tagName); + } + + @Deprecated + public static boolean tagExists(GitLabApi api, GitLabProjectId gitLabProjectId, String tagName) throws GitLabApiException + { + return tagExists(api, gitLabProjectId.getGitLabId(), tagName); + } + + public static Branch createProtectedBranchFromSourceTagAndVerify(GitLabApi api, Object projectIdOrPath, String branchName, String sourceTagName, int maxVerificationTries, long verificationWaitMillis) throws GitLabApiException + { + Tag sourceTag = getTag(api, projectIdOrPath, sourceTagName); if (sourceTag == null) { throw new LegendSDLCServerException("Source release version " + sourceTagName + " does not exist", Response.Status.CONFLICT); } - Branch targetBranch = createBranchAndVerify(api.getRepositoryApi(), projectId.getGitLabId(), branchName, sourceTag.getCommit().getId(), maxVerificationTries, verificationWaitMillis); - api.getProtectedBranchesApi().protectBranch(projectId.getGitLabId(), branchName, AccessLevel.NONE, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER, true); + Branch targetBranch = createBranchAndVerify(api.getRepositoryApi(), projectIdOrPath, branchName, sourceTag.getCommit().getId(), maxVerificationTries, verificationWaitMillis); + api.getProtectedBranchesApi().protectBranch(projectIdOrPath, branchName, AccessLevel.NONE, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER, true); return targetBranch; } - public static Tag getTag(GitLabApi api, GitLabProjectId gitLabProjectId, String tagName) throws GitLabApiException + public static Tag getTag(GitLabApi api, Object projectIdOrPath, String tagName) throws GitLabApiException { try { - return api.getTagsApi().getTag(gitLabProjectId.getGitLabId(), tagName); + return api.getTagsApi().getTag(projectIdOrPath, tagName); } catch (GitLabApiException e) { @@ -346,8 +364,8 @@ public static Tag getTag(GitLabApi api, GitLabProjectId gitLabProjectId, String } } - public static boolean tagExists(GitLabApi api, GitLabProjectId gitLabProjectId, String tagName) throws GitLabApiException + public static boolean tagExists(GitLabApi api, Object projectIdOrPath, String tagName) throws GitLabApiException { - return getTag(api, gitLabProjectId, tagName) != null; + return getTag(api, projectIdOrPath, tagName) != null; } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectFileAccessProvider.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectFileAccessProvider.java index 63dd6d36a7..ad7df03079 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectFileAccessProvider.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectFileAccessProvider.java @@ -14,10 +14,13 @@ package org.finos.legend.sdlc.server.project; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.tools.IOTools; @@ -25,6 +28,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.Collections; @@ -36,95 +40,6 @@ public interface ProjectFileAccessProvider { // File Access Context - default FileAccessContext getProjectFileAccessContext(String projectId) - { - return getFileAccessContext(projectId, null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, null); - } - - default FileAccessContext getProjectRevisionFileAccessContext(String projectId, String revisionId) - { - LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - return getFileAccessContext(projectId, null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, revisionId); - } - - default FileAccessContext getWorkspaceFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) - { - LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); - return getFileAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, null); - } - - default FileAccessContext getWorkspaceRevisionFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) - { - LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); - LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - return getFileAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, revisionId); - } - - // for backward compatibility - @Deprecated - default FileAccessContext getFileAccessContext(String projectId, String workspaceId, WorkspaceAccessType workspaceAccessType, String revisionId) - { - return getFileAccessContext(projectId, workspaceId, WorkspaceType.USER, workspaceAccessType, revisionId); - } - - /** - * Get a file access context. The project id must always be supplied, but workspace - * and revision ids are optional. If workspace is specified, workspace access type is also required - *

- * If a workspace id is supplied, then the access context is for that workspace. - * Otherwise, it is for the trunk or master branch of the project. - *

- * If a revision id is supplied, then the access context is for that particular - * revision of the project or workspace. Otherwise, the access context is for - * the current state of the project or workspace. Note that as the current - * state may change over time, calls to the access context may yield different - * results over time. - * - * @param projectId project id - * @param workspaceId workspace id (optional) - * @param workspaceType type for the workspace (e.g. user, group) (optional) - * @param workspaceAccessType access type for the workspace (e.g. conflict resolution, backup) (optional) - * @param revisionId revision id (optional) - * @return access context - */ - default FileAccessContext getFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) - { - return getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), revisionId); - } - - /** - * Get a file access context. The project id must always be supplied, but workspace - * and revision ids are optional. If workspace is specified, workspace access type is also required - *

- * If a workspace id is supplied, then the access context is for that workspace. - * Otherwise, it is for the trunk or master branch of the project. - *

- * If a revision id is supplied, then the access context is for that particular - * revision of the project or workspace. Otherwise, the access context is for - * the current state of the project or workspace. Note that as the current - * state may change over time, calls to the access context may yield different - * results over time. - * - * @param projectId project id - * @param sourceSpecification source specification - * @param revisionId revision id (optional) - * @return access context - */ - FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId); - - /** - * Get a file access context for a version of a project. Both the project and - * version ids must be supplied. - * - * @param projectId project id - * @param versionId version id - * @return access context - */ - FileAccessContext getFileAccessContext(String projectId, VersionId versionId); - interface FileAccessContext { /** @@ -244,7 +159,7 @@ default byte[] getContentAsBytes() } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } @@ -262,72 +177,225 @@ default String getContentAsString() } catch (IOException e) { - throw new RuntimeException(e); + throw new UncheckedIOException(e); } } } + /** + * Get a file access context. The project id and source specification must always be supplied, but revision id is + * optional. + *

+ * If a revision id is supplied, then the access context is for that particular revision. Otherwise, the access + * context is for the current state. Note that as the current state may change over time, calls to the access + * context may yield different results over time. + * + * @param projectId project id + * @param sourceSpecification source specification + * @param revisionId revision id (optional) + * @return access context + */ + FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId); + + /** + * Get a file access context for the current revision. Note that as the current state may change over time, calls to + * the access context may yield different results over time. + * + * @param projectId project id + * @param sourceSpecification source specification + * @return access context + */ + default FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification) + { + return getFileAccessContext(projectId, sourceSpecification, null); + } + + // Deprecated File Access APIs + + @Deprecated + default FileAccessContext getProjectFileAccessContext(String projectId) + { + return getFileAccessContext(projectId, SourceSpecification.projectSourceSpecification()); + } + + @Deprecated + default FileAccessContext getProjectRevisionFileAccessContext(String projectId, String revisionId) + { + LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); + return getFileAccessContext(projectId, SourceSpecification.projectSourceSpecification(), revisionId); + } + + @Deprecated + default FileAccessContext getWorkspaceFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) + { + LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); + LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); + return getFileAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType, WorkspaceSource.projectWorkspaceSource()))); + } + + @Deprecated + default FileAccessContext getWorkspaceRevisionFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) + { + LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); + LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); + LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); + LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); + return getFileAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType, WorkspaceSource.projectWorkspaceSource())), revisionId); + } + + @Deprecated + default FileAccessContext getFileAccessContext(String projectId, String workspaceId, WorkspaceAccessType workspaceAccessType, String revisionId) + { + return getFileAccessContext(projectId, workspaceId, WorkspaceType.USER, workspaceAccessType, revisionId); + } + + /** + * Get a file access context. The project id must always be supplied, but workspace + * and revision ids are optional. If workspace is specified, workspace access type is also required + *

+ * If a workspace id is supplied, then the access context is for that workspace. + * Otherwise, it is for the trunk or master branch of the project. + *

+ * If a revision id is supplied, then the access context is for that particular + * revision of the project or workspace. Otherwise, the access context is for + * the current state of the project or workspace. Note that as the current + * state may change over time, calls to the access context may yield different + * results over time. + * + * @param projectId project id + * @param workspaceId workspace id (optional) + * @param workspaceType type for the workspace (e.g. user, group) (optional) + * @param workspaceAccessType access type for the workspace (e.g. conflict resolution, backup) (optional) + * @param revisionId revision id (optional) + * @return access context + */ + @Deprecated + default FileAccessContext getFileAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) + { + return getFileAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), revisionId); + } + + /** + * Get a file access context for a version of a project. Both the project and + * version ids must be supplied. + * + * @param projectId project id + * @param versionId version id + * @return access context + */ + @Deprecated + default FileAccessContext getFileAccessContext(String projectId, VersionId versionId) + { + return getFileAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId)); + } + // Revision Access Context + interface RevisionAccessContext + { + Revision getBaseRevision(); + + Revision getCurrentRevision(); + + Revision getRevision(String revisionId); + + Stream getAllRevisions(Predicate predicate, Instant since, Instant until, Integer limit); + } + + /** + * Get a revision access context. The project id and source specification must always be supplied, but the paths are + * optional. If paths are supplied, then the revision access context is for those paths. The paths can be either + * file or directory paths. They should use the slash character ('/') to separate directories, and should all start + * with a slash. + * + * @param projectId project id + * @param sourceSpecification source specification + * @param paths file or directory paths (optional) + * @return revision access context + */ + RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification, Iterable paths); + + /** + * Get a revision access context. + * + * @param projectId project id + * @param sourceSpecification source specification + * @return revision access context + */ + default RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification) + { + return getRevisionAccessContext(projectId, sourceSpecification, null); + } + + // Deprecated Revision Access APIs + + @Deprecated default RevisionAccessContext getProjectRevisionAccessContext(String projectId) { - return getRevisionAccessContext(projectId, null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, (String) null); + return getRevisionAccessContext(projectId, SourceSpecification.projectSourceSpecification(), null); } + @Deprecated default RevisionAccessContext getProjectPathRevisionAccessContext(String projectId, String path) { LegendSDLCServerException.validateNonNull(path, "path may not be null"); - return getRevisionAccessContext(projectId, null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, path); + return getRevisionAccessContext(projectId, SourceSpecification.projectSourceSpecification(), Collections.singleton(path)); } + @Deprecated default RevisionAccessContext getWorkspaceRevisionAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) { LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); - return getRevisionAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, (String) null); + return getRevisionAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType)), null); } + @Deprecated default RevisionAccessContext getWorkspaceRevisionAccessContext(String projectId, SourceSpecification sourceSpecification) { - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - LegendSDLCServerException.validateNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); + LegendSDLCServerException.validate(sourceSpecification, spec -> spec instanceof WorkspaceSourceSpecification, "source specification must be a workspace source specification"); return getRevisionAccessContext(projectId, sourceSpecification, null); } + @Deprecated default RevisionAccessContext getWorkspacePathRevisionAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String path) { LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); LegendSDLCServerException.validateNonNull(path, "path may not be null"); - return getRevisionAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, path); + return getRevisionAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType)), Collections.singleton(path)); } + @Deprecated default RevisionAccessContext getWorkspacePathsRevisionAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, Iterable paths) { LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); LegendSDLCServerException.validateNonNull(paths, "paths may not be null"); - return getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), paths); + return getRevisionAccessContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, workspaceType, workspaceAccessType)), paths); } + @Deprecated default RevisionAccessContext getVersionRevisionAccessContext(String projectId, VersionId versionId) { - return getRevisionAccessContext(projectId, versionId); + return getRevisionAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId), null); } + @Deprecated default RevisionAccessContext getVersionPathRevisionAccessContext(String projectId, VersionId versionId, String path) { LegendSDLCServerException.validateNonNull(path, "path may not be null"); - return getRevisionAccessContext(projectId, versionId, path); + return getRevisionAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId), Collections.singleton(path)); } + @Deprecated default RevisionAccessContext getVersionPathRevisionAccessContext(String projectId, VersionId versionId, Iterable paths) { LegendSDLCServerException.validateNonNull(paths, "paths may not be null"); - return getRevisionAccessContext(projectId, versionId, paths); + return getRevisionAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId), paths); } /** @@ -338,9 +406,10 @@ default RevisionAccessContext getVersionPathRevisionAccessContext(String project * @param versionId version id * @return revision access context */ + @Deprecated default RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId) { - return getRevisionAccessContext(projectId, versionId, (Iterable) null); + return getRevisionAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId), null); } /** @@ -356,9 +425,10 @@ default RevisionAccessContext getRevisionAccessContext(String projectId, Version * @param path file or directory path (optional) * @return revision access context */ + @Deprecated default RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, String path) { - return getRevisionAccessContext(projectId, versionId, (path == null) ? null : Collections.singleton(path)); + return getRevisionAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId), (path == null) ? null : Collections.singleton(path)); } /** @@ -374,7 +444,11 @@ default RevisionAccessContext getRevisionAccessContext(String projectId, Version * @param paths file or directory paths (optional) * @return revision access context */ - RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, Iterable paths); + @Deprecated + default RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, Iterable paths) + { + return getRevisionAccessContext(projectId, SourceSpecification.versionSourceSpecification(versionId), paths); + } /** * Get a revision access context. The project id must always be supplied, but workspace id is optional. If @@ -389,9 +463,10 @@ default RevisionAccessContext getRevisionAccessContext(String projectId, Version * @param workspaceAccessType access type for the workspace (e.g. conflict resolution, backup) * @return revision access context */ + @Deprecated default RevisionAccessContext getRevisionAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) { - return getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), (Iterable) null); + return getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), null); } /** @@ -412,103 +487,87 @@ default RevisionAccessContext getRevisionAccessContext(String projectId, String * @param path file or directory path (optional) * @return revision access context */ + @Deprecated default RevisionAccessContext getRevisionAccessContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String path) { return getRevisionAccessContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), (path == null) ? null : Collections.singleton(path)); } + // File Modification Context + + interface FileModificationContext + { + Revision submit(String message, List operations); + } + /** - * Get a revision access context. The project id must always be supplied, but workspace id and paths are optional. - * If workspace id is specified, workspace access type must also be specified. - *

- * If a workspace id is supplied, then the revision access context is for that workspace. Otherwise, it is for the - * trunk or master branch of the project. - *

- * If paths is supplied, then the revision access context is for those paths. The paths can be either file or - * directory paths. They should use the slash character ('/') to separate directories, and should all start with a - * slash. + * Get a modification context. The project id and source specification must always be supplied, but revision id is + * optional. If a revision id is supplied, it is used to validate the current revision before making any + * modifications. Note that not all source specifications need be supported for modification. * - * @param projectId project id + * @param projectId project id * @param sourceSpecification source specification - * @param paths file or directory paths (optional) - * @return revision access context + * @param revisionId revision id (optional, for validation) + * @return modification context + * @throws UnsupportedOperationException if the source specification is not supported for modification */ - RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification, Iterable paths); + FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification, String revisionId); - interface RevisionAccessContext + /** + * Get a modification context. + * + * @param projectId project id + * @param sourceSpecification source specification + * @return modification context + * @throws UnsupportedOperationException if the source specification is not supported for modification + */ + default FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification) { - Revision getBaseRevision(); - - Revision getCurrentRevision(); - - Revision getRevision(String revisionId); - - Stream getAllRevisions(Predicate predicate, Instant since, Instant until, Integer limit); + return getFileModificationContext(projectId, sourceSpecification, null); } - // File Modification Context - + @Deprecated default FileModificationContext getProjectFileModificationContext(String projectId) { - return getFileModificationContext(projectId, null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, null); + return getFileModificationContext(projectId, SourceSpecification.projectSourceSpecification(), null); } + @Deprecated default FileModificationContext getProjectFileModificationContext(String projectId, String revisionId) { LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - return getFileModificationContext(projectId, null, WorkspaceType.USER, WorkspaceAccessType.WORKSPACE, revisionId); + return getFileModificationContext(projectId, SourceSpecification.projectSourceSpecification(), revisionId); } + @Deprecated default FileModificationContext getWorkspaceFileModificationContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType) { LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); - return getFileModificationContext(projectId, workspaceId, workspaceType, workspaceAccessType, null); + return getFileModificationContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), null); } + @Deprecated default FileModificationContext getWorkspaceFileModificationContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) { LegendSDLCServerException.validateNonNull(workspaceId, "workspaceId may not be null"); LegendSDLCServerException.validateNonNull(workspaceType, "workspaceType may not be null"); LegendSDLCServerException.validateNonNull(workspaceAccessType, "workspaceAccessType may not be null"); LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null"); - return getFileModificationContext(projectId, workspaceId, workspaceType, workspaceAccessType, revisionId); + return getFileModificationContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), revisionId); } - // for backward compatibility @Deprecated default FileModificationContext getFileModificationContext(String projectId, String workspaceId, WorkspaceAccessType workspaceAccessType, String revisionId) { return getFileModificationContext(projectId, workspaceId, WorkspaceType.USER, workspaceAccessType, revisionId); } - /** - * Get a modification context. The project id must always be supplied, but workspace and revision ids are optional. - * If workspace id is specified, workspace access type must also be specified. - *

- * If a workspace id is supplied, then the modification context is for that workspace. Otherwise, it is for the - * trunk or master branch of the project. Note that it is generally advisable to perform modifications within a - * workspace. - *

- * If a revision id is supplied, it is used to validate the current revision of the project or workspace before - * making any modifications. - * - * @param projectId project id - * @param sourceSpecification source specification - * @param revisionId revision id (optional, for validation) - * @return modification context - */ - FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification, String revisionId); - + @Deprecated default FileModificationContext getFileModificationContext(String projectId, String workspaceId, WorkspaceType workspaceType, WorkspaceAccessType workspaceAccessType, String revisionId) { - return this.getFileModificationContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), revisionId); - } - - interface FileModificationContext - { - Revision submit(String message, List operations); + return getFileModificationContext(projectId, SourceSpecification.newSourceSpecification(workspaceId, workspaceType, workspaceAccessType), revisionId); } enum WorkspaceAccessType diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectStructure.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectStructure.java index 01d8527600..fe605be9ac 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectStructure.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/project/ProjectStructure.java @@ -48,7 +48,8 @@ import org.finos.legend.sdlc.serialization.EntitySerializer; import org.finos.legend.sdlc.serialization.EntitySerializers; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationUpdater; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.FileAccessContext; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider.ProjectFile; @@ -66,7 +67,6 @@ import java.util.Comparator; import java.util.EnumSet; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -1032,7 +1032,7 @@ private UpdateBuilder(ProjectFileAccessProvider projectFileAccessProvider, Strin { this.projectFileAccessProvider = projectFileAccessProvider; this.projectId = projectId; - this.sourceSpecification = SourceSpecification.newSourceSpecification(null, null, null); + this.sourceSpecification = SourceSpecification.projectSourceSpecification(); this.configUpdater = (configUpdater == null) ? getDefaultProjectConfigurationUpdater() : configUpdater; } @@ -1078,22 +1078,30 @@ private ProjectConfigurationUpdater getDefaultProjectConfigurationUpdater() return ProjectConfigurationUpdater.newUpdater().withProjectId(this.projectId); } - // Workspace + // Source specification - public void setWorkspace(SourceSpecification sourceSpecification) + public void setSourceSpecification(SourceSpecification sourceSpec) { - Objects.requireNonNull(sourceSpecification.getWorkspaceId(), "workspaceId may not be null"); - Objects.requireNonNull(sourceSpecification.getWorkspaceType(), "workspaceType may not be null"); - Objects.requireNonNull(sourceSpecification.getWorkspaceAccessType(), "workspaceAccessType may not be null"); - this.sourceSpecification = sourceSpecification; + this.sourceSpecification = sourceSpec; } - public UpdateBuilder withWorkspace(SourceSpecification sourceSpecification) + public UpdateBuilder withSourceSpecification(SourceSpecification sourceSpec) { - setWorkspace(sourceSpecification); + setSourceSpecification(sourceSpec); return this; } + public UpdateBuilder withWorkspace(WorkspaceSpecification workspaceSpec) + { + return withSourceSpecification(SourceSpecification.workspaceSourceSpecification(workspaceSpec)); + } + + @Deprecated + public UpdateBuilder withWorkspace(SourceSpecification sourceSpecification) + { + return withSourceSpecification(sourceSpecification); + } + // Revision id public String getRevisionId() diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntitiesResource.java index c9c78e16da..aa5c3320f4 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntityPathsResource.java index 86ae3a23f8..6fca143091 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceProjectConfigurationResource.java index de5b350f8a..c30d3e90ac 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceProjectConfigurationResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceResource.java index 9e23bd5e94..8507b9af40 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.backup.BackupApi; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntitiesResource.java index 38698ce390..6c967b1976 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntityPathsResource.java index e3171ce2cb..1279007112 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionProjectConfigurationResource.java index 9a900230c7..89e78514f1 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionProjectConfigurationResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionsResource.java index 11f2b77f5a..e6d6712c83 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/group/BackupPatchesGroupWorkspaceRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntitiesResource.java index 2f5b501f48..fb1d22d2f7 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntityPathsResource.java index 163848cbf9..9c5cb2468f 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceProjectConfigurationResource.java index 5620460161..b922abcf99 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceProjectConfigurationResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceResource.java index e9c41ed4b1..5dd252a000 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.backup.BackupApi; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntitiesResource.java index 58ffe5624d..fd296622c7 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntityPathsResource.java index 2f13e42384..5b4471eabc 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionProjectConfigurationResource.java index b7dffa9ea9..a096e34ac8 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionProjectConfigurationResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionsResource.java index 73f9d5e951..1a464138e2 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/backup/patch/user/BackupPatchesWorkspaceRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/group/PatchesGroupComparisonWorkspaceResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/group/PatchesGroupComparisonWorkspaceResource.java index fa97b7a852..77f5c01208 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/group/PatchesGroupComparisonWorkspaceResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/group/PatchesGroupComparisonWorkspaceResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.comparison.Comparison; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.comparison.ComparisonApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/user/ComparisonPatchesWorkspaceResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/user/ComparisonPatchesWorkspaceResource.java index 67dd79e062..aa5c329f80 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/user/ComparisonPatchesWorkspaceResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/comparison/patch/user/ComparisonPatchesWorkspaceResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.comparison.Comparison; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.comparison.ComparisonApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntitiesResource.java index da2b7c2cf8..eb3316e6df 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntityPathsResource.java index ba9d0ae4be..9acf052aaf 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceProjectConfigurationResource.java index e236297f9d..d978d0100f 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceProjectConfigurationResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceResource.java index 1324a96ecc..a32f6bf1a6 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; import org.finos.legend.sdlc.server.domain.api.conflictResolution.ConflictResolutionApi; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntitiesResource.java index a376aa3894..8e3e7a8a2e 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntityPathsResource.java index 0718367fed..a20b648623 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionProjectConfigurationResource.java index 308bc5faf4..77b2dfa68c 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionProjectConfigurationResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionsResource.java index 5cb68f7d67..dd32900acc 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/group/ConflictResolutionPatchesGroupWorkspaceRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntitiesResource.java index 923f92b780..a1c5680763 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntityPathsResource.java index 98b10f2bcd..2e15951e18 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceProjectConfigurationResource.java index 81e35053dc..6fdeab8556 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceProjectConfigurationResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceResource.java index 056003c862..4cdbf7d8dd 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; import org.finos.legend.sdlc.server.domain.api.conflictResolution.ConflictResolutionApi; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntitiesResource.java index 02e233ee52..259de14c05 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntityPathsResource.java index b643cc55c9..e80830ce6b 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionProjectConfigurationResource.java index 9146aa681d..0da89b119c 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionProjectConfigurationResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionsResource.java index e03d4782be..85d70ce255 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/conflictResolution/patch/user/ConflictResolutionPatchesWorkspaceRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/group/PatchesGroupWorkspaceRevisionDependenciesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/group/PatchesGroupWorkspaceRevisionDependenciesResource.java index f7ae250445..2f85476e76 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/group/PatchesGroupWorkspaceRevisionDependenciesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/group/PatchesGroupWorkspaceRevisionDependenciesResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/user/PatchesWorkspaceRevisionDependenciesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/user/PatchesWorkspaceRevisionDependenciesResource.java index 804fedb9d2..c9fa0adc7c 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/user/PatchesWorkspaceRevisionDependenciesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/dependency/patch/user/PatchesWorkspaceRevisionDependenciesResource.java @@ -19,7 +19,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntitiesResource.java index 7bafc454cd..8eebf9a09a 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntitiesResource.java @@ -25,7 +25,7 @@ import org.finos.legend.sdlc.server.application.entity.DeleteEntityCommand; import org.finos.legend.sdlc.server.application.entity.UpdateEntitiesCommand; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityChangesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityChangesResource.java index 96ed371a34..1ee4c87b58 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityChangesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityChangesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityPathsResource.java index f5f4a316bc..ebfab73ad9 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntitiesResource.java index 8134f19e67..53030bbb14 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntityPathsResource.java index 1c8f33e537..46059d77eb 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/group/PatchesGroupWorkspaceRevisionEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntitiesResource.java index 50187c354a..75a693c556 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntitiesResource.java @@ -25,7 +25,7 @@ import org.finos.legend.sdlc.server.application.entity.DeleteEntityCommand; import org.finos.legend.sdlc.server.application.entity.UpdateEntitiesCommand; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityChangesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityChangesResource.java index 6427a25a23..8f87cb52cf 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityChangesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityChangesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityPathsResource.java index 19ca0af877..887a629b2c 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntitiesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntitiesResource.java index 44285cf3ff..6fa3399cfc 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntitiesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntitiesResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntityPathsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntityPathsResource.java index 1165a290cd..00fb075544 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntityPathsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/entity/patch/user/PatchesWorkspaceRevisionEntityPathsResource.java @@ -19,7 +19,7 @@ import io.swagger.annotations.ApiParam; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.EntityAccessResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspacePureModelContextDataResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspacePureModelContextDataResource.java index d74ffc1edd..fa486b02c3 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspacePureModelContextDataResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspacePureModelContextDataResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.PureModelContextDataResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspaceRevisionPureModelContextDataResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspaceRevisionPureModelContextDataResource.java index ec82743940..cd682ad9a9 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspaceRevisionPureModelContextDataResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/group/PatchesGroupWorkspaceRevisionPureModelContextDataResource.java @@ -20,7 +20,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.PureModelContextDataResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspacePureModelContextDataResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspacePureModelContextDataResource.java index 58e144ba58..2f1b7feaf0 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspacePureModelContextDataResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspacePureModelContextDataResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.PureModelContextDataResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspaceRevisionPureModelContextDataResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspaceRevisionPureModelContextDataResource.java index ea16d8a3ba..add51101b5 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspaceRevisionPureModelContextDataResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/pmcd/patch/user/PatchesWorkspaceRevisionPureModelContextDataResource.java @@ -20,7 +20,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.PureModelContextDataResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/PatchProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/PatchProjectConfigurationResource.java index 2a6ad8aa32..30d75e6758 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/PatchProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/PatchProjectConfigurationResource.java @@ -20,9 +20,11 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; +import java.util.List; import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -31,7 +33,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.List; @Path("/projects/{projectId}/patches/{patchReleaseVersionId}/configuration") @Api("Project Configuration") @@ -49,7 +50,7 @@ public PatchProjectConfigurationResource(ProjectConfigurationApi projectConfigur @GET @ApiOperation("Get the configuration of a project for patch release version") - public ProjectConfiguration getProjectProjectConfiguration(@PathParam("projectId") String projectId, @PathParam("patchReleaseVersionId") String patchReleaseVersionId) + public ProjectConfiguration getPatchProjectConfiguration(@PathParam("projectId") String projectId, @PathParam("patchReleaseVersionId") String patchReleaseVersionId) { LegendSDLCServerException.validateNonNull(patchReleaseVersionId, "patchReleaseVersionId may not be null"); VersionId versionId; @@ -62,8 +63,8 @@ public ProjectConfiguration getProjectProjectConfiguration(@PathParam("projectId throw new LegendSDLCServerException(e.getMessage(), Response.Status.BAD_REQUEST, e); } return executeWithLogging( - "getting project " + projectId + " configuration" + " for patch release version " + patchReleaseVersionId, - () -> this.projectConfigurationApi.getProjectProjectConfiguration(projectId, versionId) + "getting project " + projectId + " configuration for patch version " + patchReleaseVersionId, + () -> this.projectConfigurationApi.getProjectConfiguration(projectId, SourceSpecification.patchSourceSpecification(versionId)) ); } @@ -84,7 +85,7 @@ public List getProjectSupportedArtifactGene } return executeWithLogging( "getting project " + projectId + " available generations configurations" + " for patch release version " + patchReleaseVersionId, - () -> this.projectConfigurationApi.getProjectAvailableArtifactGenerations(projectId, versionId) + () -> this.projectConfigurationApi.getAvailableArtifactGenerations(projectId, SourceSpecification.patchSourceSpecification(versionId)) ); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceProjectConfigurationResource.java index 7c47c918f2..5a0e2ad156 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceProjectConfigurationResource.java @@ -22,7 +22,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.application.project.UpdateProjectConfigurationCommand; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceRevisionProjectConfigurationResource.java index b10c4620db..4418405ea4 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/group/PatchesGroupWorkspaceRevisionProjectConfigurationResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceProjectConfigurationResource.java index 80df6c00cc..0bcb2a27ad 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceProjectConfigurationResource.java @@ -22,7 +22,7 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.application.project.UpdateProjectConfigurationCommand; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceRevisionProjectConfigurationResource.java index 05139e4a08..f182bf808a 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/patch/user/PatchesWorkspaceRevisionProjectConfigurationResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectConfigurationResource.java index 87ea8866e0..e1fd8e21c0 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectConfigurationResource.java @@ -19,9 +19,11 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ArtifactTypeGenerationConfiguration; import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.project.ProjectConfigurationStatusReport; import org.finos.legend.sdlc.server.resources.BaseResource; +import java.util.List; import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -29,7 +31,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import java.util.List; @Path("/projects/{projectId}/configuration") @Api("Project Configuration") @@ -51,7 +52,7 @@ public ProjectConfiguration getProjectProjectConfiguration(@PathParam("projectId { return executeWithLogging( "getting project " + projectId + " configuration", - () -> this.projectConfigurationApi.getProjectProjectConfiguration(projectId) + () -> this.projectConfigurationApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()) ); } @@ -62,7 +63,7 @@ public List getProjectSupportedArtifactGene { return executeWithLogging( "getting project " + projectId + " available generations configurations", - () -> this.projectConfigurationApi.getProjectAvailableArtifactGenerations(projectId) + () -> this.projectConfigurationApi.getAvailableArtifactGenerations(projectId, SourceSpecification.projectSourceSpecification()) ); } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectRevisionProjectConfigurationResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectRevisionProjectConfigurationResource.java index f34fbd7576..7b71295777 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectRevisionProjectConfigurationResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/project/project/ProjectRevisionProjectConfigurationResource.java @@ -20,8 +20,10 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ArtifactTypeGenerationConfiguration; import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.resources.BaseResource; +import java.util.List; import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -29,7 +31,6 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import java.util.List; @Path("/projects/{projectId}/revisions/{revisionId}/configuration") @Api("Project Configuration") @@ -52,7 +53,7 @@ public ProjectConfiguration getProjectRevisionProjectConfiguration(@PathParam("p { return executeWithLogging( "getting project " + projectId + " configuration at revision " + revisionId, - () -> this.projectConfigurationApi.getProjectRevisionProjectConfiguration(projectId, revisionId) + () -> this.projectConfigurationApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification(), revisionId) ); } @@ -65,7 +66,7 @@ public List getProjectSupportedArtifactGene { return executeWithLogging( "getting project " + projectId + " available generations configurations at revision" + revisionId, - () -> this.projectConfigurationApi.getRevisionAvailableArtifactGenerations(projectId, revisionId) + () -> this.projectConfigurationApi.getAvailableArtifactGenerations(projectId, SourceSpecification.projectSourceSpecification(), revisionId) ); } } diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/review/patch/PatchReviewsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/review/patch/PatchReviewsResource.java index 1478b90f0c..55074db422 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/review/patch/PatchReviewsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/review/patch/PatchReviewsResource.java @@ -27,7 +27,7 @@ import org.finos.legend.sdlc.server.application.review.EditReviewCommand; import org.finos.legend.sdlc.server.domain.api.review.ReviewApi; import org.finos.legend.sdlc.server.domain.api.review.ReviewApi.ReviewUpdateStatus; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.ReviewFilterResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceEntityRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceEntityRevisionsResource.java index 3b38b34d0c..aa3dd37d57 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceEntityRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceEntityRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspacePackageRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspacePackageRevisionsResource.java index 8c5235e390..6861be2693 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspacePackageRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspacePackageRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceRevisionsResource.java index 70815229bf..f8b19e49bb 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/group/PatchesGroupWorkspaceRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceEntityRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceEntityRevisionsResource.java index b28f26b623..e77fddf5f3 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceEntityRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceEntityRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspacePackageRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspacePackageRevisionsResource.java index 3f219eef53..7039cd8efc 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspacePackageRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspacePackageRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceRevisionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceRevisionsResource.java index 13a80d50bf..8fbaf1e58c 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceRevisionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/revision/patch/user/PatchesWorkspaceRevisionsResource.java @@ -20,7 +20,7 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; import org.finos.legend.sdlc.server.time.EndInstant; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/version/VersionsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/version/VersionsResource.java index e029d2ba9c..09bfa3b66a 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/version/VersionsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/version/VersionsResource.java @@ -22,10 +22,12 @@ import org.finos.legend.sdlc.server.application.version.CreateVersionCommand; import org.finos.legend.sdlc.server.config.LegendSDLCServerFeaturesConfiguration; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.version.VersionApi; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; +import java.util.List; import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -36,7 +38,6 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.util.List; @Path("/projects/{projectId}/versions") @Api("Versions") @@ -141,11 +142,11 @@ public Version getVersion(@PathParam("projectId") String projectId, @PathParam(" public Version createVersion(@PathParam("projectId") String projectId, CreateVersionCommand command) { LegendSDLCServerException.validateNonNull(command, "Input required to create version"); - if (!featuresConfiguration.canCreateVersion) + if (!this.featuresConfiguration.canCreateVersion) { throw new LegendSDLCServerException("Server does not support creating project version(s)", Response.Status.METHOD_NOT_ALLOWED); } - ProjectType type = projectConfigurationApi.getProjectProjectConfiguration(projectId).getProjectType(); + ProjectType type = this.projectConfigurationApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectType(); if (type == ProjectType.EMBEDDED) { throw new LegendSDLCServerException("Creating a version of a project of type " + type + " is not allowed", Response.Status.CONFLICT); diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowJobsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowJobsResource.java index 8e66fae410..32e8ef231e 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowJobsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowJobsResource.java @@ -22,7 +22,7 @@ import org.finos.legend.sdlc.domain.model.workflow.WorkflowJob; import org.finos.legend.sdlc.domain.model.workflow.WorkflowJobStatus; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowJobApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowsResource.java index 3eadf5bba7..2c4414819c 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/group/PatchesGroupWorkspaceWorkflowsResource.java @@ -22,7 +22,7 @@ import org.finos.legend.sdlc.domain.model.workflow.WorkflowStatus; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowJobsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowJobsResource.java index d073c9a294..390809f8fb 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowJobsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowJobsResource.java @@ -22,7 +22,7 @@ import org.finos.legend.sdlc.domain.model.workflow.WorkflowJob; import org.finos.legend.sdlc.domain.model.workflow.WorkflowJobStatus; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowJobApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowsResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowsResource.java index b2a2663b71..f21d4d2d70 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowsResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workflow/patch/user/PatchesWorkspaceWorkflowsResource.java @@ -22,7 +22,7 @@ import org.finos.legend.sdlc.domain.model.workflow.WorkflowStatus; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/group/PatchesGroupWorkspacesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/group/PatchesGroupWorkspacesResource.java index a1c281b62a..25e3318eb7 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/group/PatchesGroupWorkspacesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/group/PatchesGroupWorkspacesResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/user/PatchesWorkspacesResource.java b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/user/PatchesWorkspacesResource.java index d783d46e92..659408e065 100644 --- a/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/user/PatchesWorkspacesResource.java +++ b/legend-sdlc-server/src/main/java/org/finos/legend/sdlc/server/resources/workspace/patch/user/PatchesWorkspacesResource.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.resources.BaseResource; diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApiTestResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApiTestResource.java index 57814cf5e4..2fe287bca1 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApiTestResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabComparisonApiTestResource.java @@ -28,7 +28,7 @@ import org.finos.legend.sdlc.domain.model.version.Version; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.version.NewVersionType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.gitlab.api.server.AbstractGitLabServerApiTest; import org.junit.Assert; import org.slf4j.Logger; diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApiTestResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApiTestResource.java index 0982abc3d3..9053a18256 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApiTestResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabEntityApiTestResource.java @@ -26,8 +26,8 @@ import org.finos.legend.sdlc.domain.model.review.ReviewState; import org.finos.legend.sdlc.domain.model.version.Version; import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.version.NewVersionType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.api.server.AbstractGitLabServerApiTest; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; @@ -56,15 +56,15 @@ public class GitLabEntityApiTestResource private final GitLabEntityApi gitLabEntityApi; private final GitLabReviewApi gitLabCommitterReviewApi; private final GitLabReviewApi gitLabApproverReviewApi; - private final GitLabPatchApi gitlabPatchApi; - private final GitLabVersionApi gitlabVersionApi; + private final GitLabPatchApi gitLabPatchApi; + private final GitLabVersionApi gitLabVersionApi; private final GitLabRevisionApi gitLabRevisionApi; private final GitLabUserContext gitLabMemberUserContext; private static final Logger LOGGER = LoggerFactory.getLogger(GitLabEntityApiTestResource.class); - public GitLabEntityApiTestResource(GitLabProjectApi gitLabProjectApi, GitLabWorkspaceApi gitLabWorkspaceApi, GitLabEntityApi gitLabEntityApi, GitLabReviewApi gitLabCommitterReviewApi, GitLabReviewApi gitLabApproverReviewApi, GitLabUserContext gitLabMemberUserContext, GitLabPatchApi gitlabPatchAPi, GitLabVersionApi gitlabVersionApi, GitLabRevisionApi gitLabRevisionApi) + public GitLabEntityApiTestResource(GitLabProjectApi gitLabProjectApi, GitLabWorkspaceApi gitLabWorkspaceApi, GitLabEntityApi gitLabEntityApi, GitLabReviewApi gitLabCommitterReviewApi, GitLabReviewApi gitLabApproverReviewApi, GitLabUserContext gitLabMemberUserContext, GitLabPatchApi gitlabPatchAPi, GitLabVersionApi gitLabVersionApi, GitLabRevisionApi gitLabRevisionApi) { this.gitLabProjectApi = gitLabProjectApi; this.gitLabWorkspaceApi = gitLabWorkspaceApi; @@ -72,8 +72,8 @@ public GitLabEntityApiTestResource(GitLabProjectApi gitLabProjectApi, GitLabWork this.gitLabCommitterReviewApi = gitLabCommitterReviewApi; this.gitLabApproverReviewApi = gitLabApproverReviewApi; this.gitLabMemberUserContext = gitLabMemberUserContext; - this.gitlabPatchApi = gitlabPatchAPi; - this.gitlabVersionApi = gitlabVersionApi; + this.gitLabPatchApi = gitlabPatchAPi; + this.gitLabVersionApi = gitLabVersionApi; this.gitLabRevisionApi = gitLabRevisionApi; } @@ -86,14 +86,14 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); String workspaceName = "entitytestworkspace"; - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); String projectId = createdProject.getProjectId(); - Workspace createdWorkspace = gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceName); + Workspace createdWorkspace = this.gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceName); String workspaceId = createdWorkspace.getWorkspaceId(); - List initialWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); - List initialProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); + List initialWorkspaceEntities = this.gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + List initialProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); Assert.assertEquals(Collections.emptyList(), initialWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), initialProjectEntities); @@ -101,13 +101,13 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep String entityPath = "test::entity"; String classifierPath = "meta::test::mathematicsDepartment"; Map entityContentMap = Maps.mutable.with( - "package", "test", - "name", "entity", - "math-113", "abstract-algebra", - "math-185", "complex-analysis"); - gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); - List modifiedWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); - List modifiedProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); + "package", "test", + "name", "entity", + "math-113", "abstract-algebra", + "math-185", "complex-analysis"); + this.gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); + List modifiedWorkspaceEntities = this.gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + List modifiedProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); Assert.assertNotNull(modifiedWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), modifiedProjectEntities); @@ -118,12 +118,12 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep Assert.assertEquals(initalEntity.getContent(), entityContentMap); Map newEntityContentMap = Maps.mutable.with( - "package", "test", - "name", "entity", - "math-128", "numerical-analysis", - "math-110", "linear-algebra"); - gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); - List updatedWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + "package", "test", + "name", "entity", + "math-128", "numerical-analysis", + "math-110", "linear-algebra"); + this.gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); + List updatedWorkspaceEntities = this.gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); Assert.assertNotNull(updatedWorkspaceEntities); Assert.assertEquals(1, updatedWorkspaceEntities.size()); @@ -135,18 +135,18 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep String entityPathTwo = "testtwo::entitytwo"; String classifierPathTwo = "meta::test::csDepartment"; Map newEntityContentMapTwo = Maps.mutable.with( - "package", "testtwo", - "name", "entitytwo", - "cs-194", "computational-imaging", - "cs-189", "machine-learning"); - gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); - List postAddWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + "package", "testtwo", + "name", "entitytwo", + "cs-194", "computational-imaging", + "cs-189", "machine-learning"); + this.gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); + List postAddWorkspaceEntities = this.gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); Assert.assertNotNull(postAddWorkspaceEntities); Assert.assertEquals(2, postAddWorkspaceEntities.size()); - gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).deleteEntity(entityPath, classifierPath); - List postDeleteWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + this.gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceId).deleteEntity(entityPath, classifierPath); + List postDeleteWorkspaceEntities = this.gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); Assert.assertNotNull(postDeleteWorkspaceEntities); Assert.assertEquals(1, postDeleteWorkspaceEntities.size()); @@ -155,16 +155,16 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep Assert.assertEquals(remainedEntity.getClassifierPath(), classifierPathTwo); Assert.assertEquals(remainedEntity.getContent(), newEntityContentMapTwo); - List paths = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntityPaths(null, null, null); + List paths = this.gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceId).getEntityPaths(null, null, null); Assert.assertNotNull(paths); Assert.assertEquals(1, paths.size()); Assert.assertEquals(entityPathTwo, paths.get(0)); List labels = Collections.singletonList("default"); - Review testReview = gitLabCommitterReviewApi.createReview(projectId, workspaceId, WorkspaceType.USER, "Add Courses.", "add two courses", labels); + Review testReview = this.gitLabCommitterReviewApi.createReview(projectId, workspaceId, WorkspaceType.USER, "Add Courses.", "add two courses", labels); String reviewId = testReview.getId(); - Review approvedReview = gitLabApproverReviewApi.approveReview(projectId, reviewId); + Review approvedReview = this.gitLabApproverReviewApi.approveReview(projectId, reviewId); Assert.assertNotNull(approvedReview); Assert.assertEquals(reviewId, approvedReview.getId()); @@ -172,42 +172,42 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep Assert.assertEquals(labels, approvedReview.getLabels()); GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId); - MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); + MergeRequestApi mergeRequestApi = this.gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); int parsedMergeRequestId = Integer.parseInt(reviewId); int gitlabProjectId = sdlcGitLabProjectId.getGitLabId(); String requiredStatus = "can_be_merged"; CallUntil callUntil = CallUntil.callUntil( - () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), - mr -> requiredStatus.equals(mr.getMergeStatus()), - 20, - 1000); + () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), + mr -> requiredStatus.equals(mr.getMergeStatus()), + 20, + 1000); if (!callUntil.succeeded()) { throw new RuntimeException("Merge request " + approvedReview.getId() + " still does not have status \"" + requiredStatus + "\" after " + callUntil.getTryCount() + " tries"); } LOGGER.info("Waited {} times for merge to have status \"{}\"", callUntil.getTryCount(), requiredStatus); - gitLabCommitterReviewApi.commitReview(projectId, reviewId, "add two math courses"); + this.gitLabCommitterReviewApi.commitReview(projectId, reviewId, "add two math courses"); String requiredMergedStatus = "merged"; CallUntil callUntilMerged = CallUntil.callUntil( - () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), - mr -> requiredMergedStatus.equals(mr.getState()), - 10, - 500); + () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), + mr -> requiredMergedStatus.equals(mr.getState()), + 10, + 500); if (!callUntilMerged.succeeded()) { throw new RuntimeException("Merge request " + reviewId + " still does not have state \"" + requiredMergedStatus + "\" after " + callUntilMerged.getTryCount() + " tries"); } LOGGER.info("Waited {} times for merge request to have state \"{}\"", callUntilMerged.getTryCount(), requiredMergedStatus); - RepositoryApi repositoryApi = gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); + RepositoryApi repositoryApi = this.gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); CallUntil, GitLabApiException> callUntilBranchDeleted = CallUntil.callUntil( - () -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), - GitLabEntityApiTestResource::hasOnlyMasterBranch, - 15, - 1000); + () -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), + GitLabEntityApiTestResource::hasOnlyMasterBranch, + 15, + 1000); if (!callUntilBranchDeleted.succeeded()) { // Warn instead of throwing exception since we cannot manage time expectation on GitLab to reflect branch deletion. @@ -215,7 +215,7 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTest() throws GitLabApiExcep } LOGGER.info("Waited {} times for branch to be deleted post merge", callUntilBranchDeleted.getTryCount()); - List postCommitProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); + List postCommitProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); Assert.assertNotNull(postCommitProjectEntities); Assert.assertEquals(1, postCommitProjectEntities.size()); @@ -234,14 +234,14 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); String workspaceName = "entitytestworkspace"; - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); String projectId = createdProject.getProjectId(); - Workspace createdWorkspace = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceName); + Workspace createdWorkspace = this.gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceName); String workspaceId = createdWorkspace.getWorkspaceId(); - List initialWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); - List initialProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); + List initialWorkspaceEntities = this.gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + List initialProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); Assert.assertEquals(Collections.emptyList(), initialWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), initialProjectEntities); @@ -249,13 +249,13 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce String entityPath = "test::entity"; String classifierPath = "meta::test::mathematicsDepartment"; Map entityContentMap = Maps.mutable.with( - "package", "test", - "name", "entity", - "math-113", "abstract-algebra", - "math-185", "complex-analysis"); - gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); - List modifiedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); - List modifiedProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); + "package", "test", + "name", "entity", + "math-113", "abstract-algebra", + "math-185", "complex-analysis"); + this.gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); + List modifiedWorkspaceEntities = this.gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + List modifiedProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); Assert.assertNotNull(modifiedWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), modifiedProjectEntities); @@ -266,12 +266,12 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce Assert.assertEquals(initalEntity.getContent(), entityContentMap); Map newEntityContentMap = Maps.mutable.with( - "package", "test", - "name", "entity", - "math-128", "numerical-analysis", - "math-110", "linear-algebra"); - gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); - List updatedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + "package", "test", + "name", "entity", + "math-128", "numerical-analysis", + "math-110", "linear-algebra"); + this.gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); + List updatedWorkspaceEntities = this.gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); Assert.assertNotNull(updatedWorkspaceEntities); Assert.assertEquals(1, updatedWorkspaceEntities.size()); @@ -283,18 +283,18 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce String entityPathTwo = "testtwo::entitytwo"; String classifierPathTwo = "meta::test::csDepartment"; Map newEntityContentMapTwo = Maps.mutable.with( - "package", "testtwo", - "name", "entitytwo", - "cs-194", "computational-imaging", - "cs-189", "machine-learning"); - gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); - List postAddWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + "package", "testtwo", + "name", "entitytwo", + "cs-194", "computational-imaging", + "cs-189", "machine-learning"); + this.gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); + List postAddWorkspaceEntities = this.gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); Assert.assertNotNull(postAddWorkspaceEntities); Assert.assertEquals(2, postAddWorkspaceEntities.size()); - gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).deleteEntity(entityPath, classifierPath); - List postDeleteWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); + this.gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).deleteEntity(entityPath, classifierPath); + List postDeleteWorkspaceEntities = this.gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null); Assert.assertNotNull(postDeleteWorkspaceEntities); Assert.assertEquals(1, postDeleteWorkspaceEntities.size()); @@ -303,58 +303,58 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce Assert.assertEquals(remainedEntity.getClassifierPath(), classifierPathTwo); Assert.assertEquals(remainedEntity.getContent(), newEntityContentMapTwo); - List paths = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntityPaths(null, null, null); + List paths = this.gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntityPaths(null, null, null); Assert.assertNotNull(paths); Assert.assertEquals(1, paths.size()); Assert.assertEquals(entityPathTwo, paths.get(0)); List labels = Collections.singletonList("default"); - Review testReview = gitLabCommitterReviewApi.createReview(projectId, workspaceId, WorkspaceType.GROUP, "Add Courses.", "add two courses", labels); + Review testReview = this.gitLabCommitterReviewApi.createReview(projectId, workspaceId, WorkspaceType.GROUP, "Add Courses.", "add two courses", labels); String reviewId = testReview.getId(); - Review approvedReview = gitLabApproverReviewApi.approveReview(projectId, reviewId); + Review approvedReview = this.gitLabApproverReviewApi.approveReview(projectId, reviewId); Assert.assertNotNull(approvedReview); Assert.assertEquals(reviewId, approvedReview.getId()); Assert.assertEquals(ReviewState.OPEN, approvedReview.getState()); GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId); - MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); + MergeRequestApi mergeRequestApi = this.gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); int parsedMergeRequestId = Integer.parseInt(reviewId); int gitlabProjectId = sdlcGitLabProjectId.getGitLabId(); String requiredStatus = "can_be_merged"; CallUntil callUntil = CallUntil.callUntil( - () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), - mr -> requiredStatus.equals(mr.getMergeStatus()), - 20, - 1000); + () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), + mr -> requiredStatus.equals(mr.getMergeStatus()), + 20, + 1000); if (!callUntil.succeeded()) { throw new RuntimeException("Merge request " + approvedReview.getId() + " still does not have status \"" + requiredStatus + "\" after " + callUntil.getTryCount() + " tries"); } LOGGER.info("Waited {} times for merge to have status \"{}\"", callUntil.getTryCount(), requiredStatus); - gitLabCommitterReviewApi.commitReview(projectId, reviewId, "add two math courses"); + this.gitLabCommitterReviewApi.commitReview(projectId, reviewId, "add two math courses"); String requiredMergedStatus = "merged"; CallUntil callUntilMerged = CallUntil.callUntil( - () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), - mr -> requiredMergedStatus.equals(mr.getState()), - 10, - 500); + () -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), + mr -> requiredMergedStatus.equals(mr.getState()), + 10, + 500); if (!callUntilMerged.succeeded()) { throw new RuntimeException("Merge request " + reviewId + " still does not have state \"" + requiredMergedStatus + "\" after " + callUntilMerged.getTryCount() + " tries"); } LOGGER.info("Waited {} times for merge request to have state \"{}\"", callUntilMerged.getTryCount(), requiredMergedStatus); - RepositoryApi repositoryApi = gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); + RepositoryApi repositoryApi = this.gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); CallUntil, GitLabApiException> callUntilBranchDeleted = CallUntil.callUntil( - () -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), - GitLabEntityApiTestResource::hasOnlyMasterBranch, - 15, - 1000); + () -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), + GitLabEntityApiTestResource::hasOnlyMasterBranch, + 15, + 1000); if (!callUntilBranchDeleted.succeeded()) { // Warn instead of throwing exception since we cannot manage time expectation on GitLab to reflect branch deletion. @@ -362,7 +362,7 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiExce } LOGGER.info("Waited {} times for branch to be deleted post merge", callUntilBranchDeleted.getTryCount()); - List postCommitProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); + List postCommitProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null); Assert.assertNotNull(postCommitProjectEntities); Assert.assertEquals(1, postCommitProjectEntities.size()); @@ -381,19 +381,19 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); String workspaceName = "entitytestworkspace"; - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); String projectId = createdProject.getProjectId(); - Version version = gitlabVersionApi.newVersion(projectId, NewVersionType.PATCH, gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); - Patch patch = gitlabPatchApi.newPatch(projectId, version.getId()); + Version version = this.gitLabVersionApi.newVersion(projectId, NewVersionType.MINOR, this.gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); + Patch patch = this.gitLabPatchApi.newPatch(projectId, version.getId()); VersionId patchReleaseVersionId = patch.getPatchReleaseVersionId(); SourceSpecification sourceSpecification = SourceSpecification.newUserWorkspaceSourceSpecification(workspaceName, patchReleaseVersionId); - Workspace createdWorkspace = gitLabWorkspaceApi.newWorkspace(projectId, sourceSpecification); + Workspace createdWorkspace = this.gitLabWorkspaceApi.newWorkspace(projectId, sourceSpecification); String workspaceId = createdWorkspace.getWorkspaceId(); - List initialWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); - List initialProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); + List initialWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + List initialProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); Assert.assertEquals(Collections.emptyList(), initialWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), initialProjectEntities); @@ -405,9 +405,9 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis"); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); - List modifiedWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); - List modifiedProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); + List modifiedWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + List modifiedProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); Assert.assertNotNull(modifiedWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), modifiedProjectEntities); @@ -422,8 +422,8 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() "name", "entity", "math-128", "numerical-analysis", "math-110", "linear-algebra"); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); - List updatedWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); + List updatedWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); Assert.assertNotNull(updatedWorkspaceEntities); Assert.assertEquals(1, updatedWorkspaceEntities.size()); @@ -439,14 +439,14 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() "name", "entitytwo", "cs-194", "computational-imaging", "cs-189", "machine-learning"); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); - List postAddWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); + List postAddWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); Assert.assertNotNull(postAddWorkspaceEntities); Assert.assertEquals(2, postAddWorkspaceEntities.size()); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).deleteEntity(entityPath, classifierPath); - List postDeleteWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).deleteEntity(entityPath, classifierPath); + List postDeleteWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); Assert.assertNotNull(postDeleteWorkspaceEntities); Assert.assertEquals(1, postDeleteWorkspaceEntities.size()); @@ -455,16 +455,16 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() Assert.assertEquals(remainedEntity.getClassifierPath(), classifierPathTwo); Assert.assertEquals(remainedEntity.getContent(), newEntityContentMapTwo); - List paths = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntityPaths(null, null, null); + List paths = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntityPaths(null, null, null); Assert.assertNotNull(paths); Assert.assertEquals(1, paths.size()); Assert.assertEquals(entityPathTwo, paths.get(0)); List labels = Collections.singletonList("default"); - Review testReview = gitLabCommitterReviewApi.createReview(projectId, sourceSpecification, "Add Courses.", "add two courses", labels); + Review testReview = this.gitLabCommitterReviewApi.createReview(projectId, sourceSpecification, "Add Courses.", "add two courses", labels); String reviewId = testReview.getId(); - Review approvedReview = gitLabApproverReviewApi.approveReview(projectId, patchReleaseVersionId, reviewId); + Review approvedReview = this.gitLabApproverReviewApi.approveReview(projectId, patchReleaseVersionId, reviewId); Assert.assertNotNull(approvedReview); Assert.assertEquals(reviewId, approvedReview.getId()); @@ -472,7 +472,7 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() Assert.assertEquals(labels, approvedReview.getLabels()); GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId); - MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); + MergeRequestApi mergeRequestApi = this.gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); int parsedMergeRequestId = Integer.parseInt(reviewId); int gitlabProjectId = sdlcGitLabProjectId.getGitLabId(); @@ -488,7 +488,7 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() } LOGGER.info("Waited {} times for merge to have status \"{}\"", callUntil.getTryCount(), requiredStatus); - gitLabCommitterReviewApi.commitReview(projectId, patchReleaseVersionId, reviewId, "add two math courses"); + this.gitLabCommitterReviewApi.commitReview(projectId, patchReleaseVersionId, reviewId, "add two math courses"); String requiredMergedStatus = "merged"; CallUntil callUntilMerged = CallUntil.callUntil( @@ -502,7 +502,7 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() } LOGGER.info("Waited {} times for merge request to have state \"{}\"", callUntilMerged.getTryCount(), requiredMergedStatus); - RepositoryApi repositoryApi = gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); + RepositoryApi repositoryApi = this.gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); CallUntil, GitLabApiException> callUntilBranchDeleted = CallUntil.callUntil( () -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), GitLabEntityApiTestResource::hasOnlyMasterBranch, @@ -515,7 +515,7 @@ public void runEntitiesInNormalUserWorkspaceWorkflowTestForPatchRelaseVersion() } LOGGER.info("Waited {} times for branch to be deleted post merge", callUntilBranchDeleted.getTryCount()); - List postCommitProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); + List postCommitProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); Assert.assertNotNull(postCommitProjectEntities); Assert.assertEquals(1, postCommitProjectEntities.size()); @@ -534,19 +534,19 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); String workspaceName = "entitytestworkspace"; - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); String projectId = createdProject.getProjectId(); - Version version = gitlabVersionApi.newVersion(projectId, NewVersionType.PATCH, gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); - Patch patch = gitlabPatchApi.newPatch(projectId, version.getId()); + Version version = this.gitLabVersionApi.newVersion(projectId, NewVersionType.PATCH, this.gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); + Patch patch = this.gitLabPatchApi.newPatch(projectId, version.getId()); VersionId patchReleaseVersionId = patch.getPatchReleaseVersionId(); SourceSpecification sourceSpecification = SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceName, patchReleaseVersionId); - Workspace createdWorkspace = gitLabWorkspaceApi.newWorkspace(projectId, sourceSpecification); + Workspace createdWorkspace = this.gitLabWorkspaceApi.newWorkspace(projectId, sourceSpecification); String workspaceId = createdWorkspace.getWorkspaceId(); - List initialWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); - List initialProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); + List initialWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + List initialProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); Assert.assertEquals(Collections.emptyList(), initialWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), initialProjectEntities); @@ -558,9 +558,9 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis"); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); - List modifiedWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); - List modifiedProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPath, classifierPath, entityContentMap, "initial entity"); + List modifiedWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + List modifiedProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); Assert.assertNotNull(modifiedWorkspaceEntities); Assert.assertEquals(Collections.emptyList(), modifiedProjectEntities); @@ -575,8 +575,8 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() "name", "entity", "math-128", "numerical-analysis", "math-110", "linear-algebra"); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); - List updatedWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity"); + List updatedWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); Assert.assertNotNull(updatedWorkspaceEntities); Assert.assertEquals(1, updatedWorkspaceEntities.size()); @@ -592,14 +592,14 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() "name", "entitytwo", "cs-194", "computational-imaging", "cs-189", "machine-learning"); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); - List postAddWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity"); + List postAddWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); Assert.assertNotNull(postAddWorkspaceEntities); Assert.assertEquals(2, postAddWorkspaceEntities.size()); - gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).deleteEntity(entityPath, classifierPath); - List postDeleteWorkspaceEntities = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); + this.gitLabEntityApi.getWorkspaceEntityModificationContext(projectId, sourceSpecification).deleteEntity(entityPath, classifierPath); + List postDeleteWorkspaceEntities = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntities(null, null, null); Assert.assertNotNull(postDeleteWorkspaceEntities); Assert.assertEquals(1, postDeleteWorkspaceEntities.size()); @@ -608,16 +608,16 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() Assert.assertEquals(remainedEntity.getClassifierPath(), classifierPathTwo); Assert.assertEquals(remainedEntity.getContent(), newEntityContentMapTwo); - List paths = gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntityPaths(null, null, null); + List paths = this.gitLabEntityApi.getWorkspaceEntityAccessContext(projectId, sourceSpecification).getEntityPaths(null, null, null); Assert.assertNotNull(paths); Assert.assertEquals(1, paths.size()); Assert.assertEquals(entityPathTwo, paths.get(0)); List labels = Collections.singletonList("default"); - Review testReview = gitLabCommitterReviewApi.createReview(projectId, sourceSpecification, "Add Courses.", "add two courses", labels); + Review testReview = this.gitLabCommitterReviewApi.createReview(projectId, sourceSpecification, "Add Courses.", "add two courses", labels); String reviewId = testReview.getId(); - Review approvedReview = gitLabApproverReviewApi.approveReview(projectId, patchReleaseVersionId, reviewId); + Review approvedReview = this.gitLabApproverReviewApi.approveReview(projectId, patchReleaseVersionId, reviewId); Assert.assertNotNull(approvedReview); Assert.assertEquals(reviewId, approvedReview.getId()); @@ -625,7 +625,7 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() Assert.assertEquals(labels, approvedReview.getLabels()); GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId); - MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); + MergeRequestApi mergeRequestApi = this.gitLabMemberUserContext.getGitLabAPI().getMergeRequestApi(); int parsedMergeRequestId = Integer.parseInt(reviewId); int gitlabProjectId = sdlcGitLabProjectId.getGitLabId(); @@ -641,7 +641,7 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() } LOGGER.info("Waited {} times for merge to have status \"{}\"", callUntil.getTryCount(), requiredStatus); - gitLabCommitterReviewApi.commitReview(projectId, patchReleaseVersionId, reviewId, "add two math courses"); + this.gitLabCommitterReviewApi.commitReview(projectId, patchReleaseVersionId, reviewId, "add two math courses"); String requiredMergedStatus = "merged"; CallUntil callUntilMerged = CallUntil.callUntil( @@ -655,7 +655,7 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() } LOGGER.info("Waited {} times for merge request to have state \"{}\"", callUntilMerged.getTryCount(), requiredMergedStatus); - RepositoryApi repositoryApi = gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); + RepositoryApi repositoryApi = this.gitLabMemberUserContext.getGitLabAPI().getRepositoryApi(); CallUntil, GitLabApiException> callUntilBranchDeleted = CallUntil.callUntil( () -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), GitLabEntityApiTestResource::hasOnlyMasterBranch, @@ -668,7 +668,7 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() } LOGGER.info("Waited {} times for branch to be deleted post merge", callUntilBranchDeleted.getTryCount()); - List postCommitProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); + List postCommitProjectEntities = this.gitLabEntityApi.getProjectEntityAccessContext(projectId, patchReleaseVersionId).getEntities(null, null, null); Assert.assertNotNull(postCommitProjectEntities); Assert.assertEquals(1, postCommitProjectEntities.size()); @@ -680,7 +680,7 @@ public void runEntitiesInNormalGroupWorkspaceWorkflowTestForPatchRelaseVersion() public GitLabProjectApi getGitLabProjectApi() { - return gitLabProjectApi; + return this.gitLabProjectApi; } private static boolean hasOnlyMasterBranch(List branchList) diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApiTestResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApiTestResource.java index 9c32b08a28..96699f7541 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApiTestResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectApiTestResource.java @@ -18,14 +18,12 @@ import org.eclipse.collections.api.factory.Sets; import org.finos.legend.sdlc.domain.model.project.Project; import org.finos.legend.sdlc.domain.model.project.ProjectType; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.gitlab.api.server.AbstractGitLabServerApiTest; import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.junit.Assert; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.stream.Collectors; @@ -49,7 +47,7 @@ public void runCreateProjectTest() throws LegendSDLCServerException String artifactId = "testprojone"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - Project createdProject = gitLabProjectApi.createProject(projectName, description, null, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, null, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -60,9 +58,9 @@ public void runCreateProjectTest() throws LegendSDLCServerException String projectId = createdProject.getProjectId(); Assert.assertNotNull(projectId); - Assert.assertEquals(ProjectType.MANAGED, gitLabProjectApi.getProjectConfiguration(projectId, null).getProjectType()); + Assert.assertEquals(ProjectType.MANAGED, this.gitLabProjectApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectType()); Assert.assertNull(gitLabProjectApi.getProject(projectId).getProjectType()); - Assert.assertNotNull(gitLabProjectApi.getProjectConfiguration(projectId, null).getProjectStructureVersion().getExtensionVersion()); + Assert.assertNotNull(gitLabProjectApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectStructureVersion().getExtensionVersion()); Assert.assertEquals(Sets.mutable.with("/project.json", "/PANGRAM.TXT", @@ -72,7 +70,7 @@ public void runCreateProjectTest() throws LegendSDLCServerException "/testprojone-file-generation/pom.xml", "/testprojone-service-execution/pom.xml", "/testprojone-versioned-entities/pom.xml" - ), gitLabProjectApi.getProjectFileAccessProvider().getProjectFileAccessContext(projectId).getFiles().map(ProjectFileAccessProvider.ProjectFile::getPath).collect(Collectors.toSet())); + ), this.gitLabProjectApi.getProjectFileAccessProvider().getProjectFileAccessContext(projectId).getFiles().map(ProjectFileAccessProvider.ProjectFile::getPath).collect(Collectors.toSet())); } public void runCreateManagedProjectTest() throws LegendSDLCServerException @@ -83,7 +81,7 @@ public void runCreateManagedProjectTest() throws LegendSDLCServerException String artifactId = "testprojone"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -94,9 +92,9 @@ public void runCreateManagedProjectTest() throws LegendSDLCServerException String projectId = createdProject.getProjectId(); Assert.assertNotNull(projectId); - Assert.assertEquals(ProjectType.MANAGED, gitLabProjectApi.getProjectConfiguration(projectId, null).getProjectType()); + Assert.assertEquals(ProjectType.MANAGED, this.gitLabProjectApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectType()); Assert.assertNull(gitLabProjectApi.getProject(projectId).getProjectType()); - Assert.assertNotNull(gitLabProjectApi.getProjectConfiguration(projectId, null).getProjectStructureVersion().getExtensionVersion()); + Assert.assertNotNull(gitLabProjectApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectStructureVersion().getExtensionVersion()); Assert.assertEquals(Sets.mutable.with("/project.json", "/PANGRAM.TXT", @@ -106,7 +104,7 @@ public void runCreateManagedProjectTest() throws LegendSDLCServerException "/testprojone-file-generation/pom.xml", "/testprojone-service-execution/pom.xml", "/testprojone-versioned-entities/pom.xml" - ), gitLabProjectApi.getProjectFileAccessProvider().getProjectFileAccessContext(projectId).getFiles().map(ProjectFileAccessProvider.ProjectFile::getPath).collect(Collectors.toSet())); + ), this.gitLabProjectApi.getProjectFileAccessProvider().getFileAccessContext(projectId, SourceSpecification.projectSourceSpecification()).getFiles().map(ProjectFileAccessProvider.ProjectFile::getPath).collect(Collectors.toSet())); } public void runCreateProductionProjectTest() throws LegendSDLCServerException @@ -117,7 +115,7 @@ public void runCreateProductionProjectTest() throws LegendSDLCServerException String artifactId = "testprojone"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - LegendSDLCServerException e = Assert.assertThrows(LegendSDLCServerException.class, () -> gitLabProjectApi.createProject(projectName, description, ProjectType.PRODUCTION, groupId, artifactId, tags)); + LegendSDLCServerException e = Assert.assertThrows(LegendSDLCServerException.class, () -> this.gitLabProjectApi.createProject(projectName, description, ProjectType.PRODUCTION, groupId, artifactId, tags)); Assert.assertEquals("Invalid type: PRODUCTION", e.getMessage()); } @@ -129,7 +127,7 @@ public void runCreateEmbeddedProjectTest() throws LegendSDLCServerException String artifactId = "testprojone"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.EMBEDDED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.EMBEDDED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -140,12 +138,12 @@ public void runCreateEmbeddedProjectTest() throws LegendSDLCServerException String projectId = createdProject.getProjectId(); Assert.assertNotNull(projectId); - Assert.assertEquals(ProjectType.EMBEDDED, gitLabProjectApi.getProjectConfiguration(projectId, null).getProjectType()); + Assert.assertEquals(ProjectType.EMBEDDED, this.gitLabProjectApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectType()); Assert.assertNull(gitLabProjectApi.getProject(projectId).getProjectType()); - Assert.assertNull(gitLabProjectApi.getProjectConfiguration(projectId, null).getProjectStructureVersion().getExtensionVersion()); + Assert.assertNull(gitLabProjectApi.getProjectConfiguration(projectId, SourceSpecification.projectSourceSpecification()).getProjectStructureVersion().getExtensionVersion()); Assert.assertEquals(Sets.mutable.with("/project.json" - ), gitLabProjectApi.getProjectFileAccessProvider().getProjectFileAccessContext(projectId).getFiles().map(ProjectFileAccessProvider.ProjectFile::getPath).collect(Collectors.toSet())); + ), this.gitLabProjectApi.getProjectFileAccessProvider().getFileAccessContext(projectId, SourceSpecification.projectSourceSpecification()).getFiles().map(ProjectFileAccessProvider.ProjectFile::getPath).collect(Collectors.toSet())); } public void runGetProjectTest() throws LegendSDLCServerException @@ -156,7 +154,7 @@ public void runGetProjectTest() throws LegendSDLCServerException String artifactId = "testprojtwo"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -164,7 +162,7 @@ public void runGetProjectTest() throws LegendSDLCServerException Assert.assertNull(createdProject.getProjectType()); Assert.assertEquals(Sets.mutable.withAll(tags), Sets.mutable.withAll(createdProject.getTags())); - Project retrievedProject = gitLabProjectApi.getProject(createdProject.getProjectId()); + Project retrievedProject = this.gitLabProjectApi.getProject(createdProject.getProjectId()); Assert.assertNotNull(retrievedProject); Assert.assertEquals(projectName, retrievedProject.getName()); @@ -180,7 +178,7 @@ public void runUpdateProjectTest() String artifactId = "testprojthree"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -196,12 +194,12 @@ public void runUpdateProjectTest() List tagsToRemove = Lists.mutable.with("doe", "moffitt"); List expectedTags = Lists.mutable.with("main-stacks", "bancroft", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - gitLabProjectApi.changeProjectName(projectId, newProjectName); - gitLabProjectApi.changeProjectDescription(projectId, newProjectDescription); - gitLabProjectApi.setProjectTags(projectId, newTags); - gitLabProjectApi.updateProjectTags(projectId, tagsToRemove, tagsToAdd); + this.gitLabProjectApi.changeProjectName(projectId, newProjectName); + this.gitLabProjectApi.changeProjectDescription(projectId, newProjectDescription); + this.gitLabProjectApi.setProjectTags(projectId, newTags); + this.gitLabProjectApi.updateProjectTags(projectId, tagsToRemove, tagsToAdd); - Project reRetrievedProject = gitLabProjectApi.getProject(projectId); + Project reRetrievedProject = this.gitLabProjectApi.getProject(projectId); Assert.assertEquals(newProjectName, reRetrievedProject.getName()); Assert.assertEquals(newProjectDescription, reRetrievedProject.getDescription()); @@ -210,6 +208,6 @@ public void runUpdateProjectTest() public GitLabProjectApi getGitLabProjectApi() { - return gitLabProjectApi; + return this.gitLabProjectApi; } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApiTestResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApiTestResource.java index f3327f6492..91d2b8504c 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApiTestResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabProjectConfigurationApiTestResource.java @@ -23,12 +23,10 @@ import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; import org.finos.legend.sdlc.domain.model.version.Version; import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.version.NewVersionType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; import org.finos.legend.sdlc.server.gitlab.api.server.AbstractGitLabServerApiTest; import org.junit.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; @@ -44,9 +42,6 @@ public class GitLabProjectConfigurationApiTestResource private final GitLabVersionApi gitlabVersionApi; private final GitLabRevisionApi gitLabRevisionApi; - - private static final Logger LOGGER = LoggerFactory.getLogger(GitLabProjectConfigurationApiTestResource.class); - public GitLabProjectConfigurationApiTestResource(GitLabWorkspaceApi gitLabWorkspaceApi, GitLabProjectApi gitLabProjectApi, GitLabProjectConfigurationApi gitLabProjectConfigurationApi,GitLabPatchApi gitlabPatchAPi, GitLabVersionApi gitlabVersionApi, GitLabRevisionApi gitLabRevisionApi) { this.gitLabWorkspaceApi = gitLabWorkspaceApi; @@ -67,7 +62,7 @@ public void runUserAndGroupWorkspaceProjectConfigurationTest() String workspaceOneId = "testworkspaceone"; String workspaceTwoId = "testworkspacetwo"; - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -76,32 +71,32 @@ public void runUserAndGroupWorkspaceProjectConfigurationTest() Assert.assertNull(createdProject.getProjectType()); String projectId = createdProject.getProjectId(); - Workspace createdWorkspaceOne = gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceOneId); + Workspace createdWorkspaceOne = this.gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceOneId); Assert.assertNotNull(createdWorkspaceOne); Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId()); Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId()); Assert.assertNotNull(createdWorkspaceOne.getUserId()); - ProjectConfiguration projectConfiguration = gitLabProjectConfigurationApi.getUserWorkspaceProjectConfiguration(projectId, workspaceOneId); + ProjectConfiguration projectConfiguration = this.gitLabProjectConfigurationApi.getUserWorkspaceProjectConfiguration(projectId, workspaceOneId); Assert.assertNotNull(projectConfiguration); Assert.assertEquals(ProjectType.MANAGED, projectConfiguration.getProjectType()); Assert.assertEquals(projectConfiguration.getArtifactId(), artifactId); Assert.assertEquals(projectConfiguration.getGroupId(), groupId); - Workspace createdWorkspaceTwo = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceTwoId); + Workspace createdWorkspaceTwo = this.gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceTwoId); Assert.assertNotNull(createdWorkspaceTwo); Assert.assertEquals(workspaceTwoId, createdWorkspaceTwo.getWorkspaceId()); Assert.assertEquals(projectId, createdWorkspaceTwo.getProjectId()); Assert.assertNull(createdWorkspaceTwo.getUserId()); - ProjectConfiguration projectConfigurationTwo = gitLabProjectConfigurationApi.getGroupWorkspaceProjectConfiguration(projectId, workspaceTwoId); + ProjectConfiguration projectConfigurationTwo = this.gitLabProjectConfigurationApi.getGroupWorkspaceProjectConfiguration(projectId, workspaceTwoId); Assert.assertNotNull(projectConfigurationTwo); - Assert.assertEquals(projectConfigurationTwo.getArtifactId(), artifactId); - Assert.assertEquals(projectConfigurationTwo.getGroupId(), groupId); + Assert.assertEquals(artifactId, projectConfigurationTwo.getArtifactId()); + Assert.assertEquals(groupId, projectConfigurationTwo.getGroupId()); } public void runUserAndGroupWorkspaceProjectConfigurationTestForPatchReleaseVersion() @@ -114,7 +109,7 @@ public void runUserAndGroupWorkspaceProjectConfigurationTestForPatchReleaseVersi String workspaceOneId = "testworkspaceone"; String workspaceTwoId = "testworkspacetwo"; - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -123,35 +118,35 @@ public void runUserAndGroupWorkspaceProjectConfigurationTestForPatchReleaseVersi Assert.assertNull(createdProject.getProjectType()); String projectId = createdProject.getProjectId(); - Version version = gitlabVersionApi.newVersion(projectId, NewVersionType.PATCH, gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); - Patch patch = gitlabPatchApi.newPatch(projectId, version.getId()); + Version version = this.gitlabVersionApi.newVersion(projectId, NewVersionType.MINOR, this.gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); + Patch patch = this.gitlabPatchApi.newPatch(projectId, version.getId()); VersionId patchReleaseVersionId = patch.getPatchReleaseVersionId(); - Workspace createdWorkspaceOne = gitLabWorkspaceApi.newWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceOneId, patchReleaseVersionId)); + Workspace createdWorkspaceOne = this.gitLabWorkspaceApi.newWorkspace(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceOneId, patchReleaseVersionId)); Assert.assertNotNull(createdWorkspaceOne); Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId()); Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId()); Assert.assertNotNull(createdWorkspaceOne.getUserId()); - ProjectConfiguration projectConfiguration = gitLabProjectConfigurationApi.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceOneId, patchReleaseVersionId)); + ProjectConfiguration projectConfiguration = this.gitLabProjectConfigurationApi.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newUserWorkspaceSourceSpecification(workspaceOneId, patchReleaseVersionId)); Assert.assertNotNull(projectConfiguration); - Assert.assertEquals(projectConfiguration.getArtifactId(), artifactId); - Assert.assertEquals(projectConfiguration.getGroupId(), groupId); + Assert.assertEquals(artifactId, projectConfiguration.getArtifactId()); + Assert.assertEquals(groupId, projectConfiguration.getGroupId()); - Workspace createdWorkspaceTwo = gitLabWorkspaceApi.newWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceTwoId, patchReleaseVersionId)); + Workspace createdWorkspaceTwo = this.gitLabWorkspaceApi.newWorkspace(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceTwoId, patchReleaseVersionId)); Assert.assertNotNull(createdWorkspaceTwo); Assert.assertEquals(workspaceTwoId, createdWorkspaceTwo.getWorkspaceId()); Assert.assertEquals(projectId, createdWorkspaceTwo.getProjectId()); Assert.assertNull(createdWorkspaceTwo.getUserId()); - ProjectConfiguration projectConfigurationTwo = gitLabProjectConfigurationApi.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceTwoId, patchReleaseVersionId)); + ProjectConfiguration projectConfigurationTwo = this.gitLabProjectConfigurationApi.getWorkspaceProjectConfiguration(projectId, SourceSpecification.newGroupWorkspaceSourceSpecification(workspaceTwoId, patchReleaseVersionId)); Assert.assertNotNull(projectConfigurationTwo); - Assert.assertEquals(projectConfigurationTwo.getArtifactId(), artifactId); - Assert.assertEquals(projectConfigurationTwo.getGroupId(), groupId); + Assert.assertEquals(artifactId, projectConfigurationTwo.getArtifactId()); + Assert.assertEquals(groupId, projectConfigurationTwo.getGroupId()); } public void runProjectVersionProjectConfigurationTest() @@ -162,7 +157,7 @@ public void runProjectVersionProjectConfigurationTest() String artifactId = "pctestprojthree"; List tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG); - Project createdProject = gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); + Project createdProject = this.gitLabProjectApi.createProject(projectName, description, ProjectType.MANAGED, groupId, artifactId, tags); Assert.assertNotNull(createdProject); Assert.assertEquals(projectName, createdProject.getName()); @@ -171,17 +166,17 @@ public void runProjectVersionProjectConfigurationTest() Assert.assertNull(createdProject.getProjectType()); String projectId = createdProject.getProjectId(); - Version version = gitlabVersionApi.newVersion(projectId, NewVersionType.PATCH, gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); + Version version = this.gitlabVersionApi.newVersion(projectId, NewVersionType.PATCH, this.gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision().getId(), ""); - ProjectConfiguration projectConfigurationTwo = gitLabProjectConfigurationApi.getVersionProjectConfiguration(projectId, version.getId()); + ProjectConfiguration projectConfigurationTwo = this.gitLabProjectConfigurationApi.getVersionProjectConfiguration(projectId, version.getId()); Assert.assertNotNull(projectConfigurationTwo); - Assert.assertEquals(projectConfigurationTwo.getArtifactId(), artifactId); - Assert.assertEquals(projectConfigurationTwo.getGroupId(), groupId); + Assert.assertEquals(artifactId, projectConfigurationTwo.getArtifactId()); + Assert.assertEquals(groupId, projectConfigurationTwo.getGroupId()); } public GitLabProjectApi getGitLabProjectApi() { - return gitLabProjectApi; + return this.gitLabProjectApi; } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApiTestResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApiTestResource.java index d71b1cb325..ca13c9bd52 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApiTestResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabRevisionApiTestResource.java @@ -26,7 +26,7 @@ import org.finos.legend.sdlc.domain.model.version.Version; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.version.NewVersionType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.gitlab.api.server.AbstractGitLabServerApiTest; import org.junit.Assert; import org.slf4j.Logger; diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApiTestResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApiTestResource.java index ea9109e024..127ab2cfe6 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApiTestResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/GitLabWorkspaceApiTestResource.java @@ -28,7 +28,7 @@ import org.finos.legend.sdlc.domain.model.version.Version; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.version.NewVersionType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.gitlab.GitLabProjectId; import org.finos.legend.sdlc.server.gitlab.api.server.AbstractGitLabServerApiTest; import org.finos.legend.sdlc.server.gitlab.auth.GitLabUserContext; diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/TestBaseGitLabApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/TestBaseGitLabApi.java index 5639fea0c0..c0afd3e5bf 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/TestBaseGitLabApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/TestBaseGitLabApi.java @@ -14,9 +14,15 @@ package org.finos.legend.sdlc.server.gitlab.api; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import org.junit.Assert; import org.junit.Test; +import java.util.function.Supplier; + public class TestBaseGitLabApi { @Test @@ -121,4 +127,126 @@ public void testIsVersionTagName() Assert.assertFalse(BaseGitLabApi.isVersionTagName("release/1.2.3")); Assert.assertFalse(BaseGitLabApi.isVersionTagName("release-01.02.03")); } + + @Test + public void testGetWorkspaceBranchName() + { + Supplier userNameSupplier = () -> "userName"; + Assert.assertEquals( + "workspace/userName/wid1", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.USER), userNameSupplier)); + Assert.assertEquals( + "backup/userName/wid2", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP), userNameSupplier)); + Assert.assertEquals( + "resolution/userName/wid3", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION), userNameSupplier)); + + Assert.assertEquals( + "group/wid1", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.GROUP), userNameSupplier)); + Assert.assertEquals( + "group-backup/wid2", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP), userNameSupplier)); + Assert.assertEquals( + "group-resolution/wid3", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION), userNameSupplier)); + + Assert.assertEquals( + "patch/3.5.7/workspace/userName/wid1", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.USER, WorkspaceSource.patchWorkspaceSource("3.5.7")), userNameSupplier)); + Assert.assertEquals( + "patch/0.0.1/backup/userName/wid2", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, WorkspaceSource.patchWorkspaceSource("0.0.1")), userNameSupplier)); + Assert.assertEquals( + "patch/10.5.1/resolution/userName/wid3", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, WorkspaceSource.patchWorkspaceSource("10.5.1")), userNameSupplier)); + + Assert.assertEquals( + "patch/2.4.6/group/wid1", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.GROUP, WorkspaceSource.patchWorkspaceSource("2.4.6")), userNameSupplier)); + Assert.assertEquals( + "patch/1.0.0/group-backup/wid2", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, WorkspaceSource.patchWorkspaceSource("1.0.0")), userNameSupplier)); + Assert.assertEquals( + "patch/99.102.3/group-resolution/wid3", + BaseGitLabApi.getWorkspaceBranchName(WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, WorkspaceSource.patchWorkspaceSource("99.102.3")), userNameSupplier)); + } + + @Test + public void testParseWorkspaceBranchName() + { + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName(null)); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("main")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("master")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("other_branch_name")); + + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("wirkspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspice/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace/")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace/uid/wid/other")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace//")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("workspace_uid_wid")); + + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("grp/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("group")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("group/")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("group/wid/other")); + + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/not.a.version/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/12345678901.0.0/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1.2/group/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1.2.3/patch/1.2.3/group/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1.2.3.4/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1.2.3.4.5/groupd/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1_2_3/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("pitch/1.2.3/workspace/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch/1.2.3/workspice/uid/wid")); + Assert.assertNull(BaseGitLabApi.parseWorkspaceBranchName("patch//workspace/uid/wid")); + + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, WorkspaceSource.projectWorkspaceSource(), "uid1"), + BaseGitLabApi.parseWorkspaceBranchName("workspace/uid1/wid1")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, WorkspaceSource.projectWorkspaceSource(), "uid2"), + BaseGitLabApi.parseWorkspaceBranchName("backup/uid2/wid2")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, WorkspaceSource.projectWorkspaceSource(), "uid3"), + BaseGitLabApi.parseWorkspaceBranchName("resolution/uid3/wid3")); + + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, WorkspaceSource.projectWorkspaceSource()), + BaseGitLabApi.parseWorkspaceBranchName("group/wid1")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, WorkspaceSource.projectWorkspaceSource()), + BaseGitLabApi.parseWorkspaceBranchName("group-backup/wid2")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, WorkspaceSource.projectWorkspaceSource()), + BaseGitLabApi.parseWorkspaceBranchName("group-resolution/wid3")); + + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, WorkspaceSource.patchWorkspaceSource("1.2.3"), "uid1"), + BaseGitLabApi.parseWorkspaceBranchName("patch/1.2.3/workspace/uid1/wid1")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, WorkspaceSource.patchWorkspaceSource("4.5.6"), "uid2"), + BaseGitLabApi.parseWorkspaceBranchName("patch/4.5.6/backup/uid2/wid2")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, WorkspaceSource.patchWorkspaceSource("41.25.63"), "uid3"), + BaseGitLabApi.parseWorkspaceBranchName("patch/41.25.63/resolution/uid3/wid3")); + + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid1", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, WorkspaceSource.patchWorkspaceSource("3.2.1")), + BaseGitLabApi.parseWorkspaceBranchName("patch/3.2.1/group/wid1")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid2", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.BACKUP, WorkspaceSource.patchWorkspaceSource("0.0.2")), + BaseGitLabApi.parseWorkspaceBranchName("patch/0.0.2/group-backup/wid2")); + Assert.assertEquals( + WorkspaceSpecification.newWorkspaceSpecification("wid3", WorkspaceType.GROUP, ProjectFileAccessProvider.WorkspaceAccessType.CONFLICT_RESOLUTION, WorkspaceSource.patchWorkspaceSource("9.9.9")), + BaseGitLabApi.parseWorkspaceBranchName("patch/9.9.9/group-resolution/wid3")); + } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/docker/IntegrationTestGitLabComparisonApis.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/docker/IntegrationTestGitLabComparisonApis.java index 62035b8bf5..824a632c23 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/docker/IntegrationTestGitLabComparisonApis.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/docker/IntegrationTestGitLabComparisonApis.java @@ -77,7 +77,7 @@ private static void setUpComparisonApi() GitLabRevisionApi gitLabRevisionApi = new GitLabRevisionApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); GitLabWorkspaceApi gitLabWorkspaceApi = new GitLabWorkspaceApi(gitLabConfig, gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor); GitLabEntityApi gitLabEntityApi = new GitLabEntityApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); - GitLabComparisonApi gitLabComparisonApi = new GitLabComparisonApi(gitLabConfig, gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor); + GitLabComparisonApi gitLabComparisonApi = new GitLabComparisonApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); GitLabPatchApi gitLabPatchApi = new GitLabPatchApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); GitLabVersionApi gitLabVersionApi = new GitLabVersionApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/server/TestGitLabServerComparisonApis.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/server/TestGitLabServerComparisonApis.java index 6c468642d4..cd50dff9cd 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/server/TestGitLabServerComparisonApis.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/gitlab/api/server/TestGitLabServerComparisonApis.java @@ -77,7 +77,7 @@ private static void setUpComparisonApi() GitLabRevisionApi gitLabRevisionApi = new GitLabRevisionApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); GitLabWorkspaceApi gitLabWorkspaceApi = new GitLabWorkspaceApi(gitLabConfig, gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor); GitLabEntityApi gitLabEntityApi = new GitLabEntityApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); - GitLabComparisonApi gitLabComparisonApi = new GitLabComparisonApi(gitLabConfig, gitLabMemberUserContext, gitLabRevisionApi, backgroundTaskProcessor); + GitLabComparisonApi gitLabComparisonApi = new GitLabComparisonApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); GitLabPatchApi gitLabPatchApi = new GitLabPatchApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); GitLabVersionApi gitLabVersionApi = new GitLabVersionApi(gitLabConfig, gitLabMemberUserContext, backgroundTaskProcessor); diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryBackupApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryBackupApi.java index 99b377668b..5c52318dfd 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryBackupApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryBackupApi.java @@ -15,7 +15,7 @@ package org.finos.legend.sdlc.server.inmemory.backend.api; import org.finos.legend.sdlc.server.domain.api.backup.BackupApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import javax.inject.Inject; @@ -27,13 +27,13 @@ public InMemoryBackupApi() } @Override - public void discardBackupWorkspace(String projectId, SourceSpecification sourceSpecification) + public void discardBackupWorkspace(String projectId, WorkspaceSpecification workspaceSpecification) { throw new UnsupportedOperationException("Not implemented"); } @Override - public void recoverBackupWorkspace(String projectId, SourceSpecification sourceSpecification, boolean forceRecovery) + public void recoverBackupWorkspace(String projectId, WorkspaceSpecification workspaceSpecification, boolean forceRecovery) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryComparisonApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryComparisonApi.java index e57fc61609..e5a21a5e0f 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryComparisonApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryComparisonApi.java @@ -15,9 +15,8 @@ package org.finos.legend.sdlc.server.inmemory.backend.api; import org.finos.legend.sdlc.domain.model.comparison.Comparison; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.comparison.ComparisonApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import javax.inject.Inject; @@ -29,25 +28,25 @@ public InMemoryComparisonApi() } @Override - public Comparison getWorkspaceCreationComparison(String projectId, SourceSpecification sourceSpecification) + public Comparison getWorkspaceCreationComparison(String projectId, WorkspaceSpecification sourceSpecification) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Comparison getWorkspaceProjectComparison(String projectId, SourceSpecification sourceSpecification) + public Comparison getWorkspaceSourceComparison(String projectId, WorkspaceSpecification workspaceSpecification) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Comparison getReviewComparison(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Comparison getReviewComparison(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Comparison getReviewWorkspaceCreationComparison(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Comparison getReviewWorkspaceCreationComparison(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryConflictResolutionApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryConflictResolutionApi.java index 36d34593fb..aa9da8a8aa 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryConflictResolutionApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryConflictResolutionApi.java @@ -16,7 +16,7 @@ import org.finos.legend.sdlc.server.application.entity.PerformChangesCommand; import org.finos.legend.sdlc.server.domain.api.conflictResolution.ConflictResolutionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import javax.inject.Inject; @@ -28,19 +28,19 @@ public InMemoryConflictResolutionApi() } @Override - public void discardConflictResolution(String projectId, SourceSpecification sourceSpecification) + public void discardConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification) { throw new UnsupportedOperationException("Not implemented"); } @Override - public void discardChangesConflictResolution(String projectId, SourceSpecification sourceSpecification) + public void discardChangesConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification) { throw new UnsupportedOperationException("Not implemented"); } @Override - public void acceptConflictResolution(String projectId, SourceSpecification sourceSpecification, PerformChangesCommand command) + public void acceptConflictResolution(String projectId, WorkspaceSpecification workspaceSpecification, PerformChangesCommand command) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryEntityApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryEntityApi.java index 9df97e76c9..ca2880c307 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryEntityApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryEntityApi.java @@ -14,28 +14,39 @@ package org.finos.legend.sdlc.server.inmemory.backend.api; +import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.impl.utility.Iterate; +import org.eclipse.collections.impl.utility.ListIterate; import org.finos.legend.sdlc.domain.model.entity.Entity; import org.finos.legend.sdlc.domain.model.entity.change.EntityChange; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.server.domain.api.entity.EntityAccessContext; import org.finos.legend.sdlc.server.domain.api.entity.EntityApi; import org.finos.legend.sdlc.server.domain.api.entity.EntityModificationContext; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.PatchSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.ProjectSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationVisitor; +import org.finos.legend.sdlc.server.domain.api.project.source.VersionSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.ProjectWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceVisitor; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend; +import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryPatch; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryProject; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryRevision; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryVersion; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryWorkspace; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; -import javax.inject.Inject; import java.util.List; import java.util.Map; import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; +import javax.inject.Inject; public class InMemoryEntityApi implements EntityApi { @@ -48,145 +59,141 @@ public InMemoryEntityApi(InMemoryBackend backend) } @Override - public EntityAccessContext getProjectEntityAccessContext(String projectId, VersionId patchReleaseVersionId) - { - InMemoryProject project = this.backend.getProject(projectId); - return new InMemoryEntityAccessContext(project.getCurrentRevision().getEntities()); - } - - @Override - public EntityAccessContext getProjectRevisionEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String revisionId) + public EntityAccessContext getEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) { InMemoryProject project = this.backend.getProject(projectId); - return new InMemoryEntityAccessContext(project.getCurrentRevision().getEntities()); - } - - @Override - public EntityAccessContext getWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification) - { - InMemoryProject project = this.backend.getProject(projectId); - InMemoryWorkspace workspace = sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP ? project.getGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()) : project.getUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); - return new InMemoryEntityAccessContext(workspace.getCurrentRevision().getEntities()); - } - - @Override - public EntityAccessContext getBackupWorkspaceEntityAccessContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public EntityAccessContext getWorkspaceWithConflictResolutionEntityAccessContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } + InMemoryRevision revision = sourceSpecification.visit(new SourceSpecificationVisitor() + { + @Override + public InMemoryRevision visit(ProjectSourceSpecification sourceSpec) + { + return (revisionId == null) ? project.getCurrentRevision() : project.getRevision(revisionId); + } - @Override - public EntityAccessContext getWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - InMemoryProject project = this.backend.getProject(projectId); - InMemoryWorkspace workspace = sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP ? project.getGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()) : project.getUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); - InMemoryRevision revision = workspace.getRevision(revisionId); - return new InMemoryEntityAccessContext(revision.getEntities()); - } + @Override + public InMemoryRevision visit(VersionSourceSpecification sourceSpec) + { + if (revisionId != null) + { + throw new UnsupportedOperationException("Not implemented"); + } + InMemoryVersion version = project.getVersion(sourceSpec.getVersionId().toVersionIdString()); + return version.getRevision(); + } - @Override - public EntityAccessContext getBackupWorkspaceRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - throw new UnsupportedOperationException("Not implemented"); - } + @Override + public InMemoryRevision visit(PatchSourceSpecification sourceSpec) + { + InMemoryPatch patch = project.getPatch(sourceSpec.getVersionId()); + return (revisionId == null) ? patch.getCurrentRevision() : patch.getRevision(revisionId); + } - @Override - public EntityAccessContext getWorkspaceWithConflictResolutionRevisionEntityAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - throw new UnsupportedOperationException("Not implemented"); + @Override + public InMemoryRevision visit(WorkspaceSourceSpecification sourceSpec) + { + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + if (workspaceSpec.getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE) + { + throw new UnsupportedOperationException("Not implemented"); + } + VersionId patchVersionId = workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public VersionId visit(ProjectWorkspaceSource source) + { + return null; + } + + @Override + public VersionId visit(PatchWorkspaceSource source) + { + return source.getPatchVersionId(); + } + }); + InMemoryWorkspace workspace = (workspaceSpec.getType() == WorkspaceType.GROUP) ? + project.getGroupWorkspace(workspaceSpec.getId(), patchVersionId) : + project.getUserWorkspace(workspaceSpec.getId(), patchVersionId); + return (revisionId == null) ? workspace.getCurrentRevision() : workspace.getRevision(revisionId); + } + }); + return new InMemoryEntityAccessContext(revision); } @Override - public EntityAccessContext getReviewFromEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public EntityAccessContext getReviewFromEntityAccessContext(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public EntityAccessContext getReviewToEntityAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public EntityAccessContext getReviewToEntityAccessContext(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public EntityAccessContext getVersionEntityAccessContext(String projectId, VersionId versionId) + public EntityModificationContext getEntityModificationContext(String projectId, WorkspaceSourceSpecification sourceSpecification) { + WorkspaceSpecification workspaceSpec = sourceSpecification.getWorkspaceSpecification(); + if (workspaceSpec.getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE) + { + throw new UnsupportedOperationException("Not implemented"); + } InMemoryProject project = this.backend.getProject(projectId); - InMemoryVersion version = project.getVersion(versionId.toVersionIdString()); - return new InMemoryEntityAccessContext(version.getRevision().getEntities()); - } + VersionId patchVersionId = workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public VersionId visit(ProjectWorkspaceSource source) + { + return null; + } - @Override - public EntityModificationContext getWorkspaceEntityModificationContext(String projectId, SourceSpecification sourceSpecification) - { - InMemoryProject project = this.backend.getProject(projectId); - InMemoryWorkspace workspace = sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP ? project.getGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()) : project.getUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); + @Override + public VersionId visit(PatchWorkspaceSource source) + { + return source.getPatchVersionId(); + } + }); + InMemoryWorkspace workspace = (workspaceSpec.getType() == WorkspaceType.GROUP) ? + project.getGroupWorkspace(workspaceSpec.getId(), patchVersionId) : + project.getUserWorkspace(workspaceSpec.getId(), patchVersionId); return new InMemoryEntityModificationContext(workspace.getCurrentRevision().getEntities()); } - @Override - public EntityModificationContext getWorkspaceWithConflictResolutionEntityModificationContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - static class InMemoryEntityAccessContext implements EntityAccessContext { - private final Iterable entities; + private final InMemoryRevision revision; - public InMemoryEntityAccessContext(Iterable entities) + public InMemoryEntityAccessContext(InMemoryRevision revision) { - this.entities = entities; + this.revision = revision; } @Override public Entity getEntity(String path) { - List matches = this.getEntities((p) -> p.equals(path), null, null); - if (matches.size() > 1) - { - throw new IllegalStateException(String.format("Found %d instead of 1 matches for entity with path %s", matches.size(), path)); - } - if (matches.size() == 0) + Entity entity = this.revision.getEntity(path); + if (entity == null) { - throw new IllegalStateException(String.format("Entity with path %s not found", path)); + throw new IllegalStateException("Entity with path " + path + " not found"); } - return matches.get(0); + return entity; } @Override public List getEntities(Predicate entityPathPredicate, Predicate classifierPathPredicate, Predicate> entityContentPredicate, boolean excludeInvalid) { - Stream stream = StreamSupport.stream(this.entities.spliterator(), false); - if (entityPathPredicate != null) - { - stream = stream.filter(entity -> entityPathPredicate.test(entity.getPath())); - } - - if (classifierPathPredicate != null) - { - stream = stream.filter(entity -> classifierPathPredicate.test(entity.getClassifierPath())); - } - - if (entityContentPredicate != null) - { - stream = stream.filter(entity -> entityContentPredicate.test(entity.getContent())); - } - - return stream.collect(Collectors.toList()); + return Iterate.select(this.revision.getEntities(), + e -> ((entityPathPredicate == null) || entityPathPredicate.test(e.getPath())) && + ((classifierPathPredicate == null) || classifierPathPredicate.test(e.getClassifierPath())) && + ((entityContentPredicate == null) || entityContentPredicate.test(e.getContent())), + Lists.mutable.empty()); } @Override public List getEntityPaths(Predicate entityPathPredicate, Predicate classifierPathPredicate, Predicate> entityContentPredicate) { - List entities = this.getEntities(entityPathPredicate, classifierPathPredicate, entityContentPredicate); - return entities.stream().map(Entity::getPath).collect(Collectors.toList()); + return ListIterate.collect(getEntities(entityPathPredicate, classifierPathPredicate, entityContentPredicate), Entity::getPath); } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryProjectConfigurationApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryProjectConfigurationApi.java index 759d63d981..cf9e4331b7 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryProjectConfigurationApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryProjectConfigurationApi.java @@ -22,13 +22,23 @@ import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationApi; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationUpdater; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.PatchSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.ProjectSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationVisitor; +import org.finos.legend.sdlc.server.domain.api.project.source.VersionSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.ProjectWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceVisitor; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryPatch; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryProject; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryRevision; -import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryVersion; +import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryWorkspace; import org.finos.legend.sdlc.server.project.ProjectConfigurationStatusReport; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; import java.util.List; import javax.inject.Inject; @@ -44,136 +54,81 @@ public InMemoryProjectConfigurationApi(InMemoryBackend backend) } @Override - public ProjectConfiguration getProjectProjectConfiguration(String projectId, VersionId patchReleaseVersionId) + public ProjectConfiguration getProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) { InMemoryProject project = this.backend.getProject(projectId); - return project.getCurrentRevision().getConfiguration(); - } - - @Override - public ProjectConfiguration getProjectRevisionProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String revisionId) - { - InMemoryProject project = this.backend.getProject(projectId); - if (patchReleaseVersionId != null) + return sourceSpecification.visit(new SourceSpecificationVisitor() { - InMemoryPatch patch = project.getPatch(patchReleaseVersionId); - InMemoryRevision revision = patch.getRevision(revisionId); - return revision.getConfiguration(); - } - else - { - InMemoryRevision revision = project.getRevision(revisionId); - return revision.getConfiguration(); - } - } - - @Override - public ProjectConfiguration getWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public ProjectConfiguration getBackupWorkspaceProjectConfiguration(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public ProjectConfiguration getWorkspaceWithConflictResolutionProjectConfiguration(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public ProjectConfiguration getWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - InMemoryProject project = backend.getProject(projectId); - InMemoryRevision revision = sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP ? project.getGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()).getRevision(revisionId) : project.getUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()).getRevision(revisionId); - return revision.getConfiguration(); - } - - @Override - public ProjectConfiguration getBackupUserWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public ProjectConfiguration getBackupGroupWorkspaceRevisionProjectConfiguration(String projectId, String workspaceId, String revisionId) - { - throw new UnsupportedOperationException("Not implemented"); - } + @Override + public ProjectConfiguration visit(ProjectSourceSpecification sourceSpec) + { + return ((revisionId == null) ? project.getCurrentRevision() : project.getRevision(revisionId)).getConfiguration(); + } - @Override - public ProjectConfiguration getBackupWorkspaceRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public ProjectConfiguration getWorkspaceWithConflictResolutionRevisionProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String revisionId) - { - throw new UnsupportedOperationException("Not implemented"); - } + @Override + public ProjectConfiguration visit(VersionSourceSpecification sourceSpec) + { + return project.getVersion(sourceSpec.getVersionId().toVersionIdString()).getConfiguration(); + } - @Override - public ProjectConfiguration getVersionProjectConfiguration(String projectId, VersionId versionId) - { - InMemoryVersion version = backend.getProject(projectId).getVersion(versionId.toVersionIdString()); - return version.getConfiguration(); - } + @Override + public ProjectConfiguration visit(PatchSourceSpecification sourceSpec) + { + InMemoryPatch patch = project.getPatch(sourceSpec.getVersionId()); + return ((revisionId == null) ? patch.getCurrentRevision() : patch.getRevision(revisionId)).getConfiguration(); + } - @Override - public ProjectConfiguration getReviewFromProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId) - { - throw new UnsupportedOperationException("Not implemented"); - } + @Override + public ProjectConfiguration visit(WorkspaceSourceSpecification sourceSpec) + { + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + if (workspaceSpec.getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE) + { + throw new UnsupportedOperationException("Not implemented"); + } + VersionId patchVersionId = workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public VersionId visit(ProjectWorkspaceSource source) + { + return null; + } - @Override - public ProjectConfiguration getReviewToProjectConfiguration(String projectId, VersionId patchReleaseVersionId, String reviewId) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public Revision updateProjectConfiguration(String projectId, SourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public Revision updateProjectConfigurationForWorkspaceWithConflictResolution(String projectId, String workspaceId, String message, ProjectConfigurationUpdater updater) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public List getProjectAvailableArtifactGenerations(String projectId, VersionId patchReleaseVersionId) - { - throw new UnsupportedOperationException("Not implemented"); + @Override + public VersionId visit(PatchWorkspaceSource source) + { + return source.getPatchVersionId(); + } + }); + InMemoryWorkspace workspace = (workspaceSpec.getType() == WorkspaceType.GROUP) ? + project.getGroupWorkspace(workspaceSpec.getId(), patchVersionId) : + project.getUserWorkspace(workspaceSpec.getId(), patchVersionId); + InMemoryRevision revision = (revisionId == null) ? workspace.getCurrentRevision() : workspace.getRevision(revisionId); + return revision.getConfiguration(); + } + }); } @Override - public List getRevisionAvailableArtifactGenerations(String projectId, String revisionId) + public ProjectConfiguration getReviewFromProjectConfiguration(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public List getWorkspaceRevisionAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId) + public ProjectConfiguration getReviewToProjectConfiguration(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public List getWorkspaceAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification) + public Revision updateProjectConfiguration(String projectId, WorkspaceSourceSpecification sourceSpecification, String message, ProjectConfigurationUpdater updater) { throw new UnsupportedOperationException("Not implemented"); } @Override - public List getVersionAvailableArtifactGenerations(String projectId, String versionId) + public List getAvailableArtifactGenerations(String projectId, SourceSpecification sourceSpecification, String revisionId) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryReviewApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryReviewApi.java index 7a89f77109..ad743c5acd 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryReviewApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryReviewApi.java @@ -14,21 +14,20 @@ package org.finos.legend.sdlc.server.inmemory.backend.api; +import org.eclipse.collections.api.factory.Lists; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.review.Approval; import org.finos.legend.sdlc.domain.model.review.Review; import org.finos.legend.sdlc.domain.model.review.ReviewState; -import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.review.ReviewApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryProject; -import org.eclipse.collections.api.factory.Lists; -import javax.inject.Inject; import java.time.Instant; import java.util.List; import java.util.function.BiPredicate; +import javax.inject.Inject; public class InMemoryReviewApi implements ReviewApi { @@ -41,7 +40,7 @@ public InMemoryReviewApi(InMemoryBackend backend) } @Override - public Review getReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review getReview(String projectId, String reviewId) { InMemoryProject inMemoryProject = this.backend.getProject(projectId); Review result = inMemoryProject.getReview(reviewId); @@ -50,11 +49,10 @@ public Review getReview(String projectId, VersionId patchReleaseVersionId, Strin } @Override - public List getReviews(String projectId, VersionId patchReleaseVersionId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit) + public List getReviews(String projectId, ReviewState state, Iterable revisionIds, BiPredicate workspaceIdAndTypePredicate, Instant since, Instant until, Integer limit) { InMemoryProject inMemoryProject = this.backend.getProject(projectId); - - return Lists.mutable.withAll(inMemoryProject.getReviews(patchReleaseVersionId, state, revisionIds, since, until, limit)); + return Lists.mutable.withAll(inMemoryProject.getReviews(state, revisionIds, since, until, limit)); } @Override @@ -64,67 +62,67 @@ public List getReviews(boolean assignedToMe, boolean authoredByMe, List< } @Override - public Review createReview(String projectId, SourceSpecification sourceSpecification, String title, String description, List labels) + public Review createReview(String projectId, WorkspaceSpecification workspaceSpecification, String title, String description, List labels) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review closeReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review closeReview(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review reopenReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review reopenReview(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review approveReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review approveReview(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review revokeReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review revokeReviewApproval(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review rejectReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Review rejectReview(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Approval getReviewApproval(String projectId, VersionId patchReleaseVersionId, String reviewId) + public Approval getReviewApproval(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review commitReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String message) + public Review commitReview(String projectId, String reviewId, String message) { throw new UnsupportedOperationException("Not implemented"); } @Override - public ReviewUpdateStatus getReviewUpdateStatus(String projectId, VersionId patchReleaseVersionId, String reviewId) + public ReviewUpdateStatus getReviewUpdateStatus(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public ReviewUpdateStatus updateReview(String projectId, VersionId patchReleaseVersionId, String reviewId) + public ReviewUpdateStatus updateReview(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } @Override - public Review editReview(String projectId, VersionId patchReleaseVersionId, String reviewId, String title, String description, List labels) + public Review editReview(String projectId, String reviewId, String title, String description, List labels) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryRevisionApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryRevisionApi.java index 009038e168..d581e7883c 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryRevisionApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryRevisionApi.java @@ -17,20 +17,27 @@ import org.eclipse.collections.api.factory.Lists; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.revision.RevisionStatus; -import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.PatchSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.ProjectSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationVisitor; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; import org.finos.legend.sdlc.server.domain.api.revision.RevisionAccessContext; import org.finos.legend.sdlc.server.domain.api.revision.RevisionApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.ProjectWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceVisitor; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryPatch; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryProject; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryWorkspace; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; -import javax.inject.Inject; import java.time.Instant; import java.util.List; import java.util.function.Predicate; +import javax.inject.Inject; public class InMemoryRevisionApi implements RevisionApi { @@ -43,109 +50,171 @@ public InMemoryRevisionApi(InMemoryBackend backend) } @Override - public RevisionAccessContext getProjectRevisionContext(String projectId, VersionId patchReleaseVersionId) + public RevisionAccessContext getRevisionContext(String projectId, SourceSpecification sourceSpec) { InMemoryProject project = this.backend.getProject(projectId); - InMemoryPatch patch = project.getPatch(patchReleaseVersionId); - return new RevisionAccessContext() + return sourceSpec.visit(new SourceSpecificationVisitor() { @Override - public Revision getRevision(String revisionId) - { - return patch == null ? project.getRevision(revisionId) : patch.getRevision(revisionId); - } - - @Override - public Revision getBaseRevision() + public RevisionAccessContext visit(ProjectSourceSpecification sourceSpec) { - throw new UnsupportedOperationException("Not implemented"); + return new RevisionAccessContext() + { + @Override + public Revision getRevision(String revisionId) + { + return project.getRevision(revisionId); + } + + @Override + public Revision getBaseRevision() + { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Revision getCurrentRevision() + { + return project.getCurrentRevision(); + } + + @Override + public List getRevisions(Predicate predicate, Instant since, Instant until, Integer limit) + { + throw new UnsupportedOperationException("Not implemented"); + } + }; } @Override - public Revision getCurrentRevision() + public RevisionAccessContext visit(PatchSourceSpecification sourceSpec) { - return patch == null ? project.getCurrentRevision() : patch.getCurrentRevision(); + InMemoryPatch patch = project.getPatch(sourceSpec.getVersionId()); + return new RevisionAccessContext() + { + @Override + public Revision getRevision(String revisionId) + { + return patch.getRevision(revisionId); + } + + @Override + public Revision getBaseRevision() + { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Revision getCurrentRevision() + { + return patch.getCurrentRevision(); + } + + @Override + public List getRevisions(Predicate predicate, Instant since, Instant until, Integer limit) + { + throw new UnsupportedOperationException("Not implemented"); + } + }; } @Override - public List getRevisions(Predicate predicate, Instant since, Instant until, Integer limit) + public RevisionAccessContext visit(WorkspaceSourceSpecification sourceSpec) { - throw new UnsupportedOperationException("Not implemented"); + InMemoryWorkspace workspace = getWorkspace(project, sourceSpec.getWorkspaceSpecification()); + return new RevisionAccessContext() + { + @Override + public Revision getRevision(String revisionId) + { + return workspace.getRevision(revisionId); + } + + @Override + public Revision getBaseRevision() + { + throw new UnsupportedOperationException("Not implemented"); + } + + @Override + public Revision getCurrentRevision() + { + return workspace.getCurrentRevision(); + } + + @Override + public List getRevisions(Predicate predicate, Instant since, Instant until, Integer limit) + { + return Lists.mutable.withAll(workspace.getRevisions()); + } + }; } - }; + }); } - @Override - public RevisionAccessContext getProjectEntityRevisionContext(String projectId, VersionId patchReleaseVersionId, String entityPath) + private InMemoryWorkspace getWorkspace(InMemoryProject project, WorkspaceSpecification workspaceSpec) { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public RevisionAccessContext getProjectPackageRevisionContext(String projectId, VersionId patchReleaseVersionId, String packagePath) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public RevisionAccessContext getWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpecification) - { - InMemoryProject project = backend.getProject(projectId); - InMemoryWorkspace workspace = sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP ? project.getGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()) : project.getUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); - return new RevisionAccessContext() + if (workspaceSpec.getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE) { - @Override - public Revision getRevision(String revisionId) - { - return workspace.getRevision(revisionId); - } - - @Override - public Revision getBaseRevision() + throw new UnsupportedOperationException("Not implemented"); + } + switch (workspaceSpec.getType()) + { + case USER: { - throw new UnsupportedOperationException("Not implemented"); + return workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public InMemoryWorkspace visit(ProjectWorkspaceSource source) + { + return project.getUserWorkspace(workspaceSpec.getId(), null); + } + + @Override + public InMemoryWorkspace visit(PatchWorkspaceSource source) + { + return project.getUserWorkspace(workspaceSpec.getId(), source.getPatchVersionId()); + } + }); } - - @Override - public Revision getCurrentRevision() + case GROUP: { - return workspace.getCurrentRevision(); + return workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public InMemoryWorkspace visit(ProjectWorkspaceSource source) + { + return project.getGroupWorkspace(workspaceSpec.getId(), null); + } + + @Override + public InMemoryWorkspace visit(PatchWorkspaceSource source) + { + return project.getGroupWorkspace(workspaceSpec.getId(), source.getPatchVersionId()); + } + }); } - - @Override - public List getRevisions(Predicate predicate, Instant since, Instant until, Integer limit) + default: { - return Lists.mutable.withAll(workspace.getRevisions()); + throw new UnsupportedOperationException("Unsupported workspace type: " + workspaceSpec.getType()); } - }; - } - - @Override - public RevisionAccessContext getBackupWorkspaceRevisionContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public RevisionAccessContext getWorkspaceWithConflictResolutionRevisionContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); + } } @Override - public RevisionAccessContext getWorkspaceEntityRevisionContext(String projectId, SourceSpecification sourceSpecification, String entityPath) + public RevisionAccessContext getPackageRevisionContext(String projectId, SourceSpecification sourceSpec, String packagePath) { throw new UnsupportedOperationException("Not implemented"); } @Override - public RevisionAccessContext getWorkspacePackageRevisionContext(String projectId, SourceSpecification sourceSpecification, String packagePath) + public RevisionAccessContext getEntityRevisionContext(String projectId, SourceSpecification sourceSpec, String entityPath) { throw new UnsupportedOperationException("Not implemented"); } @Override - public RevisionStatus getRevisionStatus(String projectId, VersionId patchReleaseVersionId, String revisionId) + public RevisionStatus getRevisionStatus(String projectId, String revisionId) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowApi.java index 1495a3997b..5796da851a 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowApi.java @@ -14,10 +14,9 @@ package org.finos.legend.sdlc.server.inmemory.backend.api; -import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowAccessContext; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; import javax.inject.Inject; @@ -29,25 +28,13 @@ public InMemoryWorkflowApi() } @Override - public WorkflowAccessContext getProjectWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId) + public WorkflowAccessContext getWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification) { throw new UnsupportedOperationException("Not implemented"); } @Override - public WorkflowAccessContext getWorkspaceWorkflowAccessContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public WorkflowAccessContext getVersionWorkflowAccessContext(String projectId, VersionId versionId) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public WorkflowAccessContext getReviewWorkflowAccessContext(String projectId, String reviewId) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowJobApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowJobApi.java index b403621a76..19d2d7c317 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowJobApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkflowJobApi.java @@ -14,10 +14,9 @@ package org.finos.legend.sdlc.server.inmemory.backend.api; -import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowJobAccessContext; import org.finos.legend.sdlc.server.domain.api.workflow.WorkflowJobApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; import javax.inject.Inject; @@ -29,25 +28,13 @@ public InMemoryWorkflowJobApi() } @Override - public WorkflowJobAccessContext getProjectWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId) + public WorkflowJobAccessContext getWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification) { throw new UnsupportedOperationException(); } @Override - public WorkflowJobAccessContext getWorkspaceWorkflowJobAccessContext(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException(); - } - - @Override - public WorkflowJobAccessContext getVersionWorkflowJobAccessContext(String projectId, VersionId versionId) - { - throw new UnsupportedOperationException(); - } - - @Override - public WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, VersionId patchReleaseVersionId, String reviewId) + public WorkflowJobAccessContext getReviewWorkflowJobAccessContext(String projectId, String reviewId) { throw new UnsupportedOperationException(); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkspaceApi.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkspaceApi.java index f3afa14113..19291277a6 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkspaceApi.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/backend/api/InMemoryWorkspaceApi.java @@ -19,11 +19,17 @@ import org.finos.legend.sdlc.domain.model.project.workspace.Workspace; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.version.VersionId; +import org.finos.legend.sdlc.server.domain.api.workspace.PatchWorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.ProjectWorkspaceSource; import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceApi; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSource; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSourceVisitor; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend; import org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryProject; +import org.finos.legend.sdlc.server.project.ProjectFileAccessProvider; +import java.util.EnumSet; import java.util.List; import java.util.Set; import javax.inject.Inject; @@ -39,104 +45,133 @@ public InMemoryWorkspaceApi(InMemoryBackend inMemoryBackend) } @Override - public List getWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes) + public Workspace getWorkspace(String projectId, WorkspaceSpecification workspaceSpec) { - InMemoryProject inMemoryProject = this.backend.getProject(projectId); - MutableList result = Lists.mutable.empty(); - if (workspaceTypes.contains(WorkspaceType.GROUP)) + if (workspaceSpec.getAccessType() != ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE) { - result.addAllIterable(inMemoryProject.getGroupWorkspaces(patchReleaseVersionId)); + throw new UnsupportedOperationException("Not implemented"); } - if (workspaceTypes.contains(WorkspaceType.USER)) + InMemoryProject inMemoryProject = this.backend.getProject(projectId); + VersionId patchVersion = workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() { - result.addAllIterable(inMemoryProject.getUserWorkspaces(patchReleaseVersionId)); - } - return result; + @Override + public VersionId visit(ProjectWorkspaceSource source) + { + return null; + } + + @Override + public VersionId visit(PatchWorkspaceSource source) + { + return source.getPatchVersionId(); + } + }); + return (workspaceSpec.getType() == WorkspaceType.GROUP) ? + inMemoryProject.getGroupWorkspace(workspaceSpec.getId(), patchVersion) : + inMemoryProject.getUserWorkspace(workspaceSpec.getId(), patchVersion); } @Override - public List getWorkspacesWithConflictResolution(String projectId, VersionId patchReleaseVersionId) + public List getWorkspaces(String projectId, Set types, Set accessTypes, Set sources) { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public List getBackupWorkspaces(String projectId, VersionId patchReleaseVersionId) - { - throw new UnsupportedOperationException("Not implemented"); - } + if (sources == null) + { + throw new UnsupportedOperationException("Not implemented"); + } - @Override - public List getAllWorkspaces(String projectId, VersionId patchReleaseVersionId, Set workspaceTypes) - { - return getWorkspaces(projectId, patchReleaseVersionId, workspaceTypes); - } + Set resolvedTypes = (types == null) ? EnumSet.allOf(WorkspaceType.class) : types; + Set resolvedAccessTypes = (accessTypes == null) ? EnumSet.allOf(ProjectFileAccessProvider.WorkspaceAccessType.class) : accessTypes; - @Override - public Workspace getWorkspace(String projectId, SourceSpecification sourceSpecification) - { InMemoryProject inMemoryProject = this.backend.getProject(projectId); - return sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP ? inMemoryProject.getGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()) : inMemoryProject.getUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); + MutableList result = Lists.mutable.empty(); + // currently only WORKSPACE access type is supported + if (resolvedAccessTypes.contains(ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + { + for (WorkspaceSource source : sources) + { + VersionId patchVersionId = source.visit(new WorkspaceSourceVisitor() + { + @Override + public VersionId visit(ProjectWorkspaceSource source) + { + return null; + } + + @Override + public VersionId visit(PatchWorkspaceSource source) + { + return source.getPatchVersionId(); + } + }); + if (resolvedTypes.contains(WorkspaceType.GROUP)) + { + result.addAllIterable(inMemoryProject.getGroupWorkspaces(patchVersionId)); + } + if (resolvedTypes.contains(WorkspaceType.USER)) + { + result.addAllIterable(inMemoryProject.getUserWorkspaces(patchVersionId)); + } + } + } + return result; } @Override - public Workspace getWorkspaceWithConflictResolution(String projectId, SourceSpecification sourceSpecification) + public List getAllWorkspaces(String projectId, Set types, Set accessTypes, Set sources) { - throw new UnsupportedOperationException("Not implemented"); + return getWorkspaces(projectId, types, accessTypes, sources); } @Override - public Workspace getBackupWorkspace(String projectId, SourceSpecification sourceSpecification) + public Workspace newWorkspace(String projectId, String workspaceId, WorkspaceType type, WorkspaceSource source) { throw new UnsupportedOperationException("Not implemented"); } @Override - public boolean isWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification) + public void deleteWorkspace(String projectId, WorkspaceSpecification workspaceSpec) { - return false; - } - - @Override - public boolean isWorkspaceWithConflictResolutionOutdated(String projectId, SourceSpecification sourceSpecification) - { - return false; + InMemoryProject project = this.backend.getProject(projectId); + VersionId patchVersion = workspaceSpec.getSource().visit(new WorkspaceSourceVisitor() + { + @Override + public VersionId visit(ProjectWorkspaceSource source) + { + return null; + } + + @Override + public VersionId visit(PatchWorkspaceSource source) + { + return source.getPatchVersionId(); + } + }); + if (workspaceSpec.getType() == WorkspaceType.GROUP) + { + project.deleteGroupWorkspace(workspaceSpec.getId(), patchVersion); + } + else + { + project.deleteUserWorkspace(workspaceSpec.getId(), patchVersion); + } } @Override - public boolean isBackupWorkspaceOutdated(String projectId, SourceSpecification sourceSpecification) + public boolean isWorkspaceOutdated(String projectId, WorkspaceSpecification workspaceSpecification) { + // TODO implement return false; } @Override - public boolean isWorkspaceInConflictResolutionMode(String projectId, SourceSpecification sourceSpecification) + public boolean isWorkspaceInConflictResolutionMode(String projectId, WorkspaceSpecification workspaceSpecification) { + // TODO implement return false; } @Override - public Workspace newWorkspace(String projectId, SourceSpecification sourceSpecification) - { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public void deleteWorkspace(String projectId, SourceSpecification sourceSpecification) - { - InMemoryProject inMemoryProject = this.backend.getProject(projectId); - if (sourceSpecification.getWorkspaceType() == WorkspaceType.GROUP) - { - inMemoryProject.deleteGroupWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); - } - else - { - inMemoryProject.deleteUserWorkspace(sourceSpecification.getWorkspaceId(), sourceSpecification.getPatchReleaseVersionId()); - } - } - - @Override - public WorkspaceUpdateReport updateWorkspace(String projectId, SourceSpecification sourceSpecification) + public WorkspaceUpdateReport updateWorkspace(String projectId, WorkspaceSpecification workspaceSpecification) { throw new UnsupportedOperationException("Not implemented"); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryProject.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryProject.java index 21edf7f0dd..3f7bec5f2a 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryProject.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryProject.java @@ -16,19 +16,19 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import org.eclipse.collections.api.factory.Maps; -import org.eclipse.collections.api.map.MutableMap; import org.eclipse.collections.api.factory.Lists; +import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.api.map.MutableMap; import org.finos.legend.sdlc.domain.model.project.Project; import org.finos.legend.sdlc.domain.model.project.ProjectType; import org.finos.legend.sdlc.domain.model.review.ReviewState; import org.finos.legend.sdlc.domain.model.version.VersionId; -import javax.inject.Inject; -import java.util.List; import java.time.Instant; +import java.util.List; import java.util.stream.Collectors; +import javax.inject.Inject; @JsonIgnoreProperties(ignoreUnknown = true) public class InMemoryProject implements Project @@ -240,21 +240,9 @@ public InMemoryReview getReview(String reviewId) } @JsonIgnore - public MutableList getReviews(VersionId patchReleaseVersionId, ReviewState state, Iterable revisionIds, Instant since, Instant until, Integer limit) + public MutableList getReviews(ReviewState state, Iterable revisionIds, Instant since, Instant until, Integer limit) { - MutableList filteredReviews = Lists.mutable.empty(); - Iterable reviews = this.reviews.valuesView(); - - for (InMemoryReview rev : reviews) - { - - if (((state == null) || (state == rev.getState())) && rev.getTargetBranch().equals(getSourceBranch(patchReleaseVersionId))) - { - filteredReviews.add(rev); - } - } - - return filteredReviews; + return this.reviews.select(r -> (state == null) || (state == r.getState()), Lists.mutable.empty()); } @JsonIgnore diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryRevision.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryRevision.java index b4d2a679f6..c6690b1141 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryRevision.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/inmemory/domain/api/InMemoryRevision.java @@ -22,8 +22,8 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.server.inmemory.backend.RevisionIdGenerator; -import javax.inject.Inject; import java.time.Instant; +import javax.inject.Inject; @JsonIgnoreProperties(ignoreUnknown = true) public class InMemoryRevision implements Revision @@ -122,6 +122,12 @@ public void removeEntities(Iterable entitiesToRemove) entitiesToRemove.forEach(this::removeEntity); } + @JsonIgnore + public Entity getEntity(String path) + { + return this.entities.get(path); + } + @JsonIgnore public Iterable getEntities() { diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/InMemoryProjectFileAccessProvider.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/InMemoryProjectFileAccessProvider.java index f4ac8a58cf..5269eac38b 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/InMemoryProjectFileAccessProvider.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/InMemoryProjectFileAccessProvider.java @@ -16,22 +16,28 @@ import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.list.MutableList; +import org.eclipse.collections.api.map.MutableMap; +import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.SimpleInMemoryVCS; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.ProjectSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecificationVisitor; +import org.finos.legend.sdlc.server.domain.api.project.source.VersionSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import java.io.InputStream; import java.time.Instant; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.function.Predicate; import java.util.stream.Stream; public class InMemoryProjectFileAccessProvider implements ProjectFileAccessProvider { - private final Map projects = Maps.mutable.empty(); + private final MutableMap projects = Maps.mutable.empty(); private final String defaultAuthor; private final String defaultCommitter; @@ -41,150 +47,130 @@ public InMemoryProjectFileAccessProvider(String defaultAuthor, String defaultCom this.defaultCommitter = defaultCommitter; } - // File Access Context - @Override public FileAccessContext getFileAccessContext(String projectId, SourceSpecification sourceSpecification, String revisionId) { - AbstractInMemoryFileAccessContext abstractInMemoryFileAccessContext = new AbstractInMemoryFileAccessContext(revisionId) + return sourceSpecification.visit(new SourceSpecificationVisitor() { @Override - protected SimpleInMemoryVCS getContextVCS() - { - return getVCS(projectId, sourceSpecification.getWorkspaceId()); - } - }; - if (sourceSpecification.getWorkspaceAccessType() == null || sourceSpecification.getWorkspaceAccessType() == WorkspaceAccessType.WORKSPACE) - { - return abstractInMemoryFileAccessContext; - } - switch (sourceSpecification.getWorkspaceType()) - { - case USER: - case GROUP: + public FileAccessContext visit(ProjectSourceSpecification sourceSpec) { - switch (sourceSpecification.getWorkspaceAccessType()) + return new AbstractInMemoryFileAccessContext(revisionId) { - case WORKSPACE: - { - return abstractInMemoryFileAccessContext; - } - default: + @Override + protected SimpleInMemoryVCS getContextVCS() { - throw new UnsupportedOperationException("Special workspace access type is not supported for getting file access context"); + return getVCS(projectId); } - } + }; } - default: + + @Override + public FileAccessContext visit(VersionSourceSpecification sourceSpec) { - throw new UnsupportedOperationException("Special workspace type is not supported for getting file access context"); + return new AbstractInMemoryFileAccessContext(revisionId) + { + @Override + protected SimpleInMemoryVCS getContextVCS() + { + return getVCS(projectId, sourceSpec.getVersionId()); + } + }; } - } - } - @Override - public FileAccessContext getFileAccessContext(String projectId, VersionId versionId) - { - return new AbstractInMemoryFileAccessContext() - { @Override - protected SimpleInMemoryVCS getContextVCS() + public FileAccessContext visit(WorkspaceSourceSpecification sourceSpec) { - return getVCS(projectId, versionId); + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + if (workspaceSpec.getAccessType() != WorkspaceAccessType.WORKSPACE) + { + throw new UnsupportedOperationException("Unsupported workspace specification: " + workspaceSpec); + } + return new AbstractInMemoryFileAccessContext(revisionId) + { + @Override + protected SimpleInMemoryVCS getContextVCS() + { + return getVCS(projectId, workspaceSpec.getId()); + } + }; } - }; + }); } - - // Revision Access Context - @Override public RevisionAccessContext getRevisionAccessContext(String projectId, SourceSpecification sourceSpecification, Iterable paths) { - if (sourceSpecification.getWorkspaceId() != null) + return sourceSpecification.visit(new SourceSpecificationVisitor() { - switch (sourceSpecification.getWorkspaceType()) + @Override + public RevisionAccessContext visit(ProjectSourceSpecification sourceSpec) { - case USER: + return new AbstractRevisionAccessContext(paths) { - switch (sourceSpecification.getWorkspaceAccessType()) + @Override + protected SimpleInMemoryVCS getContextVCS() { - case WORKSPACE: - { - return new AbstractRevisionAccessContext(paths) - { - @Override - protected SimpleInMemoryVCS getContextVCS() - { - return getVCS(projectId, sourceSpecification.getWorkspaceId()); - } - }; - } - default: - { - throw new UnsupportedOperationException("Special workspace access type is not supported for getting revision access context"); - } + return getVCS(projectId); } - } - default: - { - throw new UnsupportedOperationException("Special workspace type is not supported for getting revision access context"); - } + }; } - } - return new AbstractRevisionAccessContext(paths) - { + @Override - protected SimpleInMemoryVCS getContextVCS() + public RevisionAccessContext visit(VersionSourceSpecification sourceSpec) { - return getVCS(projectId, (String) null); + return new AbstractRevisionAccessContext(paths) + { + @Override + protected SimpleInMemoryVCS getContextVCS() + { + return getVCS(projectId, sourceSpec.getVersionId()); + } + }; } - }; - } - @Override - public RevisionAccessContext getRevisionAccessContext(String projectId, VersionId versionId, Iterable paths) - { - return new AbstractRevisionAccessContext(paths) - { @Override - protected SimpleInMemoryVCS getContextVCS() + public RevisionAccessContext visit(WorkspaceSourceSpecification sourceSpec) { - return getVCS(projectId, versionId); + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + if ((workspaceSpec.getType() != WorkspaceType.USER) || (workspaceSpec.getAccessType() != WorkspaceAccessType.WORKSPACE)) + { + throw new UnsupportedOperationException("Unsupported workspace specification: " + workspaceSpec); + } + return new AbstractRevisionAccessContext(paths) + { + @Override + protected SimpleInMemoryVCS getContextVCS() + { + return getVCS(projectId, workspaceSpec.getId()); + } + }; } - }; + }); } - // File Modification Context - @Override public FileModificationContext getFileModificationContext(String projectId, SourceSpecification sourceSpecification, String revisionId) { - if (sourceSpecification.getWorkspaceId() != null) + return sourceSpecification.visit(new SourceSpecificationVisitor() { - switch (sourceSpecification.getWorkspaceType()) + @Override + public FileModificationContext visit(ProjectSourceSpecification sourceSpec) { - case USER: - { - switch (sourceSpecification.getWorkspaceAccessType()) - { - case WORKSPACE: - { - return new InMemoryFileModificationContext(projectId, sourceSpecification.getWorkspaceId(), revisionId); - } - default: - { - throw new UnsupportedOperationException("Special workspace access type is not supported for getting file modification context"); - } - } - } - default: + return new InMemoryFileModificationContext(projectId, null, revisionId); + } + + @Override + public FileModificationContext visit(WorkspaceSourceSpecification sourceSpec) + { + WorkspaceSpecification workspaceSpec = sourceSpec.getWorkspaceSpecification(); + if ((workspaceSpec.getType() != WorkspaceType.USER) || (workspaceSpec.getAccessType() != WorkspaceAccessType.WORKSPACE)) { - throw new UnsupportedOperationException("Special workspace type is not supported for getting file modification context"); + throw new UnsupportedOperationException("Unsupported workspace specification: " + workspaceSpec); } + return new InMemoryFileModificationContext(projectId, workspaceSpec.getId(), revisionId); } - } - return new InMemoryFileModificationContext(projectId, null, revisionId); + }); } public void createWorkspace(String projectId, String workspaceId) @@ -214,21 +200,15 @@ public void createVersion(String projectId, VersionId versionId) private SimpleInMemoryVCS getVCS(String projectId) { - return this.projects.computeIfAbsent(projectId, pid -> new SimpleInMemoryVCS()); + return this.projects.getIfAbsentPut(projectId, SimpleInMemoryVCS::new); } private SimpleInMemoryVCS getVCS(String projectId, String workspaceId) { - SimpleInMemoryVCS vcs = this.projects.computeIfAbsent(projectId, pid -> new SimpleInMemoryVCS()); - if (workspaceId != null) - { - vcs = vcs.getBranch(workspaceId); - if (vcs == null) - { - throw new RuntimeException("Unknown workspace in project " + projectId + ": " + workspaceId); - } - } - return vcs; + SimpleInMemoryVCS vcs = getVCS(projectId); + return (workspaceId == null) ? + vcs : + Objects.requireNonNull(vcs.getBranch(workspaceId), () -> "Unknown workspace in project " + projectId + ": " + workspaceId); } private SimpleInMemoryVCS getVCS(String projectId, VersionId versionId) diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestMultiGenerationProjectStructure.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestMultiGenerationProjectStructure.java index 852f143aac..537515997c 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestMultiGenerationProjectStructure.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestMultiGenerationProjectStructure.java @@ -21,7 +21,7 @@ import org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration; import org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency; import org.finos.legend.sdlc.domain.model.project.workspace.WorkspaceType; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.project.maven.LegendVersionPackagePluginMavenHelper; import org.finos.legend.sdlc.server.project.maven.MavenProjectStructure; import org.finos.legend.sdlc.server.project.maven.MultiModuleMavenProjectStructure; diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestProjectStructure.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestProjectStructure.java index fd3422848a..e397cae55b 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestProjectStructure.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/project/TestProjectStructure.java @@ -41,7 +41,9 @@ import org.finos.legend.sdlc.domain.model.revision.Revision; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.finos.legend.sdlc.server.domain.api.project.ProjectConfigurationUpdater; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.WorkspaceSourceSpecification; +import org.finos.legend.sdlc.server.domain.api.workspace.WorkspaceSpecification; import org.finos.legend.sdlc.server.error.LegendSDLCServerException; import org.finos.legend.sdlc.server.project.extension.DefaultProjectStructureExtension; import org.finos.legend.sdlc.server.project.extension.DefaultProjectStructureExtensionProvider; @@ -113,7 +115,7 @@ public void testBuild() String message = "Build project structure (version " + this.projectStructureVersion + ((this.projectStructureExtensionVersion == null) ? "" : (" extension version " + this.projectStructureExtensionVersion)) + ")"; Instant before = Instant.now(); buildProjectStructure(message); - Revision revision = this.fileAccessProvider.getProjectRevisionAccessContext(PROJECT_ID).getCurrentRevision(); + Revision revision = this.fileAccessProvider.getRevisionAccessContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).getCurrentRevision(); Instant after = Instant.now(); Assert.assertEquals(AUTHOR, revision.getAuthorName()); Assert.assertEquals(COMMITTER, revision.getCommitterName()); @@ -123,7 +125,7 @@ public void testBuild() Assert.assertTrue(after.compareTo(revision.getAuthoredTimestamp()) >= 0); Assert.assertTrue(after.compareTo(revision.getCommittedTimestamp()) >= 0); - ProjectConfiguration configuration = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration configuration = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, configuration.getProjectId()); Assert.assertEquals(GROUP_ID, configuration.getGroupId()); Assert.assertEquals(ARTIFACT_ID, configuration.getArtifactId()); @@ -139,13 +141,13 @@ public void testBuild() public void testEntities() { buildProjectStructure(); - ProjectStructure projectStructure = ProjectStructure.getProjectStructure(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectStructure projectStructure = ProjectStructure.getProjectStructure(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); String message = "Add entities"; Instant before = Instant.now(); - Revision revision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit(message, addEntityOperations); + Revision revision = this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit(message, addEntityOperations); Instant after = Instant.now(); Assert.assertEquals(AUTHOR, revision.getAuthorName()); Assert.assertEquals(COMMITTER, revision.getCommitterName()); @@ -167,13 +169,13 @@ public void testEntities() public void testUpdateGroupAndArtifactIds() { buildProjectStructure(); - ProjectStructure projectStructure = ProjectStructure.getProjectStructure(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectStructure projectStructure = ProjectStructure.getProjectStructure(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - Revision entitiesRevision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + Revision entitiesRevision = this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -184,8 +186,10 @@ public void testUpdateGroupAndArtifactIds() assertStateValid(PROJECT_ID, null, null); String workspaceId = "UpdateGroupAndArtifactIds"; + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER); + WorkspaceSourceSpecification workspaceSourceSpec = SourceSpecification.workspaceSourceSpecification(workspaceSpec); this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -197,13 +201,13 @@ public void testUpdateGroupAndArtifactIds() Revision configUpdateRevision = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withGroupId(GROUP_ID_2).withArtifactId(ARTIFACT_ID_2)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withRevisionId(entitiesRevision.getId()) .withMessage("Update group and artifact ids") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, workspaceSourceSpec, null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID_2, afterWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID_2, afterWorkspaceConfig.getArtifactId()); @@ -215,7 +219,7 @@ public void testUpdateGroupAndArtifactIds() this.fileAccessProvider.commitWorkspace(PROJECT_ID, workspaceId); - ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID_2, afterProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID_2, afterProjectConfig.getArtifactId()); @@ -226,7 +230,7 @@ public void testUpdateGroupAndArtifactIds() assertStateValid(PROJECT_ID, null, null); - ProjectConfiguration projectEntitiesRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), entitiesRevision.getId(), this.fileAccessProvider); + ProjectConfiguration projectEntitiesRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), entitiesRevision.getId(), this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, projectEntitiesRevisionConfig.getProjectId()); Assert.assertEquals(GROUP_ID, projectEntitiesRevisionConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, projectEntitiesRevisionConfig.getArtifactId()); @@ -235,7 +239,7 @@ public void testUpdateGroupAndArtifactIds() Assert.assertEquals(Collections.emptyList(), projectEntitiesRevisionConfig.getMetamodelDependencies()); Assert.assertEquals(Collections.emptyList(), projectEntitiesRevisionConfig.getProjectDependencies()); - ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), configUpdateRevision.getId(), this.fileAccessProvider); + ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), configUpdateRevision.getId(), this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId()); Assert.assertEquals(GROUP_ID_2, projectConfigUpdateRevisionConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID_2, projectConfigUpdateRevisionConfig.getArtifactId()); @@ -245,7 +249,7 @@ public void testUpdateGroupAndArtifactIds() Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getProjectDependencies()); assertEntitiesEquivalent(testEntities, getActualEntities(PROJECT_ID)); - Map actualFiles = this.fileAccessProvider.getFileAccessContext(PROJECT_ID, null, null, null, configUpdateRevision.getId()).getFiles().collect(Collectors.toMap(ProjectFileAccessProvider.ProjectFile::getPath, ProjectFileAccessProvider.ProjectFile::getContentAsString)); + Map actualFiles = this.fileAccessProvider.getFileAccessContext(PROJECT_ID, SourceSpecification.projectSourceSpecification(), configUpdateRevision.getId()).getFiles().collect(Collectors.toMap(ProjectFileAccessProvider.ProjectFile::getPath, ProjectFileAccessProvider.ProjectFile::getContentAsString)); List unExpectedFiles = actualFiles.keySet().stream().filter(filePath -> !filePath.equals("/pom.xml") && filePath.endsWith("/pom.xml") && !filePath.startsWith("/" + ARTIFACT_ID_2)).collect(Collectors.toList()); Assert.assertTrue("non expected files " + Arrays.toString(unExpectedFiles.toArray()), unExpectedFiles.isEmpty()); @@ -270,9 +274,9 @@ public void testUpdateProjectDependencies() List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -283,8 +287,9 @@ public void testUpdateProjectDependencies() assertStateValid(PROJECT_ID, null, null); String addDependenciesWorkspaceId = "AddDependencies"; + WorkspaceSpecification addDependenciesWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(addDependenciesWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, addDependenciesWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -296,12 +301,12 @@ public void testUpdateProjectDependencies() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectDependenciesToAdd(projectDependencies)) - .withWorkspace(SourceSpecification.newSourceSpecification(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addDependenciesWorkspaceSpec) .withMessage("Add dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE),null, this.fileAccessProvider); + ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(addDependenciesWorkspaceSpec),null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId()); @@ -313,7 +318,7 @@ public void testUpdateProjectDependencies() this.fileAccessProvider.commitWorkspace(PROJECT_ID, addDependenciesWorkspaceId); - ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId()); @@ -324,16 +329,17 @@ public void testUpdateProjectDependencies() assertStateValid(PROJECT_ID, null, null); String noChangeWorkspaceId = "NoChangeToDependencies"; + WorkspaceSpecification noChangeWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(noChangeWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, noChangeWorkspaceId); Revision newRevision = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withGroupId("temp.group.id")) - .withWorkspace(SourceSpecification.newSourceSpecification(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null)) + .withWorkspace(noChangeWorkspaceSpec) .withMessage("No change to dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); Assert.assertNotNull(newRevision); - ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(noChangeWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, noChangeWorkspaceConfig.getProjectId()); Assert.assertEquals("temp.group.id", noChangeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, noChangeWorkspaceConfig.getArtifactId()); @@ -346,9 +352,10 @@ public void testUpdateProjectDependencies() for (int i = 0; i < projectDependencies.size(); i++) { - String removeDependencyWorkspaceId = "RemoveDependency" + 0; + String removeDependencyWorkspaceId = "RemoveDependency" + i; + WorkspaceSpecification removeDependencyWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, removeDependencyWorkspaceId); - ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeRemovalConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeRemovalConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeRemovalConfig.getArtifactId()); @@ -360,12 +367,12 @@ public void testUpdateProjectDependencies() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectDependencyToRemove(projectDependencies.get(i))) - .withWorkspace(SourceSpecification.newSourceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null)) + .withWorkspace(removeDependencyWorkspaceSpec) .withMessage("Remove dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(removeDependencyWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterRemovalWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterRemovalWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterRemovalWorkspaceConfig.getArtifactId()); @@ -377,7 +384,7 @@ public void testUpdateProjectDependencies() this.fileAccessProvider.commitWorkspace(PROJECT_ID, removeDependencyWorkspaceId); - ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterRemovalProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterRemovalProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterRemovalProjectConfig.getArtifactId()); @@ -388,7 +395,7 @@ public void testUpdateProjectDependencies() assertStateValid(PROJECT_ID, null, null); } - ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId()); Assert.assertEquals(GROUP_ID, projectConfigUpdateRevisionConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, projectConfigUpdateRevisionConfig.getArtifactId()); @@ -411,7 +418,7 @@ public void testUpdateOldProjectDependencies() ProjectStructure projectStructure = buildProjectStructure(); createProjectWithVersions(oldProjectDependency.getProjectId(), GROUP_ID, "testproject3", oldProjectDependency.getVersionId()); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -426,9 +433,9 @@ public void testUpdateOldProjectDependencies() String serializedConfig = serializeConfig(newConfig); List operations = Lists.mutable.empty(); operations.add(ProjectFileOperation.modifyFile("/project.json", serializedConfig)); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("set dependencies", operations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("set dependencies", operations); - ProjectConfiguration afterUpdateProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterUpdateProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterUpdateProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterUpdateProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterUpdateProjectConfig.getArtifactId()); @@ -438,15 +445,16 @@ public void testUpdateOldProjectDependencies() Assert.assertEquals(oldProjectDependencyList, afterUpdateProjectConfig.getProjectDependencies()); String updateOldDependenciesId = "UpdateOldDependencies"; + WorkspaceSpecification updateOldDependenciesWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(updateOldDependenciesId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, updateOldDependenciesId); ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectDependencyToRemove(oldProjectDependencyToRemove)) - .withWorkspace(SourceSpecification.newSourceSpecification(updateOldDependenciesId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(updateOldDependenciesWorkspaceSpec) .withMessage("Update Old Dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterUpdateWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(updateOldDependenciesId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterUpdateWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(updateOldDependenciesWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterUpdateWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterUpdateWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterUpdateWorkspaceConfig.getArtifactId()); @@ -497,9 +505,9 @@ public void testUpdateMetamodelDependencies() List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -509,8 +517,9 @@ public void testUpdateMetamodelDependencies() assertStateValid(PROJECT_ID, null, null); String addDependenciesWorkspaceId = "AddDependencies"; + WorkspaceSpecification addDependenciesWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(addDependenciesWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, addDependenciesWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -522,12 +531,12 @@ public void testUpdateMetamodelDependencies() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withMetamodelDependenciesToAdd(metamodelDependencies)) - .withWorkspace(SourceSpecification.newSourceSpecification(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null)) + .withWorkspace(addDependenciesWorkspaceSpec) .withMessage("Add dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(addDependenciesWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId()); @@ -539,7 +548,7 @@ public void testUpdateMetamodelDependencies() this.fileAccessProvider.commitWorkspace(PROJECT_ID, addDependenciesWorkspaceId); - ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId()); @@ -550,16 +559,17 @@ public void testUpdateMetamodelDependencies() assertStateValid(PROJECT_ID, null, null); String noChangeWorkspaceId = "NoChangeToDependencies"; + WorkspaceSpecification noChangeWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(noChangeWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, noChangeWorkspaceId); Revision newRevision = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withGroupId("temp.group.id")) - .withWorkspace(SourceSpecification.newSourceSpecification(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(noChangeWorkspaceSpec) .withMessage("No change to dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); Assert.assertNotNull(newRevision); - ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(noChangeWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, noChangeWorkspaceConfig.getProjectId()); Assert.assertEquals("temp.group.id", noChangeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, noChangeWorkspaceConfig.getArtifactId()); @@ -572,9 +582,10 @@ public void testUpdateMetamodelDependencies() for (int i = 0; i < metamodelDependencies.size(); i++) { - String removeDependencyWorkspaceId = "RemoveDependency" + 0; + String removeDependencyWorkspaceId = "RemoveDependency" + i; + WorkspaceSpecification removeDependencyWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, removeDependencyWorkspaceId); - ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, beforeRemovalConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeRemovalConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeRemovalConfig.getArtifactId()); @@ -586,12 +597,12 @@ public void testUpdateMetamodelDependencies() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withMetamodelDependencyToRemove(metamodelDependencies.get(i))) - .withWorkspace(SourceSpecification.newSourceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(removeDependencyWorkspaceSpec) .withMessage("Remove dependencies") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(removeDependencyWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterRemovalWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterRemovalWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterRemovalWorkspaceConfig.getArtifactId()); @@ -603,7 +614,7 @@ public void testUpdateMetamodelDependencies() this.fileAccessProvider.commitWorkspace(PROJECT_ID, removeDependencyWorkspaceId); - ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterRemovalProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterRemovalProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterRemovalProjectConfig.getArtifactId()); @@ -614,7 +625,7 @@ public void testUpdateMetamodelDependencies() assertStateValid(PROJECT_ID, null, null); } - ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId()); Assert.assertEquals(GROUP_ID, projectConfigUpdateRevisionConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, projectConfigUpdateRevisionConfig.getArtifactId()); @@ -645,9 +656,9 @@ public void testUpgradeProjectStructureVersion() ProjectStructure otherProjectStructure = buildProjectStructure(i, null, null, null); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, otherProjectStructure); - Revision revision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + Revision revision = this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeConfig.getArtifactId()); @@ -656,10 +667,11 @@ public void testUpgradeProjectStructureVersion() Assert.assertEquals(Collections.emptyList(), beforeConfig.getProjectDependencies()); String workspaceId = "ConvertProjectToVersion" + i; + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId); ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectStructureVersion(this.projectStructureVersion).withProjectStructureExtensionVersion(this.projectStructureExtensionVersion)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withRevisionId(revision.getId()) .withMessage("Update project structure version") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) @@ -669,7 +681,7 @@ public void testUpgradeProjectStructureVersion() this.fileAccessProvider.commitWorkspace(PROJECT_ID, workspaceId); assertStateValid(PROJECT_ID, null, null); - ProjectConfiguration afterConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterConfig.getArtifactId()); @@ -690,8 +702,8 @@ public void testConvertManagedToEmbeddedAndBack() List testEntities = getTestEntities(); ProjectStructure otherProjectStructure = buildProjectStructure(this.projectStructureVersion, this.projectStructureExtensionVersion, null, null); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, otherProjectStructure); - Revision revision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); - ProjectConfiguration initialConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + Revision revision = this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); + ProjectConfiguration initialConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, initialConfig.getProjectId()); Assert.assertEquals(GROUP_ID, initialConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, initialConfig.getArtifactId()); @@ -701,10 +713,11 @@ public void testConvertManagedToEmbeddedAndBack() Assert.assertEquals(Collections.emptyList(), initialConfig.getMetamodelDependencies()); Assert.assertEquals(Collections.emptyList(), initialConfig.getProjectDependencies()); String workspaceId = "ConvertManagedToEmbedded"; + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId); Revision nextRevision = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectType(ProjectType.EMBEDDED)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withRevisionId(revision.getId()) .withMessage("Update project structure version") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) @@ -713,12 +726,12 @@ public void testConvertManagedToEmbeddedAndBack() assertStateValid(PROJECT_ID, workspaceId, null); this.fileAccessProvider.commitWorkspace(PROJECT_ID, workspaceId); assertStateValid(PROJECT_ID, null, null); - ProjectConfiguration embeddedConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration embeddedConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, embeddedConfig.getProjectId()); Assert.assertEquals(GROUP_ID, embeddedConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, embeddedConfig.getArtifactId()); Assert.assertEquals(this.projectStructureVersion, embeddedConfig.getProjectStructureVersion().getVersion()); - Assert.assertEquals(null, embeddedConfig.getProjectStructureVersion().getExtensionVersion()); + Assert.assertNull(embeddedConfig.getProjectStructureVersion().getExtensionVersion()); Assert.assertEquals(ProjectType.EMBEDDED, embeddedConfig.getProjectType()); Assert.assertEquals(Collections.emptyList(), embeddedConfig.getMetamodelDependencies()); Assert.assertEquals(Collections.emptyList(), embeddedConfig.getProjectDependencies()); @@ -726,7 +739,7 @@ public void testConvertManagedToEmbeddedAndBack() this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId); ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectType(ProjectType.MANAGED)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withRevisionId(nextRevision.getId()) .withMessage("Update project structure version") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) @@ -735,7 +748,7 @@ public void testConvertManagedToEmbeddedAndBack() assertStateValid(PROJECT_ID, workspaceId, null); this.fileAccessProvider.commitWorkspace(PROJECT_ID, workspaceId); assertStateValid(PROJECT_ID, null, null); - ProjectConfiguration managedConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration managedConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, managedConfig.getProjectId()); Assert.assertEquals(GROUP_ID, managedConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, managedConfig.getArtifactId()); @@ -767,15 +780,16 @@ public void testUpdateFullProjectConfig() ProjectStructure otherProjectStructure = buildProjectStructure(i, null, null, null); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, otherProjectStructure); - Revision revision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + Revision revision = this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeConfig.getArtifactId()); Assert.assertEquals(i, beforeConfig.getProjectStructureVersion().getVersion()); String workspaceId = "ConvertProjectToVersion" + i; + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId); ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() @@ -783,7 +797,7 @@ public void testUpdateFullProjectConfig() .withProjectStructureExtensionVersion(this.projectStructureExtensionVersion) .withGroupId(GROUP_ID_2) .withArtifactId(ARTIFACT_ID_2)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withRevisionId(revision.getId()) .withMessage("Update project configuration") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) @@ -793,7 +807,7 @@ public void testUpdateFullProjectConfig() this.fileAccessProvider.commitWorkspace(PROJECT_ID, workspaceId); assertStateValid(PROJECT_ID, null, null); - ProjectConfiguration afterConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterConfig.getProjectId()); Assert.assertEquals(GROUP_ID_2, afterConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID_2, afterConfig.getArtifactId()); @@ -808,21 +822,22 @@ public void testUpdateFullProjectConfig() public void testVacuousProjectConfigUpdate() { buildProjectStructure(); - Revision revision = this.fileAccessProvider.getProjectRevisionAccessContext(PROJECT_ID).getCurrentRevision(); + Revision revision = this.fileAccessProvider.getRevisionAccessContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).getCurrentRevision(); String workspaceId = "UpdateWorkspace"; + WorkspaceSpecification workspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId); - Assert.assertEquals(revision, this.fileAccessProvider.getWorkspaceRevisionAccessContext(PROJECT_ID, workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).getCurrentRevision()); + Assert.assertEquals(revision, this.fileAccessProvider.getRevisionAccessContext(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(workspaceSpec)).getCurrentRevision()); assertStateValid(PROJECT_ID, workspaceId, null); Revision revision2 = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withMessage("Vacuous update") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); Assert.assertNull(revision2); - Assert.assertEquals(revision, this.fileAccessProvider.getWorkspaceRevisionAccessContext(PROJECT_ID, workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).getCurrentRevision()); + Assert.assertEquals(revision, this.fileAccessProvider.getRevisionAccessContext(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(workspaceSpec)).getCurrentRevision()); assertStateValid(PROJECT_ID, workspaceId, null); Revision revision3 = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) @@ -831,7 +846,7 @@ public void testVacuousProjectConfigUpdate() .withProjectStructureExtensionVersion(this.projectStructureExtensionVersion) .withGroupId(GROUP_ID) .withArtifactId(ARTIFACT_ID)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(workspaceSpec) .withMessage("Vacuous update") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) @@ -982,6 +997,7 @@ protected T buildProjectStructure() return buildProjectStructure(null); } + @SuppressWarnings("unchecked") protected T buildProjectStructure(String message) { return (T) buildProjectStructure(this.projectStructureVersion, this.projectStructureExtensionVersion, null, message); @@ -1032,13 +1048,13 @@ protected ProjectStructure buildProjectStructure(String projectId, Integer proje .withProjectStructureExtensionVersion(projectStructureExtensionVersion) .withGroupId(groupId) .withArtifactId(artifactId)) - .withWorkspace(SourceSpecification.newSourceSpecification(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER)) .withMessage(message) .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .build(); this.fileAccessProvider.commitWorkspace(projectId, workspaceId); - return ProjectStructure.getProjectStructure(projectId, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + return ProjectStructure.getProjectStructure(projectId, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider); } private void createProjectWithVersions(String projectId, String groupId, String artifactId, String... versionIds) @@ -1053,7 +1069,7 @@ private void createProjectWithVersions(String projectId, String groupId, String this.fileAccessProvider.createWorkspace(projectId, workspaceId); Entity newClass = TestTools.newClassEntity(entityName, modelPackage, TestTools.newProperty("prop1", "String", 0, 1)); ProjectFileOperation addEntityOperation = generateAddOperationForEntity(newClass, projectStructure); - this.fileAccessProvider.getWorkspaceFileModificationContext(projectId, workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).submit("Add " + modelPackage + EntityPaths.PACKAGE_SEPARATOR + entityName, Collections.singletonList(addEntityOperation)); + this.fileAccessProvider.getFileModificationContext(projectId, SourceSpecification.workspaceSourceSpecification(WorkspaceSpecification.newWorkspaceSpecification(workspaceId, WorkspaceType.USER))).submit("Add " + modelPackage + EntityPaths.PACKAGE_SEPARATOR + entityName, Collections.singletonList(addEntityOperation)); this.fileAccessProvider.commitWorkspace(projectId, workspaceId); this.fileAccessProvider.createVersion(projectId, VersionId.parseVersionId(versionId)); } @@ -1083,9 +1099,9 @@ public void testUpdateProjectArtifactGeneration() List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -1096,7 +1112,7 @@ public void testUpdateProjectArtifactGeneration() String addGenerationsWorkspaceId = "AddGeneration"; this.fileAccessProvider.createWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -1127,7 +1143,7 @@ public void testUpdateProjectArtifactGeneration() this.fileAccessProvider.commitWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId()); @@ -1137,16 +1153,17 @@ public void testUpdateProjectArtifactGeneration() assertStateValid(PROJECT_ID, null, null); // String noChangeWorkspaceId = "NoChangeToGeneration"; + WorkspaceSpecification noChangeWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(noChangeWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, noChangeWorkspaceId); Revision newRevision = ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withGroupId("temp.group.id")) - .withWorkspace(SourceSpecification.newSourceSpecification(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null)) + .withWorkspace(noChangeWorkspaceSpec) .withMessage("No change to generation") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); Assert.assertNotNull(newRevision); - ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(noChangeWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, noChangeWorkspaceConfig.getProjectId()); Assert.assertEquals("temp.group.id", noChangeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, noChangeWorkspaceConfig.getArtifactId()); @@ -1158,9 +1175,11 @@ public void testUpdateProjectArtifactGeneration() for (int i = 0; i < generations.size(); i++) { - String removeDependencyWorkspaceId = "RemoveGeneration" + 0; + String removeDependencyWorkspaceId = "RemoveGeneration" + i; + WorkspaceSpecification removeDependencyWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER); + this.fileAccessProvider.createWorkspace(PROJECT_ID, removeDependencyWorkspaceId); - ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeRemovalConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeRemovalConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeRemovalConfig.getArtifactId()); @@ -1173,12 +1192,12 @@ public void testUpdateProjectArtifactGeneration() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withArtifactGenerationsToRemove(Collections.singletonList(generations.get(i).getName()))) - .withWorkspace(SourceSpecification.newSourceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null)) + .withWorkspace(removeDependencyWorkspaceSpec) .withMessage("Remove generations") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(removeDependencyWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterRemovalWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterRemovalWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterRemovalWorkspaceConfig.getArtifactId()); @@ -1190,7 +1209,7 @@ public void testUpdateProjectArtifactGeneration() this.fileAccessProvider.commitWorkspace(PROJECT_ID, removeDependencyWorkspaceId); - ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterRemovalProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterRemovalProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterRemovalProjectConfig.getArtifactId()); @@ -1201,7 +1220,7 @@ public void testUpdateProjectArtifactGeneration() assertStateValid(PROJECT_ID, null, null); } - ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId()); Assert.assertEquals(GROUP_ID, projectConfigUpdateRevisionConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, projectConfigUpdateRevisionConfig.getArtifactId()); @@ -1244,9 +1263,9 @@ public void testAddSameTypeProjectArtifactGenerations() List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -1256,8 +1275,9 @@ public void testAddSameTypeProjectArtifactGenerations() assertStateValid(PROJECT_ID, null, null); String addGenerationsWorkspaceId = "AddGeneration"; + WorkspaceSpecification addGenerationsWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -1270,13 +1290,13 @@ public void testAddSameTypeProjectArtifactGenerations() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withArtifactGenerationsToAdd(generations)) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add generation multiple same types") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(addGenerationsWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId()); @@ -1288,7 +1308,7 @@ public void testAddSameTypeProjectArtifactGenerations() this.fileAccessProvider.commitWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId()); @@ -1305,9 +1325,9 @@ public void testCantAddInvalidProjectArtifactGenerations() List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -1317,8 +1337,9 @@ public void testCantAddInvalidProjectArtifactGenerations() assertStateValid(PROJECT_ID, null, null); String addGenerationsWorkspaceId = "AddInvalidGeneration"; + WorkspaceSpecification addGenerationsWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -1334,7 +1355,7 @@ public void testCantAddInvalidProjectArtifactGenerations() () -> ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() .withArtifactGenerationsToAdd(Lists.fixedSize.with(new SimpleArtifactGeneration().withType(ArtifactType.entities).withName("invalid"), new SimpleArtifactGeneration().withType(ArtifactType.versioned_entities).withName("invalid2")))) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add invalid type generations") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) @@ -1352,7 +1373,7 @@ public void testCantAddInvalidProjectArtifactGenerations() () -> ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() .withArtifactGenerationsToAdd(Lists.fixedSize.with(new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("dup"), new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("dup").withParameters(params)))) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add duplicate generations") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) @@ -1368,7 +1389,7 @@ public void testCantAddInvalidProjectArtifactGenerations() () -> ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() .withArtifactGenerationsToAdd(Lists.fixedSize.with(new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("same"), new SimpleArtifactGeneration().withType(ArtifactType.java).withName("same")))) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add duplicate names generations") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) @@ -1380,7 +1401,7 @@ public void testCantAddInvalidProjectArtifactGenerations() () -> ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() .withArtifactGenerationsToAdd(Lists.fixedSize.with(new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("dup"), new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("dup")))) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add a names generations") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) @@ -1390,7 +1411,7 @@ public void testCantAddInvalidProjectArtifactGenerations() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() .withArtifactGenerationsToAdd(Lists.fixedSize.with(new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("dup")))) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add a names generations") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) @@ -1400,7 +1421,7 @@ public void testCantAddInvalidProjectArtifactGenerations() () -> ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater() .withArtifactGenerationsToAdd(Lists.fixedSize.with(new SimpleArtifactGeneration().withType(ArtifactType.avro).withName("dup").withParameters(params)))) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add a duplicate name") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) @@ -1423,9 +1444,9 @@ public void testMultiFormatArtifactGeneration() { List testEntities = getTestEntities(); List addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure); - this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations); + this.fileAccessProvider.getFileModificationContext(PROJECT_ID, SourceSpecification.projectSourceSpecification()).submit("Add entities", addEntityOperations); - ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId()); @@ -1435,8 +1456,9 @@ public void testMultiFormatArtifactGeneration() assertStateValid(PROJECT_ID, null, null); String addGenerationsWorkspaceId = "AddGeneration"; + WorkspaceSpecification addGenerationsWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -1460,13 +1482,13 @@ public void testMultiFormatArtifactGeneration() ProjectStructure.newUpdateBuilder(this.fileAccessProvider, PROJECT_ID) .withProjectConfigurationUpdater(ProjectConfigurationUpdater.newUpdater().withProjectDependenciesToAdd(projectDependencies)) - .withWorkspace(SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)) + .withWorkspace(addGenerationsWorkspaceSpec) .withMessage("Add multi generation") .withProjectStructureExtensionProvider(this.projectStructureExtensionProvider) .withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions) .update(); - ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider); + ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.workspaceSourceSpecification(addGenerationsWorkspaceSpec), null, this.fileAccessProvider); Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId()); @@ -1489,8 +1511,9 @@ public void testMultiFormatArtifactGeneration() private void testMultiFormatFormatGeneration(ArtifactType type, List generations) { String addGenerationsWorkspaceId = "AddGeneration" + type.name(); + WorkspaceSpecification addGenerationsWorkspaceSpec = WorkspaceSpecification.newWorkspaceSpecification(addGenerationsWorkspaceId, WorkspaceType.USER); this.fileAccessProvider.createWorkspace(PROJECT_ID, addGenerationsWorkspaceId); - ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.newSourceSpecification(null, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE), null, this.fileAccessProvider);; + ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, SourceSpecification.projectSourceSpecification(), null, this.fileAccessProvider);; Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId()); Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId()); Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId()); @@ -1500,12 +1523,12 @@ private void testMultiFormatFormatGeneration(ArtifactType type, List patches, VersionId patchReleaseVersionId) { - return patches.stream().filter(patch -> patch.getPatchReleaseVersionId().equals(patchReleaseVersionId)).findFirst().get(); + return ListIterate.detect(patches, p -> patchReleaseVersionId.equals(p.getPatchReleaseVersionId())); } } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/TestReviewsResource.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/TestReviewsResource.java index 4414a9baa4..2d341c8406 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/TestReviewsResource.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/resources/TestReviewsResource.java @@ -15,7 +15,6 @@ package org.finos.legend.sdlc.server.resources; import org.apache.http.client.HttpResponseException; -import org.finos.legend.sdlc.domain.model.project.Project; import org.finos.legend.sdlc.domain.model.review.Review; import org.finos.legend.sdlc.domain.model.version.VersionId; import org.junit.Assert; @@ -28,43 +27,43 @@ public class TestReviewsResource extends AbstractLegendSDLCServerResourceTest { @Test - public void testGetReviewForProject() throws HttpResponseException + public void testGetReviewForProject() throws HttpResponseException { - this.backend.project("A").addReview("1"); + this.backend.project("A").addReview("1"); Response response = this.clientFor("/api/projects/A/reviews/1").request().get(); if (response.getStatus() != 200) { throw new HttpResponseException(response.getStatus(), "Error during http call with status: " + response.getStatus() + " , entity: " + response.readEntity(String.class)); - } - + } + Review review = response.readEntity(new GenericType() - { - }); - - + { + }); + + Assert.assertEquals("A", review.getProjectId()); Assert.assertEquals("111", review.getWorkspaceId()); } @Test - public void testGetReviewsForProject() throws HttpResponseException + public void testGetReviewsForProject() throws HttpResponseException { - this.backend.project("A").addReview("456"); + this.backend.project("A").addReview("456"); Response response = this.clientFor("/api/projects/A/reviews?state=OPEN&limit=2").request().get(); if (response.getStatus() != 200) { throw new HttpResponseException(response.getStatus(), "Error during http call with status: " + response.getStatus() + " , entity: " + response.readEntity(String.class)); - } - + } + List reviews = response.readEntity(new GenericType>() - { - }); - - + { + }); + + Assert.assertNotNull(reviews); Assert.assertEquals(1, reviews.size()); } diff --git a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/utils/TestModelBuilderTest.java b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/utils/TestModelBuilderTest.java index 73816f0ec3..2e4e90d666 100644 --- a/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/utils/TestModelBuilderTest.java +++ b/legend-sdlc-server/src/test/java/org/finos/legend/sdlc/server/utils/TestModelBuilderTest.java @@ -27,7 +27,7 @@ import org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApi; import org.finos.legend.sdlc.server.domain.api.dependency.DependenciesApiImpl; import org.finos.legend.sdlc.server.domain.api.test.TestModelBuilder; -import org.finos.legend.sdlc.server.domain.api.project.SourceSpecification; +import org.finos.legend.sdlc.server.domain.api.project.source.SourceSpecification; import org.finos.legend.sdlc.server.inmemory.backend.InMemoryBackend; import org.finos.legend.sdlc.server.inmemory.backend.metadata.InMemoryMetadataBackend; import org.junit.Assert; @@ -150,15 +150,8 @@ public void deleteEntitiesFromUpstreamProject() .removeEntities("w1", entityB1InVersion1); // entity b1 not found in ws1 - try - { - this.backend.getEntityApi().getUserWorkspaceEntityAccessContext("PROD-1", "w1").getEntity("PROD-1::b1"); - Assert.fail("Failed to get entity not found exception"); - } - catch (IllegalStateException e) - { - Assert.assertEquals("Entity with path PROD-1::b1 not found", e.getMessage()); - } + IllegalStateException e = Assert.assertThrows(IllegalStateException.class, () -> this.backend.getEntityApi().getUserWorkspaceEntityAccessContext("PROD-1", "w1").getEntity("PROD-1::b1")); + Assert.assertEquals("Entity with path PROD-1::b1 not found", e.getMessage()); List entitiesAfter = this.testModelBuilder.buildEntitiesForTest( "PROD-1",