Search in sources :

Example 1 with BasicColumnProvider

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

the class DataCSVReader method calculateIgnoredColumns.

private List<String> calculateIgnoredColumns() {
    final CSVDataExportParameters csvExportConfig = new CSVDataExportParameters();
    csvExportConfig.setIncludeCodeItemLabelColumn(true);
    csvExportConfig.setIncludeEnumeratedEntities(false);
    CollectSurvey survey = (CollectSurvey) parentEntityDefinition.getSurvey();
    ColumnProviderChain columnProvider = new CSVDataExportColumnProviderGenerator(survey, csvExportConfig).generateColumnProviderChain(parentEntityDefinition);
    List<String> result = new ArrayList<String>();
    List<String> colNames = getColumnNames();
    for (final String colName : colNames) {
        final MutableBoolean ignored = new MutableBoolean(false);
        columnProvider.traverseProviders(new Visitor<ColumnProvider>() {

            public void visit(ColumnProvider p) {
                if (!(p instanceof ColumnProviderChain) && p instanceof BasicColumnProvider) {
                    List<String> finalColumnHeadings = ((BasicColumnProvider) p).generateFinalColumnHeadings();
                    if (finalColumnHeadings.contains(colName)) {
                        if (p instanceof CodeColumnProvider && colName.endsWith(csvExportConfig.getFieldHeadingSeparator() + CodeColumnProvider.ITEM_LABEL_SUFFIX)) {
                            ignored.setTrue();
                        }
                    }
                }
            }
        });
        if (ignored.booleanValue()) {
            result.add(colName);
        }
    }
    return result;
}
Also used : ColumnProviderChain(org.openforis.collect.io.data.csv.ColumnProviderChain) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) ArrayList(java.util.ArrayList) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CodeColumnProvider(org.openforis.collect.io.data.csv.CodeColumnProvider) BasicColumnProvider(org.openforis.collect.io.data.csv.BasicColumnProvider) CodeColumnProvider(org.openforis.collect.io.data.csv.CodeColumnProvider) ColumnProvider(org.openforis.collect.io.data.csv.ColumnProvider) BasicColumnProvider(org.openforis.collect.io.data.csv.BasicColumnProvider) ArrayList(java.util.ArrayList) List(java.util.List) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 BasicColumnProvider (org.openforis.collect.io.data.csv.BasicColumnProvider)1 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)1 CodeColumnProvider (org.openforis.collect.io.data.csv.CodeColumnProvider)1 ColumnProvider (org.openforis.collect.io.data.csv.ColumnProvider)1 ColumnProviderChain (org.openforis.collect.io.data.csv.ColumnProviderChain)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1