Search in sources :

Example 1 with DataTransformation

use of org.openforis.collect.io.data.csv.DataTransformation in project collect by openforis.

the class CSVDataExportColumnProviderGenerator method generateDataTransformation.

public DataTransformation generateDataTransformation(int entityDefId) throws InvalidExpressionException {
    Schema schema = survey.getSchema();
    EntityDefinition entityDefn = (EntityDefinition) schema.getDefinitionById(entityDefId);
    ColumnProvider provider = generateColumnProviderChain(entityDefn);
    String axisPath = entityDefn.getPath();
    return new DataTransformation(axisPath, provider);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) DataTransformation(org.openforis.collect.io.data.csv.DataTransformation) PivotExpressionColumnProvider(org.openforis.collect.io.data.csv.PivotExpressionColumnProvider) AutomaticColumnProvider(org.openforis.collect.io.data.csv.AutomaticColumnProvider) ColumnProvider(org.openforis.collect.io.data.csv.ColumnProvider) NodePositionColumnProvider(org.openforis.collect.io.data.csv.NodePositionColumnProvider)

Example 2 with DataTransformation

use of org.openforis.collect.io.data.csv.DataTransformation in project collect by openforis.

the class CSVDataExportProcess method exportData.

// private String calculateOutputFileName() {
// return "data.zip";
// /*
// StringBuilder sb = new StringBuilder();
// sb.append(survey.getName());
// sb.append("_");
// sb.append(rootEntityName);
// sb.append("_");
// sb.append("csv_data");
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// String today = formatter.format(new Date());
// sb.append(today);
// sb.append(".zip");
// return sb.toString();
// */
// }
private void exportData(OutputStream outputStream, int entityDefId) throws InvalidExpressionException, IOException, RecordPersistenceException {
    Writer outputWriter = new OutputStreamWriter(outputStream, OpenForisIOUtils.UTF_8);
    CSVDataExportColumnProviderGenerator csvDataExportColumnProviderGenerator = new CSVDataExportColumnProviderGenerator(recordFilter.getSurvey(), configuration);
    DataTransformation transform = csvDataExportColumnProviderGenerator.generateDataTransformation(entityDefId);
    @SuppressWarnings("resource") ModelCsvWriter // closing modelWriter will close referenced output stream
    modelWriter = new ModelCsvWriter(outputWriter, transform);
    modelWriter.printColumnHeadings();
    CollectSurvey survey = recordFilter.getSurvey();
    Step step = recordFilter.getStepGreaterOrEqual();
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
    for (CollectRecordSummary s : summaries) {
        if (status.isRunning()) {
            try {
                CollectRecord record = recordManager.load(survey, s.getId(), step, false);
                modelWriter.printData(record);
            } catch (Exception e) {
                LOG.error(e.getMessage(), e);
            }
            status.incrementProcessed();
        } else {
            break;
        }
    }
    modelWriter.flush();
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) DataTransformation(org.openforis.collect.io.data.csv.DataTransformation) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) OutputStreamWriter(java.io.OutputStreamWriter) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) ModelCsvWriter(org.openforis.collect.io.data.csv.ModelCsvWriter) ModelCsvWriter(org.openforis.collect.io.data.csv.ModelCsvWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) IOException(java.io.IOException)

Aggregations

DataTransformation (org.openforis.collect.io.data.csv.DataTransformation)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 AutomaticColumnProvider (org.openforis.collect.io.data.csv.AutomaticColumnProvider)1 ColumnProvider (org.openforis.collect.io.data.csv.ColumnProvider)1 ModelCsvWriter (org.openforis.collect.io.data.csv.ModelCsvWriter)1 NodePositionColumnProvider (org.openforis.collect.io.data.csv.NodePositionColumnProvider)1 PivotExpressionColumnProvider (org.openforis.collect.io.data.csv.PivotExpressionColumnProvider)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 RecordPersistenceException (org.openforis.collect.persistence.RecordPersistenceException)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 Schema (org.openforis.idm.metamodel.Schema)1 InvalidExpressionException (org.openforis.idm.model.expression.InvalidExpressionException)1