use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportProcess method setRecordKeys.
private void setRecordKeys(DataLine line, CollectRecord record) {
EntityDefinition rootEntityDefn = record.getRootEntity().getDefinition();
Value[] recordKeyValues = line.getRecordKeyValues(rootEntityDefn);
List<AttributeDefinition> keyAttributeDefinitions = rootEntityDefn.getKeyAttributeDefinitions();
for (int i = 0; i < keyAttributeDefinitions.size(); i++) {
AttributeDefinition keyDefn = keyAttributeDefinitions.get(i);
// for record key attributes, absolute path must be equal to relative path
Attribute<?, ?> keyAttr = record.findNodeByPath(keyDefn.getPath());
Value keyVal = recordKeyValues[i];
setValueInField(keyAttr, keyDefn.getMainFieldName(), ((AbstractValue) keyVal).toInternalString(), line.getLineNumber(), null);
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportProcess method createParentEntitySearchError.
private ParsingError createParentEntitySearchError(CollectRecord record, DataLine line, EntityIdentifier<?> identifier, String messageKey) {
EntityIdentifierDefinition identifierDefn = identifier.getDefinition();
Survey survey = record.getSurvey();
Schema schema = survey.getSchema();
EntityDefinition parentEntityDefn = (EntityDefinition) schema.getDefinitionById(identifierDefn.getEntityDefinitionId());
String[] colNames = DataCSVReader.getKeyAttributeColumnNames(parentEntityDefn, parentEntityDefn.getKeyAttributeDefinitions());
ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), colNames, messageKey);
List<String> recordKeys = record.getRootEntityKeyValues();
CollectionUtils.filter(recordKeys, new Predicate() {
@Override
public boolean evaluate(Object object) {
return StringUtils.isNotBlank((String) object);
}
});
String jointRecordKeys = StringUtils.join(recordKeys, ", ");
String jointParentEntityKeys = identifier instanceof EntityPositionIdentifier ? "[" + ((EntityPositionIdentifier) identifier).getPosition() + "]" : StringUtils.join(((EntityKeysIdentifier) identifier).getKeyValues(), ", ");
error.setMessageArgs(new String[] { parentEntityDefn.getName(), jointParentEntityKeys, jointRecordKeys });
return error;
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportProcess method setKeyValues.
private void setKeyValues(Entity entity, Value[] values, Map<FieldValueKey, String> colNamesByField, long row) {
// create key attribute values by name
Map<FieldValueKey, String> keyValuesByField = new HashMap<FieldValueKey, String>();
EntityDefinition entityDefn = entity.getDefinition();
List<AttributeDefinition> keyDefns = entityDefn.getKeyAttributeDefinitions();
for (int i = 0; i < keyDefns.size(); i++) {
AttributeDefinition keyDefn = keyDefns.get(i);
Value keyValue = values[i];
Map<String, Object> keyValueMap = keyValue.toMap();
List<String> keyFieldNames = keyDefn.getKeyFieldNames();
for (String keyFieldName : keyFieldNames) {
Object keyValueFieldVal = keyValueMap.get(keyFieldName);
keyValuesByField.put(new FieldValueKey(keyDefn, keyFieldName), keyValueFieldVal.toString());
}
}
setValuesInAttributes(entity, keyValuesByField, colNamesByField, row);
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class DataCSVReader method getKeyAttributeColumnNames.
protected static List<String> getKeyAttributeColumnNames(EntityDefinition parentEntityDefinition, AttributeDefinition keyAttrDefn) {
EntityDefinition parentDefn = keyAttrDefn.getParentEntityDefinition();
String prefix = parentDefn == parentEntityDefinition ? "" : parentDefn.getName() + "_";
List<String> keyFieldNames = keyAttrDefn.getKeyFieldNames();
if (keyFieldNames.size() == 1) {
return Arrays.asList(prefix + keyAttrDefn.getName());
} else {
List<String> result = new ArrayList<String>(keyFieldNames.size());
for (String fieldName : keyFieldNames) {
result.add(prefix + keyAttrDefn.getName() + "_" + fieldName);
}
return result;
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class DataCSVReader method getExpectedAncestorKeyColumnNames.
private List<String> getExpectedAncestorKeyColumnNames() {
List<EntityIdentifierDefinition> entityIdentifierDefns = getAncestorIdentifiers();
// validate ancestor key columns
Schema schema = parentEntityDefinition.getSchema();
List<String> expectedEntityKeyColumns = new ArrayList<String>();
for (EntityIdentifierDefinition identifier : entityIdentifierDefns) {
int defnId = identifier.getEntityDefinitionId();
EntityDefinition defn = (EntityDefinition) schema.getDefinitionById(defnId);
if (identifier instanceof EntityPositionIdentifierDefinition) {
String expectedColName = getPositionColumnName(defn);
expectedEntityKeyColumns.add(expectedColName);
} else if (identifier instanceof SingleEntityIdentifierDefinition) {
// skip
} else {
List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
for (AttributeDefinition keyDefn : keyDefns) {
List<String> expectedColNames = getKeyAttributeColumnNames(parentEntityDefinition, keyDefn);
expectedEntityKeyColumns.addAll(expectedColNames);
}
}
}
return expectedEntityKeyColumns;
}
Aggregations