use of com.b2international.snowowl.core.compare.ConceptMapCompareResultItem in project snow-owl by b2ihealthcare.
the class ConceptMapCompareDsvExportRequest method execute.
@Override
public File execute(ServiceProvider context) {
final List<ConceptMapCompareResultItem> resultsToExport = items.stream().filter(item -> changeKinds.contains(item.getChangeKind())).collect(Collectors.toList());
final CsvMapper mapper = new CsvMapper();
final CsvSchema schema = mapper.schemaFor(ConceptMapCompareResultItem.class).withHeader().withoutQuoteChar().withColumnSeparator(delimiter).withNullValue("");
try (OutputStream newOutputStream = Files.newOutputStream(Paths.get(filePath), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
mapper.writer(schema).writeValue(newOutputStream, resultsToExport);
} catch (Exception e) {
throw new BadRequestException("An error occured durin Concept Map Compare DSV export: %s", Throwables.getRootCause(e).getMessage());
}
return Paths.get(filePath).toFile();
}
use of com.b2international.snowowl.core.compare.ConceptMapCompareResultItem in project snow-owl by b2ihealthcare.
the class ConceptMapCompareDsvExportTest method assertFile.
private void assertFile(final File file, final List<ConceptMapCompareResultItem> expectedItems) throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
int i = 0;
// Read header
String line = reader.readLine();
line = reader.readLine();
while (line != null) {
final String[] fields = line.split(";", -1);
final ConceptMapCompareResultItem item = expectedItems.get(i);
assertThat(fields).containsOnly(toFieldsArray(item));
i++;
line = reader.readLine();
}
assertEquals(expectedItems.size(), i);
} catch (Exception e) {
throw e;
} finally {
Files.delete(file);
}
}
Aggregations