use of org.broadinstitute.consent.http.models.dto.DatasetDTO 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.dto.DatasetDTO in project consent by DataBiosphere.
the class DataSetPropertiesMapper method map.
public DatasetDTO map(ResultSet r, StatementContext ctx) throws SQLException {
DatasetDTO dataSetDTO;
Integer dataSetId = r.getInt("dataSetId");
String consentId = r.getString("consentId");
Integer alias = r.getInt("alias");
if (!dataSets.containsKey(dataSetId)) {
dataSetDTO = new DatasetDTO(new ArrayList<>());
if (hasColumn(r, "dac_id")) {
int dacId = r.getInt("dac_id");
if (dacId > 0) {
dataSetDTO.setDacId(dacId);
}
}
dataSetDTO.setConsentId(consentId);
dataSetDTO.setAlias(alias);
dataSetDTO.setDataSetId(dataSetId);
dataSetDTO.setActive(r.getBoolean("active"));
dataSetDTO.setTranslatedUseRestriction(r.getString("translatedUseRestriction"));
if (hasColumn(r, "datause")) {
dataSetDTO.setDataUse(DataUse.parseDataUse(r.getString("datause")).orElse(null));
}
if (hasColumn(r, "createdate")) {
dataSetDTO.setCreateDate(r.getDate("createdate"));
}
if (hasColumn(r, "create_user_id")) {
int userId = r.getInt("create_user_id");
if (userId > 0) {
dataSetDTO.setCreateUserId(userId);
}
}
if (hasColumn(r, "update_date")) {
dataSetDTO.setUpdateDate(r.getTimestamp("update_date"));
}
if (hasColumn(r, "update_user_id")) {
int userId = r.getInt("update_user_id");
if (userId > 0) {
dataSetDTO.setUpdateUserId(userId);
}
}
DataSetPropertyDTO property = new DataSetPropertyDTO("Dataset Name", r.getString("name"));
dataSetDTO.addProperty(property);
property = new DataSetPropertyDTO(r.getString(PROPERTY_KEY), r.getString(PROPERTY_PROPERTYVALUE));
if (property.getPropertyName() != null) {
dataSetDTO.addProperty(property);
}
dataSetDTO.setNeedsApproval(r.getBoolean("needs_approval"));
dataSetDTO.setObjectId(r.getString("objectId"));
dataSets.put(dataSetId, dataSetDTO);
} else {
dataSetDTO = dataSets.get(dataSetId);
DataSetPropertyDTO property = new DataSetPropertyDTO(r.getString(PROPERTY_KEY), r.getString(PROPERTY_PROPERTYVALUE));
if (property.getPropertyName() != null) {
dataSetDTO.addProperty(property);
}
}
return dataSetDTO;
}
use of org.broadinstitute.consent.http.models.dto.DatasetDTO in project consent by DataBiosphere.
the class DatasetResourceTest method testDescribeDataSetSuccess.
@Test
public void testDescribeDataSetSuccess() {
DatasetDTO testDTO = createMockDatasetDTO();
when(datasetService.getDatasetDTO(any())).thenReturn(testDTO);
initResource();
Response response = resource.describeDataSet(1);
assertEquals(200, response.getStatus());
}
use of org.broadinstitute.consent.http.models.dto.DatasetDTO in project consent by DataBiosphere.
the class DatasetResourceTest method testCreateDatasetSuccess.
@Test
public void testCreateDatasetSuccess() throws Exception {
DatasetDTO result = createMockDatasetDTO();
Consent consent = new Consent();
String json = createPropertiesJson("Dataset Name", "test");
when(datasetService.getDatasetByName("test")).thenReturn(null);
when(datasetService.createDatasetWithConsent(any(), any(), anyInt())).thenReturn(result);
when(datasetService.createConsentForDataset(any())).thenReturn(consent);
when(datasetService.getDatasetDTO(any())).thenReturn(result);
when(authUser.getGoogleUser()).thenReturn(googleUser);
when(googleUser.getEmail()).thenReturn("email@email.com");
when(userService.findUserByEmail(any())).thenReturn(dacUser);
when(dacUser.getDacUserId()).thenReturn(1);
when(uriInfo.getRequestUriBuilder()).thenReturn(uriBuilder);
when(uriBuilder.replacePath(anyString())).thenReturn(uriBuilder);
when(uriBuilder.build(anyString())).thenReturn(new URI("/api/dataset/1"));
initResource();
Response response = resource.createDataset(authUser, uriInfo, json);
assertEquals(201, response.getStatus());
assertEquals(result, response.getEntity());
}
use of org.broadinstitute.consent.http.models.dto.DatasetDTO in project consent by DataBiosphere.
the class DatasetResource method downloadDataSets.
@POST
@Path("/download")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public Response downloadDataSets(List<Integer> idList) {
try {
String msg = "GETing DataSets to download";
logger().debug(msg);
JSONObject json = new JSONObject();
Collection<Dictionary> headers = datasetService.describeDictionaryByReceiveOrder();
StringBuilder sb = new StringBuilder();
String TSV_DELIMITER = "\t";
for (Dictionary header : headers) {
if (sb.length() > 0)
sb.append(TSV_DELIMITER);
sb.append(header.getKey());
}
sb.append(END_OF_LINE);
if (CollectionUtils.isEmpty(idList)) {
json.put("datasets", sb.toString());
return Response.ok(json.toString(), MediaType.APPLICATION_JSON).build();
}
Collection<DatasetDTO> rows = datasetService.describeDataSetsByReceiveOrder(idList);
for (DatasetDTO row : rows) {
StringBuilder sbr = new StringBuilder();
DataSetPropertyDTO property = new DataSetPropertyDTO("Consent ID", row.getConsentId());
List<DataSetPropertyDTO> props = row.getProperties();
props.add(property);
for (DataSetPropertyDTO prop : props) {
if (sbr.length() > 0)
sbr.append(TSV_DELIMITER);
sbr.append(prop.getPropertyValue());
}
sbr.append(END_OF_LINE);
sb.append(sbr);
}
String tsv = sb.toString();
json.put("datasets", tsv);
return Response.ok(json.toString(), MediaType.APPLICATION_JSON).build();
} catch (Exception e) {
return createExceptionResponse(e);
}
}
Aggregations