Commit 93e64abc authored by Matija Obreza's avatar Matija Obreza
Browse files

Added separator to Column and column editor, added regexp pattern to UI

RowConverter respects separator and pattern
parent 55200aba
......@@ -5,6 +5,10 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.management.RuntimeErrorException;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -45,7 +49,7 @@ public class RowConverter {
continue;
}
Object rowValue = convertCellValue(row[i], column.isMultiple());
Object rowValue = convertCellValue(row[i], column.isMultiple(), column.getSeparator(), column.getPattern());
Object mapValue = map.get(columnDef.getRdfTerm());
if (mapValue == null) {
......@@ -88,7 +92,7 @@ public class RowConverter {
return map;
}
private static Object convertCellValue(Object value, boolean splitString) {
private static Object convertCellValue(Object value, boolean splitString, String separator, String pattern) {
if (value != null) {
if (value instanceof String) {
String stringValue = ((String) value);
......@@ -96,24 +100,47 @@ public class RowConverter {
return null;
}
if (splitString) {
String[] split = stringValue.split(";");
String[] split = stringValue.split(separator);
for (int i = split.length - 1; i >= 0; i--) {
split[i] = split[i].trim();
if (pattern != null) {
split[i] = valueFromPattern(split[i].trim(), pattern);
} else {
split[i] = split[i].trim();
}
}
return split;
}
return valueFromPattern(stringValue.trim(), pattern);
}
}
// IGNORE?
return value;
}
private static String valueFromPattern(String trim, String pattern) {
if (StringUtils.isBlank(pattern)) {
return trim;
}
Pattern pat = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher matcher = pat.matcher(trim);
if (matcher.find()) {
String res = matcher.groupCount() == 0 ? matcher.group() : matcher.group(1);
// System.err.println("Pattern=" + pattern + " groups=" + matcher.groupCount() + " res=" + res);
// throw new RuntimeException("foobar");
return res;
}
return null;
}
private static ColumnDef findColumnDef(Column column, List<ColumnDef> columnDefList) {
for (ColumnDef columnDef : columnDefList) {
if (columnDef.getRdfTerm().equals(column.getRdfTerm())) {
return columnDef;
}
}
_log.warn("ColumnDef not found for column=" + column.getPreferredName() + " term=" + column.getRdfTerm());
// _log.trace("ColumnDef not found for column=" + column.getPreferredName() + " term=" + column.getRdfTerm());
return null;
}
......@@ -151,7 +178,7 @@ public class RowConverter {
int dotPost = fieldName.lastIndexOf('.');
if (dotPost > -1)
fieldName = fieldName.substring(dotPost + 1);
System.err.println(">> " + jsonField.getFieldName() + " field=" + fieldName);
// System.err.println(">> " + jsonField.getFieldName() + " field=" + fieldName);
JsonNode valueNode = containerNode.get(fieldName);
if (valueNode == null) {
......@@ -172,8 +199,8 @@ public class RowConverter {
arrayNode.add(coerce(jsonField.getType(), rdfValue));
}
} else {
System.err.println("Putting field=" + fieldName + " type=" + rdfValues.getClass());
containerNode.put(fieldName, coerce(jsonField.getType(), rdfValues));
// System.err.println("Putting field=" + fieldName + " type=" + rdfValues.getClass());
containerNode.set(fieldName, coerce(jsonField.getType(), rdfValues));
}
}
......
......@@ -174,6 +174,7 @@ public class DataSourceSheet extends AbstractModelObject {
if (columnDef.getPreferredName().equalsIgnoreCase(column.getPreferredName())) {
column.setRdfTerm(columnDef.getRdfTerm());
column.setMultiple(columnDef.hasAllowMultiple());
column.setDescription(columnDef.getTitle());
}
}
}
......
......@@ -86,7 +86,7 @@ public class PushDialog extends Dialog {
@Override
public void run() {
try {
List<Object[]> rows = dataSourceLoader.loadDataRows(dataSourceSheet, 10);
List<Object[]> rows = dataSourceLoader.loadDataRows(dataSourceSheet, 200);
_log.info("Loaded rows " + rows.size());
List<Map<String, ?>> list = new ArrayList<Map<String, ?>>();
......
......@@ -121,6 +121,8 @@ public class SheetDisplay extends Composite {
private Composite compoCSV;
private Combo comboCharset;
private Button btnReload;
private Text txtSeparator;
private Text txtRegExp;
/**
* Create the composite.
......@@ -178,63 +180,79 @@ public class SheetDisplay extends Composite {
scrolledComposite.setExpandHorizontal(true);
tbtmColumnProperties.setControl(scrolledComposite);
Composite composite = new Composite(scrolledComposite, SWT.V_SCROLL | SWT.NO_BACKGROUND);
composite.setLayout(new GridLayout(3, false));
Composite composite = new Composite(scrolledComposite, SWT.V_SCROLL);
composite.setLayout(new GridLayout(4, false));
scrolledComposite.setContent(composite);
composite.pack();
Label lblThisIsA = new Label(composite, SWT.NONE);
lblThisIsA.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblThisIsA.setText("Column name");
txtColumnName = new Text(composite, SWT.BORDER);
txtColumnName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblColumnDescription = new Label(composite, SWT.NONE);
lblColumnDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblColumnDescription.setText("Column description");
txtColumnDescription = new Text(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gd_txtColumnDescription = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
gd_txtColumnDescription.minimumHeight = 30;
gd_txtColumnDescription.heightHint = 40;
txtColumnDescription.setLayoutData(gd_txtColumnDescription);
new Label(composite, SWT.NONE);
Label lblThisIsA = new Label(composite, SWT.NONE);
lblThisIsA.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblThisIsA.setText("Column name");
txtColumnName = new Text(composite, SWT.BORDER);
txtColumnName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
Label lblColumnDescription = new Label(composite, SWT.NONE);
lblColumnDescription.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
lblColumnDescription.setText("Column description");
txtColumnDescription = new Text(composite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
GridData gd_txtColumnDescription = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gd_txtColumnDescription.minimumHeight = 30;
gd_txtColumnDescription.heightHint = 40;
txtColumnDescription.setLayoutData(gd_txtColumnDescription);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
btnContainsMultipleValues = new Button(composite, SWT.CHECK);
btnContainsMultipleValues.setText("Contains multiple values, separated");
new Label(composite, SWT.NONE);
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("RDF Term");
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setText("Data type");
Combo comboDataType = new Combo(composite, SWT.NONE);
comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
btnContainsMultipleValues = new Button(composite, SWT.CHECK);
btnContainsMultipleValues.setText("Contains multiple values, separated");
Label lblSeparator_1 = new Label(composite, SWT.NONE);
lblSeparator_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSeparator_1.setText("Separator");
txtSeparator = new Text(composite, SWT.BORDER);
txtSeparator.setText(";");
GridData gd_txtSeparator = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
gd_txtSeparator.widthHint = 30;
gd_txtSeparator.minimumWidth = 30;
txtSeparator.setLayoutData(gd_txtSeparator);
Label lblRegexpPattern = new Label(composite, SWT.RIGHT);
lblRegexpPattern.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblRegexpPattern.setText("RegExp pattern");
txtRegExp = new Text(composite, SWT.BORDER);
txtRegExp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("RDF Term");
txtRdfTerm = new Text(composite, SWT.BORDER);
txtRdfTerm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblData = new Label(composite, SWT.NONE);
lblData.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblData.setText("Data type");
Combo comboDataType = new Combo(composite, SWT.NONE);
comboDataType.setItems(new String[] { "Text (general blah-blah)", "Number", "Date, time, timestamp" });
comboDataType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.debug("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Button btnAnalyzeColumnData = new Button(composite, SWT.NONE);
btnAnalyzeColumnData.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
_log.debug("Do column analysis");
}
});
btnAnalyzeColumnData.setText("Analyze column data");
DropTarget dropTarget = new DropTarget(composite, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT | DND.DROP_LINK);
dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
......@@ -357,7 +375,7 @@ public class SheetDisplay extends Composite {
}
});
btnReload.setText("Reload");
sashForm.setWeights(new int[] { 269, 226 });
sashForm.setWeights(new int[] {274, 254});
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
......@@ -452,7 +470,6 @@ public class SheetDisplay extends Composite {
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
......@@ -484,6 +501,18 @@ public class SheetDisplay extends Composite {
IObservableValue selectedColumnpreferredNameDswObserveValue = BeanProperties.value("selectedColumn.preferredName").observe(dsw);
bindingContext.bindValue(observeTextTxtColumnNameObserveWidget, selectedColumnpreferredNameDswObserveValue, null, null);
//
IObservableValue observeEnabledTxtSeparatorObserveWidget = WidgetProperties.enabled().observe(txtSeparator);
IObservableValue observeSelectionBtnContainsMultipleValuesObserveWidget_1 = WidgetProperties.selection().observe(btnContainsMultipleValues);
bindingContext.bindValue(observeEnabledTxtSeparatorObserveWidget, observeSelectionBtnContainsMultipleValuesObserveWidget_1, null, null);
//
IObservableValue observeTextTxtRegExpObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtRegExp);
IObservableValue selectedColumnpatternDswObserveValue = BeanProperties.value("selectedColumn.pattern").observe(dsw);
bindingContext.bindValue(observeTextTxtRegExpObserveWidget, selectedColumnpatternDswObserveValue, null, null);
//
IObservableValue observeTextTxtSeparatorObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtSeparator);
IObservableValue selectedColumnseparatorDswObserveValue = BeanProperties.value("selectedColumn.separator").observe(dsw);
bindingContext.bindValue(observeTextTxtSeparatorObserveWidget, selectedColumnseparatorDswObserveValue, null, null);
//
return bindingContext;
}
}
......@@ -25,6 +25,7 @@ public class Column extends AbstractModelObject {
private ColumnDataType dataType;
private boolean unique;
private boolean multiple;
private String separator = ";";
private String pattern;
public Column() {
......@@ -92,7 +93,6 @@ public class Column extends AbstractModelObject {
firePropertyChange("multiple", null, this.multiple);
}
public String getPattern() {
return pattern;
}
......@@ -101,4 +101,13 @@ public class Column extends AbstractModelObject {
this.pattern = pattern;
firePropertyChange("pattern", null, this.pattern);
}
public String getSeparator() {
return separator;
}
public void setSeparator(String separator) {
this.separator = separator;
firePropertyChange("separator", null, this.separator);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment