use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.
the class HierarchyClassImporter method validateInstance.
@Override
public void validateInstance(SourceRow row, List<ValidationResult> results) {
// Start from the leaf level and work our way up to the parent levels
for (Level level : levels) {
InstanceScoreSource scoreSource = scoreSources.get(level.getFormId());
if (scoreSource != null) {
InstanceScorer instanceScorer = new InstanceScorer(scoreSource);
final InstanceScorer.Score score = instanceScorer.score(row);
final int bestMatchIndex = score.getBestMatchIndex();
if (bestMatchIndex != -1) {
for (int i = 0; i < sourceColumns.size(); i++) {
String matched = scoreSource.getReferenceValues().get(bestMatchIndex)[i];
final ValidationResult converted = ValidationResult.converted(matched, score.getBestScores()[i]);
converted.setRef(new RecordRef(level.getFormId(), scoreSource.getReferenceInstanceIds().get(bestMatchIndex)));
results.add(converted);
}
return;
}
}
}
for (int i = 0; i < sourceColumns.size(); i++) {
results.add(ValidationResult.error("No match"));
}
}
use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.
the class SingleClassImporter method updateInstance.
@Override
public boolean updateInstance(SourceRow row, FormInstance instance) {
final List<ValidationResult> validationResults = Lists.newArrayList();
validateInstance(row, validationResults);
for (ValidationResult result : validationResults) {
if (result.isPersistable() && result.getRef() != null) {
instance.set(fieldId, new ReferenceValue(result.getRef()));
break;
}
}
return true;
}
Aggregations