use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow 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();
}
}
use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow 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;
}
use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow in project activityinfo by bedatadriven.
the class PersistImportCommand method apply.
@Nullable
@Override
public Promise<Void> apply(Void input) {
final ImportModel model = commandExecutor.getImportModel();
final ResourceId formClassId = model.getFormTree().getRootFields().iterator().next().getDefiningFormClass().getId();
final List<FormInstance> toPersist = Lists.newArrayList();
final ValidatedRowTable validatedRowTable = model.getValidatedRowTable();
for (SourceRow row : model.getSource().getRows()) {
ValidatedRow validatedRow = validatedRowTable.getRow(row);
if (validatedRow.isValid()) {
// persist instance only if it's valid
// new instance per row
FormInstance newInstance = new FormInstance(CuidAdapter.newLegacyFormInstanceId(formClassId), formClassId);
for (FieldImporter importer : commandExecutor.getImporters()) {
importer.updateInstance(row, newInstance);
}
toPersist.add(newInstance);
}
}
SerialQueue queue = new SerialQueue(commandExecutor.getResourceLocator(), toPersist, monitor);
return queue.execute();
}
Aggregations