use of org.openforis.idm.model.Value 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.model.Value 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.model.Value in project collect by openforis.
the class UpdateAttributeCommandHandler method execute.
@Override
public List<RecordEvent> execute(UpdateAttributeCommand command) {
CollectRecord record = findRecord(command);
Attribute<?, Value> attribute = findAttribute(command, record);
Value value = extractValue(command);
NodeChangeSet changeSet = recordUpdater.updateAttribute(attribute, value);
recordManager.save(record);
List<RecordEvent> events = new EventProducer().produceFor(changeSet, command.getUsername());
return events;
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class NodeBuilder method createAttribute.
private Attribute<?, ?> createAttribute(Entity parent) {
AttributeDefinition def = (AttributeDefinition) parent.getDefinition().getChildDefinition(name);
@SuppressWarnings("unchecked") Attribute<?, Value> attr = (Attribute<?, Value>) def.createNode();
if (value != null) {
if (value instanceof Value) {
attr.setValue((Value) value);
} else {
attr.setValue(def.<Value>createValue(value.toString()));
}
attr.updateSummaryInfo();
}
return attr;
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class EntityKeyValidator method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> keyAttribute) {
Entity multipleEntity = keyAttribute.getNearestMultipleEntityAncestor();
EntityDefinition multipleEntityDef = multipleEntity.getDefinition();
if (multipleEntityDef.isRoot()) {
return ValidationResultFlag.OK;
}
Value[] keyValues = multipleEntity.getKeyAttributeValues();
if (keyValues == null) {
return null;
}
List<Entity> entities = multipleEntity.getParent().findChildEntitiesByKeys(multipleEntityDef, keyValues);
if (entities.size() > 1) {
return ValidationResultFlag.ERROR;
} else {
return ValidationResultFlag.OK;
}
}
Aggregations