add null row
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -2,7 +2,7 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.nexacro.spring</groupId>
|
<groupId>com.nexacro.spring</groupId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.2</version>
|
||||||
<artifactId>nexacro-core</artifactId>
|
<artifactId>nexacro-core</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>nexacro-core</name>
|
<name>nexacro-core</name>
|
||||||
|
|||||||
@@ -39,12 +39,13 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
|||||||
* @throws NexacroConvertException
|
* @throws NexacroConvertException
|
||||||
*/
|
*/
|
||||||
protected void addRowIntoDataSet(DataSet ds, Map map, boolean disallowChangeStructure) throws NexacroConvertException {
|
protected void addRowIntoDataSet(DataSet ds, Map map, boolean disallowChangeStructure) throws NexacroConvertException {
|
||||||
// ignore null data.
|
|
||||||
|
int newRow = ds.newRow();
|
||||||
|
// ignore null data. (add null row)
|
||||||
if(map == null) {
|
if(map == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newRow = ds.newRow();
|
|
||||||
Iterator iterator = map.keySet().iterator();
|
Iterator iterator = map.keySet().iterator();
|
||||||
while(iterator.hasNext()) {
|
while(iterator.hasNext()) {
|
||||||
Object key = iterator.next();
|
Object key = iterator.next();
|
||||||
@@ -91,12 +92,11 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
|||||||
*/
|
*/
|
||||||
protected void addRowIntoDataSet(DataSet ds, Object obj) {
|
protected void addRowIntoDataSet(DataSet ds, Object obj) {
|
||||||
|
|
||||||
if(obj == null) { // ignore null data
|
int newRow = ds.newRow();
|
||||||
|
if(obj == null) { // ignore null data (add null row)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newRow = ds.newRow();
|
|
||||||
|
|
||||||
NexacroBeanWrapper beanWrapper = NexacroBeanWrapper.createBeanWrapper(obj);
|
NexacroBeanWrapper beanWrapper = NexacroBeanWrapper.createBeanWrapper(obj);
|
||||||
|
|
||||||
NexacroBeanProperty[] beanProperties = beanWrapper.getProperties();
|
NexacroBeanProperty[] beanProperties = beanWrapper.getProperties();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.nexacro.spring.data.support;
|
package com.nexacro.spring.data.support;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -83,7 +84,8 @@ public class ListToDataSetConverter extends AbstractDataSetConverter implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
// apply null row (empty column)
|
||||||
|
return new HashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSet convertListMapToDataSet(List source, ConvertDefinition definition, Map availableFirstData) throws NexacroConvertException {
|
private DataSet convertListMapToDataSet(List source, ConvertDefinition definition, Map availableFirstData) throws NexacroConvertException {
|
||||||
@@ -99,11 +101,6 @@ public class ListToDataSetConverter extends AbstractDataSetConverter implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(Object obj: source) {
|
for(Object obj: source) {
|
||||||
|
|
||||||
if(!(obj instanceof Map)) {
|
|
||||||
throw new NexacroConvertException("list should use the generic type. target="+ds.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
addRowIntoDataSet(ds, (Map) obj, definition.isDisallowChangeStructure());
|
addRowIntoDataSet(ds, (Map) obj, definition.isDisallowChangeStructure());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.nexacro.spring.data.support;
|
package com.nexacro.spring.data.support;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -20,6 +22,7 @@ import com.nexacro.spring.util.ReflectionUtil;
|
|||||||
import com.nexacro.xapi.data.ColumnHeader;
|
import com.nexacro.xapi.data.ColumnHeader;
|
||||||
import com.nexacro.xapi.data.ConstantColumnHeader;
|
import com.nexacro.xapi.data.ConstantColumnHeader;
|
||||||
import com.nexacro.xapi.data.DataSet;
|
import com.nexacro.xapi.data.DataSet;
|
||||||
|
import com.nexacro.xapi.data.Debugger;
|
||||||
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -437,6 +440,65 @@ public class ListToDataSetConverterTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertListMapToDataSetIncludeNullRow() {
|
||||||
|
|
||||||
|
List<Map<String, Object>> defaultMap = new ArrayList<Map<String, Object>>();
|
||||||
|
defaultMap.add(null); // add null row
|
||||||
|
|
||||||
|
{
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("col1", "value");
|
||||||
|
defaultMap.add(map);
|
||||||
|
}
|
||||||
|
defaultMap.add(null); // add null row
|
||||||
|
{
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
map.put("col1", "value");
|
||||||
|
defaultMap.add(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||||
|
|
||||||
|
Object dsObj = null;
|
||||||
|
try {
|
||||||
|
dsObj = converter.convert(defaultMap, definition);
|
||||||
|
} catch (NexacroConvertException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSet ds = (DataSet) dsObj;
|
||||||
|
|
||||||
|
assertEquals(defaultMap.size(), ds.getRowCount());
|
||||||
|
Assert.assertTrue(ds.containsColumn("col1"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertListBeanToDataSetIncludeNullRow() {
|
||||||
|
|
||||||
|
List<DefaultBean> defaultBean = NexacroTestUtil.createDefaultBeans();
|
||||||
|
defaultBean.add(0, null); // add null row
|
||||||
|
defaultBean.add(null); // add null row
|
||||||
|
|
||||||
|
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||||
|
|
||||||
|
Object dsObj = null;
|
||||||
|
try {
|
||||||
|
dsObj = converter.convert(defaultBean, definition);
|
||||||
|
} catch (NexacroConvertException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assert.fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSet ds = (DataSet) dsObj;
|
||||||
|
|
||||||
|
assertEquals(defaultBean.size(), ds.getRowCount());
|
||||||
|
Assert.assertTrue(ds.containsColumn("employeeId"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpperCase() {
|
public void testUpperCase() {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user