use of org.openforis.collect.io.data.DataLine.FieldValueKey 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.collect.io.data.DataLine.FieldValueKey in project collect by openforis.
the class CSVDataImportProcess method setValuesInAttributes.
private void setValuesInAttributes(Entity ancestorEntity, Map<FieldValueKey, String> fieldValues, Map<FieldValueKey, String> colNameByField, long row) {
Set<Entry<FieldValueKey, String>> entrySet = fieldValues.entrySet();
// delete all multiple attributes
for (Entry<FieldValueKey, String> entry : entrySet) {
FieldValueKey fieldValueKey = entry.getKey();
EntityDefinition ancestorDefn = ancestorEntity.getDefinition();
Schema schema = ancestorDefn.getSchema();
AttributeDefinition attrDefn = (AttributeDefinition) schema.getDefinitionById(fieldValueKey.getAttributeDefinitionId());
Entity parentEntity = getOrCreateParentEntity(ancestorEntity, attrDefn);
if (attrDefn.isMultiple()) {
List<Node<?>> attributes = parentEntity.getChildren(attrDefn);
int tot = attributes.size();
for (int i = 0; i < tot; i++) {
Node<?> node = attributes.get(0);
NodeChangeSet changes = recordUpdater.deleteNode(node);
if (nodeChangeBatchProcessor != null) {
nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
}
}
}
}
// set values
for (Entry<FieldValueKey, String> entry : entrySet) {
FieldValueKey fieldValueKey = entry.getKey();
String strValue = entry.getValue();
EntityDefinition ancestorDefn = ancestorEntity.getDefinition();
Schema schema = ancestorDefn.getSchema();
AttributeDefinition attrDefn = (AttributeDefinition) schema.getDefinitionById(fieldValueKey.getAttributeDefinitionId());
String fieldName = fieldValueKey.getFieldName();
Entity parentEntity = getOrCreateParentEntity(ancestorEntity, attrDefn);
String colName = colNameByField.get(fieldValueKey);
int attrPos = fieldValueKey.getAttributePosition();
setValueInField(parentEntity, attrDefn, attrPos - 1, fieldName, strValue, colName, row);
}
}
Aggregations