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