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