Search in sources :

Example 6 with ValidationResult

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"));
    }
}
Also used : RecordRef(org.activityinfo.model.type.RecordRef) Level(org.activityinfo.ui.client.component.form.field.hierarchy.Level) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 7 with ValidationResult

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;
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Aggregations

ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)7 RecordRef (org.activityinfo.model.type.RecordRef)2 ReferenceValue (org.activityinfo.model.type.ReferenceValue)2 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 SourceRow (org.activityinfo.ui.client.component.importDialog.model.source.SourceRow)2 ValidatedRow (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 FormTree (org.activityinfo.model.formTree.FormTree)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 Level (org.activityinfo.ui.client.component.form.field.hierarchy.Level)1 FieldImporter (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)1 FieldImporterColumn (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporterColumn)1 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)1