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();
}
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
}
}
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;
}
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();
}
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();
}
Aggregations