Search in sources :

Example 56 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class DataCSVReader method getAncestorIdentifiers.

private List<EntityIdentifierDefinition> getAncestorIdentifiers() {
    List<EntityDefinition> ancestorEntityDefns = parentEntityDefinition.getAncestorEntityDefinitionsInReverseOrder();
    ancestorEntityDefns.add(parentEntityDefinition);
    List<EntityIdentifierDefinition> entityIdentifierDefns = new ArrayList<DataLine.EntityIdentifierDefinition>();
    for (EntityDefinition ancestorEntityDefn : ancestorEntityDefns) {
        EntityIdentifierDefinition identifier;
        if (ancestorEntityDefn.isMultiple()) {
            List<AttributeDefinition> keyDefns = ancestorEntityDefn.getKeyAttributeDefinitions();
            if (keyDefns.isEmpty()) {
                identifier = new DataLine.EntityPositionIdentifierDefinition(ancestorEntityDefn.getId());
            } else {
                identifier = new DataLine.EntityKeysIdentifierDefintion(ancestorEntityDefn);
            }
        } else {
            identifier = new DataLine.SingleEntityIdentifierDefinition(ancestorEntityDefn.getId());
        }
        entityIdentifierDefns.add(identifier);
    }
    return entityIdentifierDefns;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) EntityKeysIdentifierDefintion(org.openforis.collect.io.data.DataLine.EntityKeysIdentifierDefintion) SingleEntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) EntityPositionIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityPositionIdentifierDefinition) SingleEntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.SingleEntityIdentifierDefinition) EntityIdentifierDefinition(org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition)

Example 57 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class AutomaticColumnProvider method createProviders.

private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition rowDefn, List<String> exclusions) {
    List<ColumnProvider> cols = new ArrayList<ColumnProvider>();
    CollectSurvey survey = (CollectSurvey) rowDefn.getSurvey();
    CollectAnnotations surveyAnnotations = survey.getAnnotations();
    List<NodeDefinition> childDefinitions = rowDefn.getChildDefinitions();
    for (NodeDefinition childDefn : childDefinitions) {
        if (includeChild(exclusions, childDefn)) {
            if (childDefn instanceof EntityDefinition) {
                createEntityProviders(config, (EntityDefinition) childDefn, cols);
            } else if (childDefn instanceof AttributeDefinition && surveyAnnotations.isIncludedInDataExport(childDefn)) {
                cols.add(ColumnProviders.createAttributeProvider(config, (AttributeDefinition) childDefn));
            }
        }
    }
    return cols;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 58 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition 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)

Example 59 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class EnumerableEntityColumnProvider method createProviders.

private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition defn) {
    List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
    List<AttributeDefinition> keyDefs = defn.getKeyAttributeDefinitions();
    CodeAttributeDefinition keyDef = (CodeAttributeDefinition) keyDefs.get(0);
    CodeList codeList = keyDef.getList();
    SurveyContext context = defn.getSurvey().getContext();
    CodeListService codeListService = context.getCodeListService();
    List<CodeListItem> items = codeListService.loadRootItems(codeList);
    for (CodeListItem item : items) {
        String code = item.getCode();
        String keyName = keyDef.getName();
        EnumeratedCodeItemColumnProvider p = new EnumeratedCodeItemColumnProvider(config, defn, keyName, code);
        providers.add(p);
    }
    return providers;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) SurveyContext(org.openforis.idm.metamodel.SurveyContext) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 60 with AttributeDefinition

use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.

the class XPathDataQueryEvaluator method evaluate.

@Override
public List<Node<?>> evaluate(CollectRecord record) {
    List<Node<?>> result = new ArrayList<Node<?>>();
    String condition = query.getConditions();
    AttributeDefinition attrDef = query.getAttributeDefinition();
    SurveyContext surveyContext = record.getSurveyContext();
    ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
    List<Node<?>> nodes = record.findNodesByPath(attrDef.getPath());
    for (Node<?> node : nodes) {
        try {
            if (expressionEvaluator.evaluateBoolean(node.getParent(), node, condition)) {
                result.add(node);
            }
        } catch (InvalidExpressionException e) {
            throw new RuntimeException(e);
        }
    }
    return result;
}
Also used : InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) ExpressionEvaluator(org.openforis.idm.model.expression.ExpressionEvaluator) SurveyContext(org.openforis.idm.metamodel.SurveyContext)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8