use of org.broadinstitute.consent.http.models.DataUse in project consent by DataBiosphere.
the class DacWithDatasetsReducer method accumulate.
@Override
public void accumulate(Map<Integer, Dac> container, RowView rowView) {
try {
Dac dac = container.computeIfAbsent(rowView.getColumn("dac_id", Integer.class), id -> rowView.getRow(Dac.class));
if (Objects.nonNull(rowView.getColumn("datasetid", Integer.class))) {
DatasetDTO dto = rowView.getRow(DatasetDTO.class);
try {
if (Objects.nonNull(rowView.getColumn("dataset_alias", String.class))) {
String dsAlias = rowView.getColumn("dataset_alias", String.class);
try {
dto.setAlias(Integer.parseInt(dsAlias));
} catch (Exception e) {
logger.error("Exception parsing dataset alias: " + dsAlias, e);
}
}
if (Objects.nonNull(rowView.getColumn("dataset_create_date", Date.class))) {
Date createDate = rowView.getColumn("dataset_create_date", Date.class);
dto.setCreateDate(createDate);
}
if (Objects.nonNull(rowView.getColumn("dataset_update_date", Timestamp.class))) {
Timestamp updateDate = rowView.getColumn("dataset_update_date", Timestamp.class);
dto.setUpdateDate(updateDate);
}
} catch (Exception e) {
// no values for these columns
}
if (Objects.nonNull(rowView.getColumn("consent_data_use", String.class))) {
String duStr = rowView.getColumn("consent_data_use", String.class);
Optional<DataUse> du = DataUse.parseDataUse(duStr);
du.ifPresent(dto::setDataUse);
}
if (Objects.nonNull(dto)) {
dac.addDatasetDTO(dto);
}
}
} catch (MappingException e) {
logger.warn(e.getMessage());
}
}
use of org.broadinstitute.consent.http.models.DataUse in project consent by DataBiosphere.
the class UseRestrictionConverterTest method testTranslateFalseValues.
/*
* Test that the DataUse parser does not set false values incorrectly
*/
@Test
public void testTranslateFalseValues() {
Client client = ClientBuilder.newClient();
UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
String json = "{ " + "\"methods\":false, " + "\"population\":false, " + "\"controls\":false, " + "\"poa\":false, " + "\"hmb\":false " + "}";
DataUse dataUse = converter.parseDataUsePurpose(json);
assertNull(dataUse.getMethodsResearch());
assertNull(dataUse.getPopulationStructure());
assertNull(dataUse.getControlSetOption());
assertNull(dataUse.getPopulationOriginsAncestry());
assertNull(dataUse.getHmbResearch());
}
use of org.broadinstitute.consent.http.models.DataUse in project consent by DataBiosphere.
the class UseRestrictionConverterTest method testFailedUseRestrictionConverterConnection.
/*
* Test that when the UseRestrictionConverter makes a failed call to the ontology service, a null is returned.
*/
@Test
public void testFailedUseRestrictionConverterConnection() {
mockDarTranslateFailure();
Client client = ClientBuilder.newClient();
UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
DataUse dataUse = converter.parseDataUsePurpose("{ }");
UseRestriction restriction = converter.parseUseRestriction(dataUse);
assertNull(restriction);
}
use of org.broadinstitute.consent.http.models.DataUse in project consent by DataBiosphere.
the class UseRestrictionConverterTest method testTranslateDataUsePurpose.
/*
* Test that the UseRestrictionConverter makes a call to the ontology service and gets back a valid translation
*/
@Test
public void testTranslateDataUsePurpose() {
mockDataUseTranslateSuccess();
Client client = ClientBuilder.newClient();
UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
DataUse dataUse = new DataUseBuilder().setHmbResearch(true).build();
String translation = converter.translateDataUse(dataUse, DataUseTranslationType.PURPOSE);
assertNotNull(translation);
}
use of org.broadinstitute.consent.http.models.DataUse in project consent by DataBiosphere.
the class UseRestrictionConverterTest method testParseDataUseInvalidOntologiesCase1.
/*
* Testing a DataUse with invalid ontologies.
*/
@Test
public void testParseDataUseInvalidOntologiesCase1() {
String json = "{ " + "\"hmb\":true, " + "\"ontologies\":[{},{},{}]" + "}";
Client client = ClientBuilder.newClient();
UseRestrictionConverter converter = new UseRestrictionConverter(client, config());
DataUse dataUse = converter.parseDataUsePurpose(json);
assertNotNull(dataUse);
assertNull(dataUse.getDiseaseRestrictions());
}
Aggregations