Commit f1441c02 authored by Matija Obreza's avatar Matija Obreza

Include null valued columns

parent e36382d8
......@@ -43,17 +43,21 @@ public class RowConverter {
List<Column> columns = dataSourceSheet.getColumns();
for (int i = 0; i < columns.size(); i++) {
if (i >= row.length) {
_log.warn("Row has less than " + (i + 1) + " columns: len=" + row.length + " " + ArrayUtils.toString(row));
continue;
}
Column column = columns.get(i);
ColumnDef columnDef = findColumnDef(column, columnDefs.getColumnDefs());
if (columnDef == null) {
continue;
}
if (i >= row.length) {
if (column.isIncludeNull()) {
map.put(columnDef.getRdfTerm(), null);
}
_log.debug("Row has less than " + (i + 1) + " columns: len=" + row.length + " " + ArrayUtils.toString(row));
continue;
}
Object rowValue = convertCellValue(row[i], column.isMultiple(), column.getSeparator(), column.getPattern(), column.getGroupPattern());
Object mapValue = map.get(columnDef.getRdfTerm());
......@@ -83,6 +87,10 @@ public class RowConverter {
newVal.add(rowValue);
}
map.put(columnDef.getRdfTerm(), newVal);
} else if (rowValue == null) {
if (column.isIncludeNull()) {
map.put(columnDef.getRdfTerm(), null);
}
}
}
......@@ -227,7 +235,7 @@ public class RowConverter {
}
if (rdfValues == null) {
// skip
containerNode.set(fieldName, null);
} else if (rdfValues instanceof ArrayList<?>) {
ArrayNode arrayNode = (ArrayNode) valueNode;
for (String rdfValue : (ArrayList<String>) rdfValues) {
......
......@@ -85,6 +85,7 @@ import swing2swt.layout.BorderLayout;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.eclipse.core.databinding.beans.PojoProperties;
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SheetDisplay extends Composite {
......@@ -162,6 +163,7 @@ public class SheetDisplay extends Composite {
private Text txtGroupPattern;
private Text txtQueryName;
private IDataSource dataSource;
private Button btnIncludeNullValues;
/**
* Create the composite.
......@@ -359,6 +361,12 @@ public class SheetDisplay extends Composite {
txtGroupPattern = new Text(composite, SWT.BORDER);
txtGroupPattern.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new Label(composite, SWT.NONE);
btnIncludeNullValues = new Button(composite, SWT.CHECK);
btnIncludeNullValues.setText("Include null values");
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
dropTarget.addDropListener(new DropTargetAdapter() {
@Override
......@@ -645,16 +653,15 @@ public class SheetDisplay extends Composite {
bindingContext.bindValue(observeTextTxtCsvQuoteCharObserveWidget, dataSourceSheetsheetQuoteCharDswObserveValue, null, null);
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue observeSelectionChkbxContainsHeadersObserveWidget_1 = WidgetProperties.selection().observe(chkbxContainsHeaders);
IObservableValue headersIncludedGetDataSourceSheetObserveValue = BeanProperties.value("dataSourceSheet.headersIncluded").observe(dsw);
IObservableValue headersIncludedGetDataSourceSheetObserveValue = PojoProperties.value("dataSourceSheet.headersIncluded").observe(dsw);
bindingContext.bindValue(observeSelectionChkbxContainsHeadersObserveWidget_1, headersIncludedGetDataSourceSheetObserveValue, null, null);
//
IObservableValue observeTextTxtHeaderRowIndexObserveWidget_1 = WidgetProperties.text(SWT.Modify).observe(txtHeaderRowIndex);
IObservableValue headerRowIndexGetDataSourceSheetObserveValue = BeanProperties.value("dataSourceSheet.headerRowIndex").observe(dsw);
IObservableValue headerRowIndexGetDataSourceSheetObserveValue = PojoProperties.value("dataSourceSheet.headerRowIndex").observe(dsw);
bindingContext.bindValue(observeTextTxtHeaderRowIndexObserveWidget_1, headerRowIndexGetDataSourceSheetObserveValue, null, null);
//
IObservableValue observeEnabledTxtHeaderRowIndexObserveWidget = WidgetProperties.enabled().observe(txtHeaderRowIndex);
......@@ -693,6 +700,10 @@ public class SheetDisplay extends Composite {
IObservableValue selectedColumngroupPatternDswObserveValue = BeanProperties.value("selectedColumn.groupPattern").observe(dsw);
bindingContext.bindValue(observeTextTxtGroupPatternObserveWidget, selectedColumngroupPatternDswObserveValue, null, null);
//
IObservableValue observeSelectionBtnIncludeNullValuesObserveWidget = WidgetProperties.selection().observe(btnIncludeNullValues);
IObservableValue selectedColumnincludeNullDswObserveValue = BeanProperties.value("selectedColumn.includeNull").observe(dsw);
bindingContext.bindValue(observeSelectionBtnIncludeNullValuesObserveWidget, selectedColumnincludeNullDswObserveValue, null, null);
//
return bindingContext;
}
}
......@@ -28,6 +28,7 @@ public class Column extends AbstractModelObject {
private String separator = ";";
private String pattern;
private String groupPattern;
private boolean includeNull = false;
public Column() {
}
......@@ -121,17 +122,31 @@ public class Column extends AbstractModelObject {
firePropertyChange("groupPattern", null, this.groupPattern);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
public void setIncludeNull(boolean includeNull) {
this.includeNull = includeNull;
}
public boolean isIncludeNull() {
return includeNull;
}
Column column = (Column) o;
public boolean getIncludeNull() {
return includeNull;
}
if (preferredName != null ? !preferredName.equals(column.preferredName) : column.preferredName != null)
return false;
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
return true;
}
Column column = (Column) o;
if (preferredName != null ? !preferredName.equals(column.preferredName) : column.preferredName != null)
return false;
return true;
}
}
......@@ -10,7 +10,6 @@ import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
......
Markdown is supported
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