XMLMessage BIGDECIMAL validation 추가 및 isValid() 공통화
- Converter.isValid(): JSONMessage의 private isValid()를 static 공통 메서드로 이동 (지수형 정규화 포함, 빈 문자열은 검증 대상 아님) - JSONMessage: Converter.isValid() 위임, private isValid() 제거 - XMLMessage: doSetValue()에서 TYPE_BIGDECIMAL 필드 validation 추가 (try-catch 예외 삼킴 블록 앞에 위치시켜 예외가 전파되도록 함) - BytesMessageValidationTest: VALID_RAW 길이 오류 수정(32→35바이트), TYPE_BYTEARRAY isolation 검증 - XMLMessageValidationTest: validation 정상/오류/경계 케이스 10개 추가 (C-1 assertThrows 포함)
This commit is contained in:
@@ -211,6 +211,32 @@ public class Converter {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValid(String value, int length, int pointLength) {
|
||||
String normalized = value.replaceAll(" ", "");
|
||||
if (SystemKeys.isScientificNormalizeEnabled()) {
|
||||
try {
|
||||
normalized = new BigDecimal(normalized).toPlainString();
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String[] data = normalized.split("[.]");
|
||||
if (pointLength > 0) {
|
||||
if (data.length == 1) {
|
||||
if (data[0].length() > length - pointLength - 1) return false;
|
||||
} else if (data.length == 2) {
|
||||
if (data[0].length() > length - pointLength - 1) return false;
|
||||
if (data[1].length() > pointLength) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (data.length != 1) return false;
|
||||
if (data[0].length() > length) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String addPoint(String dpNum, int tLen , int dLen) {
|
||||
if (dpNum == null || dpNum.trim().length() ==0 ){
|
||||
return "0";
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Stack;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.transformer.SystemKeys;
|
||||
import com.eactive.eai.transformer.layout.Converter;
|
||||
import com.eactive.eai.transformer.layout.InvalidNodeException;
|
||||
import com.eactive.eai.transformer.layout.Item;
|
||||
import com.eactive.eai.transformer.layout.Types;
|
||||
@@ -268,7 +269,7 @@ public class JSONMessage extends Message {
|
||||
setLong( itemPath, new Long(value) );
|
||||
break;
|
||||
case Types.TYPE_BIGDECIMAL :
|
||||
if (SystemKeys.isValidationEnabled() && !isValid(value, item.getLength(), item.getDecimalPointLength())) {
|
||||
if (SystemKeys.isValidationEnabled() && !Converter.isValid(value, item.getLength(), item.getDecimalPointLength())) {
|
||||
throw new InvalidAccessException(
|
||||
String.format("Invalid decimal point format Error value=%s,length=%d,pointLength=%d",
|
||||
value, item.getLength(), item.getDecimalPointLength()),
|
||||
@@ -662,7 +663,7 @@ public class JSONMessage extends Message {
|
||||
|
||||
private String getFormat(String value, int length, int pointLength, boolean isValidation) throws Exception{
|
||||
if(isValidation) {
|
||||
if (!isValid(value,length,pointLength)){
|
||||
if (!Converter.isValid(value,length,pointLength)){
|
||||
throw new Exception(String.format("Invalid decimal point format Error value=%s,length=%d,pointLength=%d"
|
||||
, value,length,pointLength)
|
||||
);
|
||||
@@ -702,44 +703,6 @@ public class JSONMessage extends Message {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValid(String value,int length,int pointLength){
|
||||
String normalized = value.replaceAll(" ", "");
|
||||
if (SystemKeys.isScientificNormalizeEnabled()) {
|
||||
try {
|
||||
normalized = new BigDecimal(normalized).toPlainString();
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
String[] data = normalized.split("[.]");
|
||||
if (pointLength > 0 ){
|
||||
if (data.length ==1){
|
||||
if (data[0].length() > length - pointLength - 1 ){ //정수부 오류
|
||||
return false;
|
||||
}
|
||||
}else if (data.length ==2){
|
||||
if (data[0].length() > length - pointLength - 1 ){ //정수부 오류
|
||||
return false;
|
||||
}
|
||||
if (data[1].length() > pointLength ){ //실수부 오류
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
//오류
|
||||
return false;
|
||||
}
|
||||
|
||||
}else{
|
||||
if (data.length != 1){ //소수점이 들어와서 오류
|
||||
return false;
|
||||
}
|
||||
if (data[0].length() > length){ //정수부 오류
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// private Object toJsonObjectType(int itemType, String value) {
|
||||
// Object jsonValueObject = null;
|
||||
//
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.dom4j.Namespace;
|
||||
import org.dom4j.QName;
|
||||
|
||||
import com.eactive.eai.transformer.SystemKeys;
|
||||
import com.eactive.eai.transformer.layout.Converter;
|
||||
import com.eactive.eai.transformer.layout.InvalidNodeException;
|
||||
import com.eactive.eai.transformer.layout.Item;
|
||||
import com.eactive.eai.transformer.layout.Layout;
|
||||
@@ -198,8 +199,17 @@ public class XMLMessage extends Message {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (item.isField()) {
|
||||
else if (item.isField()) {
|
||||
Object data = child.getData();
|
||||
if (data instanceof String
|
||||
&& item.getDataTypeId() == Types.TYPE_BIGDECIMAL
|
||||
&& SystemKeys.isValidationEnabled()
|
||||
&& !Converter.isValid((String) data, item.getLength(), item.getDecimalPointLength())) {
|
||||
throw new InvalidAccessException(
|
||||
String.format("Invalid decimal point format Error value=%s,length=%d,pointLength=%d",
|
||||
data, item.getLength(), item.getDecimalPointLength()),
|
||||
childPath);
|
||||
}
|
||||
try {
|
||||
if (data instanceof String){
|
||||
setString(childPath, (String) data);
|
||||
|
||||
Reference in New Issue
Block a user