Search in sources :

Example 11 with Cohort

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

the class CohortAnnotationDefinitionControllerTest method createCohortAnnotationDefinition_NameConflict.

@Test
public void createCohortAnnotationDefinition_NameConflict() throws Exception {
    String namespace = "aou-test";
    String name = "test";
    long cohortId = 1;
    long workspaceId = 1;
    long annotationDefinitionId = 1;
    final String columnName = "testing";
    Cohort cohort = createCohort(workspaceId);
    Workspace workspace = createWorkspace(namespace, name, workspaceId);
    CohortAnnotationDefinition request = createClientCohortAnnotationDefinition(annotationDefinitionId, cohortId, columnName, AnnotationType.STRING);
    org.pmiops.workbench.db.model.CohortAnnotationDefinition existingDefinition = createDBCohortAnnotationDefinition(cohortId, annotationDefinitionId, request.getAnnotationType(), request.getColumnName());
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(cohort);
    when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
    when(cohortAnnotationDefinitionDao.findByCohortIdAndColumnName(cohortId, columnName)).thenReturn(existingDefinition);
    CohortAnnotationDefinition expectedResponse = createClientCohortAnnotationDefinition(annotationDefinitionId, cohortId, columnName, AnnotationType.STRING);
    try {
        cohortAnnotationDefinitionController.createCohortAnnotationDefinition(namespace, name, cohortId, request);
        fail("Should have thrown a ConflictException!");
    } catch (ConflictException e) {
        assertEquals("Conflict: Cohort Annotation Definition name exists for: " + columnName, e.getMessage());
    }
    verify(cohortDao, times(1)).findOne(cohortId);
    verify(workspaceService, times(1)).getRequired(namespace, name);
    verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndColumnName(cohortId, columnName);
    verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.model.CohortAnnotationDefinition) Cohort(org.pmiops.workbench.db.model.Cohort) ConflictException(org.pmiops.workbench.exceptions.ConflictException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 12 with Cohort

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

the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinition_NotFoundAnnotationDefinition.

@Test
public void getCohortAnnotationDefinition_NotFoundAnnotationDefinition() throws Exception {
    String namespace = "aou-test";
    String name = "test";
    long cohortId = 1;
    long workspaceId = 1;
    long annotationDefinitionId = 1;
    Cohort cohort = createCohort(workspaceId);
    Workspace workspace = createWorkspace(namespace, name, workspaceId);
    WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
    when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
    when(cohortDao.findOne(cohortId)).thenReturn(cohort);
    when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
    when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(null);
    try {
        cohortAnnotationDefinitionController.getCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
        fail("Should have thrown a NotFoundException!");
    } catch (NotFoundException e) {
        assertEquals("Not Found: No Cohort Annotation Definition exists for annotationDefinitionId: " + annotationDefinitionId, e.getMessage());
    }
    verify(cohortDao, times(1)).findOne(cohortId);
    verify(workspaceService, times(1)).getRequired(namespace, name);
    verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId);
    verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER);
    verifyNoMoreMockInteractions();
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 13 with Cohort

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

the class CohortDaoTest method findCohortByCohortId.

@Test
public void findCohortByCohortId() throws Exception {
    String cohortJson = "{\"includes\":[{\"items\":[{\"type\":\"DEMO\",\"searchParameters\":" + "[{\"value\":\"Age\",\"subtype\":\"AGE\",\"conceptId\":null,\"attribute\":" + "{\"operator\":\"between\",\"operands\":[18,66]}}],\"modifiers\":[]}]}],\"excludes\":[]}";
    Cohort cohort = new Cohort();
    cohort.setWorkspaceId(WORKSPACE_ID);
    cohort.setCriteria(cohortJson);
    // need to insert a workspace to satisfy the foreign key contraint of cohort
    jdbcTemplate.execute("insert into workspace" + "(workspace_id, name, workspace_namespace, firecloud_name, data_access_level, creation_time, last_modified_time)" + "values (" + WORKSPACE_ID + ", 'name', 'name', 'name', 1, sysdate(), sysdate())");
    cohortDao.save(cohort);
    assertEquals(cohortJson, cohort.getCriteria());
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 14 with Cohort

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

the class CohortReviewDaoTest method setup.

@Before
public void setup() throws Exception {
    Cohort cohort = new Cohort();
    cohort.setWorkspaceId(workspaceDao.save(new Workspace()).getWorkspaceId());
    cohortId = cohortDao.save(cohort).getCohortId();
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) Workspace(org.pmiops.workbench.db.model.Workspace) Before(org.junit.Before)

Example 15 with Cohort

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

the class CohortService method saveAndCloneReviews.

@Transactional
public Cohort saveAndCloneReviews(Cohort from, Cohort to) {
    Cohort saved = cohortDao.save(to);
    for (CohortReview fromReview : from.getCohortReviews()) {
        CohortReview cr = new CohortReview();
        cr.setCohortId(saved.getCohortId());
        cr.creationTime(saved.getCreationTime());
        cr.setLastModifiedTime(saved.getLastModifiedTime());
        cr.setCdrVersionId(fromReview.getCdrVersionId());
        cr.setMatchedParticipantCount(fromReview.getMatchedParticipantCount());
        cr.setReviewSize(fromReview.getReviewSize());
        cr.setReviewedCount(fromReview.getReviewedCount());
        cr.setReviewStatus(fromReview.getReviewStatus());
        cr = cohortReviewDao.save(cr);
        participantCohortStatusDao.bulkCopyByCohortReview(fromReview.getCohortReviewId(), cr.getCohortReviewId());
    }
    return saved;
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) CohortReview(org.pmiops.workbench.db.model.CohortReview) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Cohort (org.pmiops.workbench.db.model.Cohort)33 Workspace (org.pmiops.workbench.db.model.Workspace)23 Test (org.junit.Test)17 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)15 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)10 CohortReview (org.pmiops.workbench.db.model.CohortReview)6 CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)6 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)4 ConflictException (org.pmiops.workbench.exceptions.ConflictException)4 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)4 Before (org.junit.Before)3 org.pmiops.workbench.model (org.pmiops.workbench.model)3 Gson (com.google.gson.Gson)2 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)2 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)2 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)2 EmptyResponse (org.pmiops.workbench.model.EmptyResponse)2 Transactional (org.springframework.transaction.annotation.Transactional)2 QueryResult (com.google.cloud.bigquery.QueryResult)1 Date (java.sql.Date)1