Search in sources :

Example 1 with ValidationResult

use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.

the class ValidateClassImportCommand method doClassValidation.

private List<ValidationResult> doClassValidation() {
    final ImportModel model = commandExecutor.getImportModel();
    final List<ValidationResult> validationResults = Lists.newArrayList();
    // Class based validation : check whether all mandatory fields has mapped
    for (FormTree.Node node : model.getFormTree().getRootFields()) {
        if (node.getField().isRequired() && model.getMapExistingActions(node.getField().getId()).isEmpty()) {
            final String fieldLabel = node.getField().getLabel();
            validationResults.add(ValidationResult.error(I18N.MESSAGES.fieldIsMandatory(fieldLabel)));
        }
    }
    return validationResults;
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 2 with ValidationResult

use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.

the class ValidationResultCell method render.

@Override
public void render(Context context, ValidatedRow data, SafeHtmlBuilder sb) {
    ValidationResult result = data.getResult(columnIndex);
    SafeHtml safeHtml = Templates.INSTANCE.html(style(result), tooltip(result), accessor.getValue(data.getSourceRow()));
    sb.append(correctNewLineCharacter(safeHtml));
}
Also used : SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 3 with ValidationResult

use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.

the class AbstractImporterTest method dumpRows.

protected void dumpRows(ValidatedRowTable table) {
    int numRows = table.getRows().size();
    int numColumns = table.getColumns().size();
    for (int i = 0; i != numRows; ++i) {
        SourceRow sourceRow = importModel.getSource().getRows().get(i);
        ValidatedRow resultRow = table.getRows().get(i);
        for (int j = 0; j != numColumns; ++j) {
            FieldImporterColumn column = table.getColumns().get(j);
            String importedValue = Strings.nullToEmpty(column.getAccessor().getValue(sourceRow));
            ValidationResult result = resultRow.getResult(j);
            String cell = "";
            if (result.wasConverted()) {
                cell = importedValue + " [" + result.getTargetValue() + "]";
            } else {
                cell = importedValue;
            }
            System.out.print(" " + icon(result) + Strings.padEnd(cell, COLUMN_WIDTH - 2, ' '));
        }
        System.out.println();
    }
}
Also used : FieldImporterColumn(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporterColumn) ValidatedRow(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 4 with ValidationResult

use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.

the class ValidateRowsImportCommand method doRowValidation.

private ValidatedRowTable doRowValidation() {
    final List<ValidatedRow> rows = Lists.newArrayList();
    final ImportModel model = commandExecutor.getImportModel();
    // Row based validation
    for (SourceRow row : model.getSource().getRows()) {
        List<ValidationResult> results = Lists.newArrayList();
        for (FieldImporter importer : commandExecutor.getImporters()) {
            importer.validateInstance(row, results);
        }
        rows.add(new ValidatedRow(row, results));
    }
    ValidatedRowTable validatedRowTable = new ValidatedRowTable(commandExecutor.getColumns(), rows);
    model.setValidatedRowTable(validatedRowTable);
    return validatedRowTable;
}
Also used : FieldImporter(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) ValidatedRow(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 5 with ValidationResult

use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult in project activityinfo by bedatadriven.

the class HierarchyClassImporter method updateInstance.

@Override
public boolean updateInstance(SourceRow row, FormInstance instance) {
    final List<ValidationResult> validationResults = Lists.newArrayList();
    validateInstance(row, validationResults);
    final Map<ResourceId, RecordRef> toSave = Maps.newHashMap();
    for (ValidationResult result : validationResults) {
        if (result.isPersistable() && result.getRef() != null) {
            ResourceId range = result.getRef().getFormId();
            RecordRef value = toSave.get(range);
            if (value == null) {
                toSave.put(range, result.getRef());
            }
        }
    }
    if (!toSave.isEmpty()) {
        instance.set(rootField.getFieldId(), new ReferenceValue(toSave.values()));
        return true;
    }
    return false;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) 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