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());
}
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;
}
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;
}
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;
}
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);
}
Aggregations