Search in sources :

Example 6 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testCloneWorkspaceWithNotebooks.

@Test
public void testCloneWorkspaceWithNotebooks() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    req.setWorkspace(modWorkspace);
    org.pmiops.workbench.firecloud.model.Workspace fcWorkspace = createFcWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL);
    fcWorkspace.setBucketName("bucket2");
    stubGetWorkspace(fcWorkspace, WorkspaceAccessLevel.OWNER);
    String f1 = "notebooks/f1.ipynb";
    String f2 = "notebooks/f2.ipynb";
    String f3 = "notebooks/f3.vcf";
    // Note: mockBlob cannot be inlined into thenReturn() due to Mockito nuances.
    List<Blob> blobs = ImmutableList.of(mockBlob(BUCKET_NAME, f1), mockBlob(BUCKET_NAME, f2), mockBlob(BUCKET_NAME, f3));
    when(cloudStorageService.getBlobList(BUCKET_NAME, "notebooks")).thenReturn(blobs);
    workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
    verify(cloudStorageService).copyBlob(BlobId.of(BUCKET_NAME, f1), BlobId.of("bucket2", f1));
    verify(cloudStorageService).copyBlob(BlobId.of(BUCKET_NAME, f2), BlobId.of("bucket2", f2));
    verify(cloudStorageService, never()).copyBlob(BlobId.of(BUCKET_NAME, f3), BlobId.of("bucket2", f3));
}
Also used : Blob(com.google.cloud.storage.Blob) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) Matchers.anyString(org.mockito.Matchers.anyString) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 7 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testRejectAfterApproveThrows.

@Test(expected = BadRequestException.class)
public void testRejectAfterApproveThrows() throws Exception {
    Workspace ws = createDefaultWorkspace();
    ResearchPurpose researchPurpose = ws.getResearchPurpose();
    workspacesController.createWorkspace(ws);
    ResearchPurposeReviewRequest request = new ResearchPurposeReviewRequest();
    request.setApproved(true);
    workspacesController.reviewWorkspace(ws.getNamespace(), ws.getName(), request);
    request.setApproved(false);
    workspacesController.reviewWorkspace(ws.getNamespace(), ws.getName(), request);
}
Also used : ResearchPurposeReviewRequest(org.pmiops.workbench.model.ResearchPurposeReviewRequest) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 8 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class CohortsControllerTest method setUp.

@Before
public void setUp() throws Exception {
    User user = new User();
    user.setEmail("bob@gmail.com");
    user.setUserId(123L);
    user.setDisabled(false);
    user.setEmailVerificationStatus(EmailVerificationStatus.SUBSCRIBED);
    user = userDao.save(user);
    when(userProvider.get()).thenReturn(user);
    cdrVersion = new CdrVersion();
    cdrVersion.setName(CDR_VERSION_NAME);
    cdrVersionDao.save(cdrVersion);
    searchRequest = SearchRequests.males();
    cohortCriteria = new Gson().toJson(searchRequest);
    workspace = new Workspace();
    workspace.setName(WORKSPACE_NAME);
    workspace.setNamespace(WORKSPACE_NAMESPACE);
    workspace.setDataAccessLevel(DataAccessLevel.PROTECTED);
    workspace.setResearchPurpose(new ResearchPurpose());
    workspace.setCdrVersionId(String.valueOf(cdrVersion.getCdrVersionId()));
    CLOCK.setInstant(NOW);
    WorkspacesController workspacesController = new WorkspacesController(workspaceService, cdrVersionDao, userDao, userProvider, fireCloudService, cloudStorageService, CLOCK, "https://api.blah.com", userService);
    stubGetWorkspace(WORKSPACE_NAMESPACE, WORKSPACE_NAME, "bob@gmail.com", WorkspaceAccessLevel.OWNER);
    workspace = workspacesController.createWorkspace(workspace).getBody();
    this.cohortsController = new CohortsController(workspaceService, cohortDao, cdrVersionDao, cohortReviewDao, cohortMaterializationService, userProvider, CLOCK);
}
Also used : CdrVersion(org.pmiops.workbench.db.model.CdrVersion) User(org.pmiops.workbench.db.model.User) Gson(com.google.gson.Gson) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) Before(org.junit.Before)

Example 9 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testCloneWorkspaceWithCohorts.

@Test
public void testCloneWorkspaceWithCohorts() throws Exception {
    CdrVersionContext.setCdrVersion(cdrVersion);
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    Cohort c1 = createDefaultCohort("c1");
    c1 = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), c1).getBody();
    Cohort c2 = createDefaultCohort("c2");
    c2 = cohortsController.createCohort(workspace.getNamespace(), workspace.getId(), c2).getBody();
    stubBigQueryCohortCalls();
    CreateReviewRequest reviewReq = new CreateReviewRequest();
    reviewReq.setSize(1);
    CohortReview cr1 = cohortReviewController.createCohortReview(workspace.getNamespace(), workspace.getId(), c1.getId(), cdrVersion.getCdrVersionId(), reviewReq).getBody();
    reviewReq.setSize(2);
    CohortReview cr2 = cohortReviewController.createCohortReview(workspace.getNamespace(), workspace.getId(), c2.getId(), cdrVersion.getCdrVersionId(), reviewReq).getBody();
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    req.setWorkspace(modWorkspace);
    stubGetWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    Workspace cloned = workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
    List<Cohort> cohorts = cohortsController.getCohortsInWorkspace(cloned.getNamespace(), cloned.getId()).getBody().getItems();
    Map<String, Cohort> cohortsByName = Maps.uniqueIndex(cohorts, c -> c.getName());
    assertThat(cohortsByName.keySet()).containsExactlyElementsIn(ImmutableSet.of("c1", "c2"));
    assertThat(cohorts.stream().map(c -> c.getId()).collect(Collectors.toList())).containsNoneOf(c1.getId(), c2.getId());
    CohortReview gotCr1 = cohortReviewController.getParticipantCohortStatuses(cloned.getNamespace(), cloned.getId(), cohortsByName.get("c1").getId(), cdrVersion.getCdrVersionId(), new ParticipantCohortStatuses().pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES)).getBody();
    assertThat(gotCr1.getReviewSize()).isEqualTo(cr1.getReviewSize());
    assertThat(gotCr1.getParticipantCohortStatuses()).isEqualTo(cr1.getParticipantCohortStatuses());
    CohortReview gotCr2 = cohortReviewController.getParticipantCohortStatuses(cloned.getNamespace(), cloned.getId(), cohortsByName.get("c2").getId(), cdrVersion.getCdrVersionId(), new ParticipantCohortStatuses().pageFilterType(PageFilterType.PARTICIPANTCOHORTSTATUSES)).getBody();
    assertThat(gotCr2.getReviewSize()).isEqualTo(cr2.getReviewSize());
    assertThat(gotCr2.getParticipantCohortStatuses()).isEqualTo(cr2.getParticipantCohortStatuses());
    assertThat(ImmutableSet.of(gotCr1.getCohortReviewId(), gotCr2.getCohortReviewId())).containsNoneOf(cr1.getCohortReviewId(), cr2.getCohortId());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) FieldValue(com.google.cloud.bigquery.FieldValue) Provider(javax.inject.Provider) ReviewTabQueryBuilder(org.pmiops.workbench.cohortreview.ReviewTabQueryBuilder) FireCloudService(org.pmiops.workbench.firecloud.FireCloudService) GenderRaceEthnicityType(org.pmiops.workbench.cdr.cache.GenderRaceEthnicityType) Autowired(org.springframework.beans.factory.annotation.Autowired) BlobId(com.google.cloud.storage.BlobId) ShareWorkspaceResponse(org.pmiops.workbench.model.ShareWorkspaceResponse) CohortReviewServiceImpl(org.pmiops.workbench.cohortreview.CohortReviewServiceImpl) PageFilterType(org.pmiops.workbench.model.PageFilterType) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) TestConfiguration(org.springframework.boot.test.context.TestConfiguration) Blob(com.google.cloud.storage.Blob) GenderRaceEthnicityConcept(org.pmiops.workbench.cdr.cache.GenderRaceEthnicityConcept) org.pmiops.workbench.db.dao(org.pmiops.workbench.db.dao) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) Gson(com.google.gson.Gson) Map(java.util.Map) WorkspaceACLUpdate(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate) CloudStorageService(org.pmiops.workbench.google.CloudStorageService) WorkspaceACLUpdateResponseList(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList) SpringRunner(org.springframework.test.context.junit4.SpringRunner) User(org.pmiops.workbench.db.model.User) MockBean(org.springframework.boot.test.mock.mockito.MockBean) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Timestamp(java.sql.Timestamp) CdrVersion(org.pmiops.workbench.db.model.CdrVersion) Cohort(org.pmiops.workbench.model.Cohort) ConflictException(org.pmiops.workbench.exceptions.ConflictException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) UpdateWorkspaceRequest(org.pmiops.workbench.model.UpdateWorkspaceRequest) List(java.util.List) CohortMaterializationService(org.pmiops.workbench.cohorts.CohortMaterializationService) AutoConfigureTestDatabase(org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase) CreateReviewRequest(org.pmiops.workbench.model.CreateReviewRequest) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) ResearchPurposeReviewRequest(org.pmiops.workbench.model.ResearchPurposeReviewRequest) QueryResult(com.google.cloud.bigquery.QueryResult) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) ShareWorkspaceRequest(org.pmiops.workbench.model.ShareWorkspaceRequest) TestCase.assertEquals(junit.framework.TestCase.assertEquals) UserRole(org.pmiops.workbench.model.UserRole) ParticipantCohortStatuses(org.pmiops.workbench.model.ParticipantCohortStatuses) Mock(org.mockito.Mock) Workspace(org.pmiops.workbench.model.Workspace) RunWith(org.junit.runner.RunWith) ApiException(org.pmiops.workbench.firecloud.ApiException) HashMap(java.util.HashMap) LiquibaseAutoConfiguration(org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) SearchRequests(org.pmiops.workbench.test.SearchRequests) ParticipantCounter(org.pmiops.workbench.cohortbuilder.ParticipantCounter) ImmutableList(com.google.common.collect.ImmutableList) CohortReview(org.pmiops.workbench.model.CohortReview) Propagation(org.springframework.transaction.annotation.Propagation) FailedPreconditionException(org.pmiops.workbench.exceptions.FailedPreconditionException) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Before(org.junit.Before) CdrVersionContext(org.pmiops.workbench.cdr.CdrVersionContext) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) Iterator(java.util.Iterator) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) Matchers.anyListOf(org.mockito.Matchers.anyListOf) TestCase.fail(junit.framework.TestCase.fail) Import(org.springframework.context.annotation.Import) Test(org.junit.Test) FileDetail(org.pmiops.workbench.model.FileDetail) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) FakeClock(org.pmiops.workbench.test.FakeClock) Mockito(org.mockito.Mockito) DataAccessLevel(org.pmiops.workbench.model.DataAccessLevel) ForbiddenException(org.pmiops.workbench.exceptions.ForbiddenException) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) EmailVerificationStatus(org.pmiops.workbench.model.EmailVerificationStatus) Clock(java.time.Clock) Bean(org.springframework.context.annotation.Bean) Transactional(org.springframework.transaction.annotation.Transactional) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) Cohort(org.pmiops.workbench.model.Cohort) CreateReviewRequest(org.pmiops.workbench.model.CreateReviewRequest) CohortReview(org.pmiops.workbench.model.CohortReview) Matchers.anyString(org.mockito.Matchers.anyString) Workspace(org.pmiops.workbench.model.Workspace) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) ParticipantCohortStatuses(org.pmiops.workbench.model.ParticipantCohortStatuses) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Example 10 with ResearchPurpose

use of org.pmiops.workbench.model.ResearchPurpose in project workbench by all-of-us.

the class WorkspacesControllerTest method testCloneWorkspace.

@Test
public void testCloneWorkspace() throws Exception {
    Workspace workspace = createDefaultWorkspace();
    workspace = workspacesController.createWorkspace(workspace).getBody();
    // The original workspace is shared with one other user.
    User writerUser = new User();
    writerUser.setEmail("writerfriend@gmail.com");
    writerUser.setUserId(124L);
    writerUser.setFreeTierBillingProjectName("TestBillingProject2");
    writerUser.setDisabled(false);
    writerUser = userDao.save(writerUser);
    ShareWorkspaceRequest shareWorkspaceRequest = new ShareWorkspaceRequest();
    shareWorkspaceRequest.setWorkspaceEtag(workspace.getEtag());
    UserRole creator = new UserRole();
    creator.setEmail(LOGGED_IN_USER_EMAIL);
    creator.setRole(WorkspaceAccessLevel.OWNER);
    shareWorkspaceRequest.addItemsItem(creator);
    UserRole writer = new UserRole();
    writer.setEmail(writerUser.getEmail());
    writer.setRole(WorkspaceAccessLevel.WRITER);
    shareWorkspaceRequest.addItemsItem(writer);
    when(fireCloudService.updateWorkspaceACL(anyString(), anyString(), anyListOf(WorkspaceACLUpdate.class))).thenReturn(new WorkspaceACLUpdateResponseList());
    workspacesController.shareWorkspace(workspace.getNamespace(), workspace.getName(), shareWorkspaceRequest);
    stubGetWorkspace(workspace.getNamespace(), workspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    CloneWorkspaceRequest req = new CloneWorkspaceRequest();
    Workspace modWorkspace = new Workspace();
    modWorkspace.setName("cloned");
    modWorkspace.setNamespace("cloned-ns");
    ResearchPurpose modPurpose = new ResearchPurpose();
    modPurpose.setAncestry(true);
    modWorkspace.setResearchPurpose(modPurpose);
    req.setWorkspace(modWorkspace);
    stubGetWorkspace(modWorkspace.getNamespace(), modWorkspace.getName(), LOGGED_IN_USER_EMAIL, WorkspaceAccessLevel.OWNER);
    Workspace workspace2 = workspacesController.cloneWorkspace(workspace.getNamespace(), workspace.getId(), req).getBody().getWorkspace();
    assertWithMessage("get and clone responses are inconsistent").that(workspace2).isEqualTo(workspacesController.getWorkspace(workspace2.getNamespace(), workspace2.getId()).getBody().getWorkspace());
    assertThat(workspace2.getName()).isEqualTo(modWorkspace.getName());
    assertThat(workspace2.getNamespace()).isEqualTo(modWorkspace.getNamespace());
    assertThat(workspace2.getResearchPurpose()).isEqualTo(modPurpose);
    // Original description should have been copied.
    assertThat(workspace2.getDescription()).isEqualTo(workspace.getDescription());
    // User roles should *not* be copied.
    assertThat(workspace2.getUserRoles().size()).isEqualTo(1);
    assertThat(workspace2.getUserRoles().get(0).getRole()).isEqualTo(WorkspaceAccessLevel.OWNER);
}
Also used : User(org.pmiops.workbench.db.model.User) CloneWorkspaceRequest(org.pmiops.workbench.model.CloneWorkspaceRequest) UserRole(org.pmiops.workbench.model.UserRole) WorkspaceACLUpdateResponseList(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdateResponseList) ShareWorkspaceRequest(org.pmiops.workbench.model.ShareWorkspaceRequest) Workspace(org.pmiops.workbench.model.Workspace) WorkspaceACLUpdate(org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate) ResearchPurpose(org.pmiops.workbench.model.ResearchPurpose) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Test(org.junit.Test)

Aggregations

ResearchPurpose (org.pmiops.workbench.model.ResearchPurpose)13 Workspace (org.pmiops.workbench.model.Workspace)13 Test (org.junit.Test)10 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)10 CloneWorkspaceRequest (org.pmiops.workbench.model.CloneWorkspaceRequest)7 User (org.pmiops.workbench.db.model.User)6 Blob (com.google.cloud.storage.Blob)4 ApiException (org.pmiops.workbench.firecloud.ApiException)4 ResearchPurposeReviewRequest (org.pmiops.workbench.model.ResearchPurposeReviewRequest)4 UserRole (org.pmiops.workbench.model.UserRole)3 Gson (com.google.gson.Gson)2 Timestamp (java.sql.Timestamp)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)2 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)2 ConflictException (org.pmiops.workbench.exceptions.ConflictException)2 FailedPreconditionException (org.pmiops.workbench.exceptions.FailedPreconditionException)2 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)2 WorkspaceACLUpdate (org.pmiops.workbench.firecloud.model.WorkspaceACLUpdate)2