Search in sources :

Example 1 with ColumnProviderChain

use of org.openforis.collect.io.data.csv.ColumnProviderChain 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)

Example 2 with ColumnProviderChain

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

the class CSVDataExportColumnProviderGenerator method generateColumnProviderChain.

public ColumnProviderChain generateColumnProviderChain(EntityDefinition entityDefn) {
    List<ColumnProvider> columnProviders = new ArrayList<ColumnProvider>();
    // entity children columns
    AutomaticColumnProvider entityColumnProvider = createEntityColumnProvider(entityDefn);
    // ancestor columns
    columnProviders.addAll(createAncestorsColumnsProvider(entityDefn));
    // position column
    if (isPositionColumnRequired(entityDefn)) {
        columnProviders.add(createPositionColumnProvider(entityDefn));
    }
    columnProviders.add(entityColumnProvider);
    // create data transformation
    ColumnProviderChain provider = new ColumnProviderChain(configuration, columnProviders);
    return provider;
}
Also used : ColumnProviderChain(org.openforis.collect.io.data.csv.ColumnProviderChain) ArrayList(java.util.ArrayList) 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) AutomaticColumnProvider(org.openforis.collect.io.data.csv.AutomaticColumnProvider)

Example 3 with ColumnProviderChain

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

the class CSVDataExportColumnProviderGenerator method createAncestorColumnProvider.

private ColumnProvider createAncestorColumnProvider(EntityDefinition contextEntityDefn, EntityDefinition ancestorEntityDefn) {
    List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
    if (configuration.isIncludeAllAncestorAttributes()) {
        AutomaticColumnProvider ancestorEntityColumnProvider = new AutomaticColumnProvider(configuration, ColumnProviders.generateHeadingPrefix(ancestorEntityDefn, configuration) + configuration.getFieldHeadingSeparator(), ancestorEntityDefn);
        providers.add(0, ancestorEntityColumnProvider);
    } else {
        // include only key attributes
        List<AttributeDefinition> keyAttrDefns = ancestorEntityDefn.getKeyAttributeDefinitions();
        for (AttributeDefinition keyDefn : keyAttrDefns) {
            String relativePath = contextEntityDefn.getRelativePath(ancestorEntityDefn);
            ColumnProvider keyColumnProvider = ColumnProviders.createAttributeProvider(configuration, keyDefn);
            String headingPrefix = configuration.isIncludeGroupingLabels() ? ColumnProviders.generateHeadingPrefix(keyDefn.getParentEntityDefinition(), configuration) + configuration.getFieldHeadingSeparator() : "";
            PivotExpressionColumnProvider columnProvider = new PivotExpressionColumnProvider(configuration, relativePath, headingPrefix, keyColumnProvider);
            providers.add(columnProvider);
        }
        if (isPositionColumnRequired(ancestorEntityDefn)) {
            String relativePath = contextEntityDefn.getRelativePath(ancestorEntityDefn);
            ColumnProvider positionColumnProvider = createPositionColumnProvider(ancestorEntityDefn);
            PivotExpressionColumnProvider columnProvider = new PivotExpressionColumnProvider(configuration, relativePath, "", positionColumnProvider);
            providers.add(columnProvider);
        }
    }
    return new ColumnProviderChain(configuration, providers);
}
Also used : ColumnProviderChain(org.openforis.collect.io.data.csv.ColumnProviderChain) PivotExpressionColumnProvider(org.openforis.collect.io.data.csv.PivotExpressionColumnProvider) ArrayList(java.util.ArrayList) 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) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) AutomaticColumnProvider(org.openforis.collect.io.data.csv.AutomaticColumnProvider)

Aggregations

ArrayList (java.util.ArrayList)3 ColumnProvider (org.openforis.collect.io.data.csv.ColumnProvider)3 ColumnProviderChain (org.openforis.collect.io.data.csv.ColumnProviderChain)3 AutomaticColumnProvider (org.openforis.collect.io.data.csv.AutomaticColumnProvider)2 NodePositionColumnProvider (org.openforis.collect.io.data.csv.NodePositionColumnProvider)2 PivotExpressionColumnProvider (org.openforis.collect.io.data.csv.PivotExpressionColumnProvider)2 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 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1