Search in sources :

Example 1 with PivotExpressionColumnProvider

use of org.openforis.collect.io.data.csv.PivotExpressionColumnProvider 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)1 AutomaticColumnProvider (org.openforis.collect.io.data.csv.AutomaticColumnProvider)1 ColumnProvider (org.openforis.collect.io.data.csv.ColumnProvider)1 ColumnProviderChain (org.openforis.collect.io.data.csv.ColumnProviderChain)1 NodePositionColumnProvider (org.openforis.collect.io.data.csv.NodePositionColumnProvider)1 PivotExpressionColumnProvider (org.openforis.collect.io.data.csv.PivotExpressionColumnProvider)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1