Search in sources :

Example 16 with Workspace

use of org.pmiops.workbench.db.model.Workspace 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 17 with Workspace

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

the class WorkspaceDaoTest method testWorkspaceVersionLocking.

@Test
public void testWorkspaceVersionLocking() {
    Workspace ws = new Workspace();
    ws.setVersion(1);
    ws = workspaceDao.save(ws);
    // Version incremented to 2.
    ws.setName("foo");
    ws = workspaceDao.save(ws);
    try {
        ws.setName("bar");
        ws.setVersion(1);
        workspaceDao.save(ws);
        fail("expected optimistic lock exception on stale version update");
    } catch (ObjectOptimisticLockingFailureException e) {
    // expected
    }
}
Also used : Workspace(org.pmiops.workbench.db.model.Workspace) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 18 with Workspace

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

the class WorkspaceServiceImpl method saveAndCloneCohorts.

@Override
@Transactional
public Workspace saveAndCloneCohorts(Workspace from, Workspace to) {
    // Save the workspace first to allocate an ID.
    Workspace saved = workspaceDao.save(to);
    for (Cohort fromCohort : from.getCohorts()) {
        Cohort c = new Cohort();
        c.setCriteria(fromCohort.getCriteria());
        c.setDescription(fromCohort.getDescription());
        c.setName(fromCohort.getName());
        c.setType(fromCohort.getType());
        c.setCreator(saved.getCreator());
        c.setWorkspaceId(saved.getWorkspaceId());
        c.setCreationTime(saved.getCreationTime());
        c.setLastModifiedTime(saved.getLastModifiedTime());
        c.setVersion(1);
        cohortService.saveAndCloneReviews(fromCohort, c);
    }
    return saved;
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) Workspace(org.pmiops.workbench.db.model.Workspace) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with Workspace

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

the class CohortReviewControllerTest method assertCreateParticipantCohortAnnotation.

private void assertCreateParticipantCohortAnnotation(ParticipantCohortAnnotation request, AnnotationType annotationType) throws Exception {
    ParticipantCohortStatusKey key = new ParticipantCohortStatusKey().cohortReviewId(cohortReviewId).participantId(participantId);
    ParticipantCohortStatus participantCohortStatus = new ParticipantCohortStatus().participantKey(key);
    CohortAnnotationDefinition cohortAnnotationDefinition = new CohortAnnotationDefinition().annotationType(annotationType);
    if (request.getAnnotationValueEnum() != null) {
        CohortAnnotationEnumValue cohortAnnotationEnumValue = new CohortAnnotationEnumValue().name(request.getAnnotationValueEnum());
        cohortAnnotationDefinition.setEnumValues(new TreeSet(Arrays.asList(cohortAnnotationEnumValue)));
    }
    when(cohortReviewService.findCohort(cohortId)).thenReturn(createCohort(cohortId, workspaceId, null));
    when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER)).thenReturn(new Workspace());
    when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(createCohortReview(0, cohortId, cohortReviewId, cdrVersionId, null));
    when(cohortReviewService.saveParticipantCohortAnnotation(isA(Long.class), isA(org.pmiops.workbench.db.model.ParticipantCohortAnnotation.class))).thenReturn(createParticipantCohortAnnotation(request));
    ParticipantCohortAnnotation response = reviewController.createParticipantCohortAnnotation(namespace, name, cohortId, cdrVersionId, participantId, request).getBody();
    assertEquals(request, response);
    verify(cohortReviewService, atLeastOnce()).findCohort(cohortId);
    verify(cohortReviewService, atLeastOnce()).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER);
    verify(cohortReviewService, atLeastOnce()).findCohortReview(cohortId, cdrVersionId);
    verify(cohortReviewService, atLeastOnce()).saveParticipantCohortAnnotation(isA(Long.class), isA(org.pmiops.workbench.db.model.ParticipantCohortAnnotation.class));
    verifyNoMoreMockInteractions();
}
Also used : CohortAnnotationDefinition(org.pmiops.workbench.db.model.CohortAnnotationDefinition) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) TreeSet(java.util.TreeSet) ParticipantCohortStatusKey(org.pmiops.workbench.db.model.ParticipantCohortStatusKey) CohortAnnotationEnumValue(org.pmiops.workbench.db.model.CohortAnnotationEnumValue) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 20 with Workspace

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

the class CohortReviewControllerTest method updateParticipantCohortAnnotation.

@Test
public void updateParticipantCohortAnnotation() throws Exception {
    long annotationId = 1;
    long cohortReviewId = 1;
    ModifyParticipantCohortAnnotationRequest request = new ModifyParticipantCohortAnnotationRequest();
    when(cohortReviewService.findCohort(cohortId)).thenReturn(createCohort(cohortId, workspaceId, null));
    when(cohortReviewService.validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER)).thenReturn(new Workspace());
    when(cohortReviewService.findCohortReview(cohortId, cdrVersionId)).thenReturn(createCohortReview(0, cohortId, cohortReviewId, cdrVersionId, null));
    when(cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, request)).thenReturn(new org.pmiops.workbench.db.model.ParticipantCohortAnnotation());
    reviewController.updateParticipantCohortAnnotation(namespace, name, cohortId, cdrVersionId, participantId, 1L, request);
    verify(cohortReviewService).findCohort(cohortId);
    verify(cohortReviewService).validateMatchingWorkspace(namespace, name, workspaceId, WorkspaceAccessLevel.WRITER);
    verify(cohortReviewService).findCohortReview(cohortId, cdrVersionId);
    verify(cohortReviewService).updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, request);
    verifyNoMoreMockInteractions();
}
Also used : org.pmiops.workbench.model(org.pmiops.workbench.model) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Aggregations

Workspace (org.pmiops.workbench.db.model.Workspace)38 Cohort (org.pmiops.workbench.db.model.Cohort)23 Test (org.junit.Test)21 WorkspaceAccessLevel (org.pmiops.workbench.model.WorkspaceAccessLevel)18 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)15 CohortReview (org.pmiops.workbench.db.model.CohortReview)7 ParticipantCohortStatus (org.pmiops.workbench.db.model.ParticipantCohortStatus)6 BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)5 CohortAnnotationDefinition (org.pmiops.workbench.model.CohortAnnotationDefinition)5 Gson (com.google.gson.Gson)4 Timestamp (java.sql.Timestamp)4 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)4 org.pmiops.workbench.model (org.pmiops.workbench.model)4 ModifyCohortAnnotationDefinitionRequest (org.pmiops.workbench.model.ModifyCohortAnnotationDefinitionRequest)4 Before (org.junit.Before)3 ConflictException (org.pmiops.workbench.exceptions.ConflictException)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 PageRequest (org.pmiops.workbench.cohortreview.util.PageRequest)2 ParticipantCohortStatusKey (org.pmiops.workbench.db.model.ParticipantCohortStatusKey)2 EmptyResponse (org.pmiops.workbench.model.EmptyResponse)2