use of org.molgenis.data.csv.CsvWriter in project molgenis by molgenis.
the class CsvHttpMessageConverter method writeInternal.
@Override
protected void writeInternal(EntityCollection entities, HttpOutputMessage outputMessage) throws IOException {
OutputStreamWriter out = new OutputStreamWriter(outputMessage.getBody(), getCharset(outputMessage.getHeaders()));
CsvWriter writer = new CsvWriter(out);
try {
writer.writeAttributeNames(entities.getAttributeNames());
writer.add(entities.stream());
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.molgenis.data.csv.CsvWriter in project molgenis by molgenis.
the class SortaController method download.
@GetMapping("/match/download/{sortaJobExecutionId}")
public void download(@PathVariable String sortaJobExecutionId, HttpServletResponse response) throws IOException {
try (CsvWriter csvWriter = new CsvWriter(response.getOutputStream(), SortaServiceImpl.DEFAULT_SEPARATOR)) {
SortaJobExecution sortaJobExecution = findSortaJobExecution(sortaJobExecutionId);
response.setContentType("text/csv");
response.addHeader("Content-Disposition", "attachment; filename=" + generateCsvFileName());
List<String> columnHeaders = new ArrayList<>();
EntityType targetMetadata = entityTypeFactory.create("SortaDownload" + sortaJobExecutionId);
EntityType sourceMetaData = dataService.getEntityType(sortaJobExecution.getSourceEntityName());
for (Attribute attribute : sourceMetaData.getAttributes()) {
if (!attribute.getName().equalsIgnoreCase(SortaCsvRepository.ALLOWED_IDENTIFIER)) {
columnHeaders.add(attribute.getName());
targetMetadata.addAttribute(attrMetaFactory.create().setName(attribute.getName()));
}
}
columnHeaders.addAll(Arrays.asList(OntologyTermMetaData.ONTOLOGY_TERM_NAME, OntologyTermMetaData.ONTOLOGY_TERM_IRI, MatchingTaskContentMetaData.SCORE, MatchingTaskContentMetaData.VALIDATED));
targetMetadata.addAttribute(ontologyTermMetaData.getAttribute(OntologyTermMetaData.ONTOLOGY_TERM_NAME));
targetMetadata.addAttribute(ontologyTermMetaData.getAttribute(OntologyTermMetaData.ONTOLOGY_TERM_IRI));
targetMetadata.addAttribute(Attribute.newInstance(matchingTaskContentMetaData.getAttribute(MatchingTaskContentMetaData.SCORE), EntityType.AttributeCopyMode.SHALLOW_COPY_ATTRS, attrMetaFactory).setDataType(AttributeType.STRING));
targetMetadata.addAttribute(matchingTaskContentMetaData.getAttribute(MatchingTaskContentMetaData.VALIDATED));
csvWriter.writeAttributeNames(columnHeaders);
dataService.findAll(sortaJobExecution.getResultEntityName(), new QueryImpl<>()).forEach(resultEntity -> csvWriter.add(toDownloadRow(sortaJobExecution, resultEntity, targetMetadata)));
}
}
use of org.molgenis.data.csv.CsvWriter in project molgenis by molgenis.
the class DataExplorerDownloadHandler method writeToCsv.
public void writeToCsv(DataRequest dataRequest, OutputStream outputStream, char separator, boolean noQuotes) throws IOException {
try (CsvWriter csvWriter = new CsvWriter(outputStream, separator, noQuotes)) {
csvWriter.setEntityWriteMode(getEntityWriteMode(dataRequest.getEntityValues()));
String entityTypeId = dataRequest.getEntityName();
writeCsvHeaders(dataRequest, csvWriter);
csvWriter.add(dataService.findAll(entityTypeId, dataRequest.getQuery()));
}
}
Aggregations