use of org.sagebionetworks.bridge.models.subpopulations.StudyConsent in project BridgeServer2 by Sage-Bionetworks.
the class StudyConsentService method deleteAllConsentsPermanently.
/**
* Physically delete all the consents for a subpopulation.
*/
public void deleteAllConsentsPermanently(SubpopulationGuid subpopulationGuid) {
checkNotNull(subpopulationGuid);
// We need to load all consents, so we know their storage paths and can delete their S3 contents.
List<StudyConsent> consentList = getAllConsents(subpopulationGuid);
for (StudyConsent consent : consentList) {
studyConsentDao.deleteConsentPermanently(consent);
s3Client.deleteObject(consentsBucket, consent.getStoragePath());
}
// We need to delete from the publications bucket.
s3Client.deleteObject(publicationsBucket, subpopulationGuid.getGuid() + CONSENT_HTML_SUFFIX);
s3Client.deleteObject(publicationsBucket, subpopulationGuid.getGuid() + CONSENT_PDF_SUFFIX);
}
use of org.sagebionetworks.bridge.models.subpopulations.StudyConsent in project BridgeServer2 by Sage-Bionetworks.
the class StudyConsentService method addConsent.
/**
* Adds a new consent document to the study, and sets that consent document as active.
*
* @param subpopGuid
* the subpopulation associated with this consent
* @param form
* form filled out by researcher including the path to the consent document and the minimum age required
* to consent.
* @return the added consent document of type StudyConsent along with its document content
*/
public StudyConsentView addConsent(SubpopulationGuid subpopGuid, StudyConsentForm form) {
checkNotNull(subpopGuid);
checkNotNull(form);
String sanitizedContent = sanitizeHTML(form.getDocumentContent());
Validate.entityThrowingException(validator, new StudyConsentForm(sanitizedContent));
sanitizedContent = appendSignatureBlockIfNeeded(sanitizedContent);
long createdOn = DateUtils.getCurrentMillisFromEpoch();
String storagePath = subpopGuid.getGuid() + "." + createdOn;
logger.info("Accessing bucket: " + consentsBucket + " with storagePath: " + storagePath);
try {
Stopwatch stopwatch = Stopwatch.createStarted();
s3Helper.writeBytesToS3(consentsBucket, storagePath, sanitizedContent.getBytes(defaultCharset()));
logger.info("Finished writing consent to bucket " + consentsBucket + " storagePath " + storagePath + " (" + sanitizedContent.length() + " chars) in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
StudyConsent consent = studyConsentDao.addConsent(subpopGuid, storagePath, createdOn);
return new StudyConsentView(consent, sanitizedContent);
} catch (Throwable t) {
throw new BridgeServiceException(t);
}
}
use of org.sagebionetworks.bridge.models.subpopulations.StudyConsent in project BridgeServer2 by Sage-Bionetworks.
the class StudyConsentService method publishConsent.
/**
* Set the specified consent document as active, setting all other consent documents
* as inactive.
*
* @param app
* app for this consent
* @param subpop
* the subpopulation associated with this consent
* @param timestamp
* time the consent document was added to the database.
* @return the activated consent document along with its document content
*/
public StudyConsentView publishConsent(App app, Subpopulation subpop, long timestamp) {
checkNotNull(app);
checkNotNull(subpop);
checkArgument(timestamp > 0, "Timestamp is 0");
StudyConsent consent = studyConsentDao.getConsent(subpop.getGuid(), timestamp);
if (consent == null) {
throw new EntityNotFoundException(StudyConsent.class);
}
// Only if we can publish the document, do we mark it as published in the database.
String documentContent = loadDocumentContent(consent);
try {
publishFormatsToS3(app, subpop.getGuid(), documentContent);
subpop.setPublishedConsentCreatedOn(timestamp);
subpopService.updateSubpopulation(app, subpop);
} catch (IOException | DocumentException | XRRuntimeException e) {
throw new BridgeServiceException(e.getMessage());
}
return new StudyConsentView(consent, documentContent);
}
use of org.sagebionetworks.bridge.models.subpopulations.StudyConsent in project BridgeServer2 by Sage-Bionetworks.
the class StudyConsentService method getMostRecentConsent.
/**
* Gets the most recently created consent document for the study.
*
* @param subpopGuid
* the subpopulation associated with this consent
* @return the most recent StudyConsent along with its document content
*/
public StudyConsentView getMostRecentConsent(SubpopulationGuid subpopGuid) {
checkNotNull(subpopGuid);
StudyConsent consent = studyConsentDao.getMostRecentConsent(subpopGuid);
if (consent == null) {
throw new EntityNotFoundException(StudyConsent.class);
}
String documentContent = loadDocumentContent(consent);
return new StudyConsentView(consent, documentContent);
}
use of org.sagebionetworks.bridge.models.subpopulations.StudyConsent in project BridgeServer2 by Sage-Bionetworks.
the class SubpopulationService method updateSubpopulation.
/**
* Update a subpopulation.
* @param app
* @param subpop
* @return
*/
public Subpopulation updateSubpopulation(App app, Subpopulation subpop) {
checkNotNull(app);
checkNotNull(subpop);
subpop.setAppId(app.getIdentifier());
// Verify this subpopulation is part of the app. Existing code also doesn't submit
// this publication timestamp back to the server, so set if it doesn't exist.
Subpopulation existingSubpop = getSubpopulation(app.getIdentifier(), subpop.getGuid());
if (subpop.getPublishedConsentCreatedOn() == 0L) {
subpop.setPublishedConsentCreatedOn(existingSubpop.getPublishedConsentCreatedOn());
}
// Verify that the publishedConsentCreatedOn field points to a real app consent. Don't use the service
// because it loads the document from S3.
StudyConsent consent = studyConsentDao.getConsent(subpop.getGuid(), subpop.getPublishedConsentCreatedOn());
if (consent == null) {
throw new EntityNotFoundException(StudyConsent.class);
}
Set<String> studyIds = studyService.getStudyIds(app.getIdentifier());
Validator validator = new SubpopulationValidator(app.getDataGroups(), studyIds);
Validate.entityThrowingException(validator, subpop);
Subpopulation updated = subpopDao.updateSubpopulation(subpop);
cacheProvider.removeObject(CacheKey.subpop(updated.getGuid(), app.getIdentifier()));
cacheProvider.removeObject(CacheKey.subpopList(app.getIdentifier()));
return updated;
}
Aggregations