use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class TestWorkspaceEntitiesResource method testGetUserWorkspaceEntities.
@Test
public void testGetUserWorkspaceEntities() throws HttpResponseException {
String projectId = "A";
String workspaceOneId = "entityw1";
String entityOneName = "testentityone";
String entityTwoName = "testentitytwo";
String entityPackageName = "testpkg";
this.backend.project(projectId).addEntities(workspaceOneId, InMemoryEntity.newEntity(entityOneName, entityPackageName), InMemoryEntity.newEntity(entityTwoName, entityPackageName));
Response responseOne = this.clientFor("/api/projects/A/workspaces/entityw1").request().get();
if (responseOne.getStatus() != 200) {
throw new HttpResponseException(responseOne.getStatus(), "Error during getting user workspace with status: " + responseOne.getStatus() + ", entity: " + responseOne.readEntity(String.class));
}
Workspace workspace = responseOne.readEntity(new GenericType<Workspace>() {
});
Assert.assertNotNull(workspace);
Assert.assertEquals(workspaceOneId, workspace.getWorkspaceId());
Assert.assertEquals(projectId, workspace.getProjectId());
Response responseTwo = this.clientFor("/api/projects/A/workspaces/entityw1/entities").request().get();
if (responseTwo.getStatus() != 200) {
throw new HttpResponseException(responseTwo.getStatus(), "Error during getting entities in user workspace with status: " + responseTwo.getStatus() + ", entity: " + responseTwo.readEntity(String.class));
}
List<Entity> entities = responseTwo.readEntity(new GenericType<List<Entity>>() {
});
Assert.assertNotNull(entities);
Assert.assertEquals(2, entities.size());
Entity entityOne = findEntity(entities, entityOneName, entityPackageName);
Entity entityTwo = findEntity(entities, entityTwoName, entityPackageName);
Assert.assertEquals(entityPackageName + "::" + entityOneName, entityOne.getPath());
Assert.assertEquals(entityPackageName + "::" + entityTwoName, entityTwo.getPath());
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class TestWorkspaceEntitiesResource method testGetAndUpdateUserWorkspaceEntity.
@Test
public void testGetAndUpdateUserWorkspaceEntity() throws HttpResponseException {
String projectId = "A";
String workspaceOneId = "entityw3";
String entityOneName = "testentityone";
String entityPackageName = "testpkg";
this.backend.project(projectId).addEntities(workspaceOneId, InMemoryEntity.newEntity(entityOneName, entityPackageName));
Response responseOne = this.clientFor("/api/projects/A/workspaces/entityw3").request().get();
if (responseOne.getStatus() != 200) {
throw new HttpResponseException(responseOne.getStatus(), "Error during getting user workspace with status: " + responseOne.getStatus() + ", entity: " + responseOne.readEntity(String.class));
}
Workspace workspace = responseOne.readEntity(new GenericType<Workspace>() {
});
Assert.assertNotNull(workspace);
Assert.assertEquals(workspaceOneId, workspace.getWorkspaceId());
Assert.assertEquals(projectId, workspace.getProjectId());
Response responseTwo = this.clientFor("/api/projects/A/workspaces/entityw3/entities/testpkg::testentityone").request().get();
if (responseTwo.getStatus() != 200) {
throw new HttpResponseException(responseTwo.getStatus(), "Error during getting entity in user workspace with status: " + responseTwo.getStatus() + ", entity: " + responseTwo.readEntity(String.class));
}
Entity entity = responseTwo.readEntity(new GenericType<Entity>() {
});
Assert.assertNotNull(entity);
Assert.assertEquals(entityPackageName + "::" + entityOneName, entity.getPath());
Assert.assertEquals(entityPackageName, entity.getContent().get("package"));
Assert.assertEquals(entityOneName, entity.getContent().get("name"));
UpdateEntitiesCommand updateEntitiesCommand = new UpdateEntitiesCommand();
updateEntitiesCommand.setReplace(true);
Response responseThree = this.clientFor("/api/projects/A/workspaces/entityw3/entities").request().post(javax.ws.rs.client.Entity.entity(updateEntitiesCommand, MediaType.APPLICATION_JSON));
if (responseThree.getStatus() != 200) {
throw new HttpResponseException(responseThree.getStatus(), "Error during updating entity in user workspace with status: " + responseThree.getStatus() + ", entity: " + responseThree.readEntity(String.class));
}
Revision revision = responseThree.readEntity(new GenericType<Revision>() {
});
Assert.assertNotNull(revision);
Assert.assertNotNull(revision.getId());
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabRevisionApi method getRevisionStatus.
@Override
public RevisionStatus getRevisionStatus(String projectId, String revisionId) {
LegendSDLCServerException.validateNonNull(projectId, "projectId may not be null");
LegendSDLCServerException.validateNonNull(revisionId, "revisionId may not be null");
GitLabProjectId gitLabProjectId = parseProjectId(projectId);
try {
GitLabApi gitLabApi = getGitLabApi(gitLabProjectId.getGitLabMode());
CommitsApi commitsApi = gitLabApi.getCommitsApi();
Revision revision = getProjectRevisionContext(projectId).getRevision(revisionId);
Pager<CommitRef> commitRefPager = withRetries(() -> commitsApi.getCommitRefs(gitLabProjectId.getGitLabId(), revision.getId(), RefType.ALL, ITEMS_PER_PAGE));
List<CommitRef> commitRefs = PagerTools.stream(commitRefPager).collect(Collectors.toList());
boolean isCommitted = commitRefs.stream().anyMatch(cr -> MASTER_BRANCH.equals(cr.getName()));
List<Version> versions;
List<String> versionTagNames = commitRefs.stream().filter(cr -> (RefType.TAG == cr.getType()) && isVersionTagName(cr.getName())).map(CommitRef::getName).collect(Collectors.toList());
if (versionTagNames.isEmpty()) {
versions = Collections.emptyList();
} else {
TagsApi tagsApi = gitLabApi.getTagsApi();
versions = Lists.mutable.ofInitialCapacity(versionTagNames.size());
for (String tagName : versionTagNames) {
Tag tag = withRetries(() -> tagsApi.getTag(gitLabProjectId.getGitLabId(), tagName));
versions.add(fromGitLabTag(projectId, tag));
}
versions.sort(Comparator.comparing(Version::getId));
}
List<Workspace> workspaces;
if (isCommitted) {
workspaces = Collections.emptyList();
} else {
// 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, cr.getName(), WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE)).collect(Collectors.toList());
}
return new RevisionStatus() {
@Override
public Revision getRevision() {
return revision;
}
@Override
public boolean isCommitted() {
return isCommitted;
}
@Override
public List<Workspace> getWorkspaces() {
return workspaces;
}
@Override
public List<Version> getVersions() {
return versions;
}
};
} catch (Exception e) {
throw buildException(e, () -> "User " + getCurrentUser() + " is not allowed to access the status for revision " + revisionId + " of project " + projectId, () -> "Unknown: revision " + revisionId + " of project " + projectId, () -> "Error getting the status for revision " + revisionId + " of project " + projectId);
}
}
Aggregations