Search in sources :

Example 11 with Consent

use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.

the class ConsentElectionResource method createConsentElectionForDac.

@POST
@Consumes("application/json")
@Path("/dac/{dacId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response createConsentElectionForDac(@Auth AuthUser authUser, @Context UriInfo info, @PathParam("consentId") String consentId, @PathParam("dacId") Integer dacId, Election election) {
    URI uri;
    try {
        Consent consent = consentService.getById(consentId);
        Dac dac = dacService.findById(dacId);
        if (dac == null) {
            throw new NotFoundException("Cannot find DAC with the provided id: " + dacId);
        }
        if (consent.getDacId() != null && !consent.getDacId().equals(dacId)) {
            throw new BadRequestException("Consent is already associated to a DAC.");
        }
        try {
            consentService.updateConsentDac(consentId, dacId);
        } catch (Exception e) {
            logger().error("Exception updating consent id: '" + consentId + "', with dac id: '" + dacId + "'");
            throw new InternalServerErrorException("Unable to associate consent to dac.");
        }
        uri = createElectionURI(info, election, consentId);
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
    return Response.created(uri).build();
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) Dac(org.broadinstitute.consent.http.models.Dac) NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) URI(java.net.URI) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 12 with Consent

use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.

the class DataAccessRequestResource method describeConsentForDAR.

/**
 * Note that this method assumes a single consent for a DAR. The UI doesn't curently handle the
 * case where there are multiple datasets associated to a DAR.
 * See https://broadinstitute.atlassian.net/browse/BTRX-717 to handle that condition.
 *
 * @param id The Data Access Request ID
 * @return consent The consent associated to the first dataset id the DAR refers to.
 */
@GET
@Path("/find/{id}/consent")
@Produces("application/json")
@PermitAll
public Consent describeConsentForDAR(@Auth AuthUser authUser, @PathParam("id") String id) {
    validateAuthedRoleUser(Stream.of(UserRoles.ADMIN, UserRoles.CHAIRPERSON, UserRoles.MEMBER).collect(Collectors.toList()), authUser, id);
    Optional<Integer> dataSetId = getDatasetIdForDarId(id);
    Consent c;
    if (dataSetId.isPresent()) {
        c = consentService.getConsentFromDatasetID(dataSetId.get());
        if (c == null) {
            throw new NotFoundException("Unable to find the consent related to the datasetId present in the DAR.");
        }
    } else {
        throw new NotFoundException("Unable to find the datasetId related to the DAR.");
    }
    return c;
}
Also used : Consent(org.broadinstitute.consent.http.models.Consent) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 13 with Consent

use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.

the class ElectionService method sendResearcherNotification.

private void sendResearcherNotification(String referenceId) throws Exception {
    DataAccessRequest dar = dataAccessRequestService.findByReferenceId(referenceId);
    List<Integer> dataSetIdList = dar.getData().getDatasetIds();
    if (CollectionUtils.isNotEmpty(dataSetIdList)) {
        List<DataSet> dataSets = dataSetDAO.findDatasetsByIdList(dataSetIdList);
        List<DatasetMailDTO> datasetsDetail = new ArrayList<>();
        dataSets.forEach(ds -> datasetsDetail.add(new DatasetMailDTO(ds.getName(), ds.getDatasetIdentifier())));
        Consent consent = consentDAO.findConsentFromDatasetID(dataSets.get(0).getDataSetId());
        // Legacy behavior was to populate the plain language translation we received from ORSP
        // If we don't have that and have a valid data use, use that instead as it is more up to date.
        String translatedUseRestriction = consent.getTranslatedUseRestriction();
        if (Objects.isNull(translatedUseRestriction)) {
            if (Objects.nonNull(consent.getDataUse())) {
                translatedUseRestriction = useRestrictionConverter.translateDataUse(consent.getDataUse(), DataUseTranslationType.DATASET);
                // update so we don't have to make this check again
                consentDAO.updateConsentTranslatedUseRestriction(consent.getConsentId(), translatedUseRestriction);
            } else {
                logger.error("Error finding translation for consent id: " + consent.getConsentId());
                translatedUseRestriction = "";
            }
        }
        emailNotifierService.sendResearcherDarApproved(dar.getData().getDarCode(), dar.getUserId(), datasetsDetail, translatedUseRestriction);
    }
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) ArrayList(java.util.ArrayList) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) DatasetMailDTO(org.broadinstitute.consent.http.models.dto.DatasetMailDTO)

Example 14 with Consent

use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.

the class ElectionService method validateAndGetDULElection.

private Election validateAndGetDULElection(String referenceId, ElectionType electionType) throws Exception {
    Election consentElection = null;
    if (electionType.equals(ElectionType.DATA_ACCESS)) {
        DataAccessRequest dataAccessRequest = dataAccessRequestService.findByReferenceId(referenceId);
        if (Objects.isNull(dataAccessRequest) || Objects.isNull(dataAccessRequest.getData())) {
            throw new NotFoundException();
        }
        List<DataSet> dataSets = verifyActiveDataSets(dataAccessRequest, referenceId);
        Consent consent = consentDAO.findConsentFromDatasetID(dataSets.get(0).getDataSetId());
        consentElection = electionDAO.findLastElectionByReferenceIdAndStatus(consent.getConsentId(), ElectionStatus.CLOSED.getValue());
    }
    return consentElection;
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) Consent(org.broadinstitute.consent.http.models.Consent) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) NotFoundException(javax.ws.rs.NotFoundException) Election(org.broadinstitute.consent.http.models.Election)

Example 15 with Consent

use of org.broadinstitute.consent.http.models.Consent in project consent by DataBiosphere.

the class ReviewResultsService method describeElectionReviewByElectionId.

public ElectionReview describeElectionReviewByElectionId(Integer electionId) {
    ElectionReview review = null;
    Election election = electionDAO.findElectionWithFinalVoteById(electionId);
    if (election != null) {
        review = new ElectionReview();
        review.setElection(election);
        Consent consent = consentDAO.findConsentById(review.getElection().getReferenceId());
        List<ElectionReviewVote> rVotes = voteDAO.findAllElectionReviewVotesByElectionId(electionId);
        review.setReviewVote(rVotes);
        review.setConsent(consent);
    }
    return review;
}
Also used : ElectionReview(org.broadinstitute.consent.http.models.ElectionReview) ElectionReviewVote(org.broadinstitute.consent.http.models.ElectionReviewVote) Consent(org.broadinstitute.consent.http.models.Consent) Election(org.broadinstitute.consent.http.models.Election)

Aggregations

Consent (org.broadinstitute.consent.http.models.Consent)163 Test (org.junit.Test)127 DataSet (org.broadinstitute.consent.http.models.DataSet)86 Election (org.broadinstitute.consent.http.models.Election)72 Dac (org.broadinstitute.consent.http.models.Dac)61 User (org.broadinstitute.consent.http.models.User)56 Vote (org.broadinstitute.consent.http.models.Vote)48 ElectionReviewVote (org.broadinstitute.consent.http.models.ElectionReviewVote)32 Response (javax.ws.rs.core.Response)31 Date (java.util.Date)25 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)23 UnknownIdentifierException (org.broadinstitute.consent.http.exceptions.UnknownIdentifierException)13 NotFoundException (javax.ws.rs.NotFoundException)12 AuthUser (org.broadinstitute.consent.http.models.AuthUser)12 IOException (java.io.IOException)8 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Timestamp (java.sql.Timestamp)6 List (java.util.List)6