use of org.openforis.collect.io.data.DataLine.EntityKeysIdentifier 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.collect.io.data.DataLine.EntityKeysIdentifier 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;
}
}
use of org.openforis.collect.io.data.DataLine.EntityKeysIdentifier in project collect by openforis.
the class CSVDataImportProcess method findChildEntities.
private List<Entity> findChildEntities(Entity currentParent, String childName, EntityIdentifier<?> identifier) {
if (identifier instanceof EntityPositionIdentifier) {
int position = ((EntityPositionIdentifier) identifier).getPosition();
if (currentParent.getCount(childName) >= position) {
ArrayList<Entity> result = new ArrayList<Entity>();
Entity child = (Entity) currentParent.getChild(childName, position - 1);
result.add(child);
return result;
} else {
return Collections.emptyList();
}
} else {
EntityDefinition parentDefn = currentParent.getDefinition();
EntityDefinition childDefn = parentDefn.getChildDefinition(childName, EntityDefinition.class);
Value[] keyValues = ((EntityKeysIdentifier) identifier).getKeyValues();
return currentParent.findChildEntitiesByKeys(childDefn, keyValues);
}
}
Aggregations