Search in sources :

Example 1 with CsvListWriter

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

the class BaseDataExtractor method writeFile.

protected Object writeFile(String suggestedFilename, CSVSerializer extractor, Response response) throws Exception {
    response.type(MimeTypes.Type.TEXT_PLAIN.name());
    response.header("Content-disposition", "attachment; filename=" + suggestedFilename);
    StringWriter bodyWriter = new StringWriter();
    CsvPreference csvPreference = CsvPreference.EXCEL_PREFERENCE;
    CsvListWriter csvWriter = new CsvListWriter(bodyWriter, csvPreference);
    csvWriter.write("sep=" + Character.toString((char) csvPreference.getDelimiterChar()));
    extractor.accept(csvWriter);
    csvWriter.flush();
    return bodyWriter.toString();
}
Also used : CsvPreference(org.supercsv.prefs.CsvPreference) StringWriter(java.io.StringWriter) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 2 with CsvListWriter

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

the class SeparatedValuesOutputFormat method print.

@Override
public int print(Rows rows) {
    CsvPreference csvPreference = getCsvPreference();
    CsvListWriter writer = new CsvListWriter(this.buffer, csvPreference);
    int count = 0;
    Rows.Row labels = (Rows.Row) rows.next();
    if (beeLine.getOpts().getShowHeader()) {
        fillBuffer(writer, labels);
        String line = getLine(this.buffer);
        beeLine.output(line);
    }
    while (rows.hasNext()) {
        fillBuffer(writer, (Rows.Row) rows.next());
        String line = getLine(this.buffer);
        beeLine.output(line);
        count++;
    }
    return count;
}
Also used : CsvPreference(org.supercsv.prefs.CsvPreference) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 3 with CsvListWriter

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

the class FlowSummaryWithTypesAndPhysicalsExport method setupCSVWriter.

private static CsvListWriter setupCSVWriter() throws IOException {
    CsvListWriter csvWriter = new CsvListWriter(new OutputStreamWriter(new FileOutputStream("/temp/flows.csv")), CsvPreference.EXCEL_PREFERENCE);
    csvWriter.write("Source App", "Source Asset Code", "Source App Kind", "Source App Status", // src OU
    "Source App Org Unit", "Source In Scope", "Target App", "Target Asset Code", "Target App Kind", "Target App Status", // src OU
    "Target App Org Unit", "Target In Scope", "Data Types", "Physical Name", "Physical ExtId", "Physical Transport", "Physical Format", "Physical Frequency", "Criticality");
    return csvWriter;
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 4 with CsvListWriter

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

the class FlowSummaryWithTypesAndPhysicalsExport method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationIdSelectorFactory appIdSelectorFactory = new ApplicationIdSelectorFactory();
    ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
    OrganisationalUnitDao organisationalUnitDao = ctx.getBean(OrganisationalUnitDao.class);
    LogicalFlowDao logicalFlowDao = ctx.getBean(LogicalFlowDao.class);
    LogicalFlowDecoratorDao decoratorDao = ctx.getBean(LogicalFlowDecoratorDao.class);
    DataTypeDao dataTypeDao = ctx.getBean(DataTypeDao.class);
    Select<Record1<Long>> appSelector = mkAppIdSelector(appIdSelectorFactory);
    Select<Record1<Long>> logicalFlowSelector = mkLogicalFlowSelectorFromAppSelector(appSelector);
    System.out.println("Loading apps");
    Set<Application> allApps = fromCollection(applicationDao.findAll());
    System.out.println("Loading in scope apps");
    Set<Long> inScopeAppIds = toIds(applicationDao.findByAppIdSelector(appSelector));
    System.out.println("Loading OUs");
    List<OrganisationalUnit> allOUs = organisationalUnitDao.findAll();
    System.out.println("Loading DTs");
    List<DataType> allDataTypes = dataTypeDao.findAll();
    System.out.println("Loading Logical Flows");
    List<LogicalFlow> logicalFlows = logicalFlowDao.findBySelector(logicalFlowSelector);
    System.out.println("Loading decorators");
    List<DataTypeDecorator> decorators = decoratorDao.findByAppIdSelector(appSelector);
    System.out.println("Loading phys flows");
    Map<Long, Collection<Tuple7<Long, String, String, String, String, String, String>>> physicalsByLogical = loadPhysicalsByLogical(dsl, logicalFlowSelector);
    System.out.println("Indexing");
    Map<Optional<Long>, Application> appsById = indexByOptId(allApps);
    Map<Optional<Long>, DataType> dataTypesById = indexByOptId(allDataTypes);
    Map<Optional<Long>, OrganisationalUnit> ousById = indexByOptId(allOUs);
    Map<Long, Collection<DataTypeDecorator>> decoratorsByLogicalFlowId = groupBy(DataTypeDecorator::dataFlowId, decorators);
    System.out.println("Processing");
    CsvListWriter csvWriter = setupCSVWriter();
    logicalFlows.stream().filter(lf -> lf.source().kind() == EntityKind.APPLICATION && lf.target().kind() == EntityKind.APPLICATION).map(Tuple::tuple).map(t -> t.concat(appsById.get(Optional.of(t.v1.source().id())))).map(t -> t.concat(appsById.get(Optional.of(t.v1.target().id())))).filter(t -> t.v2 != null && t.v3 != null).map(t -> t.concat(ousById.get(Optional.of(t.v2.organisationalUnitId())))).map(t -> t.concat(ousById.get(Optional.of(t.v3.organisationalUnitId())))).map(t -> t.concat(decoratorsByLogicalFlowId.getOrDefault(t.v1.id().orElse(-1L), emptyList()).stream().filter(d -> d.decoratorEntity().kind() == EntityKind.DATA_TYPE).map(d -> dataTypesById.get(Optional.of(d.decoratorEntity().id()))).sorted(Comparator.comparing(NameProvider::name)).collect(Collectors.toList()))).map(t -> t.concat(inScopeAppIds.contains(t.v2.id().get()))).map(t -> t.concat(inScopeAppIds.contains(t.v3.id().get()))).flatMap(t -> physicalsByLogical.getOrDefault(t.v1.id().orElse(-1L), newArrayList(tuple(-1L, "-", "-", "-", "-", "-", "-"))).stream().map(p -> t.concat(p.skip1()))).map(t -> newArrayList(// src
    t.v2.name(), t.v2.assetCode().map(ExternalIdValue::value).orElse(""), t.v2.applicationKind().name(), t.v2.entityLifecycleStatus().name(), // src OU
    Optional.ofNullable(t.v4).map(NameProvider::name).orElse("?"), t.v7.toString(), // trg
    t.v3.name(), t.v3.assetCode().map(ExternalIdValue::value).orElse(""), t.v3.applicationKind().name(), t.v3.entityLifecycleStatus().name(), // trg OU
    Optional.ofNullable(t.v5).map(NameProvider::name).orElse("?"), t.v8.toString(), StringUtilities.joinUsing(t.v6, NameProvider::name, ","), t.v9, t.v10, t.v11, t.v12, t.v13, t.v14)).forEach(Unchecked.consumer(csvWriter::write));
}
Also used : OrganisationalUnitDao(org.finos.waltz.data.orgunit.OrganisationalUnitDao) OrganisationalUnitDao(org.finos.waltz.data.orgunit.OrganisationalUnitDao) java.util(java.util) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) DIConfiguration(org.finos.waltz.service.DIConfiguration) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) CsvPreference(org.supercsv.prefs.CsvPreference) Function(java.util.function.Function) Condition(org.jooq.Condition) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) DataType(org.finos.waltz.model.datatype.DataType) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) LOGICAL_NOT_REMOVED(org.finos.waltz.data.logical_flow.LogicalFlowDao.LOGICAL_NOT_REMOVED) Record1(org.jooq.Record1) CsvListWriter(org.supercsv.io.CsvListWriter) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Tuple7(org.jooq.lambda.tuple.Tuple7) DSLContext(org.jooq.DSLContext) OutputStreamWriter(java.io.OutputStreamWriter) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) Select(org.jooq.Select) StringUtilities(org.finos.waltz.common.StringUtilities) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) Unchecked(org.jooq.lambda.Unchecked) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Application(org.finos.waltz.model.application.Application) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) IdUtilities.toIds(org.finos.waltz.model.utils.IdUtilities.toIds) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) NameProvider(org.finos.waltz.model.NameProvider) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) LogicalFlowDecoratorDao(org.finos.waltz.data.datatype_decorator.LogicalFlowDecoratorDao) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Tuple(org.jooq.lambda.tuple.Tuple) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) EntityReference(org.finos.waltz.model.EntityReference) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) IdUtilities.indexByOptId(org.finos.waltz.model.utils.IdUtilities.indexByOptId) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) LogicalFlowDecoratorDao(org.finos.waltz.data.datatype_decorator.LogicalFlowDecoratorDao) DataType(org.finos.waltz.model.datatype.DataType) Record1(org.jooq.Record1) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) NameProvider(org.finos.waltz.model.NameProvider) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) Application(org.finos.waltz.model.application.Application) CsvListWriter(org.supercsv.io.CsvListWriter)

Example 5 with CsvListWriter

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

the class AttestationExtractor method mkCSVReport.

private byte[] mkCSVReport(List<String> columnDefinitions, Set<ApplicationAttestationInstanceSummary> reportRows) throws IOException {
    StringWriter writer = new StringWriter();
    CsvListWriter csvWriter = new CsvListWriter(writer, CsvPreference.EXCEL_PREFERENCE);
    csvWriter.write(columnDefinitions);
    reportRows.forEach(unchecked(r -> {
        List<Object> values = asList(r.appRef().id(), r.appRef().name().get(), r.appAssetCode(), r.appCriticality(), r.appLifecyclePhase(), r.appKind(), r.attestedAt(), r.attestedBy());
        csvWriter.write(values);
    }));
    csvWriter.flush();
    return writer.toString().getBytes();
}
Also used : CellType(org.apache.poi.ss.usermodel.CellType) Spark.get(spark.Spark.get) APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) Spark.post(spark.Spark.post) CsvPreference(org.supercsv.prefs.CsvPreference) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) SelectConditionStep(org.jooq.SelectConditionStep) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) CsvListWriter(org.supercsv.io.CsvListWriter) ATTESTATION_INSTANCE_RECIPIENT(org.finos.waltz.schema.tables.AttestationInstanceRecipient.ATTESTATION_INSTANCE_RECIPIENT) Cell(org.apache.poi.ss.usermodel.Cell) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) ApplicationAttestationInstanceSummary(org.finos.waltz.model.attestation.ApplicationAttestationInstanceSummary) Record(org.jooq.Record) StringWriter(java.io.StringWriter) ATTESTATION_INSTANCE(org.finos.waltz.schema.tables.AttestationInstance.ATTESTATION_INSTANCE) Set(java.util.Set) IOException(java.io.IOException) ATTESTATION_RUN(org.finos.waltz.schema.tables.AttestationRun.ATTESTATION_RUN) String.format(java.lang.String.format) ApplicationAttestationInstanceInfo(org.finos.waltz.model.attestation.ApplicationAttestationInstanceInfo) Objects(java.util.Objects) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ExternalIdValue(org.finos.waltz.model.external_identifier.ExternalIdValue) CheckedConsumer.unchecked(org.jooq.lambda.fi.util.function.CheckedConsumer.unchecked) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) ListUtilities(org.finos.waltz.common.ListUtilities) AttestationInstanceService(org.finos.waltz.service.attestation.AttestationInstanceService) WebUtilities(org.finos.waltz.web.WebUtilities) Row(org.apache.poi.ss.usermodel.Row) EntityReference(org.finos.waltz.model.EntityReference) Optional(java.util.Optional) StringWriter(java.io.StringWriter) List(java.util.List) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) 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