Search in sources :

Example 1 with FieldImporter

use of org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter 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 2 with FieldImporter

use of org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter in project activityinfo by bedatadriven.

the class ImportCommandExecutor method createImporters.

private List<FieldImporter> createImporters(final ImportModel model) {
    final List<FieldImporter> importers = Lists.newArrayList();
    for (Importer.TargetField field : fields) {
        Map<TargetSiteId, ColumnAccessor> mappedColumns = model.getMappedColumns(field.node.getFieldId());
        if (!mappedColumns.isEmpty()) {
            System.out.println(field + " => " + mappedColumns);
            FieldImporter importer = field.strategy.createImporter(field.node, mappedColumns, model);
            importers.add(importer);
        }
    }
    return importers;
}
Also used : FieldImporter(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter) ColumnAccessor(org.activityinfo.ui.client.component.importDialog.model.strategy.ColumnAccessor) TargetSiteId(org.activityinfo.ui.client.component.importDialog.model.strategy.TargetSiteId) FieldImporter(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)

Example 3 with FieldImporter

use of org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter 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();
}
Also used : FieldImporter(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter) ResourceId(org.activityinfo.model.resource.ResourceId) 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) FormInstance(org.activityinfo.model.form.FormInstance) Nullable(javax.annotation.Nullable)

Aggregations

FieldImporter (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)3 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 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)2 Nullable (javax.annotation.Nullable)1 FormInstance (org.activityinfo.model.form.FormInstance)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 ColumnAccessor (org.activityinfo.ui.client.component.importDialog.model.strategy.ColumnAccessor)1 TargetSiteId (org.activityinfo.ui.client.component.importDialog.model.strategy.TargetSiteId)1 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)1