Search in sources :

Example 26 with Cohort

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

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

the class CohortAnnotationDefinitionController method getCohortAnnotationDefinitions.

@Override
public ResponseEntity<CohortAnnotationDefinitionListResponse> getCohortAnnotationDefinitions(String workspaceNamespace, String workspaceId, Long cohortId) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.READER);
    Cohort cohort = findCohort(cohortId);
    // this validates that the user is in the proper workspace
    validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId());
    List<org.pmiops.workbench.db.model.CohortAnnotationDefinition> dbList = cohortAnnotationDefinitionDao.findByCohortId(cohortId);
    CohortAnnotationDefinitionListResponse responseList = new CohortAnnotationDefinitionListResponse();
    responseList.setItems(dbList.stream().map(TO_CLIENT_COHORT_ANNOTATION_DEFINITION).collect(Collectors.toList()));
    return ResponseEntity.ok(responseList);
}
Also used : CohortAnnotationDefinitionListResponse(org.pmiops.workbench.model.CohortAnnotationDefinitionListResponse) CohortAnnotationDefinition(org.pmiops.workbench.model.CohortAnnotationDefinition) Cohort(org.pmiops.workbench.db.model.Cohort)

Example 28 with Cohort

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

the class CohortAnnotationDefinitionController method createCohortAnnotationDefinition.

@Override
public ResponseEntity<CohortAnnotationDefinition> createCohortAnnotationDefinition(String workspaceNamespace, String workspaceId, Long cohortId, CohortAnnotationDefinition request) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.WRITER);
    Cohort cohort = findCohort(cohortId);
    // this validates that the user is in the proper workspace
    validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId());
    request.setCohortId(cohortId);
    org.pmiops.workbench.db.model.CohortAnnotationDefinition cohortAnnotationDefinition = FROM_CLIENT_COHORT_ANNOTATION_DEFINITION.apply(request);
    org.pmiops.workbench.db.model.CohortAnnotationDefinition existingDefinition = cohortAnnotationDefinitionDao.findByCohortIdAndColumnName(cohortId, request.getColumnName());
    if (existingDefinition != null) {
        throw new ConflictException(String.format("Conflict: Cohort Annotation Definition name exists for: %s", request.getColumnName()));
    }
    cohortAnnotationDefinition = cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    return ResponseEntity.ok(TO_CLIENT_COHORT_ANNOTATION_DEFINITION.apply(cohortAnnotationDefinition));
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) ConflictException(org.pmiops.workbench.exceptions.ConflictException)

Example 29 with Cohort

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

the class CohortAnnotationDefinitionController method deleteCohortAnnotationDefinition.

@Override
public ResponseEntity<EmptyResponse> deleteCohortAnnotationDefinition(String workspaceNamespace, String workspaceId, Long cohortId, Long annotationDefinitionId) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.WRITER);
    Cohort cohort = findCohort(cohortId);
    // this validates that the user is in the proper workspace
    validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId());
    findCohortAnnotationDefinition(cohortId, annotationDefinitionId);
    cohortAnnotationDefinitionDao.delete(annotationDefinitionId);
    return ResponseEntity.ok(new EmptyResponse());
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) EmptyResponse(org.pmiops.workbench.model.EmptyResponse)

Example 30 with Cohort

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

the class CohortAnnotationDefinitionController method updateCohortAnnotationDefinition.

@Override
public ResponseEntity<CohortAnnotationDefinition> updateCohortAnnotationDefinition(String workspaceNamespace, String workspaceId, Long cohortId, Long annotationDefinitionId, ModifyCohortAnnotationDefinitionRequest modifyCohortAnnotationDefinitionRequest) {
    // This also enforces registered auth domain.
    workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.WRITER);
    String columnName = modifyCohortAnnotationDefinitionRequest.getColumnName();
    Cohort cohort = findCohort(cohortId);
    // this validates that the user is in the proper workspace
    validateMatchingWorkspace(workspaceNamespace, workspaceId, cohort.getWorkspaceId());
    org.pmiops.workbench.db.model.CohortAnnotationDefinition cohortAnnotationDefinition = findCohortAnnotationDefinition(cohortId, annotationDefinitionId);
    org.pmiops.workbench.db.model.CohortAnnotationDefinition existingDefinition = cohortAnnotationDefinitionDao.findByCohortIdAndColumnName(cohortId, columnName);
    if (existingDefinition != null) {
        throw new ConflictException(String.format("Conflict: Cohort Annotation Definition name exists for: %s", columnName));
    }
    cohortAnnotationDefinition.columnName(columnName);
    cohortAnnotationDefinition = cohortAnnotationDefinitionDao.save(cohortAnnotationDefinition);
    return ResponseEntity.ok(TO_CLIENT_COHORT_ANNOTATION_DEFINITION.apply(cohortAnnotationDefinition));
}
Also used : Cohort(org.pmiops.workbench.db.model.Cohort) ConflictException(org.pmiops.workbench.exceptions.ConflictException)

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