use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method deleteCohortAnnotationDefinition_BadWorkspace.
@Test
public void deleteCohortAnnotationDefinition_BadWorkspace() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long annotationDefinitionId = 1;
long workspaceId = 1;
long badWorkspaceId = 0;
Cohort cohort = createCohort(workspaceId);
Workspace workspace = createWorkspace(namespace, name, badWorkspaceId);
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);
try {
cohortAnnotationDefinitionController.deleteCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No workspace matching workspaceNamespace: " + namespace + ", workspaceId: " + name, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinitions.
@Test
public void getCohortAnnotationDefinitions() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long workspaceId = 1;
Cohort cohort = createCohort(workspaceId);
Workspace workspace = createWorkspace(namespace, name, workspaceId);
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(cohortDao.findOne(cohortId)).thenReturn(cohort);
when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
when(cohortAnnotationDefinitionDao.findByCohortId(cohortId)).thenReturn(new ArrayList<>());
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
cohortAnnotationDefinitionController.getCohortAnnotationDefinitions(namespace, name, cohortId);
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(cohortAnnotationDefinitionDao, times(1)).findByCohortId(cohortId);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class WorkspaceServiceImpl method setResearchPurposeApproved.
@Override
public void setResearchPurposeApproved(String ns, String firecloudName, boolean approved) {
Workspace workspace = getRequired(ns, firecloudName);
if (workspace.getReviewRequested() == null || !workspace.getReviewRequested()) {
throw new BadRequestException(String.format("No review requested for workspace %s/%s.", ns, firecloudName));
}
if (workspace.getApproved() != null) {
throw new BadRequestException(String.format("Workspace %s/%s already %s.", ns, firecloudName, workspace.getApproved() ? "approved" : "rejected"));
}
Timestamp now = new Timestamp(clock.instant().toEpochMilli());
workspace.setApproved(approved);
saveWithLastModified(workspace, now);
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortReviewController method validateRequestAndSetCdrVersion.
private CohortReview validateRequestAndSetCdrVersion(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, WorkspaceAccessLevel level) {
Cohort cohort = cohortReviewService.findCohort(cohortId);
// this validates that the user is in the proper workspace
Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), level);
CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
return cohortReviewService.findCohortReview(cohort.getCohortId(), cdrVersionId);
}
use of org.pmiops.workbench.db.model.Workspace in project workbench by all-of-us.
the class CohortReviewController method getParticipantCohortStatuses.
/**
* Get all participants for the specified cohortId and cdrVersionId. This endpoint does pagination
* based on page, pageSize, sortOrder and sortColumn.
*/
@Override
public ResponseEntity<org.pmiops.workbench.model.CohortReview> getParticipantCohortStatuses(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, PageFilterRequest request) {
CohortReview cohortReview = null;
Cohort cohort = cohortReviewService.findCohort(cohortId);
Workspace workspace = cohortReviewService.validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId(), WorkspaceAccessLevel.READER);
CdrVersionContext.setCdrVersion(workspace.getCdrVersion());
try {
cohortReview = cohortReviewService.findCohortReview(cohortId, cdrVersionId);
} catch (NotFoundException nfe) {
cohortReview = initializeCohortReview(cdrVersionId, cohort);
}
PageRequest pageRequest = createPageRequest(request);
List<Filter> filters = request.getFilters() == null ? Collections.<Filter>emptyList() : request.getFilters().getItems();
List<ParticipantCohortStatus> participantCohortStatuses = cohortReviewService.findAll(cohortReview.getCohortReviewId(), filters, pageRequest);
org.pmiops.workbench.model.CohortReview responseReview = TO_CLIENT_COHORTREVIEW.apply(cohortReview, pageRequest);
responseReview.setParticipantCohortStatuses(participantCohortStatuses.stream().map(TO_CLIENT_PARTICIPANT).collect(Collectors.toList()));
return ResponseEntity.ok(responseReview);
}
Aggregations