package com.vci.client.bof;
|
|
import java.util.HashMap;
|
|
import com.vci.client.common.datatype.VTDouble;
|
import com.vci.client.common.datatype.VTInteger;
|
import com.vci.client.common.datatype.VTLong;
|
import com.vci.client.omd.attribpool.toOutside.Tool;
|
import com.vci.client.omd.provider.ApProvider;
|
import com.vci.corba.omd.atm.AttribItem;
|
import com.vci.omd.constants.BusinessConstants;
|
import com.vci.omd.constants.LinkConstants;
|
|
public class AttributeChecker {
|
|
public static HashMap<String, AttribItem> attrItemMap = new HashMap<String, AttribItem>();
|
public static AttribItem[] attrItems = null;
|
|
public void getAllAttribute() {
|
if (attrItems == null) {
|
attrItems = ApProvider.getInstance().getAllAbItems();
|
for (AttribItem attrItem : attrItems) {
|
attrItemMap.put(attrItem.name, attrItem);
|
}
|
}
|
}
|
|
/**
|
* 判断传入的属性值是否符合值域要求
|
* @param attrName
|
* @param attrVal
|
* @return 0:代表符合;1代表长度不符合要求;2代表值不符合要求;3代表值和长度均不符合要求
|
*/
|
public int isAttrValValid(String attrName, String attrVal) {
|
if (BusinessConstants.BO_CONSTANTS.containsKey(attrName.toUpperCase())
|
|| LinkConstants.LO_CONSTANTS.containsKey(attrName.toUpperCase())) {
|
return 0;
|
} else if (attrVal == null || attrVal.trim().equals("")) {
|
return 0;
|
}
|
getAllAttribute();
|
|
int rs = 0;
|
AttribItem attrItem = attrItemMap.get(attrName);
|
if (attrItem == null) {
|
return 0;
|
}
|
String attrType = attrItem.vtDataType;
|
if (attrType.equals("VTString")){
|
rs = checkVTStringValValid(attrItem, attrName, attrVal);
|
} else if (attrType.equals("VTInteger")){
|
rs = checkVTIntegerValValid(attrItem, attrName, attrVal);
|
} else if (attrType.equals("VTLong")){
|
rs = checkVTLongValValid(attrItem, attrName, attrVal);
|
} else if (attrType.equals("VTDouble")){
|
rs = checkVTDoubleValValid(attrItem, attrName, attrVal);
|
} else if (attrType.equals("VTBoolean")){
|
rs = 0;
|
} else if (attrType.equals("VTImage")){
|
rs = 0;
|
} else if (attrType.equals("VTDate")){
|
rs = 0;
|
} else if (attrType.equals("VTTime")){
|
rs = 0;
|
} else if (attrType.equals("VTDateTime")) {
|
rs = 0;
|
} else if (attrType.equals("VTNote")){
|
rs = 0;
|
} else if (attrType.equals("VTFilePath")) {
|
rs = 0;
|
} else {
|
rs = 0;
|
}
|
|
return rs;
|
}
|
|
/**
|
* 判断VTString类型的属性值是否符合校验要求
|
* @param attrName
|
* @param attrVal
|
* @return
|
*/
|
private int checkVTStringValValid(AttribItem attrItem, String attrName, String attrVal) {
|
String other = attrItem.other;
|
int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length")).intValue();
|
int length = attrVal.length();
|
if (length > maxLength) {
|
return 1;
|
} else {
|
return 0;
|
}
|
}
|
|
/**
|
* 判断VTInteger类型的属性值是否符合校验要求
|
* @param attrName
|
* @param attrVal
|
* @return
|
*/
|
private int checkVTIntegerValValid(AttribItem attrItem, String attrName, String attrVal) {
|
VTInteger obj = new VTInteger(Integer.valueOf(attrVal).intValue());
|
if (!obj.checkRageValueByRage(attrItem.rage)) {
|
return 2;
|
} else {
|
return 0;
|
}
|
}
|
|
/**
|
* 判断VTLong类型的属性值是否符合校验要求
|
* @param attrName
|
* @param attrVal
|
* @return
|
*/
|
private int checkVTLongValValid(AttribItem attrItem, String attrName, String attrVal) {
|
VTLong obj = new VTLong(Long.valueOf(attrVal).longValue());
|
if (!obj.checkRageValueByRage(attrItem.rage)) {
|
return 2;
|
} else {
|
return 0;
|
}
|
}
|
|
/**
|
* 判断VTDouble类型的属性值是否符合校验要求
|
* @param attrName
|
* @param attrVal
|
* @return
|
*/
|
private int checkVTDoubleValValid(AttribItem attrItem, String attrName, String attrVal) {
|
VTDouble obj = new VTDouble(Double.valueOf(attrVal));
|
String other = attrItem.other;
|
int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length")).intValue();
|
int length = String.valueOf(attrVal).length() - 1;
|
|
if (length >= maxLength && !obj.checkRageValueByRage(attrItem.rage)) {
|
return 3;
|
} else if (!obj.checkRageValueByRage(attrItem.rage)) {
|
return 2;
|
} else if (length >= maxLength) {
|
return 1;
|
} else {
|
return 0;
|
}
|
}
|
}
|