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);
}
Aggregations