use of org.pmiops.workbench.exceptions.BadRequestException 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);
}
use of org.pmiops.workbench.exceptions.BadRequestException in project workbench by all-of-us.
the class CohortReviewController method createParticipantCohortAnnotation.
@Override
public ResponseEntity<ParticipantCohortAnnotation> createParticipantCohortAnnotation(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, ParticipantCohortAnnotation request) {
if (request.getCohortAnnotationDefinitionId() == null) {
throw new BadRequestException("Invalid Request: Please provide a valid cohort annotation definition id.");
}
CohortReview cohortReview = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.WRITER);
org.pmiops.workbench.db.model.ParticipantCohortAnnotation participantCohortAnnotation = FROM_CLIENT_PARTICIPANT_COHORT_ANNOTATION.apply(request);
participantCohortAnnotation = cohortReviewService.saveParticipantCohortAnnotation(cohortReview.getCohortReviewId(), participantCohortAnnotation);
return ResponseEntity.ok(TO_CLIENT_PARTICIPANT_COHORT_ANNOTATION.apply(participantCohortAnnotation));
}
use of org.pmiops.workbench.exceptions.BadRequestException in project workbench by all-of-us.
the class CohortReviewController method deleteParticipantCohortAnnotation.
@Override
public ResponseEntity<EmptyResponse> deleteParticipantCohortAnnotation(String workspaceNamespace, String workspaceId, Long cohortId, Long cdrVersionId, Long participantId, Long annotationId) {
if (annotationId == null) {
throw new BadRequestException("Invalid Request: Please provide a valid cohort annotation definition id.");
}
CohortReview cohortReview = validateRequestAndSetCdrVersion(workspaceNamespace, workspaceId, cohortId, cdrVersionId, WorkspaceAccessLevel.WRITER);
// will throw a NotFoundException if participant does not exist
cohortReviewService.findParticipantCohortStatus(cohortReview.getCohortReviewId(), participantId);
// will throw a NotFoundException if participant cohort annotation does not exist
cohortReviewService.deleteParticipantCohortAnnotation(annotationId, cohortReview.getCohortReviewId(), participantId);
return ResponseEntity.ok(new EmptyResponse());
}
use of org.pmiops.workbench.exceptions.BadRequestException in project workbench by all-of-us.
the class CohortsController method updateCohort.
@Override
public ResponseEntity<Cohort> updateCohort(String workspaceNamespace, String workspaceId, Long cohortId, Cohort cohort) {
// This also enforces registered auth domain.
workspaceService.enforceWorkspaceAccessLevel(workspaceNamespace, workspaceId, WorkspaceAccessLevel.WRITER);
org.pmiops.workbench.db.model.Cohort dbCohort = getDbCohort(workspaceNamespace, workspaceId, cohortId);
if (Strings.isNullOrEmpty(cohort.getEtag())) {
throw new BadRequestException("missing required update field 'etag'");
}
int version = Etags.toVersion(cohort.getEtag());
if (dbCohort.getVersion() != version) {
throw new ConflictException("Attempted to modify outdated cohort version");
}
if (cohort.getType() != null) {
dbCohort.setType(cohort.getType());
}
if (cohort.getName() != null) {
dbCohort.setName(cohort.getName());
}
if (cohort.getDescription() != null) {
dbCohort.setDescription(cohort.getDescription());
}
if (cohort.getCriteria() != null) {
dbCohort.setCriteria(cohort.getCriteria());
}
Timestamp now = new Timestamp(clock.instant().toEpochMilli());
dbCohort.setLastModifiedTime(now);
try {
// The version asserted on save is the same as the one we read via
// getRequired() above, see RW-215 for details.
dbCohort = cohortDao.save(dbCohort);
} catch (OptimisticLockException e) {
log.log(Level.WARNING, "version conflict for cohort update", e);
throw new ConflictException("Failed due to concurrent cohort modification");
}
return ResponseEntity.ok(TO_CLIENT_COHORT.apply(dbCohort));
}
use of org.pmiops.workbench.exceptions.BadRequestException in project workbench by all-of-us.
the class CohortMaterializationServiceTest method testMaterializeCohortPaging.
@Test
public void testMaterializeCohortPaging() {
MaterializeCohortRequest request = makeRequest(2);
MaterializeCohortResponse response = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), request);
assertPersonIds(response, 1L, 2L);
assertThat(response.getNextPageToken()).isNotNull();
request.setPageToken(response.getNextPageToken());
MaterializeCohortResponse response2 = cohortMaterializationService.materializeCohort(null, SearchRequests.allGenders(), request);
assertPersonIds(response2, 102246L);
assertThat(response2.getNextPageToken()).isNull();
try {
// Pagination token doesn't match, this should fail.
cohortMaterializationService.materializeCohort(null, SearchRequests.males(), request);
fail("Exception expected");
} catch (BadRequestException e) {
// expected
}
PaginationToken token = PaginationToken.fromBase64(response.getNextPageToken());
PaginationToken invalidToken = new PaginationToken(-1L, token.getParameterHash());
request.setPageToken(invalidToken.toBase64());
try {
// Pagination token doesn't match, this should fail.
cohortMaterializationService.materializeCohort(null, SearchRequests.males(), request);
fail("Exception expected");
} catch (BadRequestException e) {
// expected
}
}
Aggregations