use of org.openforis.idm.model.Entity in project collect by openforis.
the class AttributeUpdateRequestProxy method toAttributeUpdateRequest.
@Override
@SuppressWarnings("unchecked")
public AttributeUpdateRequest<?> toAttributeUpdateRequest(CodeListManager codeListManager, RecordSessionManager sessionManager, CollectRecord record) {
AttributeUpdateRequest<Value> opts = new NodeUpdateRequest.AttributeUpdateRequest<Value>();
Attribute<?, ?> attribute = (Attribute<?, ?>) record.getNodeByInternalId(nodeId);
opts.setAttribute((Attribute<?, Value>) attribute);
Value parsedValue;
if (attribute instanceof FileAttribute) {
parsedValue = parseFileAttributeValue(sessionManager, record, nodeId, value);
} else if (value == null) {
parsedValue = null;
} else {
Entity parentEntity = attribute.getParent();
String attributeName = attribute.getName();
parsedValue = parseCompositeAttributeValue(codeListManager, parentEntity, attributeName, value);
}
opts.setValue(parsedValue);
opts.setSymbol(symbol);
return opts;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class EntityAddRequestProxy method toNodeUpdateRequest.
@Override
public EntityAddRequest toNodeUpdateRequest(CollectRecord record) {
EntityAddRequest opts = new NodeUpdateRequest.EntityAddRequest();
Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
opts.setParentEntity(parentEntity);
opts.setNodeName(nodeName);
return opts;
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class AttributeAddRequestProxy method toAttributeUpdateRequest.
@Override
public AttributeAddRequest<?> toAttributeUpdateRequest(CodeListManager codeListManager, RecordSessionManager sessionManager, CollectRecord record) {
Entity parentEntity = (Entity) record.getNodeByInternalId(parentEntityId);
AttributeAddRequest<Value> result = new NodeUpdateRequest.AttributeAddRequest<Value>();
result.setParentEntity(parentEntity);
result.setNodeName(nodeName);
result.setRemarks(remarks);
result.setSymbol(symbol);
if (value != null) {
Value parsedValue = parseCompositeAttributeValue(codeListManager, parentEntity, nodeName, value);
result.setValue(parsedValue);
}
return result;
}
use of org.openforis.idm.model.Entity 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);
}
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class CSVDataImportProcess method createChildEntity.
private Entity createChildEntity(Entity currentParent, String childName, EntityIdentifier<?> identifier, Map<FieldValueKey, String> colNamesByField, long row) {
if (identifier instanceof EntityPositionIdentifier) {
int position = ((EntityPositionIdentifier) identifier).getPosition();
if (position == currentParent.getCount(childName) + 1) {
Entity entity = (Entity) performNodeAdd(currentParent, childName);
return entity;
} else {
throw new IllegalArgumentException(String.format("Trying to create child in a invalid position: row=%d path=%s[%d]", row, currentParent.getPath() + "/" + childName, position));
}
} else {
Entity entity = (Entity) performNodeAdd(currentParent, childName);
Value[] keyValues = ((EntityKeysIdentifier) identifier).getKeyValues();
setKeyValues(entity, keyValues, colNamesByField, row);
return entity;
}
}
Aggregations