Search in sources :

Example 1 with ProjectFileOperation

use of org.finos.legend.sdlc.server.project.ProjectFileOperation in project legend-sdlc by finos.

the class GitLabEntityApi method performChanges.

private Revision performChanges(String projectId, String workspaceId, String referenceRevisionId, String message, List<? extends EntityChange> changes, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) {
    int changeCount = changes.size();
    if (changeCount == 0) {
        LOGGER.debug("No changes for {} {} in project {}", workspaceType.getLabel() + " " + workspaceAccessType.getLabel(), workspaceId, projectId);
        return null;
    }
    LOGGER.debug("Committing {} changes to {} {} in project {}: {}", changeCount, workspaceType.getLabel() + " " + workspaceAccessType.getLabel(), workspaceId, projectId, message);
    try {
        ProjectFileAccessProvider.FileAccessContext fileAccessContext = getProjectFileAccessProvider().getFileAccessContext(projectId, workspaceId, workspaceType, workspaceAccessType, referenceRevisionId);
        ProjectStructure projectStructure = ProjectStructure.getProjectStructure(fileAccessContext);
        MutableList<ProjectFileOperation> fileOperations = ListIterate.collect(changes, c -> entityChangeToFileOperation(c, projectStructure, fileAccessContext));
        fileOperations.removeIf(Objects::isNull);
        if (fileOperations.isEmpty()) {
            LOGGER.debug("No changes for {} {} {} in project {}", workspaceType.getLabel(), workspaceAccessType.getLabel(), workspaceId, projectId);
            return null;
        }
        return getProjectFileAccessProvider().getFileModificationContext(projectId, workspaceId, workspaceType, workspaceAccessType, referenceRevisionId).submit(message, fileOperations);
    } catch (Exception e) {
        throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to perform changes on " + workspaceType.getLabel() + " " + workspaceAccessType.getLabel() + " " + workspaceId + " in project " + projectId, () -> "Unknown " + workspaceType.getLabel() + " " + workspaceAccessType.getLabel() + " (" + workspaceId + ") or project (" + projectId + ")", () -> "Failed to perform changes on " + workspaceType.getLabel() + " " + workspaceAccessType.getLabel() + " " + workspaceId + " in project " + projectId + " (message: " + message + ")");
    }
}
Also used : ProjectFileOperation(org.finos.legend.sdlc.server.project.ProjectFileOperation) ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) Objects(java.util.Objects) ProjectStructure(org.finos.legend.sdlc.server.project.ProjectStructure) LegendSDLCServerException(org.finos.legend.sdlc.server.error.LegendSDLCServerException)

Example 2 with ProjectFileOperation

use of org.finos.legend.sdlc.server.project.ProjectFileOperation in project legend-sdlc by finos.

the class TestDefaultProjectStructureExtension method testCollectUpdateProjectConfigurationOperations_EmptyStart.

@Test
public void testCollectUpdateProjectConfigurationOperations_EmptyStart() {
    String file1Path = "/file1.txt";
    String file1Content = "the quick brown fox";
    String file2Path = "/dir/file2.txt";
    String file2Content = "jumped over the lazy dog";
    DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0, file1Path, file1Content, file2Path, file2Content);
    InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
    fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
    ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    Assert.assertEquals(0L, fileAccessContext.getFiles().count());
    List<ProjectFileOperation> operations = Lists.mutable.empty();
    extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
    Assert.assertEquals(2, operations.size());
    ProjectFileAccessProvider.FileModificationContext modificationContext = fileAccessProvider.getFileModificationContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    modificationContext.submit("message", operations);
    Assert.assertEquals(2L, fileAccessContext.getFiles().count());
    ProjectFileAccessProvider.ProjectFile file1 = fileAccessContext.getFile(file1Path);
    Assert.assertNotNull(file1Path, file1);
    Assert.assertEquals(file1Content, file1.getContentAsString());
    ProjectFileAccessProvider.ProjectFile file2 = fileAccessContext.getFile(file2Path);
    Assert.assertNotNull(file2Path, file2);
    Assert.assertEquals(file2Content, file2.getContentAsString());
}
Also used : ProjectFileOperation(org.finos.legend.sdlc.server.project.ProjectFileOperation) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) Test(org.junit.Test)

Example 3 with ProjectFileOperation

use of org.finos.legend.sdlc.server.project.ProjectFileOperation in project legend-sdlc by finos.

the class TestDefaultProjectStructureExtension method testCollectUpdateProjectConfigurationOperations_Vacuous.

@Test
public void testCollectUpdateProjectConfigurationOperations_Vacuous() {
    DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0);
    InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
    fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
    ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    Assert.assertEquals(0L, fileAccessContext.getFiles().count());
    List<ProjectFileOperation> operations = Lists.mutable.empty();
    extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
    Assert.assertEquals(Collections.emptyList(), operations);
    Assert.assertEquals(0L, fileAccessContext.getFiles().count());
}
Also used : ProjectFileOperation(org.finos.legend.sdlc.server.project.ProjectFileOperation) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) Test(org.junit.Test)

Example 4 with ProjectFileOperation

use of org.finos.legend.sdlc.server.project.ProjectFileOperation in project legend-sdlc by finos.

the class TestDefaultProjectStructureExtension method testCollectUpdateProjectConfigurationOperations_NonEmptyStart.

@Test
public void testCollectUpdateProjectConfigurationOperations_NonEmptyStart() {
    String file1Path = "/file1.txt";
    String file1ContentBefore = "the quick brown fox jumped over the lazy dog";
    String file1ContentAfter = "THE QUICK BROWN FOX";
    String file2Path = "/dir/file2.txt";
    String file2ContentAfter = "JUMPED OVER THE LAZY DOG";
    DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0, file1Path, file1ContentAfter, file2Path, file2ContentAfter);
    InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
    fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
    ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    Assert.assertEquals(0L, fileAccessContext.getFiles().count());
    ProjectFileAccessProvider.FileModificationContext modificationContext = fileAccessProvider.getFileModificationContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    modificationContext.submit("initial state", Collections.singletonList(ProjectFileOperation.addFile(file1Path, file1ContentBefore)));
    Assert.assertEquals(1L, fileAccessContext.getFiles().count());
    Assert.assertNotNull(file1Path, fileAccessContext.getFile(file1Path));
    Assert.assertEquals(file1ContentBefore, fileAccessContext.getFile(file1Path).getContentAsString());
    Assert.assertNull(file2Path, fileAccessContext.getFile(file2Path));
    List<ProjectFileOperation> operations = Lists.mutable.empty();
    extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
    Assert.assertEquals(2, operations.size());
    modificationContext.submit("update", operations);
    Assert.assertEquals(2L, fileAccessContext.getFiles().count());
    Assert.assertNotNull(file1Path, fileAccessContext.getFile(file1Path));
    Assert.assertEquals(file1ContentAfter, fileAccessContext.getFile(file1Path).getContentAsString());
    Assert.assertNotNull(file2Path, fileAccessContext.getFile(file2Path));
    Assert.assertEquals(file2ContentAfter, fileAccessContext.getFile(file2Path).getContentAsString());
}
Also used : ProjectFileOperation(org.finos.legend.sdlc.server.project.ProjectFileOperation) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) Test(org.junit.Test)

Example 5 with ProjectFileOperation

use of org.finos.legend.sdlc.server.project.ProjectFileOperation in project legend-sdlc by finos.

the class TestDefaultProjectStructureExtension method testFilePathCanonicalization.

@Test
public void testFilePathCanonicalization() {
    String filePath = "file1.txt";
    String canonicalFilePath = "/file1.txt";
    String fileContent = "the quick brown fox jumped over the lazy dog";
    InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
    fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
    ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    Assert.assertEquals(0L, fileAccessContext.getFiles().count());
    DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0, filePath, fileContent);
    List<ProjectFileOperation> operations = Lists.mutable.empty();
    extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
    Assert.assertEquals(1, operations.size());
    ProjectFileAccessProvider.FileModificationContext modificationContext = fileAccessProvider.getFileModificationContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
    modificationContext.submit("update", operations);
    Assert.assertNull(filePath, fileAccessContext.getFile(filePath));
    Assert.assertNotNull(canonicalFilePath, fileAccessContext.getFile(canonicalFilePath));
    Assert.assertEquals(fileContent, fileAccessContext.getFile(canonicalFilePath).getContentAsString());
}
Also used : ProjectFileOperation(org.finos.legend.sdlc.server.project.ProjectFileOperation) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) ProjectFileAccessProvider(org.finos.legend.sdlc.server.project.ProjectFileAccessProvider) InMemoryProjectFileAccessProvider(org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider) Test(org.junit.Test)

Aggregations

ProjectFileAccessProvider (org.finos.legend.sdlc.server.project.ProjectFileAccessProvider)5 ProjectFileOperation (org.finos.legend.sdlc.server.project.ProjectFileOperation)5 InMemoryProjectFileAccessProvider (org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider)4 Test (org.junit.Test)4 Objects (java.util.Objects)1 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)1 ProjectStructure (org.finos.legend.sdlc.server.project.ProjectStructure)1