Search in sources :

Example 6 with CsvListWriter

use of org.supercsv.io.CsvListWriter in project waltz by khartec.

the class ReportGridExtractor method mkCSVReport.

private byte[] mkCSVReport(Set<Tuple2<ReportGridColumnDefinition, Boolean>> columnDefinitions, List<Tuple2<Application, ArrayList<Object>>> reportRows) throws IOException {
    List<String> headers = mkHeaderStrings(columnDefinitions);
    StringWriter writer = new StringWriter();
    CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreference.EXCEL_PREFERENCE);
    csvWriter.write(headers);
    reportRows.forEach(unchecked(row -> csvWriter.write(simplify(row))));
    csvWriter.flush();
    return writer.toString().getBytes();
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IdUtilities.getIdOrDefault(org.finos.waltz.model.utils.IdUtilities.getIdOrDefault) EntityKind(org.finos.waltz.model.EntityKind) ReportGridService(org.finos.waltz.service.report_grid.ReportGridService) org.finos.waltz.model.report_grid(org.finos.waltz.model.report_grid) SurveyQuestionService(org.finos.waltz.service.survey.SurveyQuestionService) Autowired(org.springframework.beans.factory.annotation.Autowired) Spark.post(spark.Spark.post) CollectionUtilities(org.finos.waltz.common.CollectionUtilities) CsvPreference(org.supercsv.prefs.CsvPreference) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple3(org.jooq.lambda.tuple.Tuple3) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) CsvListWriter(org.supercsv.io.CsvListWriter) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) IdUtilities.indexById(org.finos.waltz.model.utils.IdUtilities.indexById) Collectors.toSet(java.util.stream.Collectors.toSet) StringUtilities(org.finos.waltz.common.StringUtilities) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) SurveyQuestion(org.finos.waltz.model.survey.SurveyQuestion) MapUtilities(org.finos.waltz.common.MapUtilities) Application(org.finos.waltz.model.application.Application) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) NameProvider(org.finos.waltz.model.NameProvider) SettingsService(org.finos.waltz.service.settings.SettingsService) Collectors.toList(java.util.stream.Collectors.toList) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Stream(java.util.stream.Stream) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) WebUtilities(org.finos.waltz.web.WebUtilities) Row(org.apache.poi.ss.usermodel.Row) EntityReference(org.finos.waltz.model.EntityReference) IdUtilities(org.finos.waltz.model.utils.IdUtilities) EntityFieldReference(org.finos.waltz.model.entity_field_reference.EntityFieldReference) StringWriter(java.io.StringWriter) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 7 with CsvListWriter

use of org.supercsv.io.CsvListWriter in project waltz by khartec.

the class SurveyInstanceExtractor method mkCSVReport.

private byte[] mkCSVReport(List<SurveyQuestion> questions, List<List<Object>> reportRows) throws IOException {
    List<String> headers = mkHeaderStrings(questions);
    StringWriter writer = new StringWriter();
    CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreference.EXCEL_PREFERENCE);
    csvWriter.write(headers);
    reportRows.forEach(unchecked(row -> csvWriter.write(simplify(row))));
    csvWriter.flush();
    return writer.toString().getBytes();
}
Also used : DSL(org.jooq.impl.DSL) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DIConfiguration(org.finos.waltz.service.DIConfiguration) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) SURVEY_INSTANCE(org.finos.waltz.schema.tables.SurveyInstance.SURVEY_INSTANCE) SurveyInstanceStatus(org.finos.waltz.model.survey.SurveyInstanceStatus) Tuple2(org.jooq.lambda.tuple.Tuple2) Tuple3(org.jooq.lambda.tuple.Tuple3) ExtractorUtilities.sanitizeSheetName(org.finos.waltz.web.endpoints.extracts.ExtractorUtilities.sanitizeSheetName) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CsvListWriter(org.supercsv.io.CsvListWriter) org.jooq(org.jooq) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) EnumUtilities.names(org.finos.waltz.common.EnumUtilities.names) SurveyQuestion(org.finos.waltz.model.survey.SurveyQuestion) StringUtilities.mkSafe(org.finos.waltz.common.StringUtilities.mkSafe) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) Stream(java.util.stream.Stream) InlineSelectFieldFactory(org.finos.waltz.data.InlineSelectFieldFactory) WebUtilities(org.finos.waltz.web.WebUtilities) SetUtilities(org.finos.waltz.common.SetUtilities) CellType(org.apache.poi.ss.usermodel.CellType) Spark.get(spark.Spark.get) java.util(java.util) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntityKind(org.finos.waltz.model.EntityKind) CsvPreference(org.supercsv.prefs.CsvPreference) SurveyQuestionDao(org.finos.waltz.data.survey.SurveyQuestionDao) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Service(org.springframework.stereotype.Service) Request(spark.Request) SURVEY_RUN(org.finos.waltz.schema.tables.SurveyRun.SURVEY_RUN) SURVEY_QUESTION(org.finos.waltz.schema.tables.SurveyQuestion.SURVEY_QUESTION) SURVEY_QUESTION_RESPONSE(org.finos.waltz.schema.tables.SurveyQuestionResponse.SURVEY_QUESTION_RESPONSE) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) StringWriter(java.io.StringWriter) SURVEY_TEMPLATE(org.finos.waltz.schema.tables.SurveyTemplate.SURVEY_TEMPLATE) IOException(java.io.IOException) Collectors.toList(java.util.stream.Collectors.toList) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities(org.finos.waltz.common.ListUtilities) FunctionUtilities(org.finos.waltz.common.FunctionUtilities) Row(org.apache.poi.ss.usermodel.Row) SetUtilities.fromArray(org.finos.waltz.common.SetUtilities.fromArray) StringWriter(java.io.StringWriter) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 8 with CsvListWriter

use of org.supercsv.io.CsvListWriter in project hive by apache.

the class SeparatedValuesOutputFormat method getFormattedStr.

private String getFormattedStr(String[] vals) {
    StringWriter strWriter = new StringWriter();
    CsvListWriter writer = new CsvListWriter(strWriter, getCsvPreference());
    if (vals.length > 0) {
        try {
            writer.write(vals);
        } catch (IOException e) {
            beeLine.error(e);
        } finally {
            IOUtils.closeStream(writer);
        }
    }
    return strWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) IOException(java.io.IOException) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 9 with CsvListWriter

use of org.supercsv.io.CsvListWriter in project waltz by khartec.

the class CustomDataExtractor method mkCSVReport.

private byte[] mkCSVReport(List<List<Object>> reportRows, List<String> headers) throws IOException {
    StringWriter writer = new StringWriter();
    CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreference.EXCEL_PREFERENCE);
    csvWriter.write(headers);
    reportRows.forEach(unchecked(row -> csvWriter.write(simplify(row))));
    csvWriter.flush();
    return writer.toString().getBytes();
}
Also used : CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) CellType(org.apache.poi.ss.usermodel.CellType) StringWriter(java.io.StringWriter) IOException(java.io.IOException) CsvPreference(org.supercsv.prefs.CsvPreference) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Objects(java.util.Objects) ListUtilities.map(org.finos.waltz.common.ListUtilities.map) List(java.util.List) Tuple3(org.jooq.lambda.tuple.Tuple3) ExtractorUtilities.sanitizeSheetName(org.finos.waltz.web.endpoints.extracts.ExtractorUtilities.sanitizeSheetName) ExtractorUtilities.convertExcelToByteArray(org.finos.waltz.web.endpoints.extracts.ExtractorUtilities.convertExcelToByteArray) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) CsvListWriter(org.supercsv.io.CsvListWriter) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) Row(org.apache.poi.ss.usermodel.Row) Optional(java.util.Optional) StringWriter(java.io.StringWriter) CsvListWriter(org.supercsv.io.CsvListWriter)

Aggregations

CsvListWriter (org.supercsv.io.CsvListWriter)9 CsvPreference (org.supercsv.prefs.CsvPreference)7 IOException (java.io.IOException)6 StringWriter (java.io.StringWriter)6 Tuple.tuple (org.jooq.lambda.tuple.Tuple.tuple)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Cell (org.apache.poi.ss.usermodel.Cell)4 CellType (org.apache.poi.ss.usermodel.CellType)4 Row (org.apache.poi.ss.usermodel.Row)4 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)4 SXSSFSheet (org.apache.poi.xssf.streaming.SXSSFSheet)4 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)4 EntityKind (org.finos.waltz.model.EntityKind)4 CheckedConsumer.unchecked (org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked)4 Tuple3 (org.jooq.lambda.tuple.Tuple3)4 Service (org.springframework.stereotype.Service)4 java.util (java.util)3 ListUtilities (org.finos.waltz.common.ListUtilities)3 StringUtilities (org.finos.waltz.common.StringUtilities)3 EntityReference (org.finos.waltz.model.EntityReference)3