Search in sources :

Example 1 with WorkspaceResponse

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);
}
Also used : ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) CloneWorkspaceResponse(org.pmiops.workbench.model.CloneWorkspaceResponse) WorkspaceResponse(org.pmiops.workbench.model.WorkspaceResponse) ApiException(org.pmiops.workbench.firecloud.ApiException) ServerErrorException(org.pmiops.workbench.exceptions.ServerErrorException)

Example 2 with WorkspaceResponse

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);
}
Also used : ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) CloneWorkspaceResponse(org.pmiops.workbench.model.CloneWorkspaceResponse) WorkspaceResponse(org.pmiops.workbench.model.WorkspaceResponse) User(org.pmiops.workbench.db.model.User) WorkspaceResponseListResponse(org.pmiops.workbench.model.WorkspaceResponseListResponse) ArrayList(java.util.ArrayList) WorkspaceUserRole(org.pmiops.workbench.db.model.WorkspaceUserRole)

Aggregations

CloneWorkspaceResponse (org.pmiops.workbench.model.CloneWorkspaceResponse)2 ShareWorkspaceResponse (org.pmiops.workbench.model.ShareWorkspaceResponse)2 WorkspaceResponse (org.pmiops.workbench.model.WorkspaceResponse)2 ArrayList (java.util.ArrayList)1 User (org.pmiops.workbench.db.model.User)1 WorkspaceUserRole (org.pmiops.workbench.db.model.WorkspaceUserRole)1 ServerErrorException (org.pmiops.workbench.exceptions.ServerErrorException)1 ApiException (org.pmiops.workbench.firecloud.ApiException)1 WorkspaceResponseListResponse (org.pmiops.workbench.model.WorkspaceResponseListResponse)1