Search in sources :

Example 11 with CsvWriter

use of org.openforis.commons.io.csv.CsvWriter in project collect by openforis.

the class SchemaSummaryCSVExportJob method buildTasks.

@Override
protected void buildTasks() throws Throwable {
    Task task = new Task() {

        @Override
        protected void execute() throws Throwable {
            FileOutputStream out = new FileOutputStream(outputFile);
            final CsvWriter csvWriter = new CsvWriter(new BufferedWriter(new OutputStreamWriter(out, "UTF-8")), ',', '"');
            try {
                csvWriter.writeHeaders(HEADERS);
                Schema schema = survey.getSchema();
                schema.traverse(new NodeDefinitionVisitor() {

                    @Override
                    public void visit(NodeDefinition nodeDefn) {
                        csvWriter.writeNext(new String[] { Integer.toString(nodeDefn.getId()), nodeDefn.getPath(), nodeDefn instanceof EntityDefinition ? "entity" : "attribute", nodeDefn instanceof AttributeDefinition ? AttributeType.valueOf((AttributeDefinition) nodeDefn).getLabel() : "", nodeDefn.getLabel(Type.INSTANCE, labelLanguage), String.valueOf(nodeDefn.isAlwaysRelevant()), nodeDefn.isAlwaysRelevant() ? "" : nodeDefn.getRelevantExpression(), String.valueOf(nodeDefn.isAlwaysRequired()), nodeDefn.isAlwaysRequired() ? "" : nodeDefn.getMinCountExpression(), extractValidationRules(nodeDefn) });
                    }
                });
            } finally {
                IOUtils.closeQuietly(csvWriter);
            }
        }
    };
    addTask(task);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Task(org.openforis.concurrency.Task) CsvWriter(org.openforis.commons.io.csv.CsvWriter) FileOutputStream(java.io.FileOutputStream) Schema(org.openforis.idm.metamodel.Schema) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) OutputStreamWriter(java.io.OutputStreamWriter) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor) BufferedWriter(java.io.BufferedWriter)

Aggregations

CsvWriter (org.openforis.commons.io.csv.CsvWriter)11 FileOutputStream (java.io.FileOutputStream)4 ArrayList (java.util.ArrayList)4 OutputStreamWriter (java.io.OutputStreamWriter)3 TaxonSummaries (org.openforis.collect.metamodel.TaxonSummaries)3 TaxonSummary (org.openforis.collect.metamodel.TaxonSummary)3 CollectTaxonomy (org.openforis.collect.model.CollectTaxonomy)3 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)2 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)2 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Task (org.openforis.concurrency.Task)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)1 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)1 ReferenceDataDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.ReferenceDataDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1