use of org.pmiops.workbench.model.WorkspaceAccessLevel 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.model.WorkspaceAccessLevel in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method updateCohortAnnotationDefinition_BadCohortId.
@Test
public void updateCohortAnnotationDefinition_BadCohortId() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long annotationDefinitionId = 1;
ModifyCohortAnnotationDefinitionRequest request = new ModifyCohortAnnotationDefinitionRequest();
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(null);
try {
cohortAnnotationDefinitionController.updateCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId, request);
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No Cohort exists for cohortId: " + cohortId, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.model.WorkspaceAccessLevel 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.model.WorkspaceAccessLevel in project workbench by all-of-us.
the class WorkspaceServiceImpl method getWorkspaceAccessLevel.
@Override
public WorkspaceAccessLevel getWorkspaceAccessLevel(String workspaceNamespace, String workspaceId) {
String userAccess;
try {
userAccess = fireCloudService.getWorkspace(workspaceNamespace, workspaceId).getAccessLevel();
} catch (org.pmiops.workbench.firecloud.ApiException e) {
if (e.getCode() == 404) {
throw new NotFoundException(String.format("Workspace %s/%s not found", workspaceNamespace, workspaceId));
} else {
throw new ServerErrorException(e.getResponseBody());
}
}
if (userAccess.equals(PROJECT_OWNER_ACCESS_LEVEL)) {
return WorkspaceAccessLevel.OWNER;
}
WorkspaceAccessLevel result = WorkspaceAccessLevel.fromValue(userAccess);
if (result == null) {
throw new ServerErrorException("Unrecognized access level: " + userAccess);
}
return result;
}
Aggregations