Search in sources :

Example 31 with Workspace

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();
}
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 32 with Workspace

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();
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) WorkspaceAccessLevel(org.pmiops.workbench.model.WorkspaceAccessLevel) Workspace(org.pmiops.workbench.db.model.Workspace) Test(org.junit.Test)

Example 33 with Workspace

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);
}
Also used : BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) Timestamp(java.sql.Timestamp) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 34 with Workspace

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);
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 35 with Workspace

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);
}
Also used : PageRequest(org.pmiops.workbench.cohortreview.util.PageRequest) Cohort(org.pmiops.workbench.db.model.Cohort) ParticipantCohortStatus(org.pmiops.workbench.db.model.ParticipantCohortStatus) NotFoundException(org.pmiops.workbench.exceptions.NotFoundException) org.pmiops.workbench.model(org.pmiops.workbench.model) CohortReview(org.pmiops.workbench.db.model.CohortReview) Workspace(org.pmiops.workbench.db.model.Workspace)

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