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