use of org.activityinfo.ui.client.component.importDialog.model.ImportModel 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