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;
}
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;
}
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;
}
Aggregations