use of org.pmiops.workbench.model.WorkspaceResponse in project workbench by all-of-us.
the class WorkspacesController method getWorkspace.
@Override
public ResponseEntity<WorkspaceResponse> getWorkspace(String workspaceNamespace, String workspaceId) {
org.pmiops.workbench.db.model.Workspace dbWorkspace = workspaceService.getRequired(workspaceNamespace, workspaceId);
org.pmiops.workbench.firecloud.model.WorkspaceResponse fcResponse;
org.pmiops.workbench.firecloud.model.Workspace fcWorkspace;
WorkspaceResponse response = new WorkspaceResponse();
try {
// This enforces access controls.
fcResponse = fireCloudService.getWorkspace(workspaceNamespace, workspaceId);
fcWorkspace = fcResponse.getWorkspace();
} catch (org.pmiops.workbench.firecloud.ApiException e) {
throw ExceptionUtils.convertFirecloudException(e);
}
if (fcResponse.getAccessLevel().equals(WorkspaceService.PROJECT_OWNER_ACCESS_LEVEL)) {
// We don't expose PROJECT_OWNER in our API; just use OWNER.
response.setAccessLevel(WorkspaceAccessLevel.OWNER);
} else {
response.setAccessLevel(WorkspaceAccessLevel.fromValue(fcResponse.getAccessLevel()));
if (response.getAccessLevel() == null) {
throw new ServerErrorException("Unsupported access level: " + fcResponse.getAccessLevel());
}
}
response.setWorkspace(TO_SINGLE_CLIENT_WORKSPACE_FROM_FC_AND_DB.apply(dbWorkspace, fcWorkspace));
return ResponseEntity.ok(response);
}
use of org.pmiops.workbench.model.WorkspaceResponse in project workbench by all-of-us.
the class WorkspacesController method getWorkspaces.
@Override
public ResponseEntity<WorkspaceResponseListResponse> getWorkspaces() {
// TODO: use FireCloud to determine what workspaces to return, instead of just returning
// workspaces from our database.
User user = userProvider.get();
List<WorkspaceResponse> responseList = new ArrayList<WorkspaceResponse>();
if (user != null) {
for (WorkspaceUserRole userRole : user.getWorkspaceUserRoles()) {
// TODO: Use FireCloud to determine access roles, not our DB
WorkspaceResponse currentWorkspace = new WorkspaceResponse();
currentWorkspace.setWorkspace(TO_CLIENT_WORKSPACE.apply(userRole.getWorkspace()));
currentWorkspace.setAccessLevel(userRole.getRole());
responseList.add(currentWorkspace);
}
}
WorkspaceResponseListResponse response = new WorkspaceResponseListResponse();
response.setItems(responseList);
return ResponseEntity.ok(response);
}
Aggregations