use of org.broadinstitute.consent.http.models.Dictionary 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);
}
}
use of org.broadinstitute.consent.http.models.Dictionary 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());
}
Aggregations