Search in sources :

Example 1 with FieldDefinition

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

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

the class Mondrian4SchemaGenerator method createAttributesForFields.

private List<Attribute> createAttributesForFields(DataTable dataTable, AttributeDefinition attrDefn) {
    List<FieldDefinition<?>> fieldDefs = attrDefn.getFieldDefinitions();
    List<Attribute> attributes = new ArrayList<Attribute>(fieldDefs.size());
    for (FieldDefinition<?> fieldDef : fieldDefs) {
        DataColumn col = dataTable.getDataColumn(fieldDef);
        if (col != null) {
            Attribute attribute = new Attribute();
            String fieldName = fieldDef.getName();
            attribute.name = fieldName;
            attribute.caption = getAttributeCaption(fieldDef);
            attribute.keyColumn = col.getName();
            // if (attrDefn instanceof DateAttributeDefinition) {
            // attribute.levelType = getDateFieldLevelType(fieldName);
            // }
            attributes.add(attribute);
        }
    }
    return attributes;
}
Also used : Attribute(mondrian.olap.MondrianDef.Attribute) FieldDefinition(org.openforis.idm.metamodel.FieldDefinition) ArrayList(java.util.ArrayList) DataColumn(org.openforis.collect.relational.model.DataColumn)

Example 3 with FieldDefinition

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

the class DataTable method getDataColumn.

public DataColumn getDataColumn(FieldDefinition<?> fieldDefinition) {
    AttributeDefinition attributeDefinition = (AttributeDefinition) fieldDefinition.getParentDefinition();
    List<DataColumn> attributeDataColumns = getDataColumns(attributeDefinition);
    String fieldDefinitionName = fieldDefinition.getName();
    for (DataColumn column : attributeDataColumns) {
        NodeDefinition columnNodeDefn = column.getNodeDefinition();
        if (columnNodeDefn instanceof FieldDefinition && columnNodeDefn.getName().equals(fieldDefinitionName)) {
            return column;
        }
    }
    return null;
}
Also used : FieldDefinition(org.openforis.idm.metamodel.FieldDefinition) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition)

Aggregations

FieldDefinition (org.openforis.idm.metamodel.FieldDefinition)3 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 ArrayList (java.util.ArrayList)1 Attribute (mondrian.olap.MondrianDef.Attribute)1 DataColumn (org.openforis.collect.relational.model.DataColumn)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1