Search in sources :

Example 1 with AssociationType

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.");
    }
}
Also used : Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) AuditActions(org.broadinstitute.consent.http.enumeration.AuditActions) DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) HashMap(java.util.HashMap) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) DataUse(org.broadinstitute.consent.http.models.DataUse) ArrayList(java.util.ArrayList) DatasetDAO(org.broadinstitute.consent.http.db.DatasetDAO) Inject(javax.inject.Inject) HashSet(java.util.HashSet) DataSetAudit(org.broadinstitute.consent.http.models.DataSetAudit) Map(java.util.Map) DataSetPropertyDTO(org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO) UserRoleDAO(org.broadinstitute.consent.http.db.UserRoleDAO) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) DataAccessRequestData(org.broadinstitute.consent.http.models.DataAccessRequestData) DataSet(org.broadinstitute.consent.http.models.DataSet) Logger(org.slf4j.Logger) DataAccessRequestDAO(org.broadinstitute.consent.http.db.DataAccessRequestDAO) DataUseTranslationType(org.broadinstitute.consent.http.enumeration.DataUseTranslationType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) AssociationType(org.broadinstitute.consent.http.enumeration.AssociationType) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) ConsentDAO(org.broadinstitute.consent.http.db.ConsentDAO) Dictionary(org.broadinstitute.consent.http.models.Dictionary) UseRestriction(org.broadinstitute.consent.http.models.grammar.UseRestriction) Optional(java.util.Optional) Collections(java.util.Collections) Consent(org.broadinstitute.consent.http.models.Consent) DataSetPropertyDTO(org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO) UseRestriction(org.broadinstitute.consent.http.models.grammar.UseRestriction) Date(java.util.Date) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 NotFoundException (javax.ws.rs.NotFoundException)1 ConsentDAO (org.broadinstitute.consent.http.db.ConsentDAO)1 DataAccessRequestDAO (org.broadinstitute.consent.http.db.DataAccessRequestDAO)1 DatasetDAO (org.broadinstitute.consent.http.db.DatasetDAO)1 UserRoleDAO (org.broadinstitute.consent.http.db.UserRoleDAO)1