use of org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition 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.EntityIdentifierDefinition 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;
}
use of org.openforis.collect.io.data.DataLine.EntityIdentifierDefinition in project collect by openforis.
the class DataCSVReader method getAncestorIdentifiers.
private List<EntityIdentifierDefinition> getAncestorIdentifiers() {
List<EntityDefinition> ancestorEntityDefns = parentEntityDefinition.getAncestorEntityDefinitionsInReverseOrder();
ancestorEntityDefns.add(parentEntityDefinition);
List<EntityIdentifierDefinition> entityIdentifierDefns = new ArrayList<DataLine.EntityIdentifierDefinition>();
for (EntityDefinition ancestorEntityDefn : ancestorEntityDefns) {
EntityIdentifierDefinition identifier;
if (ancestorEntityDefn.isMultiple()) {
List<AttributeDefinition> keyDefns = ancestorEntityDefn.getKeyAttributeDefinitions();
if (keyDefns.isEmpty()) {
identifier = new DataLine.EntityPositionIdentifierDefinition(ancestorEntityDefn.getId());
} else {
identifier = new DataLine.EntityKeysIdentifierDefintion(ancestorEntityDefn);
}
} else {
identifier = new DataLine.SingleEntityIdentifierDefinition(ancestorEntityDefn.getId());
}
entityIdentifierDefns.add(identifier);
}
return entityIdentifierDefns;
}
Aggregations