Search in sources :

Example 16 with BadRequestException

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);
}
Also used : BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) Timestamp(java.sql.Timestamp) Workspace(org.pmiops.workbench.db.model.Workspace)

Example 17 with BadRequestException

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));
}
Also used : BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) org.pmiops.workbench.model(org.pmiops.workbench.model) CohortReview(org.pmiops.workbench.db.model.CohortReview)

Example 18 with BadRequestException

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());
}
Also used : BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) CohortReview(org.pmiops.workbench.db.model.CohortReview)

Example 19 with BadRequestException

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));
}
Also used : ConflictException(org.pmiops.workbench.exceptions.ConflictException) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) OptimisticLockException(javax.persistence.OptimisticLockException) Timestamp(java.sql.Timestamp)

Example 20 with BadRequestException

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
    }
}
Also used : MaterializeCohortRequest(org.pmiops.workbench.model.MaterializeCohortRequest) BadRequestException(org.pmiops.workbench.exceptions.BadRequestException) PaginationToken(org.pmiops.workbench.utils.PaginationToken) MaterializeCohortResponse(org.pmiops.workbench.model.MaterializeCohortResponse) BigQueryBaseTest(org.pmiops.workbench.api.BigQueryBaseTest) Test(org.junit.Test)

Aggregations

BadRequestException (org.pmiops.workbench.exceptions.BadRequestException)27 Timestamp (java.sql.Timestamp)5 CohortReview (org.pmiops.workbench.db.model.CohortReview)5 Workspace (org.pmiops.workbench.db.model.Workspace)5 NotFoundException (org.pmiops.workbench.exceptions.NotFoundException)5 Test (org.junit.Test)4 CohortAnnotationDefinition (org.pmiops.workbench.db.model.CohortAnnotationDefinition)4 WorkspaceUserRole (org.pmiops.workbench.db.model.WorkspaceUserRole)4 ConflictException (org.pmiops.workbench.exceptions.ConflictException)4 User (org.pmiops.workbench.db.model.User)3 Workspace (org.pmiops.workbench.model.Workspace)3 QueryResult (com.google.cloud.bigquery.QueryResult)2 Gson (com.google.gson.Gson)2 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ParticipantCriteria (org.pmiops.workbench.cohortbuilder.ParticipantCriteria)2 TableQueryAndConfig (org.pmiops.workbench.cohortbuilder.TableQueryAndConfig)2 CdrVersion (org.pmiops.workbench.db.model.CdrVersion)2