use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method deleteCohortAnnotationDefinition_BadCohortId.
@Test
public void deleteCohortAnnotationDefinition_BadCohortId() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long annotationDefinitionId = 1;
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.WRITER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(null);
try {
cohortAnnotationDefinitionController.deleteCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
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.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinition_NotFoundCohort.
@Test
public void getCohortAnnotationDefinition_NotFoundCohort() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long annotationDefinitionId = 1;
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(null);
try {
cohortAnnotationDefinitionController.getCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
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.READER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortAnnotationDefinitionControllerTest method getCohortAnnotationDefinition_NotFoundAnnotationDefinition.
@Test
public void getCohortAnnotationDefinition_NotFoundAnnotationDefinition() throws Exception {
String namespace = "aou-test";
String name = "test";
long cohortId = 1;
long workspaceId = 1;
long annotationDefinitionId = 1;
Cohort cohort = createCohort(workspaceId);
Workspace workspace = createWorkspace(namespace, name, workspaceId);
WorkspaceAccessLevel owner = WorkspaceAccessLevel.OWNER;
when(workspaceService.enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER)).thenReturn(owner);
when(cohortDao.findOne(cohortId)).thenReturn(cohort);
when(workspaceService.getRequired(namespace, name)).thenReturn(workspace);
when(cohortAnnotationDefinitionDao.findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId)).thenReturn(null);
try {
cohortAnnotationDefinitionController.getCohortAnnotationDefinition(namespace, name, cohortId, annotationDefinitionId);
fail("Should have thrown a NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: No Cohort Annotation Definition exists for annotationDefinitionId: " + annotationDefinitionId, e.getMessage());
}
verify(cohortDao, times(1)).findOne(cohortId);
verify(workspaceService, times(1)).getRequired(namespace, name);
verify(cohortAnnotationDefinitionDao, times(1)).findByCohortIdAndCohortAnnotationDefinitionId(cohortId, annotationDefinitionId);
verify(workspaceService).enforceWorkspaceAccessLevel(namespace, name, WorkspaceAccessLevel.READER);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class CohortReviewServiceImplTest method updateParticipantCohortAnnotationModifyNotFoundParticipantCohortAnnotation.
@Test
public void updateParticipantCohortAnnotationModifyNotFoundParticipantCohortAnnotation() throws Exception {
long annotationId = 1;
long cohortAnnotationDefinitionId = 1;
long cohortReviewId = 1;
long participantId = 1;
ModifyParticipantCohortAnnotationRequest modifyRequest = new ModifyParticipantCohortAnnotationRequest().annotationValueBoolean(Boolean.FALSE);
when(participantCohortAnnotationDao.findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId)).thenReturn(null);
try {
cohortReviewService.updateParticipantCohortAnnotation(annotationId, cohortReviewId, participantId, modifyRequest);
fail("Should have thrown NotFoundException!");
} catch (NotFoundException e) {
assertEquals("Not Found: Participant Cohort Annotation does not exist for annotationId: " + annotationId + ", cohortReviewId: " + cohortReviewId + ", participantId: " + cohortAnnotationDefinitionId, e.getMessage());
}
verify(participantCohortAnnotationDao).findByAnnotationIdAndCohortReviewIdAndParticipantId(annotationId, cohortReviewId, participantId);
verifyNoMoreMockInteractions();
}
use of org.pmiops.workbench.exceptions.NotFoundException in project workbench by all-of-us.
the class WorkspaceServiceImpl method updateUserRoles.
@Override
public Workspace updateUserRoles(Workspace workspace, Set<WorkspaceUserRole> userRoleSet) {
Map<Long, WorkspaceUserRole> userRoleMap = new HashMap<Long, WorkspaceUserRole>();
for (WorkspaceUserRole userRole : userRoleSet) {
userRole.setWorkspace(workspace);
userRoleMap.put(userRole.getUser().getUserId(), userRole);
}
ArrayList<WorkspaceACLUpdate> updateACLRequestList = new ArrayList<WorkspaceACLUpdate>();
Iterator<WorkspaceUserRole> dbUserRoles = workspace.getWorkspaceUserRoles().iterator();
while (dbUserRoles.hasNext()) {
WorkspaceUserRole currentUserRole = dbUserRoles.next();
WorkspaceUserRole mapValue = userRoleMap.get(currentUserRole.getUser().getUserId());
if (mapValue != null) {
currentUserRole.setRole(mapValue.getRole());
userRoleMap.remove(currentUserRole.getUser().getUserId());
} else {
// This is how to remove a user from the FireCloud ACL:
// Pass along an update request with NO ACCESS as the given access level.
WorkspaceACLUpdate removedUser = new WorkspaceACLUpdate();
removedUser.setEmail(currentUserRole.getUser().getEmail());
removedUser.setCanCompute(false);
removedUser.setCanShare(false);
removedUser.setAccessLevel(WorkspaceAccessLevel.NO_ACCESS.toString());
updateACLRequestList.add(removedUser);
dbUserRoles.remove();
}
}
for (Entry<Long, WorkspaceUserRole> remainingRole : userRoleMap.entrySet()) {
workspace.getWorkspaceUserRoles().add(remainingRole.getValue());
}
for (WorkspaceUserRole currentWorkspaceUser : workspace.getWorkspaceUserRoles()) {
WorkspaceACLUpdate currentUpdate = new WorkspaceACLUpdate();
currentUpdate.setEmail(currentWorkspaceUser.getUser().getEmail());
currentUpdate.setCanCompute(false);
if (currentWorkspaceUser.getRole() == WorkspaceAccessLevel.OWNER) {
currentUpdate.setCanShare(true);
currentUpdate.setAccessLevel(WorkspaceAccessLevel.OWNER.toString());
} else if (currentWorkspaceUser.getRole() == WorkspaceAccessLevel.WRITER) {
currentUpdate.setCanShare(false);
currentUpdate.setAccessLevel(WorkspaceAccessLevel.WRITER.toString());
} else {
currentUpdate.setCanShare(false);
currentUpdate.setAccessLevel(WorkspaceAccessLevel.READER.toString());
}
updateACLRequestList.add(currentUpdate);
}
try {
WorkspaceACLUpdateResponseList fireCloudResponse = fireCloudService.updateWorkspaceACL(workspace.getWorkspaceNamespace(), workspace.getFirecloudName(), updateACLRequestList);
if (fireCloudResponse.getUsersNotFound().size() != 0) {
String usersNotFound = "";
for (int i = 0; i < fireCloudResponse.getUsersNotFound().size(); i++) {
if (i > 0) {
usersNotFound += ", ";
}
usersNotFound += fireCloudResponse.getUsersNotFound().get(i).getEmail();
}
throw new BadRequestException(usersNotFound);
}
} catch (ApiException e) {
if (e.getCode() == 400) {
throw new BadRequestException(e.getResponseBody());
} else if (e.getCode() == 404) {
throw new NotFoundException("Workspace not found.");
} else if (e.getCode() == 500) {
throw new ServerErrorException(e);
} else {
throw new ServerUnavailableException(e);
}
}
return this.saveWithLastModified(workspace);
}
Aggregations