DataSet으로 데이터 변환 시 스키마 데이터셋 설정 및 스키마 변경에 대한 옵션 추가.
This commit is contained in:
386
pom.xml
386
pom.xml
@@ -1,193 +1,193 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.nexacro.spring</groupId>
|
||||
<version>1.0.0</version>
|
||||
<artifactId>nexacro-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>nexacro-core</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<organization>
|
||||
<name>nexacro-core Dev Group</name>
|
||||
</organization>
|
||||
<description>Description of nexacro-core</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.nexacro</groupId>
|
||||
<artifactId>nexacro-pom-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.maven.ide.eclipse</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>0.9.9-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<mappingId>generic</mappingId>
|
||||
<configurators></configurators>
|
||||
<mojoExecutions></mojoExecutions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.nexacro</groupId>
|
||||
<artifactId>nexacro-xapi</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
<systemPath></systemPath>
|
||||
</dependency>
|
||||
|
||||
<!-- spring config -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.maven.artifact.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springmodules</groupId>
|
||||
<artifactId>spring-modules-jakarta-commons</artifactId>
|
||||
<version>0.8a</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 배포시점에 포함시키지 않는다. 외부의 Servlet Spec을 이용한다. -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Log4j2 SLF4J Bridge -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.15</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.jms</groupId>
|
||||
<artifactId>jms</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jdmk</groupId>
|
||||
<artifactId>jmxtools</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jmx</groupId>
|
||||
<artifactId>jmxri</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<!-- junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>xmlunit</groupId>
|
||||
<artifactId>xmlunit</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<org.slf4j-version>1.7.5</org.slf4j-version>
|
||||
</properties>
|
||||
</project>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.nexacro.spring</groupId>
|
||||
<version>1.0.1</version>
|
||||
<artifactId>nexacro-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>nexacro-core</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<organization>
|
||||
<name>nexacro-core Dev Group</name>
|
||||
</organization>
|
||||
<description>Description of nexacro-core</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.nexacro</groupId>
|
||||
<artifactId>nexacro-pom-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.maven.ide.eclipse</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>0.9.9-SNAPSHOT</version>
|
||||
<configuration>
|
||||
<mappingId>generic</mappingId>
|
||||
<configurators></configurators>
|
||||
<mojoExecutions></mojoExecutions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.nexacro</groupId>
|
||||
<artifactId>nexacro-xapi</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>compile</scope>
|
||||
<systemPath></systemPath>
|
||||
</dependency>
|
||||
|
||||
<!-- spring config -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-beans</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>${spring.maven.artifact.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springmodules</groupId>
|
||||
<artifactId>spring-modules-jakarta-commons</artifactId>
|
||||
<version>0.8a</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 배포시점에 포함시키지 않는다. 외부의 Servlet Spec을 이용한다. -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||
<version>2.2.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Log4j2 SLF4J Bridge -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.15</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.jms</groupId>
|
||||
<artifactId>jms</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jdmk</groupId>
|
||||
<artifactId>jmxtools</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.sun.jmx</groupId>
|
||||
<artifactId>jmxri</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
<!-- junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>xmlunit</groupId>
|
||||
<artifactId>xmlunit</artifactId>
|
||||
<version>1.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<org.slf4j-version>1.7.5</org.slf4j-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -1,71 +1,108 @@
|
||||
package com.nexacro.spring.data.convert;
|
||||
|
||||
|
||||
/**
|
||||
* <p>데이터 변환에 대한 정보를 저장한다.
|
||||
* <p>DataSet 혹은 Variable의 명칭을 가지며, List 형식의 데이터 변환시 Generic Type 정보를 가진다.
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 07.28.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
|
||||
public class ConvertDefinition {
|
||||
|
||||
private String name;
|
||||
private Class genericType; // for generic
|
||||
private boolean isIgnoreException = false;
|
||||
|
||||
public ConvertDefinition(String name) {
|
||||
setName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
if(name == null || name.length() == 0) {
|
||||
throw new IllegalArgumentException("converted name must be not null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isIgnoreException
|
||||
*/
|
||||
public boolean isIgnoreException() {
|
||||
return isIgnoreException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isIgnoreException
|
||||
* the isIgnoreException to set
|
||||
*/
|
||||
public void setIgnoreException(boolean isIgnoreException) {
|
||||
this.isIgnoreException = isIgnoreException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the genericType
|
||||
*/
|
||||
public Class getGenericType() {
|
||||
return genericType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param genericType the genericType to set
|
||||
*/
|
||||
public void setGenericType(Class genericType) {
|
||||
this.genericType = genericType;
|
||||
}
|
||||
|
||||
}
|
||||
package com.nexacro.spring.data.convert;
|
||||
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
|
||||
|
||||
/**
|
||||
* <p>데이터 변환에 대한 정보를 저장한다.
|
||||
* <p>DataSet 혹은 Variable의 명칭을 가지며, List 형식의 데이터 변환시 Generic Type 정보를 가진다.
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 07.28.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
|
||||
public class ConvertDefinition {
|
||||
|
||||
private String name;
|
||||
private Class genericType; // for generic
|
||||
private boolean isIgnoreException = false;
|
||||
|
||||
private DataSet schemaDataSet;
|
||||
private boolean disallowChangeStructure; // (v1.0.0에서 허용 하게 되어 있음)
|
||||
|
||||
public ConvertDefinition(String name) {
|
||||
setName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
if(name == null || name.length() == 0) {
|
||||
throw new IllegalArgumentException("converted name must be not null");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isIgnoreException
|
||||
*/
|
||||
public boolean isIgnoreException() {
|
||||
return isIgnoreException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isIgnoreException
|
||||
* the isIgnoreException to set
|
||||
*/
|
||||
public void setIgnoreException(boolean isIgnoreException) {
|
||||
this.isIgnoreException = isIgnoreException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the genericType
|
||||
*/
|
||||
public Class getGenericType() {
|
||||
return genericType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param genericType the genericType to set
|
||||
*/
|
||||
public void setGenericType(Class genericType) {
|
||||
this.genericType = genericType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return disallow structure change
|
||||
*/
|
||||
public boolean isDisallowChangeStructure() {
|
||||
return disallowChangeStructure;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param disallow structure change
|
||||
*/
|
||||
public void setDisallowChangeStructure(boolean disallowChangeStructure) {
|
||||
this.disallowChangeStructure = disallowChangeStructure;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the schema dataSet
|
||||
*/
|
||||
public DataSet getSchemaDataSet() {
|
||||
return schemaDataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param schemaDataSet
|
||||
*/
|
||||
public void setSchemaDataSet(DataSet schemaDataSet) {
|
||||
this.schemaDataSet = schemaDataSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
||||
* @param map
|
||||
* @throws NexacroConvertException
|
||||
*/
|
||||
protected void addRowIntoDataSet(DataSet ds, Map map) throws NexacroConvertException {
|
||||
protected void addRowIntoDataSet(DataSet ds, Map map, boolean disallowChangeStructure) throws NexacroConvertException {
|
||||
// ignore null data.
|
||||
if(map == null) {
|
||||
return;
|
||||
@@ -62,11 +62,15 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
||||
|
||||
int columnIndex = ds.indexOfColumn(columnName);
|
||||
if(columnIndex < 0) {
|
||||
// flexible map data. 'null' data should be ignored
|
||||
ds.setChangeStructureWithData(true);
|
||||
|
||||
if(!addColumnByMap(ds, columnName, value)) {
|
||||
continue;
|
||||
if(disallowChangeStructure) {
|
||||
// ignore
|
||||
continue;
|
||||
} else {
|
||||
// flexible map data. 'null' data should be ignored
|
||||
ds.setChangeStructureWithData(true);
|
||||
if(!addColumnByMap(ds, columnName, value)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
// fire event
|
||||
@@ -108,7 +112,13 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
||||
// Byte[] 변환
|
||||
Object object = NexacroConverterHelper.toObject(propertyValue);
|
||||
|
||||
// 컬럼은 무조건 존재한다.
|
||||
int columnIndex = ds.indexOfColumn(propertyName);
|
||||
if(columnIndex < 0) {
|
||||
// Map과 달리 이미 구조 변경에 대한 처리가 되었기 때문에 컬럼이 존재하지 않을 경우 무시하도록 한다.
|
||||
continue;
|
||||
}
|
||||
|
||||
// fire event
|
||||
object = fireDataSetConvertedValue(ds, object, newRow, columnIndex, false, false);
|
||||
|
||||
@@ -127,6 +137,9 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
||||
* @throws NexacroConvertException
|
||||
*/
|
||||
protected void addColumnIntoDataSet(DataSet ds, Map map) throws NexacroConvertException {
|
||||
|
||||
ds.setChangeStructureWithData(true);
|
||||
|
||||
Iterator iterator = map.keySet().iterator();
|
||||
while(iterator.hasNext()) {
|
||||
Object key = iterator.next();
|
||||
@@ -149,6 +162,8 @@ public class AbstractDataSetConverter extends AbstractListenerHandler {
|
||||
*/
|
||||
protected void addColumnIntoDataSet(DataSet ds, Object availableFirstData) {
|
||||
|
||||
ds.setChangeStructureWithData(true);
|
||||
|
||||
NexacroBeanWrapper beanWrapper = NexacroBeanWrapper.createBeanWrapper(availableFirstData);
|
||||
|
||||
NexacroBeanProperty[] beanProperties = beanWrapper.getProperties();
|
||||
|
||||
@@ -1,126 +1,142 @@
|
||||
package com.nexacro.spring.data.support;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nexacro.spring.data.convert.ConvertDefinition;
|
||||
import com.nexacro.spring.data.convert.NexacroConvertException;
|
||||
import com.nexacro.spring.data.convert.NexacroConverter;
|
||||
import com.nexacro.spring.data.metadata.NexacroMetaData;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
|
||||
/**
|
||||
* <p>List에서 <code>DataSet</code>으로 데이터로 변환을 수행한다.
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 07.28.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
public class ListToDataSetConverter extends AbstractDataSetConverter implements NexacroConverter<List, DataSet> {
|
||||
|
||||
private static final int CHECK_INDEX = 0;
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class source, Class target) {
|
||||
|
||||
if(source == null || target == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// support list sub class
|
||||
if(List.class.isAssignableFrom(source) && DataSet.class.equals(target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.nexacro.spring.data.NexacroConverter#convert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public DataSet convert(List source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
|
||||
if(definition ==null) {
|
||||
throw new IllegalArgumentException(ConvertDefinition.class.getSimpleName()+" must not be null.");
|
||||
}
|
||||
if(source == null) {
|
||||
return new DataSet(definition.getName());
|
||||
}
|
||||
|
||||
// check first value
|
||||
Object availableFirstData = checkAvailable(source);
|
||||
if(availableFirstData == null) {
|
||||
return new DataSet(definition.getName());
|
||||
}
|
||||
|
||||
// DataSet SavedType은 처리 하지 않는다. (UI 처리 불필요)
|
||||
DataSet ds = null;
|
||||
if(availableFirstData instanceof Map) {
|
||||
ds = convertListMapToDataSet(source, definition, (Map) availableFirstData);
|
||||
} else {
|
||||
ds = convertListBeanToDataSet(source, definition, availableFirstData);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
private Object checkAvailable(List source) {
|
||||
|
||||
// for ibatis empty data
|
||||
if(source instanceof NexacroMetaData) {
|
||||
NexacroMetaData metaData = (NexacroMetaData) source;
|
||||
return metaData.getMetaData();
|
||||
}
|
||||
|
||||
if(source.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
for(Object obj: source) {
|
||||
if(obj != null) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private DataSet convertListMapToDataSet(List source, ConvertDefinition definition, Map availableFirstData) throws NexacroConvertException {
|
||||
|
||||
DataSet ds = new DataSet(definition.getName());
|
||||
|
||||
// dynamic하게 변경 된 데이터는 처리 하지 않는다.
|
||||
addColumnIntoDataSet(ds, availableFirstData);
|
||||
|
||||
for(Object obj: source) {
|
||||
|
||||
if(!(obj instanceof Map)) {
|
||||
throw new NexacroConvertException("list should use the generic type. target="+ds.getName());
|
||||
}
|
||||
|
||||
addRowIntoDataSet(ds, (Map) obj);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataSet convertListBeanToDataSet(List source, ConvertDefinition definition, Object availableFirstData) throws NexacroConvertException {
|
||||
|
||||
// 지원하는 형식인지 확인 한다.
|
||||
if(!NexacroConverterHelper.isSupportedBean(availableFirstData.getClass())) {
|
||||
throw new NexacroConvertException("unsupported generic type. type="+availableFirstData.getClass());
|
||||
}
|
||||
|
||||
DataSet ds = new DataSet(definition.getName());
|
||||
|
||||
addColumnIntoDataSet(ds, availableFirstData);
|
||||
|
||||
for(Object obj: source) {
|
||||
addRowIntoDataSet(ds, obj);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
}
|
||||
package com.nexacro.spring.data.support;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nexacro.spring.data.convert.ConvertDefinition;
|
||||
import com.nexacro.spring.data.convert.NexacroConvertException;
|
||||
import com.nexacro.spring.data.convert.NexacroConverter;
|
||||
import com.nexacro.spring.data.metadata.NexacroMetaData;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
|
||||
/**
|
||||
* <p>List에서 <code>DataSet</code>으로 데이터로 변환을 수행한다.
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 07.28.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
public class ListToDataSetConverter extends AbstractDataSetConverter implements NexacroConverter<List, DataSet> {
|
||||
|
||||
private static final int CHECK_INDEX = 0;
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class source, Class target) {
|
||||
|
||||
if(source == null || target == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// support list sub class
|
||||
if(List.class.isAssignableFrom(source) && DataSet.class.equals(target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.nexacro.spring.data.NexacroConverter#convert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public DataSet convert(List source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
|
||||
if(definition ==null) {
|
||||
throw new IllegalArgumentException(ConvertDefinition.class.getSimpleName()+" must not be null.");
|
||||
}
|
||||
if(source == null) {
|
||||
return new DataSet(definition.getName());
|
||||
}
|
||||
|
||||
// check first value
|
||||
Object availableFirstData = checkAvailable(source);
|
||||
if(availableFirstData == null) {
|
||||
return new DataSet(definition.getName());
|
||||
}
|
||||
|
||||
// DataSet SavedType은 처리 하지 않는다. (UI 처리 불필요)
|
||||
DataSet ds = null;
|
||||
if(availableFirstData instanceof Map) {
|
||||
ds = convertListMapToDataSet(source, definition, (Map) availableFirstData);
|
||||
} else {
|
||||
ds = convertListBeanToDataSet(source, definition, availableFirstData);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
private Object checkAvailable(List source) {
|
||||
|
||||
// for ibatis empty data
|
||||
if(source instanceof NexacroMetaData) {
|
||||
NexacroMetaData metaData = (NexacroMetaData) source;
|
||||
return metaData.getMetaData();
|
||||
}
|
||||
|
||||
if(source.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
for(Object obj: source) {
|
||||
if(obj != null) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private DataSet convertListMapToDataSet(List source, ConvertDefinition definition, Map availableFirstData) throws NexacroConvertException {
|
||||
|
||||
DataSet ds = null;
|
||||
|
||||
if(definition.getSchemaDataSet() != null) {
|
||||
// set schema dataSet
|
||||
ds = definition.getSchemaDataSet();
|
||||
} else {
|
||||
ds = new DataSet(definition.getName());
|
||||
addColumnIntoDataSet(ds, availableFirstData);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataSet convertListBeanToDataSet(List source, ConvertDefinition definition, Object availableFirstData) throws NexacroConvertException {
|
||||
|
||||
// 지원하는 형식인지 확인 한다.
|
||||
if(!NexacroConverterHelper.isSupportedBean(availableFirstData.getClass())) {
|
||||
throw new NexacroConvertException("unsupported generic type. type="+availableFirstData.getClass());
|
||||
}
|
||||
|
||||
DataSet ds = null;
|
||||
if(definition.getSchemaDataSet() != null) {
|
||||
// set schema dataSet
|
||||
ds = definition.getSchemaDataSet();
|
||||
|
||||
// map과 달리 bean은 이미 정의가 되어 있기 때문에 row를 추가할때 컬럼을 추가하지 않고, 미리 설정한다.
|
||||
if(!definition.isDisallowChangeStructure()) {
|
||||
addColumnIntoDataSet(ds, availableFirstData);
|
||||
}
|
||||
|
||||
} else {
|
||||
ds = new DataSet(definition.getName());
|
||||
addColumnIntoDataSet(ds, availableFirstData);
|
||||
}
|
||||
|
||||
for(Object obj: source) {
|
||||
addRowIntoDataSet(ds, obj);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,98 +1,118 @@
|
||||
package com.nexacro.spring.data.support;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nexacro.spring.data.convert.ConvertDefinition;
|
||||
import com.nexacro.spring.data.convert.NexacroConvertException;
|
||||
import com.nexacro.spring.data.convert.NexacroConverter;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
|
||||
/**
|
||||
* <p>Object에서 <code>DataSet</code>으로 데이터로 변환을 수행한다.
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 08.17.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
public class ObjectToDataSetConverter extends AbstractDataSetConverter implements NexacroConverter<Object, DataSet> {
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class source, Class target) {
|
||||
|
||||
if(source == null || target == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// support type
|
||||
if(!List.class.isAssignableFrom(source) && NexacroConverterHelper.isSupportedBean(source) && DataSet.class.equals(target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSet convert(Object source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
|
||||
if(definition ==null) {
|
||||
throw new IllegalArgumentException(ConvertDefinition.class.getSimpleName()+" must not be null.");
|
||||
}
|
||||
|
||||
if(source == null) {
|
||||
return new DataSet(definition.getName());
|
||||
}
|
||||
|
||||
// DataSet SavedType은 처리 하지 않는다. (UI 처리 불필요)
|
||||
DataSet ds = null;
|
||||
if(source instanceof Map) {
|
||||
ds = convertMapToDataSet((Map)source, definition);
|
||||
} else {
|
||||
ds = convertBeanToDataSet(source, definition);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataSet convertBeanToDataSet(Object source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
|
||||
// 지원하는 형식인지 확인 한다.
|
||||
if(!NexacroConverterHelper.isSupportedBean(source.getClass())) {
|
||||
throw new NexacroConvertException("unsupported source type. type="+source.getClass());
|
||||
}
|
||||
|
||||
DataSet ds = new DataSet(definition.getName());
|
||||
addColumnIntoDataSet(ds, source);
|
||||
addRowIntoDataSet(ds, source);
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataSet convertMapToDataSet(Map source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
DataSet ds = new DataSet(definition.getName());
|
||||
addColumnIntoDataSet(ds, source);
|
||||
addRowIntoDataSet(ds, source);
|
||||
return ds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumnIntoDataSet(DataSet ds, Map source) throws NexacroConvertException {
|
||||
super.addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumnIntoDataSet(DataSet ds, Object source) {
|
||||
super.addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRowIntoDataSet(DataSet ds, Map source) throws NexacroConvertException {
|
||||
super.addRowIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRowIntoDataSet(DataSet ds, Object source) {
|
||||
super.addRowIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
}
|
||||
package com.nexacro.spring.data.support;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nexacro.spring.data.convert.ConvertDefinition;
|
||||
import com.nexacro.spring.data.convert.NexacroConvertException;
|
||||
import com.nexacro.spring.data.convert.NexacroConverter;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
|
||||
/**
|
||||
* <p>Object에서 <code>DataSet</code>으로 데이터로 변환을 수행한다.
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 08.17.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
public class ObjectToDataSetConverter extends AbstractDataSetConverter implements NexacroConverter<Object, DataSet> {
|
||||
|
||||
@Override
|
||||
public boolean canConvert(Class source, Class target) {
|
||||
|
||||
if(source == null || target == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// support type
|
||||
if(!List.class.isAssignableFrom(source) && NexacroConverterHelper.isSupportedBean(source) && DataSet.class.equals(target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSet convert(Object source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
|
||||
if(definition ==null) {
|
||||
throw new IllegalArgumentException(ConvertDefinition.class.getSimpleName()+" must not be null.");
|
||||
}
|
||||
|
||||
if(source == null) {
|
||||
return new DataSet(definition.getName());
|
||||
}
|
||||
|
||||
// DataSet SavedType은 처리 하지 않는다. (UI 처리 불필요)
|
||||
DataSet ds = null;
|
||||
if(source instanceof Map) {
|
||||
ds = convertMapToDataSet((Map)source, definition);
|
||||
} else {
|
||||
ds = convertBeanToDataSet(source, definition);
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataSet convertBeanToDataSet(Object source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
|
||||
// 지원하는 형식인지 확인 한다.
|
||||
if(!NexacroConverterHelper.isSupportedBean(source.getClass())) {
|
||||
throw new NexacroConvertException("unsupported source type. type="+source.getClass());
|
||||
}
|
||||
|
||||
DataSet ds = null;
|
||||
if(definition.getSchemaDataSet() != null) {
|
||||
// set schema dataSet
|
||||
ds = definition.getSchemaDataSet();
|
||||
|
||||
// map과 달리 bean은 이미 정의가 되어 있기 때문에 row를 추가할때 컬럼을 추가하지 않고, 미리 설정한다.
|
||||
if(!definition.isDisallowChangeStructure()) {
|
||||
addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
} else {
|
||||
ds = new DataSet(definition.getName());
|
||||
addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
addRowIntoDataSet(ds, source);
|
||||
return ds;
|
||||
}
|
||||
|
||||
private DataSet convertMapToDataSet(Map source, ConvertDefinition definition) throws NexacroConvertException {
|
||||
DataSet ds = null;
|
||||
if(definition.getSchemaDataSet() != null) {
|
||||
// set schema dataSet
|
||||
ds = definition.getSchemaDataSet();
|
||||
} else {
|
||||
ds = new DataSet(definition.getName());
|
||||
addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
addRowIntoDataSet(ds, source, definition.isDisallowChangeStructure());
|
||||
return ds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumnIntoDataSet(DataSet ds, Map source) throws NexacroConvertException {
|
||||
super.addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addColumnIntoDataSet(DataSet ds, Object source) {
|
||||
super.addColumnIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRowIntoDataSet(DataSet ds, Map source, boolean disallowChangeStructure) throws NexacroConvertException {
|
||||
super.addRowIntoDataSet(ds, source, disallowChangeStructure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRowIntoDataSet(DataSet ds, Object source) {
|
||||
super.addRowIntoDataSet(ds, source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.nexacro.spring.util.ReflectionUtil;
|
||||
import com.nexacro.xapi.data.ColumnHeader;
|
||||
import com.nexacro.xapi.data.ConstantColumnHeader;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -100,7 +101,7 @@ public class ListToDataSetConverterTest {
|
||||
Assert.fail("converted object must be implemented DataSet");
|
||||
}
|
||||
|
||||
NexacroTestUtil.compareDefaultDataSet((DataSet) ds);
|
||||
NexacroTestUtil.compareDefaultDataSet((DataSet) ds, 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ public class ListToDataSetConverterTest {
|
||||
Assert.fail("converted object must be implemented DataSet");
|
||||
}
|
||||
|
||||
NexacroTestUtil.compareDefaultDataSet((DataSet) ds);
|
||||
NexacroTestUtil.compareDefaultDataSet((DataSet) ds, 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -235,6 +236,207 @@ public class ListToDataSetConverterTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowChangeStructure() {
|
||||
// v1.0.0에서 Map의 null 컬럼 추가 되는 것을 확인한다.
|
||||
List<Map<String, Object>> defaultMap = new ArrayList<Map<String, Object>>();
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col1", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col2", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(false); // set allow structure change
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultMap, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
|
||||
Assert.assertTrue(ds.containsColumn("col1"));
|
||||
Assert.assertTrue(ds.containsColumn("col2"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisallowChangeStructure() {
|
||||
|
||||
List<Map<String, Object>> defaultMap = new ArrayList<Map<String, Object>>();
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col1", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col2", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(true); // set disallow structure change
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultMap, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
|
||||
Assert.assertTrue(ds.containsColumn("col1"));
|
||||
Assert.assertFalse(ds.containsColumn("col2"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowChangeStructureWithSchemaDataSet() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
List<Map<String, Object>> defaultMap = new ArrayList<Map<String, Object>>();
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col1", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col2", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(false); // set allow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultMap, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
Assert.assertTrue(ds.containsColumn("col1"));
|
||||
Assert.assertTrue(ds.containsColumn("col2"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowChangeStructureWithSchemaDataSetWithBean() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
List<DefaultBean> defaultBean = NexacroTestUtil.createDefaultBeans();
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(false); // set allow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultBean, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
NexacroTestUtil.compareDefaultDataSet(ds, 1); // defaultColumn
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisallowChangeStructureWithSchemaDataSet() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
List<Map<String, Object>> defaultMap = new ArrayList<Map<String, Object>>();
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col1", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
{
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col2", "value");
|
||||
defaultMap.add(map);
|
||||
}
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(true); // set disallow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultMap, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
Assert.assertFalse(ds.containsColumn("col1"));
|
||||
Assert.assertFalse(ds.containsColumn("col2"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisallowChangeStructureWithSchemaDataSetWithBean() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
List<DefaultBean> defaultBean = NexacroTestUtil.createDefaultBeans();
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(true); // set disallow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultBean, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
|
||||
Assert.assertEquals(ds.getColumnCount(), 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpperCase() {
|
||||
|
||||
|
||||
@@ -1,396 +1,396 @@
|
||||
package com.nexacro.spring.data.support;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.nexacro.spring.data.DataSetRowTypeAccessor;
|
||||
import com.nexacro.spring.data.DataSetSavedDataAccessor;
|
||||
import com.nexacro.spring.data.support.bean.DefaultBean;
|
||||
import com.nexacro.xapi.data.ColumnHeader;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
import com.nexacro.xapi.data.datatype.DataType;
|
||||
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 08.10.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
public abstract class NexacroTestUtil {
|
||||
|
||||
private static String[] dsPropertyNames;
|
||||
private static List<Object[]> dsValuesList;
|
||||
private static DataType[] dsDataTypes;
|
||||
|
||||
// private static List<Map<String, Object>> dataMapList;
|
||||
// private static Map<String, DataType> dataTypeMap;
|
||||
|
||||
private static Map<Class, Object> supportedClassesValue;
|
||||
|
||||
static {
|
||||
initSupportedClassesValue();
|
||||
initDsPropertyNames();
|
||||
initDsValueList();
|
||||
initDsDataTypes();
|
||||
}
|
||||
|
||||
static Map<Class, Object> getSupportedClassesValue() {
|
||||
return Collections.unmodifiableMap(supportedClassesValue);
|
||||
}
|
||||
|
||||
private static void initSupportedClassesValue() {
|
||||
|
||||
supportedClassesValue = new HashMap<Class, Object>();
|
||||
|
||||
Calendar instance = null;
|
||||
Date hireDate = null;
|
||||
instance = Calendar.getInstance();
|
||||
instance.set(2009, Calendar.JANUARY, 1);
|
||||
hireDate = new Date(instance.getTimeInMillis());
|
||||
|
||||
supportedClassesValue.put(int.class, 11);
|
||||
supportedClassesValue.put(Integer.class, new Integer(11));
|
||||
supportedClassesValue.put(long.class, 11l);
|
||||
supportedClassesValue.put(Long.class, new Long(11l));
|
||||
supportedClassesValue.put(float.class, 180.1f);
|
||||
supportedClassesValue.put(Float.class, new Float(180.1f));
|
||||
supportedClassesValue.put(double.class, 11.1d);
|
||||
supportedClassesValue.put(Double.class, new Double(11.1d));
|
||||
supportedClassesValue.put(boolean.class, true);
|
||||
supportedClassesValue.put(Boolean.class, Boolean.TRUE);
|
||||
supportedClassesValue.put(byte[].class, new byte[] { 1, 1 });
|
||||
supportedClassesValue.put(Byte[].class, new Byte[] { 1, 1 });
|
||||
supportedClassesValue.put(String.class, "seongmin");
|
||||
supportedClassesValue.put(Date.class, hireDate);
|
||||
supportedClassesValue.put(BigDecimal.class, new BigDecimal("10001"));
|
||||
supportedClassesValue.put(Object.class, new Object());
|
||||
|
||||
}
|
||||
|
||||
private static void initDsPropertyNames() {
|
||||
|
||||
dsPropertyNames = new String[] { "employeeId", "access", "height", "commissionPercent", "male", "image",
|
||||
"firstName", "lastName", "email", "hireDate", "salary", "obj" };
|
||||
|
||||
}
|
||||
|
||||
private static void initDsValueList() {
|
||||
|
||||
dsValuesList = new ArrayList<Object[]>();
|
||||
|
||||
Calendar instance = null;
|
||||
Date hireDate = null;
|
||||
instance = Calendar.getInstance();
|
||||
instance.set(2009, Calendar.JANUARY, 1);
|
||||
hireDate = new Date(instance.getTimeInMillis());
|
||||
|
||||
Object[] firstValues = new Object[] { 11, 11l, 180.1f, 11.1d, true, new byte[] { 1, 1 }, "seongmin", "park",
|
||||
"seongmin@tobesoft.com", hireDate, new BigDecimal("10001"), new Object() };
|
||||
dsValuesList.add(firstValues);
|
||||
|
||||
instance = Calendar.getInstance();
|
||||
instance.set(2009, Calendar.JANUARY, 2);
|
||||
hireDate = new Date(instance.getTimeInMillis());
|
||||
Object[] secondValues = new Object[] { 12, 12l, 180.2f, 11.2d, false, new byte[] { 1, 2 }, "hyena", "lee",
|
||||
"hyena@tobesoft.com", hireDate, new BigDecimal("10002"), new Object() };
|
||||
dsValuesList.add(secondValues);
|
||||
|
||||
}
|
||||
|
||||
private static void initDsDataTypes() {
|
||||
dsDataTypes = new DataType[] { PlatformDataType.INT, PlatformDataType.LONG, PlatformDataType.FLOAT,
|
||||
PlatformDataType.DOUBLE, PlatformDataType.BOOLEAN, PlatformDataType.BLOB, PlatformDataType.STRING,
|
||||
PlatformDataType.STRING, PlatformDataType.STRING, PlatformDataType.DATE_TIME,
|
||||
PlatformDataType.BIG_DECIMAL, PlatformDataType.UNDEFINED };
|
||||
}
|
||||
|
||||
public static List<DefaultBean> createDefaultBeans() {
|
||||
|
||||
List<DefaultBean> beanList = new ArrayList<DefaultBean>();
|
||||
|
||||
for (Object[] value : dsValuesList) {
|
||||
|
||||
NexacroBeanWrapper wrapper = NexacroBeanWrapper.createBeanWrapper(DefaultBean.class);
|
||||
for (int i=0; i<dsPropertyNames.length; i++) {
|
||||
wrapper.setPropertyValue(dsPropertyNames[i], value[i]);
|
||||
}
|
||||
Object bean = wrapper.getInstance();
|
||||
beanList.add((DefaultBean) bean);
|
||||
}
|
||||
|
||||
return beanList;
|
||||
|
||||
}
|
||||
|
||||
public static DataSet createDefaultDataSet() {
|
||||
|
||||
DataSet ds = new DataSet("employee");
|
||||
for (int i = 0; i < dsPropertyNames.length; i++) {
|
||||
ds.addColumn(dsPropertyNames[i], dsDataTypes[i]);
|
||||
}
|
||||
|
||||
for (Object[] value : dsValuesList) {
|
||||
int newRow = ds.newRow();
|
||||
for (int i = 0; i < dsPropertyNames.length; i++) {
|
||||
ds.set(newRow, dsPropertyNames[i], value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> createDefaultMaps() {
|
||||
|
||||
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
for (Object[] value : dsValuesList) {
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<String, Object>();
|
||||
|
||||
for (int i=0; i<dsPropertyNames.length; i++) {
|
||||
dataMap.put(dsPropertyNames[i], value[i]);
|
||||
}
|
||||
mapList.add(dataMap);
|
||||
}
|
||||
|
||||
return mapList;
|
||||
}
|
||||
|
||||
public static void compareDefaultBeans(List<DefaultBean> beanList) {
|
||||
|
||||
if (beanList == null) {
|
||||
Assert.fail("bean list is null");
|
||||
}
|
||||
|
||||
int expectedSize = dsValuesList.size();
|
||||
int actualSize = beanList.size();
|
||||
Assert.assertEquals("bean list size does not matched. please check converted columns. expected=" + expectedSize
|
||||
+ ", actual=" + actualSize, expectedSize, actualSize);
|
||||
|
||||
for (int rowIndex = 0; rowIndex < actualSize; rowIndex++) {
|
||||
DefaultBean defaultBean = beanList.get(rowIndex);
|
||||
NexacroBeanWrapper beanWrapper = NexacroBeanWrapper.createBeanWrapper(defaultBean);
|
||||
|
||||
NexacroBeanProperty[] properties = beanWrapper.getProperties();
|
||||
if (dsPropertyNames.length != properties.length) {
|
||||
Assert.fail("bean properties does not matched. please check converted columns. expected="
|
||||
+ dsPropertyNames.length + ", actual=" + properties.length);
|
||||
}
|
||||
|
||||
Object[] values = dsValuesList.get(rowIndex);
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
NexacroBeanProperty property = beanWrapper.getProperty(dsPropertyNames[propertyIndex]);
|
||||
|
||||
Object expectedValue = values[propertyIndex];
|
||||
Object actualValue = beanWrapper.getPropertyValue(dsPropertyNames[propertyIndex]);
|
||||
|
||||
Assert.assertEquals("row(" + rowIndex + ") property(" + dsPropertyNames[propertyIndex]
|
||||
+ ") value does not matched. expected=" + expectedValue + ", actual=" + actualValue,
|
||||
expectedValue, actualValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void compareDefaultDataSet(DataSet ds) {
|
||||
|
||||
if (ds == null) {
|
||||
Assert.fail("compare DataSet is null");
|
||||
}
|
||||
|
||||
int expectedSize = dsPropertyNames.length;
|
||||
int actualSize = ds.getColumnCount();
|
||||
Assert.assertEquals("DataSet column does not matched. please check converted columns. expected=" + expectedSize
|
||||
+ ", actual=" + actualSize, expectedSize, actualSize);
|
||||
|
||||
// check column
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
|
||||
String propertyName = dsPropertyNames[propertyIndex];
|
||||
ColumnHeader column = ds.getColumn(propertyName);
|
||||
|
||||
if (!propertyName.equals(column.getName())) {
|
||||
Assert.fail("column name does not matched. expected=" + dsPropertyNames[propertyIndex] + ", autual="
|
||||
+ column.getName());
|
||||
}
|
||||
if (!dsDataTypes[propertyIndex].equals(column.getPlatformDataType())) {
|
||||
Assert.fail(column.getName() + " data type does not matched. expected=" + dsDataTypes[propertyIndex] + ", autual="
|
||||
+ column.getPlatformDataType());
|
||||
}
|
||||
}
|
||||
|
||||
// check values
|
||||
int rowCount = ds.getRowCount();
|
||||
if (dsValuesList.size() != rowCount) {
|
||||
Assert.fail("DataSet rows does not matched. expected=" + dsValuesList.size() + ", actual=" + rowCount);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
||||
|
||||
Object[] values = dsValuesList.get(rowIndex);
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
String propertyName = dsPropertyNames[propertyIndex];
|
||||
|
||||
Object expectedValue = values[propertyIndex];
|
||||
Object actualValue = ds.getObject(rowIndex, propertyName);
|
||||
|
||||
Assert.assertEquals("row(" + rowIndex + ") property(" + dsPropertyNames[propertyIndex]
|
||||
+ ") value does not matched. expected=" + expectedValue + ", actual=" + actualValue,
|
||||
expectedValue, actualValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void compareDefaultMaps(List<Map<String, Object>> mapList) {
|
||||
|
||||
if (mapList == null) {
|
||||
Assert.fail("map list is null");
|
||||
}
|
||||
|
||||
int size = mapList.size();
|
||||
if (dsValuesList.size() != size) {
|
||||
Assert.fail("map list size does not matched. expected=" + dsValuesList.size() + ", actual=" + size);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < size; rowIndex++) {
|
||||
Map<String, Object> dataMap = mapList.get(rowIndex);
|
||||
|
||||
Set<String> keySet = dataMap.keySet();
|
||||
|
||||
// row type이 추가되어 있다.
|
||||
int expectedSize = dsPropertyNames.length + 1;
|
||||
int actualSize = keySet.size();
|
||||
Assert.assertEquals("map properties does not matched. please check converted columns. expected="
|
||||
+ expectedSize + ", actual=" + actualSize, expectedSize, actualSize);
|
||||
|
||||
Object[] values = dsValuesList.get(rowIndex);
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
|
||||
String propertyName = dsPropertyNames[propertyIndex];
|
||||
|
||||
Object expectedValue = values[propertyIndex];
|
||||
Object actualValue = dataMap.get(propertyName);
|
||||
|
||||
Assert.assertEquals("row(" + rowIndex + ") property(" + dsPropertyNames[propertyIndex]
|
||||
+ ") value does not matched. expected=" + expectedValue + ", actual=" + actualValue,
|
||||
expectedValue, actualValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class StaticPropertyBean {
|
||||
|
||||
private String name;
|
||||
private static double commissionPercent;
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the commissionPercent
|
||||
*/
|
||||
public static double getCommissionPercent() {
|
||||
return commissionPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commissionPercent the commissionPercent to set
|
||||
*/
|
||||
public static void setCommissionPercent(double commissionPercent) {
|
||||
StaticPropertyBean.commissionPercent = commissionPercent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DataSetRowTypeBean implements DataSetRowTypeAccessor {
|
||||
|
||||
private String name;
|
||||
private int rowType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowType() {
|
||||
return this.rowType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowType(int rowType) {
|
||||
this.rowType = rowType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DataSetSavedDataBean implements DataSetSavedDataAccessor<DataSetSavedDataBean>, DataSetRowTypeAccessor {
|
||||
|
||||
private String name;
|
||||
private int rowType;
|
||||
|
||||
private DataSetSavedDataBean savedData;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSetSavedDataBean getData() {
|
||||
return this.savedData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(DataSetSavedDataBean savedData) {
|
||||
this.savedData = savedData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowType() {
|
||||
return this.rowType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowType(int rowType) {
|
||||
this.rowType = rowType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.nexacro.spring.data.support;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.nexacro.spring.data.DataSetRowTypeAccessor;
|
||||
import com.nexacro.spring.data.DataSetSavedDataAccessor;
|
||||
import com.nexacro.spring.data.support.bean.DefaultBean;
|
||||
import com.nexacro.xapi.data.ColumnHeader;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
import com.nexacro.xapi.data.datatype.DataType;
|
||||
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Park SeongMin
|
||||
* @since 08.10.2015
|
||||
* @version 1.0
|
||||
* @see
|
||||
*/
|
||||
public abstract class NexacroTestUtil {
|
||||
|
||||
private static String[] dsPropertyNames;
|
||||
private static List<Object[]> dsValuesList;
|
||||
private static DataType[] dsDataTypes;
|
||||
|
||||
// private static List<Map<String, Object>> dataMapList;
|
||||
// private static Map<String, DataType> dataTypeMap;
|
||||
|
||||
private static Map<Class, Object> supportedClassesValue;
|
||||
|
||||
static {
|
||||
initSupportedClassesValue();
|
||||
initDsPropertyNames();
|
||||
initDsValueList();
|
||||
initDsDataTypes();
|
||||
}
|
||||
|
||||
static Map<Class, Object> getSupportedClassesValue() {
|
||||
return Collections.unmodifiableMap(supportedClassesValue);
|
||||
}
|
||||
|
||||
private static void initSupportedClassesValue() {
|
||||
|
||||
supportedClassesValue = new HashMap<Class, Object>();
|
||||
|
||||
Calendar instance = null;
|
||||
Date hireDate = null;
|
||||
instance = Calendar.getInstance();
|
||||
instance.set(2009, Calendar.JANUARY, 1);
|
||||
hireDate = new Date(instance.getTimeInMillis());
|
||||
|
||||
supportedClassesValue.put(int.class, 11);
|
||||
supportedClassesValue.put(Integer.class, new Integer(11));
|
||||
supportedClassesValue.put(long.class, 11l);
|
||||
supportedClassesValue.put(Long.class, new Long(11l));
|
||||
supportedClassesValue.put(float.class, 180.1f);
|
||||
supportedClassesValue.put(Float.class, new Float(180.1f));
|
||||
supportedClassesValue.put(double.class, 11.1d);
|
||||
supportedClassesValue.put(Double.class, new Double(11.1d));
|
||||
supportedClassesValue.put(boolean.class, true);
|
||||
supportedClassesValue.put(Boolean.class, Boolean.TRUE);
|
||||
supportedClassesValue.put(byte[].class, new byte[] { 1, 1 });
|
||||
supportedClassesValue.put(Byte[].class, new Byte[] { 1, 1 });
|
||||
supportedClassesValue.put(String.class, "seongmin");
|
||||
supportedClassesValue.put(Date.class, hireDate);
|
||||
supportedClassesValue.put(BigDecimal.class, new BigDecimal("10001"));
|
||||
supportedClassesValue.put(Object.class, new Object());
|
||||
|
||||
}
|
||||
|
||||
private static void initDsPropertyNames() {
|
||||
|
||||
dsPropertyNames = new String[] { "employeeId", "access", "height", "commissionPercent", "male", "image",
|
||||
"firstName", "lastName", "email", "hireDate", "salary", "obj" };
|
||||
|
||||
}
|
||||
|
||||
private static void initDsValueList() {
|
||||
|
||||
dsValuesList = new ArrayList<Object[]>();
|
||||
|
||||
Calendar instance = null;
|
||||
Date hireDate = null;
|
||||
instance = Calendar.getInstance();
|
||||
instance.set(2009, Calendar.JANUARY, 1);
|
||||
hireDate = new Date(instance.getTimeInMillis());
|
||||
|
||||
Object[] firstValues = new Object[] { 11, 11l, 180.1f, 11.1d, true, new byte[] { 1, 1 }, "seongmin", "park",
|
||||
"seongmin@tobesoft.com", hireDate, new BigDecimal("10001"), new Object() };
|
||||
dsValuesList.add(firstValues);
|
||||
|
||||
instance = Calendar.getInstance();
|
||||
instance.set(2009, Calendar.JANUARY, 2);
|
||||
hireDate = new Date(instance.getTimeInMillis());
|
||||
Object[] secondValues = new Object[] { 12, 12l, 180.2f, 11.2d, false, new byte[] { 1, 2 }, "hyena", "lee",
|
||||
"hyena@tobesoft.com", hireDate, new BigDecimal("10002"), new Object() };
|
||||
dsValuesList.add(secondValues);
|
||||
|
||||
}
|
||||
|
||||
private static void initDsDataTypes() {
|
||||
dsDataTypes = new DataType[] { PlatformDataType.INT, PlatformDataType.LONG, PlatformDataType.FLOAT,
|
||||
PlatformDataType.DOUBLE, PlatformDataType.BOOLEAN, PlatformDataType.BLOB, PlatformDataType.STRING,
|
||||
PlatformDataType.STRING, PlatformDataType.STRING, PlatformDataType.DATE_TIME,
|
||||
PlatformDataType.BIG_DECIMAL, PlatformDataType.UNDEFINED };
|
||||
}
|
||||
|
||||
public static List<DefaultBean> createDefaultBeans() {
|
||||
|
||||
List<DefaultBean> beanList = new ArrayList<DefaultBean>();
|
||||
|
||||
for (Object[] value : dsValuesList) {
|
||||
|
||||
NexacroBeanWrapper wrapper = NexacroBeanWrapper.createBeanWrapper(DefaultBean.class);
|
||||
for (int i=0; i<dsPropertyNames.length; i++) {
|
||||
wrapper.setPropertyValue(dsPropertyNames[i], value[i]);
|
||||
}
|
||||
Object bean = wrapper.getInstance();
|
||||
beanList.add((DefaultBean) bean);
|
||||
}
|
||||
|
||||
return beanList;
|
||||
|
||||
}
|
||||
|
||||
public static DataSet createDefaultDataSet() {
|
||||
|
||||
DataSet ds = new DataSet("employee");
|
||||
for (int i = 0; i < dsPropertyNames.length; i++) {
|
||||
ds.addColumn(dsPropertyNames[i], dsDataTypes[i]);
|
||||
}
|
||||
|
||||
for (Object[] value : dsValuesList) {
|
||||
int newRow = ds.newRow();
|
||||
for (int i = 0; i < dsPropertyNames.length; i++) {
|
||||
ds.set(newRow, dsPropertyNames[i], value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> createDefaultMaps() {
|
||||
|
||||
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
|
||||
|
||||
for (Object[] value : dsValuesList) {
|
||||
|
||||
Map<String, Object> dataMap = new HashMap<String, Object>();
|
||||
|
||||
for (int i=0; i<dsPropertyNames.length; i++) {
|
||||
dataMap.put(dsPropertyNames[i], value[i]);
|
||||
}
|
||||
mapList.add(dataMap);
|
||||
}
|
||||
|
||||
return mapList;
|
||||
}
|
||||
|
||||
public static void compareDefaultBeans(List<DefaultBean> beanList) {
|
||||
|
||||
if (beanList == null) {
|
||||
Assert.fail("bean list is null");
|
||||
}
|
||||
|
||||
int expectedSize = dsValuesList.size();
|
||||
int actualSize = beanList.size();
|
||||
Assert.assertEquals("bean list size does not matched. please check converted columns. expected=" + expectedSize
|
||||
+ ", actual=" + actualSize, expectedSize, actualSize);
|
||||
|
||||
for (int rowIndex = 0; rowIndex < actualSize; rowIndex++) {
|
||||
DefaultBean defaultBean = beanList.get(rowIndex);
|
||||
NexacroBeanWrapper beanWrapper = NexacroBeanWrapper.createBeanWrapper(defaultBean);
|
||||
|
||||
NexacroBeanProperty[] properties = beanWrapper.getProperties();
|
||||
if (dsPropertyNames.length != properties.length) {
|
||||
Assert.fail("bean properties does not matched. please check converted columns. expected="
|
||||
+ dsPropertyNames.length + ", actual=" + properties.length);
|
||||
}
|
||||
|
||||
Object[] values = dsValuesList.get(rowIndex);
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
NexacroBeanProperty property = beanWrapper.getProperty(dsPropertyNames[propertyIndex]);
|
||||
|
||||
Object expectedValue = values[propertyIndex];
|
||||
Object actualValue = beanWrapper.getPropertyValue(dsPropertyNames[propertyIndex]);
|
||||
|
||||
Assert.assertEquals("row(" + rowIndex + ") property(" + dsPropertyNames[propertyIndex]
|
||||
+ ") value does not matched. expected=" + expectedValue + ", actual=" + actualValue,
|
||||
expectedValue, actualValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void compareDefaultDataSet(DataSet ds, int addedColumns) {
|
||||
|
||||
if (ds == null) {
|
||||
Assert.fail("compare DataSet is null");
|
||||
}
|
||||
|
||||
int expectedSize = dsPropertyNames.length + addedColumns;
|
||||
int actualSize = ds.getColumnCount();
|
||||
Assert.assertEquals("DataSet column does not matched. please check converted columns. expected=" + expectedSize
|
||||
+ ", actual=" + actualSize, expectedSize, actualSize);
|
||||
|
||||
// check column
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
|
||||
String propertyName = dsPropertyNames[propertyIndex];
|
||||
ColumnHeader column = ds.getColumn(propertyName);
|
||||
|
||||
if (!propertyName.equals(column.getName())) {
|
||||
Assert.fail("column name does not matched. expected=" + dsPropertyNames[propertyIndex] + ", autual="
|
||||
+ column.getName());
|
||||
}
|
||||
if (!dsDataTypes[propertyIndex].equals(column.getPlatformDataType())) {
|
||||
Assert.fail(column.getName() + " data type does not matched. expected=" + dsDataTypes[propertyIndex] + ", autual="
|
||||
+ column.getPlatformDataType());
|
||||
}
|
||||
}
|
||||
|
||||
// check values
|
||||
int rowCount = ds.getRowCount();
|
||||
if (dsValuesList.size() != rowCount) {
|
||||
Assert.fail("DataSet rows does not matched. expected=" + dsValuesList.size() + ", actual=" + rowCount);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
|
||||
|
||||
Object[] values = dsValuesList.get(rowIndex);
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
String propertyName = dsPropertyNames[propertyIndex];
|
||||
|
||||
Object expectedValue = values[propertyIndex];
|
||||
Object actualValue = ds.getObject(rowIndex, propertyName);
|
||||
|
||||
Assert.assertEquals("row(" + rowIndex + ") property(" + dsPropertyNames[propertyIndex]
|
||||
+ ") value does not matched. expected=" + expectedValue + ", actual=" + actualValue,
|
||||
expectedValue, actualValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void compareDefaultMaps(List<Map<String, Object>> mapList) {
|
||||
|
||||
if (mapList == null) {
|
||||
Assert.fail("map list is null");
|
||||
}
|
||||
|
||||
int size = mapList.size();
|
||||
if (dsValuesList.size() != size) {
|
||||
Assert.fail("map list size does not matched. expected=" + dsValuesList.size() + ", actual=" + size);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < size; rowIndex++) {
|
||||
Map<String, Object> dataMap = mapList.get(rowIndex);
|
||||
|
||||
Set<String> keySet = dataMap.keySet();
|
||||
|
||||
// row type이 추가되어 있다.
|
||||
int expectedSize = dsPropertyNames.length + 1;
|
||||
int actualSize = keySet.size();
|
||||
Assert.assertEquals("map properties does not matched. please check converted columns. expected="
|
||||
+ expectedSize + ", actual=" + actualSize, expectedSize, actualSize);
|
||||
|
||||
Object[] values = dsValuesList.get(rowIndex);
|
||||
for (int propertyIndex = 0; propertyIndex < dsPropertyNames.length; propertyIndex++) {
|
||||
|
||||
String propertyName = dsPropertyNames[propertyIndex];
|
||||
|
||||
Object expectedValue = values[propertyIndex];
|
||||
Object actualValue = dataMap.get(propertyName);
|
||||
|
||||
Assert.assertEquals("row(" + rowIndex + ") property(" + dsPropertyNames[propertyIndex]
|
||||
+ ") value does not matched. expected=" + expectedValue + ", actual=" + actualValue,
|
||||
expectedValue, actualValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class StaticPropertyBean {
|
||||
|
||||
private String name;
|
||||
private static double commissionPercent;
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the commissionPercent
|
||||
*/
|
||||
public static double getCommissionPercent() {
|
||||
return commissionPercent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param commissionPercent the commissionPercent to set
|
||||
*/
|
||||
public static void setCommissionPercent(double commissionPercent) {
|
||||
StaticPropertyBean.commissionPercent = commissionPercent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DataSetRowTypeBean implements DataSetRowTypeAccessor {
|
||||
|
||||
private String name;
|
||||
private int rowType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowType() {
|
||||
return this.rowType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowType(int rowType) {
|
||||
this.rowType = rowType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DataSetSavedDataBean implements DataSetSavedDataAccessor<DataSetSavedDataBean>, DataSetRowTypeAccessor {
|
||||
|
||||
private String name;
|
||||
private int rowType;
|
||||
|
||||
private DataSetSavedDataBean savedData;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSetSavedDataBean getData() {
|
||||
return this.savedData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(DataSetSavedDataBean savedData) {
|
||||
this.savedData = savedData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowType() {
|
||||
return this.rowType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowType(int rowType) {
|
||||
this.rowType = rowType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.nexacro.spring.data.support.bean.UpperCaseBean;
|
||||
import com.nexacro.spring.util.ReflectionUtil;
|
||||
import com.nexacro.xapi.data.ColumnHeader;
|
||||
import com.nexacro.xapi.data.DataSet;
|
||||
import com.nexacro.xapi.data.datatype.PlatformDataType;
|
||||
|
||||
public class ObjectToDataSetConverterTest {
|
||||
|
||||
@@ -113,6 +114,124 @@ public class ObjectToDataSetConverterTest {
|
||||
Assert.assertEquals("ds", dataset.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowChangeStructureWithSchemaDataSet() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col1", "value");
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(false); // set allow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(map, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
Assert.assertTrue(ds.containsColumn("col1"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowChangeStructureWithSchemaDataSetWithBean() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
DefaultBean defaultBean = new DefaultBean();
|
||||
defaultBean.setLastName("Kim");
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(false); // set allow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultBean, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
|
||||
Assert.assertEquals("Kim", ds.getObject(0, "lastName"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisallowChangeStructureWithSchemaDataSet() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("col1", "value");
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(true); // set disallow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(map, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
Assert.assertFalse(ds.containsColumn("col1"));
|
||||
Assert.assertFalse(ds.containsColumn("col2"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisallowChangeStructureWithSchemaDataSetWithBean() {
|
||||
|
||||
DataSet schemaDataSet = new DataSet("schemaDa");
|
||||
schemaDataSet.addColumn("defaultCol1", PlatformDataType.STRING);
|
||||
|
||||
DefaultBean defaultBean = new DefaultBean();
|
||||
defaultBean.setLastName("Kim");
|
||||
|
||||
ConvertDefinition definition = new ConvertDefinition("ds");
|
||||
definition.setDisallowChangeStructure(true); // set disallow structure change
|
||||
definition.setSchemaDataSet(schemaDataSet); // set schema dataSet
|
||||
|
||||
Object dsObj = null;
|
||||
try {
|
||||
dsObj = converter.convert(defaultBean, definition);
|
||||
} catch (NexacroConvertException e) {
|
||||
e.printStackTrace();
|
||||
Assert.fail(e.getMessage());
|
||||
}
|
||||
|
||||
DataSet ds = (DataSet) dsObj;
|
||||
Assert.assertTrue(schemaDataSet.equals(ds));
|
||||
Assert.assertTrue(ds.containsColumn("defaultCol1"));
|
||||
|
||||
Assert.assertEquals(ds.getColumnCount(), 1);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpperCase() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user