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 + ")");
}
}
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());
}
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());
}
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());
}
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());
}
Aggregations