use of org.broadinstitute.consent.http.enumeration.AssociationType in project consent by DataBiosphere.
the class DatasetService method createConsentForDataset.
/**
* Create a minimal consent from the data provided in a Dataset.
*
* @param dataset The DataSetDTO
* @return The created Consent
*/
public Consent createConsentForDataset(DatasetDTO dataset) {
String consentId = UUID.randomUUID().toString();
Optional<DataSetPropertyDTO> nameProp = dataset.getProperties().stream().filter(p -> p.getPropertyName().equalsIgnoreCase(DATASET_NAME_KEY)).findFirst();
// Typically, this is a construct from ORSP consisting of dataset name and some form of investigator code.
// In our world, we'll use that dataset name if provided, or the alias.
String groupName = nameProp.isPresent() ? nameProp.get().getPropertyValue() : dataset.getAlias();
String name = CONSENT_NAME_PREFIX + dataset.getDataSetId();
Date createDate = new Date();
if (Objects.nonNull(dataset.getDataUse())) {
boolean manualReview = isConsentDataUseManualReview(dataset.getDataUse());
/*
* Consents created for a dataset do not need the following properties:
* data user letter
* data user letter name
*/
UseRestriction useRestriction = converter.parseUseRestriction(dataset.getDataUse());
String translatedUseRestriction = converter.translateDataUse(dataset.getDataUse(), DataUseTranslationType.DATASET);
consentDAO.useTransaction(h -> {
try {
h.insertConsent(consentId, manualReview, useRestriction.toString(), dataset.getDataUse().toString(), null, name, null, createDate, createDate, translatedUseRestriction, groupName, dataset.getDacId());
if (Objects.nonNull(dataset.getDacId())) {
h.updateConsentDac(consentId, dataset.getDacId());
}
String associationType = AssociationType.SAMPLE_SET.getValue();
h.insertConsentAssociation(consentId, associationType, dataset.getDataSetId());
} catch (Exception e) {
h.rollback();
logger.error("Exception creating consent: " + e.getMessage());
throw e;
}
});
return consentDAO.findConsentById(consentId);
} else {
throw new IllegalArgumentException("Dataset is missing Data Use information. Consent could not be created.");
}
}
Aggregations