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();
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations