Search in sources :

Example 1 with ConceptMapCompareResultItem

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();
}
Also used : OutputStream(java.io.OutputStream) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Files(java.nio.file.Files) Request(com.b2international.snowowl.core.events.Request) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) StandardOpenOption(java.nio.file.StandardOpenOption) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) Set(java.util.Set) Throwables(com.google.common.base.Throwables) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Paths(java.nio.file.Paths) ConceptMapCompareChangeKind(com.b2international.snowowl.core.compare.ConceptMapCompareChangeKind) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) ConceptMapCompareResultItem(com.b2international.snowowl.core.compare.ConceptMapCompareResultItem) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) OutputStream(java.io.OutputStream) BadRequestException(com.b2international.commons.exceptions.BadRequestException) ConceptMapCompareResultItem(com.b2international.snowowl.core.compare.ConceptMapCompareResultItem) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 2 with ConceptMapCompareResultItem

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);
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ConceptMapCompareResultItem(com.b2international.snowowl.core.compare.ConceptMapCompareResultItem) IOException(java.io.IOException)

Aggregations

ConceptMapCompareResultItem (com.b2international.snowowl.core.compare.ConceptMapCompareResultItem)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)1 ConceptMapCompareChangeKind (com.b2international.snowowl.core.compare.ConceptMapCompareChangeKind)1 Request (com.b2international.snowowl.core.events.Request)1 CsvMapper (com.fasterxml.jackson.dataformat.csv.CsvMapper)1 CsvSchema (com.fasterxml.jackson.dataformat.csv.CsvSchema)1 Throwables (com.google.common.base.Throwables)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1