Search in sources :

Example 1 with SourceColumn

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

the class ColumnMappingGrid method refreshColumnStyles.

/**
 * Updates the column styles to match the column's current binding
 */
public void refreshColumnStyles(int columnIndex) {
    // update the column styles
    final SourceColumn sourceColumn = model.getSourceColumn(columnIndex);
    ColumnAction binding = model.getColumnAction(sourceColumn);
    toggleColumnStyle(columnIndex, ColumnMappingStyles.INSTANCE.stateIgnored(), binding != null && binding == IgnoreAction.INSTANCE);
    toggleColumnStyle(columnIndex, ColumnMappingStyles.INSTANCE.stateBound(), binding != null && binding != IgnoreAction.INSTANCE);
    toggleColumnStyle(columnIndex, ColumnMappingStyles.INSTANCE.stateUnset(), binding == null);
    // update the mapping description
    Cell.Context context = new Cell.Context(MAPPING_HEADER_ROW, columnIndex, null);
    SafeHtmlBuilder html = new SafeHtmlBuilder();
    headerCell.render(context, sourceColumn, html);
    getTableHead(MAPPING_HEADER_ROW, columnIndex).setInnerSafeHtml(html.toSafeHtml());
}
Also used : ColumnAction(org.activityinfo.ui.client.component.importDialog.model.ColumnAction) SourceColumn(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Cell(com.google.gwt.cell.client.Cell)

Example 2 with SourceColumn

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

the class ImportModel method getMappedColumns.

public Map<TargetSiteId, ColumnAccessor> getMappedColumns(ResourceId fieldId) {
    Map<TargetSiteId, ColumnAccessor> mappings = Maps.newHashMap();
    for (Map.Entry<SourceColumn, MapExistingAction> entry : getMapExistingActions(fieldId).entrySet()) {
        TargetSiteId site = entry.getValue().getTarget().getSite();
        ColumnAccessor column = new SourceColumnAccessor(entry.getKey());
        mappings.put(site, column);
    }
    return mappings;
}
Also used : SourceColumnAccessor(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumnAccessor) ColumnAccessor(org.activityinfo.ui.client.component.importDialog.model.strategy.ColumnAccessor) SourceColumnAccessor(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumnAccessor) SourceColumn(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn) TargetSiteId(org.activityinfo.ui.client.component.importDialog.model.strategy.TargetSiteId) Map(java.util.Map)

Example 3 with SourceColumn

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

the class ImportModel method setColumnBinding.

public SourceColumn setColumnBinding(ColumnAction action, SourceColumn sourceColumn) {
    SourceColumn removedColumn = null;
    for (Map.Entry<SourceColumn, ColumnAction> entry : Sets.newHashSet(columnActions.entrySet())) {
        final ColumnAction value = entry.getValue();
        if (value != null && value.equals(action) && value != IgnoreAction.INSTANCE) {
            removedColumn = entry.getKey();
            columnActions.remove(removedColumn);
        }
    }
    columnActions.put(sourceColumn, action);
    return removedColumn;
}
Also used : SourceColumn(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn) Map(java.util.Map)

Example 4 with SourceColumn

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

the class ColumnMappingGuesser method getMapping.

public Map<SourceColumn, ImportTarget> getMapping() {
    // lower distance between maps
    Map<SourceColumn, TreeMap<Integer, ImportTarget>> distanceWithinTargetMaps = Maps.newHashMap();
    for (SourceColumn sourceColumn : importModel.getSource().getColumns()) {
        final String sourceColumnHeader = sourceColumn.getHeader();
        final TreeMap<Integer, ImportTarget> distanceMap = getDistanceMap(sourceColumnHeader);
        if (!distanceMap.isEmpty()) {
            final Map.Entry<Integer, ImportTarget> lowerDistanceEntry = distanceMap.entrySet().iterator().next();
            // if number of transformation operations are higher then label length then ignore such mapping
            final Integer transformationOperations = lowerDistanceEntry.getKey();
            // if (transformationOperations < sourceColumnHeader.length() && transformationOperations < lowerDistanceEntry.getValue().getLabel().length()) {
            TreeMap<Integer, ImportTarget> valueMap = distanceWithinTargetMaps.get(sourceColumn);
            if (valueMap == null) {
                valueMap = Maps.newTreeMap();
                distanceWithinTargetMaps.put(sourceColumn, valueMap);
            }
            valueMap.put(transformationOperations, lowerDistanceEntry.getValue());
        // }
        }
    }
    // now re-iterate for target (different source columns may get the same target column as best match (lower distance))
    Map<ImportTarget, TreeMap<Integer, SourceColumn>> targetToSource = Maps.newHashMap();
    for (Map.Entry<SourceColumn, TreeMap<Integer, ImportTarget>> entry : distanceWithinTargetMaps.entrySet()) {
        final TreeMap<Integer, ImportTarget> value = entry.getValue();
        if (!value.isEmpty()) {
            // entry with lowest distance
            final Map.Entry<Integer, ImportTarget> bestEntry = value.entrySet().iterator().next();
            TreeMap<Integer, SourceColumn> distanceForSourceMap = targetToSource.get(bestEntry.getValue());
            if (distanceForSourceMap == null) {
                distanceForSourceMap = Maps.newTreeMap();
                targetToSource.put(bestEntry.getValue(), distanceForSourceMap);
            }
            distanceForSourceMap.put(bestEntry.getKey(), entry.getKey());
        }
    }
    // finally build mapping
    Map<SourceColumn, ImportTarget> mapping = Maps.newHashMap();
    for (Map.Entry<ImportTarget, TreeMap<Integer, SourceColumn>> entry : targetToSource.entrySet()) {
        final TreeMap<Integer, SourceColumn> map = entry.getValue();
        if (!map.isEmpty()) {
            mapping.put(map.entrySet().iterator().next().getValue(), entry.getKey());
        }
    }
    return mapping;
}
Also used : ImportTarget(org.activityinfo.ui.client.component.importDialog.model.strategy.ImportTarget) SourceColumn(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 5 with SourceColumn

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

the class PastedTableTest method parser.

@Test
public void parser() throws IOException {
    PastedTable pastedTable = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    pastedTable.parseAllRows();
    final List<SourceColumn> columns = pastedTable.getColumns();
    final List<? extends SourceRow> rows = pastedTable.getRows();
    Assert.assertEquals(columns.size(), 47);
    Assert.assertEquals(rows.size(), 63);
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SourceColumn(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn) Test(org.junit.Test)

Aggregations

SourceColumn (org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn)10 Map (java.util.Map)3 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)3 Test (org.junit.Test)3 Cell (com.google.gwt.cell.client.Cell)1 Scheduler (com.google.gwt.core.client.Scheduler)1 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 TreeMap (java.util.TreeMap)1 ColumnAction (org.activityinfo.ui.client.component.importDialog.model.ColumnAction)1 MapExistingAction (org.activityinfo.ui.client.component.importDialog.model.MapExistingAction)1 SourceColumnAccessor (org.activityinfo.ui.client.component.importDialog.model.source.SourceColumnAccessor)1 ColumnAccessor (org.activityinfo.ui.client.component.importDialog.model.strategy.ColumnAccessor)1 ImportTarget (org.activityinfo.ui.client.component.importDialog.model.strategy.ImportTarget)1 TargetSiteId (org.activityinfo.ui.client.component.importDialog.model.strategy.TargetSiteId)1