Search in sources :

Example 1 with DataSetProperty

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

the class DatasetService method getDatasetWithPropertiesById.

public DataSet getDatasetWithPropertiesById(Integer datasetId) {
    DataSet dataset = datasetDAO.findDataSetById(datasetId);
    Set<DataSetProperty> properties = getDatasetProperties(datasetId);
    dataset.setProperties(properties);
    return dataset;
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty)

Example 2 with DataSetProperty

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

the class DatasetService method processDatasetProperties.

public List<DataSetProperty> processDatasetProperties(Integer datasetId, List<DataSetPropertyDTO> properties) {
    Date now = new Date();
    List<Dictionary> dictionaries = datasetDAO.getMappedFieldsOrderByReceiveOrder();
    List<String> keys = dictionaries.stream().map(Dictionary::getKey).collect(Collectors.toList());
    return properties.stream().filter(p -> keys.contains(p.getPropertyName()) && !p.getPropertyName().equals(DATASET_NAME_KEY)).map(p -> new DataSetProperty(datasetId, dictionaries.get(keys.indexOf(p.getPropertyName())).getKeyId(), p.getPropertyValue(), now)).collect(Collectors.toList());
}
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) Dictionary(org.broadinstitute.consent.http.models.Dictionary) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) Date(java.util.Date)

Example 3 with DataSetProperty

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

the class DatasetService method createDatasetWithConsent.

public DatasetDTO createDatasetWithConsent(DatasetDTO dataset, String name, Integer userId) throws Exception {
    if (Objects.nonNull(getDatasetByName(name))) {
        throw new IllegalArgumentException("Dataset name: " + name + " is already in use");
    }
    Timestamp now = new Timestamp(new Date().getTime());
    Integer createdDatasetId = datasetDAO.inTransaction(h -> {
        try {
            Integer id = h.insertDatasetV2(name, now, userId, dataset.getObjectId(), dataset.getActive());
            List<DataSetProperty> propertyList = processDatasetProperties(id, dataset.getProperties());
            h.insertDatasetProperties(propertyList);
            h.updateDatasetNeedsApproval(id, dataset.getNeedsApproval());
            return id;
        } catch (Exception e) {
            if (Objects.nonNull(h)) {
                h.rollback();
            }
            logger.error("Exception creating dataset with consent: " + e.getMessage());
            throw e;
        }
    });
    dataset.setDataSetId(createdDatasetId);
    try {
        createConsentForDataset(dataset);
    } catch (Exception e) {
        logger.error("Exception creating consent for dataset: " + e.getMessage());
        deleteDataset(createdDatasetId, userId);
        throw e;
    }
    return getDatasetDTO(createdDatasetId);
}
Also used : DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) Timestamp(java.sql.Timestamp) Date(java.util.Date) NotFoundException(javax.ws.rs.NotFoundException)

Example 4 with DataSetProperty

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

the class DatasetDAOTest method testDeleteDatasetPropertyByKey.

@Test
public void testDeleteDatasetPropertyByKey() {
    DataSet d = createDataset();
    Set<DataSetProperty> properties = dataSetDAO.findDatasetPropertiesByDatasetId(d.getDataSetId());
    DataSetProperty propertyToDelete = properties.stream().collect(Collectors.toList()).get(0);
    dataSetDAO.deleteDatasetPropertyByKey(d.getDataSetId(), propertyToDelete.getPropertyKey());
    Set<DataSetProperty> returnedProperties = dataSetDAO.findDatasetPropertiesByDatasetId(d.getDataSetId());
    assertNotEquals(properties.size(), returnedProperties.size());
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) Test(org.junit.Test)

Example 5 with DataSetProperty

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

the class DatasetDAOTest method testFindDatasetPropertiesByDatasetId.

@Test
public void testFindDatasetPropertiesByDatasetId() {
    DataSet d = createDataset();
    Set<DataSetProperty> properties = dataSetDAO.findDatasetPropertiesByDatasetId(d.getDataSetId());
    assertEquals(properties.size(), 1);
}
Also used : DataSet(org.broadinstitute.consent.http.models.DataSet) DataSetProperty(org.broadinstitute.consent.http.models.DataSetProperty) Test(org.junit.Test)

Aggregations

DataSetProperty (org.broadinstitute.consent.http.models.DataSetProperty)9 DataSet (org.broadinstitute.consent.http.models.DataSet)7 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 Test (org.junit.Test)4 Timestamp (java.sql.Timestamp)3 NotFoundException (javax.ws.rs.NotFoundException)3 DataSetPropertyDTO (org.broadinstitute.consent.http.models.dto.DataSetPropertyDTO)3 DatasetDTO (org.broadinstitute.consent.http.models.dto.DatasetDTO)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2