Search in sources :

Example 26 with EntityDefinition

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

the class DataCSVReader method extractFieldDefinition.

private FieldDefinition<?> extractFieldDefinition(EntityDefinition parentEntityDefn, String colName) {
    String absoluteColName = getAbsoluteColName(colName);
    List<NodeDefinition> childDefns = parentEntityDefn.getChildDefinitions();
    for (NodeDefinition childDefn : childDefns) {
        String childName = childDefn.getName();
        if (absoluteColName.equals(childName)) {
            if (childDefn instanceof AttributeDefinition) {
                AttributeDefinition attrDefn = (AttributeDefinition) childDefn;
                if (attrDefn.hasMainField()) {
                    String mainFieldName = attrDefn.getMainFieldName();
                    return attrDefn.getFieldDefinition(mainFieldName);
                } else {
                    // it is a composite attribute without a "main" field (date, time, coordinate, taxon)
                    return null;
                }
            } else {
                // column name matches an entity name: error
                return null;
            }
        } else if (absoluteColName.startsWith(childName + ATTRIBUTE_FIELD_SEPARATOR)) {
            if (childDefn instanceof EntityDefinition) {
                if (childDefn.isMultiple()) {
                // ignore it
                } else {
                    String colNamePart = absoluteColName.substring(childName.length() + ATTRIBUTE_FIELD_SEPARATOR.length());
                    FieldDefinition<?> nestedFieldDefn = extractFieldDefinition((EntityDefinition) childDefn, colNamePart);
                    if (nestedFieldDefn != null) {
                        return nestedFieldDefn;
                    }
                }
            } else {
                for (FieldDefinition<?> fieldDefn : ((AttributeDefinition) childDefn).getFieldDefinitions()) {
                    if (absoluteColName.equals(childName + ATTRIBUTE_FIELD_SEPARATOR + fieldDefn.getName())) {
                        return fieldDefn;
                    }
                }
            }
        }
    }
    return null;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) FieldDefinition(org.openforis.idm.metamodel.FieldDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 27 with EntityDefinition

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

the class DataCSVReader method getAncestorKeyAttributeDefinitions.

protected List<AttributeDefinition> getAncestorKeyAttributeDefinitions() {
    List<AttributeDefinition> result = new ArrayList<AttributeDefinition>();
    List<EntityDefinition> ancestors = parentEntityDefinition.getAncestorEntityDefinitionsInReverseOrder();
    for (EntityDefinition ancestor : ancestors) {
        result.addAll(ancestor.getKeyAttributeDefinitions());
    }
    result.addAll(parentEntityDefinition.getKeyAttributeDefinitions());
    return result;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 28 with EntityDefinition

use of org.openforis.idm.metamodel.EntityDefinition 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 29 with EntityDefinition

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

the class EventProducer method getAncestorIds.

private List<String> getAncestorIds(NodeDefinition nodeDef, List<Integer> ancestorEntityIds) {
    if (nodeDef instanceof EntityDefinition && ((EntityDefinition) nodeDef).isRoot()) {
        return Collections.emptyList();
    }
    List<String> ancestorIds = new ArrayList<String>();
    if (nodeDef.isMultiple()) {
        int parentId = ancestorEntityIds.get(0);
        ancestorIds.add(getNodeCollectionId(parentId, nodeDef));
    }
    List<EntityDefinition> ancestorDefs = nodeDef.getAncestorEntityDefinitions();
    for (int ancestorIdx = 0; ancestorIdx < ancestorEntityIds.size(); ancestorIdx++) {
        int ancestorEntityId = ancestorEntityIds.get(ancestorIdx);
        EntityDefinition ancestorDef = ancestorDefs.get(ancestorIdx);
        ancestorIds.add(String.valueOf(ancestorEntityId));
        boolean inCollection = !ancestorDef.isRoot() && ancestorDef.isMultiple();
        if (inCollection) {
            Integer ancestorParentId = ancestorEntityIds.get(ancestorIdx + 1);
            ancestorIds.add(getNodeCollectionId(ancestorParentId, ancestorDef));
        }
    }
    return ancestorIds;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) ArrayList(java.util.ArrayList)

Example 30 with EntityDefinition

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

the class Entity method getKeyAttributeValues.

public Value[] getKeyAttributeValues() {
    EntityDefinition defn = getDefinition();
    List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
    if (keyDefns.isEmpty()) {
        return null;
    } else {
        Value[] result = new Value[keyDefns.size()];
        for (int i = 0; i < keyDefns.size(); i++) {
            AttributeDefinition keyDefn = keyDefns.get(i);
            Attribute<?, Value> keyAttr = getKeyAttribute(keyDefn);
            Value keyValue = keyAttr == null ? null : keyAttr.getValue();
            result[i] = keyValue;
        }
        return result;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Aggregations

EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)235 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)70 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)47 Schema (org.openforis.idm.metamodel.Schema)46 ArrayList (java.util.ArrayList)44 Test (org.junit.Test)38 Entity (org.openforis.idm.model.Entity)36 CollectRecord (org.openforis.collect.model.CollectRecord)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)28 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)24 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)24 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)19 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)18 UITab (org.openforis.collect.metamodel.ui.UITab)16 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)14 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)13 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)12 RecordFilter (org.openforis.collect.model.RecordFilter)11 SurveyObject (org.openforis.idm.metamodel.SurveyObject)10 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)9