Search in sources :

Example 1 with SourceRow

use of org.activityinfo.ui.client.component.importDialog.model.source.SourceRow in project activityinfo by bedatadriven.

the class SchemaImporterV3 method processRows.

@Override
public boolean processRows() {
    formMap.clear();
    subFormMap.clear();
    enumMap.clear();
    refMap.clear();
    fatalError = false;
    for (SourceRow row : source.getRows()) {
        try {
            FormClass parentFormClass = getFormClass(row);
            FormClass formClass = getSubFormClass(parentFormClass, row);
            String type = formFieldType.get(row);
            if (isEnum(type)) {
                addChoice(formClass, row);
            } else {
                FieldType fieldType = parseFieldType(row);
                FormField newField = addField(formClass, fieldType.getTypeClass(), row);
                newField.setType(fieldType);
                if (newField.getType() instanceof ReferenceType) {
                    refMap.put(formClass, newField);
                }
            }
        } catch (UnableToParseRowException e) {
            warnings.add(SafeHtmlUtils.fromString(e.getMessage()));
            fatalError = true;
        }
    }
    for (EnumBuilder enumBuilder : enumMap.values()) {
        enumBuilder.formField.setType(new EnumType(enumBuilder.cardinality, enumBuilder.items));
    }
    if (validationCallback != null) {
        validateReferences();
    }
    return !fatalError;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) FormField(org.activityinfo.model.form.FormField) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType)

Example 2 with SourceRow

use of org.activityinfo.ui.client.component.importDialog.model.source.SourceRow 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 3 with SourceRow

use of org.activityinfo.ui.client.component.importDialog.model.source.SourceRow 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 4 with SourceRow

use of org.activityinfo.ui.client.component.importDialog.model.source.SourceRow in project activityinfo by bedatadriven.

the class GridHeaderBuilder method renderHeaderRow.

private void renderHeaderRow(int headerRowIndex, String className) {
    TableRowBuilder tr = startRow();
    int curColumn;
    int columnCount = getTable().getColumnCount();
    for (curColumn = 0; curColumn < columnCount; curColumn++) {
        Header<?> header = getHeader(curColumn);
        Column<SourceRow, ?> column = getTable().getColumn(curColumn);
        // Render the header.
        TableCellBuilder th = tr.startTH().className(className);
        enableColumnHandlers(th, column);
        // Build the header.
        Cell.Context context = new Cell.Context(headerRowIndex, curColumn, null);
        renderHeader(th, context, header);
        th.endTH();
    }
    tr.end();
}
Also used : TableRowBuilder(com.google.gwt.dom.builder.shared.TableRowBuilder) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) TableCellBuilder(com.google.gwt.dom.builder.shared.TableCellBuilder) Cell(com.google.gwt.cell.client.Cell)

Example 5 with SourceRow

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

SourceRow (org.activityinfo.ui.client.component.importDialog.model.source.SourceRow)6 ValidatedRow (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow)3 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 FieldImporter (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)2 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 Cell (com.google.gwt.cell.client.Cell)1 TableCellBuilder (com.google.gwt.dom.builder.shared.TableCellBuilder)1 TableRowBuilder (com.google.gwt.dom.builder.shared.TableRowBuilder)1 Nullable (javax.annotation.Nullable)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormInstance (org.activityinfo.model.form.FormInstance)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 EnumType (org.activityinfo.model.type.enumerated.EnumType)1 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)1 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)1 FieldImporterColumn (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporterColumn)1