TL 重构
import dependencies.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern; public class VerifierImpl implements Verifier {
MessageDispatcher messageDispatcher = null;
Request request = null;
final static SimpleCalculator calc = new SimpleCalculator();
Convert convert = null;
private static Logger logger = Logger.getLogger(VerifierImpl.class);
Document document = null;
XMLType type = null;
boolean ommFlag = false;
private static boolean simpleMOFlag = false; @Override
public boolean verify(Document document, Request request, boolean ommFlag, HashMap<String, String> subnetAndMeIDMap,
HashMap<String, String> eNodeBIdTddMap, HashMap<String, String> eNodeBIdFddMap) {
boolean flag = true;
try {
init(document, request, ommFlag);
AttributeList attributeList = request.getAttributeList();
Map<String, FieldInfoObject> mocInfoMap = SystemConfigLoader.getInstance().getMocinfoObj().getMocinfo(); //判断XML模板的类型
if (isNotIlegalDocument(document, request)) return false;
//{{{判断userlabel是否符合规则length<=128, not include / \ : * ? " < > | ;
flag = checkUserLabel(request.getUserLabel());
String eNodeBTdd = null, eNodeBFdd = null;
//List all items to verify them, according to excel column order.
for (String excelHeader : SystemConfigLoader.getInstance().getExcelheaders()) {
String excelValue = attributeList.get(excelHeader);
String xpath = convert.getMocinfoXpath(excelHeader);
String excelName = processExcelName(excelHeader);
String radioMode = processRadioMode(excelHeader);
//1.检查Excel值是否为空
if (StringUtils.isBlank(excelValue)) {
//当XML的类型为OMMB时,判断子网id和网元id是否为空,若为空,报错并继续检查
flag = preCheckExcelName(excelHeader, excelValue, excelName);
continue;
}
//2.检查文件头是否被修改过
if (isExcelChanged(excelHeader, xpath)) return false;
//3.校验数据格式是否满足数组格式要求
//3.1当preCheck未通过时,忽略下面的检查
if (!preCheckExcelName(excelHeader, excelValue, excelName, radioMode)) {
flag = false;
continue;
}
String field = convertExcelName(excelHeader);
//3.3检查同一基站下小区ID是否重复
flag = isExistCellId(document, request, flag, excelHeader, excelValue, field);
if (field.contains("eNodeB ID")) {
if (StringUtils.contains(xpath, "ENBFunctionFDD")) {
eNodeBFdd = excelValue;
} else if (StringUtils.contains(xpath, "ENBFunctionTDD")) {
eNodeBTdd = excelValue;
}
} //5.检查枚举值类型数据是否符合规则
FieldInfoObject fieldInfoObj = mocInfoMap.get(xpath);
flag = chekCombo(flag, excelHeader, excelValue, fieldInfoObj);
//6.检查IP类型的数据是否符合规则
if (StringUtils.equals(fieldInfoObj.getWsfComponent(), "IP")) {
flag = checkIP(excelHeader, excelValue) && flag;
}
//7.检查引用的数据是否符合规则
else if (fieldInfoObj.isRef()) {
flag = checkRef(flag, attributeList, excelHeader, excelValue, xpath);
}
//8.检查atmAddr这个字段的每个元素是否在range之间
else if (isAtmAddr(xpath)) {
flag = checkAtmAddr(flag, excelHeader, excelValue, fieldInfoObj);
}
//9.如果是VLAN Parameters,检查VLAN标识是否重复
else if (isEthernetLinkVlanId(excelHeader)) {
flag = checkVLANPara(excelHeader, excelValue) && flag;
}
//10.列:VLAN Parameters VLAN参数。以太网链路所包含的VLAN标识列表不能重复
else if (IsVlanIdForIp(excelHeader)) {
flag = checkVLANID(request, excelHeader, excelValue) && flag;
}
//MP priority有多个取值范围,配置文件里填了最大的范围,其他需要代码特殊处理判断
else if (isMpPriority(excelHeader)) {
flag = checkMPpriority(excelValue) && flag;
}
//11.检查数字类型的字段是否符合其定义的规则
else if (isIlegalField(field)) {
flag = checkNumber(type, fieldInfoObj, attributeList, excelHeader) && flag;
} else {
continue;
}
}
//flag = checkSubnetAndMeID(subnetAndMeIDMap, subnetID, meID) && flag;
if (eNodeBTdd != null) {
flag = checkeNodeBIDTDD(eNodeBIdTddMap, eNodeBTdd) && flag;
}
if (eNodeBFdd != null) {
flag = checkeNodeBIDFDD(eNodeBIdFddMap, eNodeBFdd) && flag;
}
XMLUtility.addNullPara(document);
} catch (Exception e) {
logger.error("Verify Error!", e);
}
return flag;
} private boolean isNotIlegalDocument(Document document, Request request) {
if (isUnknownXMLType(document, request)) {
return true;
}
if (!XMLUtility.isContainedHeader(document)) {
processLmtHeadIllegalMessage(request);
return true;
}
return false;
} private boolean isIlegalField(String field) {
return !field.equals("eNodeB UserLabel") && !field.equals("Cell UserLabel") && !field.equals("eNodeB Name")
&& !field.equals("User Defined NE ID") && !field.equals("Cell Alias");
} private boolean isMpPriority(String excelHeader) {
return excelHeader.contains("MP priority");
} private boolean IsVlanIdForIp(String excelHeader) {
return excelHeader.contains("VLAN ID For IP");
} private boolean isEthernetLinkVlanId(String excelHeader) {
return excelHeader.contains("EthernetLink VLAN ID MerberShip");
} private boolean isAtmAddr(String xpath) {
return StringUtils.contains(xpath, "atmAddr");
} private boolean checkAtmAddr(boolean flag, String excelHeader, String excelValue, FieldInfoObject fieldInfoObj) {
String[] atmAddr = this.split(excelValue);
for (String str : atmAddr) {
int errorCode = ValidateUtility.fieldDataByRule(str, fieldInfoObj.getWsfRange(), fieldInfoObj.getType());
if (errorCode != ValidateUtility.VALUE_OK) {
numberErrorMessage(errorCode, excelHeader, excelValue, fieldInfoObj.getWsfRange(), fieldInfoObj.getType(), fieldInfoObj.getWsfStepSize());
flag = false;
break;
}
}
return flag;
} private boolean checkRef(boolean flag, AttributeList attributeList, String excelHeader, String excelValue, String xpath) {
if (StringUtils.contains(xpath, "refPlmn")) {
flag = this.checkPLMN(excelHeader, excelValue) && flag;
} else if (StringUtils.contains(xpath, "vid")) {
//检查VID参数相关约束
flag = checkVid(excelHeader, excelValue, xpath, attributeList) && flag;
} else if (excelHeader.contains("Used HDLC channel")) {
//检查HDLC参数相关约束
flag = checkHdlc(excelHeader, attributeList) && flag;
}
return flag;
} private boolean chekCombo(boolean flag, String excelHeader, String excelValue, FieldInfoObject fieldInfoObj) {
if (StringUtils.equals(fieldInfoObj.getWsfComponent(), "ComboBox") && !fieldInfoObj.isRef()) {
return checkCombo(fieldInfoObj, excelHeader, excelValue) && flag;
}
return flag;
} private String convertExcelName(String excelHeader) {
return StringUtils.substringBetween(excelHeader, "@excelName='", "']");
} private boolean isExistCellId(Document document, Request request, boolean flag, String excelHeader, String value, String field) {
if (field.contains("Cell Identity") || field.contains("Local Cell Identity")) {
flag = checkCellID(value) && flag;
}
if (!field.equals("eNodeB UserLabel") && !field.equals("Cell UserLabel") && !field.equals("eNodeB Name") && !field.equals("Cell Alias")) {
//4.1)校验记录条数是否一致
// 2)检查属性为可以修改的字段值是否与XML中一致
// 3)Userlabel不是必填字段,excel中可以为空,因此不做记录数检验。
flag = checkRecordsNumber(type, request.getQuoteTemplateName(), document, excelHeader, value) && flag;
}
return flag;
} private String processRadioMode(String excelHeader) {
if (excelHeader.contains("TDD")) {
return "TDD-LTE ";
} else if (excelHeader.contains("FDD")) {
return "FDD-LTE ";
} else {
return "";
}
} private boolean preCheckExcelName(String excelHeader, String value, String excelName) {
if (excelName.contains("Subnetwork ID")) {
processSubNetworkIllegalMessage(excelHeader, value);
return false;
} if (excelName.equals("ME ID")) {
processMeIllegalMessage(excelHeader, value);
return false;
}
return true;
} private boolean preCheckExcelName(String excelHeader, String value, String excelName, String radioMode) {
//当数据为cell userlabel时,按照userlabel的范围检测
if (excelName.contains("eNodeB UserLabel") || excelName.contains("Cell UserLabel") || excelName.contains("Cell Alias")) {
return this.checkUserLabel(value, radioMode + excelName);
} else if (excelName.contains("eNodeB Name")) {
return this.checkeNbName(value);
} else {
return preCheckExcelName(excelHeader, value);
}
} private boolean isExcelChanged(String excelHeader, String xpath) {
if (StringUtils.isEmpty(xpath)) {
//node[@radioMode='UMTS']/property[@excelName='Local Cell Identity']
//截取出字段
String field = StringUtils.substringBetween(excelHeader, "@excelName='", "']");
processExcelChangedMessage(field);
return true;
}
return false;
} private boolean isUnknownXMLType(Document document, Request request) {
//当模板类型未知时,发送消息
if (type == XMLType.UNKNOWN) {
processXMLTypeUnknownMessage(request);
return true;
}
return false;
} private void processExcelChangedMessage(String field) {
String details = I18N.getFormatString(I18NC.VERIFY_EXCEL_CHANGED, field);
String suggestion = I18N.getString(I18NC.VERIFY_EXCEL_CHANGED_SUG);
sendMessage(details, suggestion);
} private void processMeIllegalMessage(String excelHeader, String value) {
String details = I18N.getFormatString(I18NC.VERIFY_ME_NULL_ILLEGAL, processExcelName(excelHeader), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_ME_NULL_SUG, processExcelName(excelHeader));
sendMessage(details, suggestion);
} private void processSubNetworkIllegalMessage(String excelHeader, String value) {
String details = I18N.getFormatString(I18NC.VERIFY_SUBNETWORKID_NULL_ILLEGAL, processExcelName(excelHeader), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_SUBNETWORKID_NULL_SUG, processExcelName(excelHeader));
sendMessage(details, suggestion);
} private void processLmtHeadIllegalMessage(Request request) {
String details = I18N.getFormatString(I18NC.VERIFY_LMTHEAD_ILLEGAL, request.getQuoteTemplateName());
String suggestion = I18N.getString(I18NC.VERIFY_LMTHEAD_ILLEGAL_SUG);
sendMessage(details, suggestion);
} private void processXMLTypeUnknownMessage(Request request) {
String details = I18N.getFormatString(I18NC.VERIFY_XMLTYPE_UNKNOWN, request.getQuoteTemplateName());
String suggestion = I18N.getString(I18NC.VERIFY_XMLTYPE_UNKNOWN_SUG);
sendMessage(details, suggestion);
} private void delNullParas(Document document) {
if (type == XMLType.OMMB) {
XMLUtility.delNullParas(document);
}
} private void init(Document document, Request request, boolean ommFlag) {
initField(document, request, ommFlag);
SimpleMo.initMoName(simpleMOFlag);
delNullParas(document);
} private void initField(Document document, Request request, boolean ommFlag) {
this.request = request;
this.document = document;
if (XMLUtility.isXMLSimpleType(document)) {
simpleMOFlag = true;
} else {
simpleMOFlag = false;
}
this.ommFlag = ommFlag;
messageDispatcher = SystemConfigLoader.getInstance().getMsgDispatcher();
convert = SystemConfigLoader.getInstance().getConvert();
type = XMLUtility.detectXMLType(document);
} private boolean checkRecordsNumber(XMLType type, String xmlTemplate, Document document, String key, String value) {
int elemCount = 0;
//Excel中的数据
String[] values = StringUtils.split(value, ";");
//{{{增加缓存机制,加快记录条数校验的效率
Cache cache = Cache.getInstance();
Integer recordNumber = (Integer) cache.get(xmlTemplate, key);
String valueNumbers = (String) cache.get(xmlTemplate, key + "Count");
if (recordNumber != null) {
elemCount = recordNumber;
} else {
String xpath = convert.getFastConfigXpath(key, type);
if (simpleMOFlag) {
xpath = SimpleMo.convertXpath(xpath);
}
List<?> elemList = document.selectNodes(xpath);
elemCount = elemList.size();
cache.put(xmlTemplate, key, elemCount);
List<?> valueNodeList = document.selectNodes(xpath + "/" + SimpleMo.getValue());
if (valueNodeList.size() != 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < elemCount; i++) {
Element elemTmp = (Element) elemList.get(i);
List<?> children = elemTmp.elements(SimpleMo.getValue());
int branchCount = children.size();
sb.append(i == elemCount - 1 ? branchCount : branchCount + ";");
}
valueNumbers = sb.toString();
cache.put(xmlTemplate, key + "Count", sb.toString());
}
//判断元素的数量,当其有孩子节点/value的时候,数量设置为孩子节点的数量
//elemCount = valueNodeList.size() == 0 ? elemList.size() : valueNodeList.size();
//cache.put(xmlTemplate, key, elemCount);
//如果不可以修改,则搜寻xml中的值
if (!convert.isEditable(key)) {
String tmpValues = "";
//将XML中的数据读取出来,以a;a;a的方式存储
if (elemList.size() != 0) {
for (int i = 0; i < elemList.size(); i++) {
Element tmp = (Element) elemList.get(i);
tmpValues = tmpValues + tmp.attributeValue(SimpleMo.getValue()) + ";";
}
} else {
for (int i = 0; i < valueNodeList.size(); i++) {
Element tmp = (Element) valueNodeList.get(i);
tmpValues = tmpValues + tmp.getText() + ";";
}
}
//将此值保存到缓存中
cache.put(xmlTemplate, key + "Values", StringUtils.substring(tmpValues, 0, -1));
}
}
//}}}
//判断excel中的记录数与xml文件的中是否一致
if (elemCount != values.length) {
String details = I18N.getFormatString(I18NC.VERIFY_NUMBER_INCONSIST, values.length, processExcelName(key), value, elemCount);
String suggestion = I18N.getString(I18NC.VERIFY_NUMBER_INCONSIST_SUG);
sendMessage(details, suggestion);
return false;
}
//判断excel中一条记录的子记录是否一致
if (valueNumbers != null) {
String[] countArray = StringUtils.split(valueNumbers, ";");
String[] valueCount = new String[values.length];
for (int i = 0; i < values.length; i++) {
valueCount[i] = StringUtils.split(values[i], ",").length + "";
}
for (int i = 0; i < elemCount; i++) {
if (!StringUtils.equals(countArray[i], valueCount[i])) {
String details = I18N.getFormatString(I18NC.VERIFY_NUMBER_INCONSIST, valueCount[i], processExcelName(key), values[i],
countArray[i]);
String suggestion = I18N.getString(I18NC.VERIFY_NUMBER_INCONSIST_SUG);
sendMessage(details, suggestion);
return false;
}
}
}
//当字段不许修改时
if (!convert.isEditable(key)) {
String xmlValues = (String) cache.get(xmlTemplate, key + "Values");
if (!StringUtils.equals(xmlValues, value)) {
String details = I18N.getFormatString(I18NC.VERIFY_NOTWRITABLE, processExcelName(key), xmlValues, value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_NOTWRITABLE_SUG, xmlValues);
sendMessage(details, suggestion);
return false;
}
}
return true;
} /**
* 预先检查每一个字段的值,是否正常的数组类型,确保Excel中的数据均为可以";"
* 分解,而并不会出现空值
*
* @param value
*/
private boolean preCheckExcelName(String key, String value) {
if (StringUtils.isBlank(value)) {
return true;
}
//match 1;2;3 or 1,2;1,3,4
//not match ;1;2;3 or ,1,2
String regex = "[-?\\w\\.]+((;|,)[-?\\w\\.]+)*";
Pattern p = Pattern.compile(regex);
if (!p.matcher(value).matches()) {
String details = I18N.getFormatString(I18NC.VERIFY_FORMAT_ILLEGAL, processExcelName(key), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_FORMAT_ILLEGAL_SUG, processExcelName(key));
sendMessage(details, suggestion);
return false;
}
return true;
} /**
* 检查字段是否在枚举值取值范围之中
*
* @param obj
* @param key
* @param value
* @return
*/
private boolean checkCombo(FieldInfoObject obj, String key, String value) {
String[] excelValues = StringUtils.split(value, ";");
if (StringUtils.contains(obj.getValueMap(), ":")) {
String[] keyValues = StringUtils.split(obj.getValueMap(), ",");
StringBuilder sb = new StringBuilder(50);
for (int i = 0; i < excelValues.length; i++) {
boolean flag = false;
for (int j = 0; j < keyValues.length; j++) {
//here we should make sure that equals not contains
if (StringUtils.substringAfter(keyValues[j], ":").equals(excelValues[i])) {
sb.append(StringUtils.substringBefore(keyValues[j], ":") + ";");
flag = true;
break;
}
}
if (flag == false) {
String details = I18N.getFormatString(I18NC.VERIFY_COMBO_ILLEGAL, processExcelName(key), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_COMBO_ILLEGAL_SUG, processExcelName(key));
sendMessage(details, suggestion);
return false;
}
request.getAttributeList().put(key, sb.substring(0, sb.length() - 1));
}
} else {
for (int i = 0; i < excelValues.length; i++) {
int errorCode = ValidateUtility.fieldDataByRule(excelValues[i], obj.getWsfRange(), obj.getType());
if (errorCode != ValidateUtility.VALUE_OK) {
numberErrorMessage(errorCode, key, value, obj.getWsfRange(), obj.getType(), obj.getWsfStepSize());
return false;
}
}
}
return true;
} private boolean checkIP(String key, String value) {
String[] values = StringUtils.split(value, ";");
for (String ips : values) {
String[] ipArr = StringUtils.split(ips, ",");
for (String ip : ipArr) {
if (!ValidateUtility.isValidIP(ip)) {
String details = I18N.getFormatString(I18NC.VERIFY_IP_ILLEGAL, processExcelName(key), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_IP_ILLEGAL_SUG, processExcelName(key));
sendMessage(details, suggestion);
return false;
}
// 增加约束
// IP Address \ OMC Server IP Address \SCTP远端地址 地址不能为0.0.0.0
// node[@radioMode='UMTS']/property[@excelName='Local Cell Identity']
String field = processExcelName(key);
if (field.equals("IP Address") || field.equals("OMC Server IP Address") || field.equals("Remote IP Address")) {
if (ip.equals("0.0.0.0")) {
String details = I18N.getFormatString(I18NC.VERIFY_IP_ILLEGAL_ALL_ZERO, field, value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_IP_ILLEGAL_ALL_ZERO_SUG, field);
sendMessage(details, suggestion);
return false;
}
}
}
}
return true;
} /**
* 数值范围校验,OMMB界面值,LMT 内存值
*
* @param obj
* @param attributeList
* @param key
* @return
*/
private boolean checkNumber(XMLType type, FieldInfoObject obj, AttributeList attributeList, String key) {
String numberRegex = "(-?)(\\d+\\.*\\d*)(,\\d+\\.*\\d*)*(;(-?)(\\d+\\.*\\d*)(,\\d+\\.*\\d*)*)*";
String value = attributeList.get(key);
String[] excelValues = StringUtils.split(value, ";");
if (!value.matches(numberRegex)) {
String details = I18N.getFormatString(I18NC.VERIFY_NUMBER_FORMAT_ERR, processExcelName(key), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_NUMBER_FORMAT_ERR_SUG, processExcelName(key));
sendMessage(details, suggestion);
return false;
}
//{{拆分1,2;3,4合并成为{1,2,3,4}
String temp[] = null;
for (String tmp : excelValues) {
temp = ArrayUtils.addAll(temp, StringUtils.split(tmp, ","));
}
excelValues = temp;
//1.wsfformat为空时,无转换关系
if (StringUtils.isEmpty(obj.getWsfFormat())) {
for (String singleValue : excelValues) {
int errorCode = ValidateUtility.fieldDataByRule(singleValue, obj.getWsfRange(), obj.getType());
if (errorCode != ValidateUtility.VALUE_OK) {
numberErrorMessage(errorCode, key, value, obj.getWsfRange(), obj.getType(), obj.getWsfStepSize());
return false;
}
if (Integer.parseInt(singleValue) % Integer.parseInt(obj.getWsfStepSize()) != 0) {
numberErrorMessage(ValidateUtility.VALUE_STEP_INVALID, key, value, obj.getWsfRange(), obj.getType(), obj.getWsfStepSize());
return false;
}
}
}
//2.当wsfformat以"{"开头时,表明本此段存在对应转换关系
else if (StringUtils.contains(obj.getWsfFormat(), "{")) {
List<String[]> wsfRangeList = obj.getWsfRangeList();
Map<String, String> rangeMap = new HashMap<String, String>();
for (String wsfRange[] : wsfRangeList) {
rangeMap.put(wsfRange[1], wsfRange[2]);
}
List<String[]> xyConvertList = obj.getXyConvert();
Map<String, String> convertMap = new HashMap<String, String>();
for (String[] xyConvert : xyConvertList) {
convertMap.put(xyConvert[1], xyConvert[2]);
}
//获取其需要引用的字段
String refField = wsfRangeList.get(0)[0];
String refFieldKey = convert.getRefFieldKey(obj.getMocName(), refField);
String refFieldValue = attributeList.get(refFieldKey);
String[] refFieldValueArray = StringUtils.split(refFieldValue, ";");
if (excelValues.length != refFieldValueArray.length) {
String details = I18N.getFormatString(I18NC.VERIFY_REF_COUNT_ILLEGAL, processExcelName(key), value, processExcelName(refFieldKey));
String suggestion = I18N.getFormatString(I18NC.VERIFY_REF_COUNT_ILLEGAL_SUG, processExcelName(key));
sendMessage(details, suggestion);
return false;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < excelValues.length; i++) {
//获取对应的取值范围
String range = rangeMap.get(refFieldValueArray[i]);
//如果发现range为空,则表明再校验range的时候出现错误
//则不进行对应频点的校验
if (StringUtils.isEmpty(range)) {
continue;
}
int errorCode = ValidateUtility.checkStepSize(excelValues[i], obj.getWsfStepSize(), range, obj.getType()); if (errorCode == ValidateUtility.VALUE_OK) {
sb.append(calc.getXYConvert(convertMap.get(refFieldValueArray[i]), excelValues[i]) + ";");
} else {
numberErrorMessage(errorCode, key, value, obj.getWsfRange(), obj.getType(), obj.getWsfStepSize());
return false;
}
}
//LMT需要进行内存值与显示值转换
if (sb.length() != 0 && type == XMLType.LMT) {
request.getAttributeList().put(key, sb.substring(0, sb.length() - 1));
}
}
//3.其余情况只有一种转换关系
else {
StringBuilder sb = new StringBuilder();
for (String singleValue : excelValues) {
int errorCode = ValidateUtility.checkStepSize(singleValue, obj.getWsfStepSize(), obj.getWsfRange(), obj.getType());
if (errorCode == ValidateUtility.VALUE_OK) {
sb.append(calc.getXYConvert(obj.getXyConvert().get(0)[2], singleValue) + ";");
} else {
numberErrorMessage(errorCode, key, value, obj.getWsfRange(), obj.getType(), obj.getWsfStepSize());
return false;
}
}
if (sb.length() != 0 && type == XMLType.LMT) {
request.getAttributeList().put(key, sb.substring(0, sb.length() - 1));
}
}
return true;
} /**
* 检查引用的PLMN是否合法,如果合法则替换PLMN为OperatorID
*
* @param key
* @param value
* @return
*/
private boolean checkPLMN(String key, String value) {
//Match: 460-01,460-01;460-01
//Not Match: 460-1
String refPlmnRegex = "\\d{3}-(\\d{2}|\\d{3})((,|;)\\d{3}-(\\d{2}|\\d{3}))*";
if (!value.matches(refPlmnRegex)) {
String details = I18N.getFormatString(I18NC.VERIFY_PLMN_ILLEGAL, processExcelName(key), value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_PLMN_ILLEGAL_SUG, processExcelName(key));
sendMessage(details, suggestion);
return false;
}
//{{获取XML模板文件中的OperatorId数组
String[] opeartorIds = (String[]) Cache.getInstance().get(request.getQuoteTemplateName(), "opeartorId");
String[] opeartorArr = (String[]) Cache.getInstance().get(request.getQuoteTemplateName(), "opeartorId");
if (opeartorIds == null || opeartorIds.length == 0) {
//String operatorXPATH = "//Mo[@name='Operator']/Property[@name='%s']";
String operatorXPATH = "//Mo[@name='Plmn']/Property[@name='parentLDN']";
if (simpleMOFlag) {
operatorXPATH = SimpleMo.convertXpath(operatorXPATH);
}
List<?> list = document.selectNodes(operatorXPATH);
opeartorIds = new String[list.size()];
opeartorArr = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
Element tmp = (Element) list.get(i);
opeartorIds[i] = tmp.attributeValue(SimpleMo.getValue());
opeartorArr[i] = ((opeartorIds[i]).toString().split(",")[1]).split("=")[1];
}
Cache.getInstance().put(request.getQuoteTemplateName(), "opeartorId", opeartorArr);
}
//}}
//{{将PLMN Parameters PLMN参数中的MCC与MNC拼接为460-01;460-02样式的数组
String valuesMCC = request.getAttributeList().get("//node[@radioMode='PLAT']/property[@excelName='Mobile Country Code']");
String valuesMNC = request.getAttributeList().get("//node[@radioMode='PLAT']/property[@excelName='Mobile Network Code']");
String[] mccArray = StringUtils.split(valuesMCC, ";");
String[] mncArray = StringUtils.split(valuesMNC, ";");
int len = mccArray.length;
String[] mccAndmnc = new String[len];
for (int i = 0; i < len; i++) {
mccAndmnc[i] = mccArray[i] + "-" + mncArray[i];
}
//}}
//{{将匹配到的MCC-MNC替换为OperatorID
String convertValue = StringUtils.replaceEach(value, mccAndmnc, opeartorArr);
//}}
//{{判断替换后的convertValue是否正确
if (StringUtils.isEmpty(convertValue) || StringUtils.contains(convertValue, "-")) {
String details = I18N.getFormatString(I18NC.VERIFY_REF_ILLEGAL, processExcelName(key), value, "PLMN",
ArrayUtils.toString(mccAndmnc, ""));
String suggestion = I18N.getFormatString(I18NC.VERIFY_REF_ILLEGAL_SUG, processExcelName(key)); sendMessage(details, suggestion);
return false;
}
//}}
request.getAttributeList().put(key, convertValue);
return true;
} /**
* 判断一个ref字段的值是否在其应用的字段的值列表中存在
*
* @param value
* @param refValue
* @return
*/
private boolean checkRefField(String key, String value, String refFieldkey, String refValue) {
String[] valueArray = this.split(value);
String[] refValueArray = this.split(refValue);
for (String singleValue : valueArray) {
if (!ArrayUtils.contains(refValueArray, singleValue)) {
String details = I18N.getFormatString(I18NC.VERIFY_REF_ILLEGAL, processExcelName(key), value, processExcelName(refFieldkey), refValue);
String suggestion = I18N.getFormatString(I18NC.VERIFY_REF_ILLEGAL_SUG, processExcelName(key)); sendMessage(details, suggestion);
return false;
}
}
return true;
} private String processExcelName(String key) {
return StringUtils.substringBetween(key, "excelName='", "']");
} private void sendMessage(String details, String suggestion) {
Message msg = MessageUtility.createMessage(Constants.ERROR, request, details, suggestion);
messageDispatcher.sendMessage(msg);
} private void numberErrorMessage(int errorCode, String key, String value, String range, String type, String step) {
String details = "";
String suggestion = "";
switch (errorCode) {
case ValidateUtility.VALUE_OUT_RANGE:
details = I18N.getFormatString(I18NC.VERIFY_OUTRANGE, processExcelName(key), value, range);
suggestion = I18N.getString(I18NC.VERIFY_OUTRANGE_SUG);
break;
case ValidateUtility.VALUE_STEP_INVALID:
details = I18N.getFormatString(I18NC.VERIFY_STEP_ERR, processExcelName(key), value, step);
suggestion = I18N.getString(I18NC.VERIFY_STEP_ERR_SUG);
break;
case ValidateUtility.VALUE_TYPE_ERROR:
details = I18N.getFormatString(I18NC.VERIFY_TYPE_ERR, processExcelName(key), value, type);
suggestion = I18N.getString(I18NC.VERIFY_TYPE_ERR_SUG);
break;
}
Message msg = MessageUtility.createMessage(Constants.ERROR, request, details, suggestion);
messageDispatcher.sendMessage(msg);
} /**
* 用';'与','分割字符串为一个数组
*/
private String[] split(String str) {
String[] array = StringUtils.split(str, ";");
String[] finalArray = null;
for (String element : array) {
finalArray = ArrayUtils.addAll(finalArray, StringUtils.split(element, ','));
}
return finalArray;
} /**
* 检查UserLabel是否不包含特殊字符,以及长度不超过128
*
* @param userLabel
* @return
*/
private boolean checkUserLabel(String userLabel, String moName) {
boolean flag = true;
boolean lengthGT128 = StringUtils.length(userLabel) > 128;
if (lengthGT128) {
String details = moName + ": " + I18N.getString(I18NC.VERIFY_USERLABE_GT128);
String suggestion = I18N.getString(I18NC.VERIFY_USERLABE_GT128_SUG);
sendMessage(details, suggestion);
flag = false;
}
char[] illegalChars = "~&'\"<>".toCharArray();
for (int i = 0; i < illegalChars.length; i++) {
if (StringUtils.contains(userLabel, illegalChars[i])) {
String details = moName + ": " + I18N.getString(I18NC.VERIFY_USERLABE_ILLEGAL);
String suggestion = I18N.getString(I18NC.VERIFY_USERLABE_ILLEGAL_SUG);
sendMessage(details, suggestion);
flag = false;
break;
}
}
return flag;
} private boolean checkUserLabel(String userLabel) {
if (StringUtils.isBlank(userLabel)) {
String details = I18N.getString(I18NC.VERIFY_USERLABE_NULL);
String suggestion = I18N.getString(I18NC.VERIFY_USERLABE_NULL_SUG);
sendMessage(details, suggestion);
return false;
} if (StringUtils.length(userLabel) > 128) {
String details = I18N.getString(I18NC.VERIFY_USERLABE_GT128);
String suggestion = I18N.getString(I18NC.VERIFY_USERLABE_GT128_SUG);
sendMessage(details, suggestion);
return false;
}
//char []illegalChars = "`~!?@#$%^*|\\/&'\"<>.;".toCharArray();
char[] illegalChars = "~&'\"<>".toCharArray();
for (int i = 0; i < illegalChars.length; i++) {
if (StringUtils.contains(userLabel, illegalChars[i])) {
String details = I18N.getString(I18NC.VERIFY_USERLABE_ILLEGAL);
String suggestion = I18N.getString(I18NC.VERIFY_USERLABE_ILLEGAL_SUG);
sendMessage(details, suggestion);
return false;
}
} return true;
} private boolean checkeNbName(String eNbName) {
boolean flag = true;
boolean lengthGT150 = StringUtils.length(eNbName) > 150;
if (lengthGT150) {
String details = I18N.getString(I18NC.VERIFY_ENBNAME_GT150);
String suggestion = I18N.getString(I18NC.VERIFY_ENBNAME_GT150_SUG);
sendMessage(details, suggestion);
flag = false;
}
char[] illegalChars = "&!\"#$%*<>@[\\]^_`;{|}~".toCharArray();
for (int i = 0; i < illegalChars.length; i++) {
if (StringUtils.contains(eNbName, illegalChars[i])) {
String details = I18N.getString(I18NC.VERIFY_ENBNAME_ILLEGAL);
String suggestion = I18N.getString(I18NC.VERIFY_ENBNAME_ILLEGAL_SUG);
sendMessage(details, suggestion);
flag = false;
break;
}
}
return flag;
} private boolean checkVLANPara(String key, String value) {
String[] vLanIdList = value.split(";");
for (int i = 0; i < vLanIdList.length; i++) {
String[] vLanIdSubList = vLanIdList[i].split(",");
ArrayList array = new ArrayList();
for (int j = 0; j < vLanIdSubList.length; j++) {
String id = vLanIdSubList[j];
if (array.contains(id)) {
String field = StringUtils.substringBetween(key, "@excelName='", "']");
//包含相同的VLAN标识
String details = I18N.getFormatString(I18NC.VERIFY_VLANID_DUPLICATE, field, value);
String suggestion = I18N.getFormatString(I18NC.VERIFY_VLANID_DUPLICATE_SUG, field);
sendMessage(details, suggestion);
return false;
} else {
array.add(id);
}
}
}
return true;
} private boolean checkVLANID(Request request, String key, String value) {
String vLanIdList = request.getAttributeList().get(
"//node[@radioMode='PLAT']/property[@excelName='EthernetLink VLAN ID MerberShip']");
String[] vLanIdSubList = vLanIdList.split(";");
ArrayList idList = new ArrayList();
for (int i = 0; i < vLanIdSubList.length; i++) {
String[] vLanId = vLanIdSubList[i].split(",");
for (int j = 0; j < vLanId.length; j++) {
String id = vLanId[j];
if (idList.contains(id)) {
continue;
} else {
idList.add(id);
}
}
}
if (idList.contains(value)) {
return true;
} else {
String field = StringUtils.substringBetween(key, "@excelName='", "']");
//VLANID取值需要包含在VLANPara中
String details = I18N.getFormatString(I18NC.VERIFY_VLANID_DUPLICATE, field);
String suggestion = I18N.getFormatString(I18NC.VERIFY_VLANID_DUPLICATE_SUG, field);
sendMessage(details, suggestion);
return false;
}
} /**
* 描述:检验子网和网元的组合是否重复,如果重复,报错.<br>
*
* @param IDMap hashmap用来存储子网和网元的组合
* @param SubnetID 子网id
* @param MeID 网元id
*/
private boolean checkSubnetAndMeID(HashMap<String, String> IDMap, String SubnetID, String MeID) {
boolean flag = true;
String ID = SubnetID + "," + MeID;
if (IDMap != null && IDMap.containsKey(ID)) {
flag = false;
String details = I18N.getFormatString(I18NC.VERIFY_SUBNETMEID_ILLEGAL);
String suggestion = I18N.getFormatString(I18NC.VERIFY_SUBNETMEID_ILLEGAL_SUG);
sendMessage(details, suggestion);
return flag;
} else {
IDMap.put(ID, ID);
} return flag;
} /**
* 描述:检验同一基站下小区ID是否重复.<br>
*
* @param cellID 小区ID字符串,包含多个小区ID,用分号隔开
*/
private boolean checkCellID(String cellID) {
boolean flag = true; String[] cellArr = cellID.split(";");
Map<String, String> ID = new HashMap<String, String>(); for (int i = 0; i < cellArr.length; i++) {
String cellVal = cellArr[i];
if (ID != null && ID.containsKey(cellVal)) {
flag = false;
String details = I18N.getFormatString(I18NC.VERIFY_CELLID_ILLEGAL);
String suggestion = I18N.getFormatString(I18NC.VERIFY_CELLID_ILLEGAL_SUG);
sendMessage(details, suggestion);
return flag;
} else {
ID.put(cellVal, cellID);
}
}
return flag;
} /**
* 描述:检验TDD参数eNodeBID是否重复.<br>
*
* @param IDMap
* @param eNodeBIDTDD
*/
private boolean checkeNodeBIDTDD(HashMap<String, String> IDMap, String eNodeBIDTDD) {
boolean flag = true;
if (IDMap != null && IDMap.containsKey(eNodeBIDTDD)) {
flag = false;
String details = I18N.getFormatString(I18NC.VERIFY_ENODEBIDTDD_ILLEGAL);
String suggestion = I18N.getFormatString(I18NC.VERIFY_ENODEBIDTDD_ILLEGAL_SUG);
sendMessage(details, suggestion);
return flag;
} else {
IDMap.put(eNodeBIDTDD, eNodeBIDTDD);
}
return flag;
} /**
* 描述:检验FDD参数enodeBID是否重复.<br>
*
* @param IDMap
* @param eNodeBIDFDD
*/
private boolean checkeNodeBIDFDD(HashMap<String, String> IDMap, String eNodeBIDFDD) {
boolean flag = true;
if (IDMap != null && IDMap.containsKey(eNodeBIDFDD)) {
flag = false;
String details = I18N.getFormatString(I18NC.VERIFY_ENODEBIDFDD_ILLEGAL);
String suggestion = I18N.getFormatString(I18NC.VERIFY_ENODEBIDFDD_ILLEGAL_SUG);
sendMessage(details, suggestion);
return flag;
} else {
IDMap.put(eNodeBIDFDD, eNodeBIDFDD);
}
return flag;
} /**
* 描述:检验MP priority的取值范围是否在[1..8]之间或等于255.<br>
*
* @param values
* @return true:在取值范围内
* false:不在取值范围内
*/
private boolean checkMPpriority(String values) {
boolean flag = true;
String[] value = values.split(";");
for (int i = 0; i < value.length; i++) {
int val = Integer.valueOf(value[i]);
if (!((val >= 1 && val <= 8) || val == 255)) {
String details = I18N.getFormatString(I18NC.VERIFY_OUTRANGE, "MP priority", values, "[1..8],[255..255]");
String suggestion = I18N.getString(I18NC.VERIFY_OUTRANGE_SUG);
sendMessage(details, suggestion);
flag = false;
}
}
return flag;
} /**
* 描述:双CC情况下检验Vid的相关约束.<br>
*
* @param
* @return true:满足约束
* false:不满足约束
*/
private boolean checkVid(String key, String value, String xpath, AttributeList attributeList) {
boolean flag = true;
String refIPkey = "";
String refIPValue = "";
String srcRoutekey = "";
String srcRouteValue = "";
String refVidMemkey = "";
String refVidMemValue = "";
if ((StringUtils.contains(key, "1")))//第二套传输参数
{
refVidMemkey = "//node[@radioMode='PLAT']/property[@excelName='EthernetLink VLAN ID MerberShip1']";
refIPkey = "//node[@radioMode='PLAT']/property[@excelName='VLAN ID For IP1']";
srcRoutekey = "//node[@radioMode='PLAT']/property[@excelName='VLAN ID For Route1']";
} else {
refVidMemkey = "//node[@radioMode='PLAT']/property[@excelName='EthernetLink VLAN ID MerberShip']";
refIPkey = "//node[@radioMode='PLAT']/property[@excelName='VLAN ID For IP']";
srcRoutekey = "//node[@radioMode='PLAT']/property[@excelName='VLAN ID For Route']";
}
refVidMemValue = attributeList.get(refVidMemkey);
if (StringUtils.contains(xpath, "StaticRoute"))//静态路由的vid必须在ip参数的vid中
{
refIPValue = attributeList.get(refIPkey);
srcRouteValue = attributeList.get(srcRoutekey);
flag = checkRefField(srcRoutekey, srcRouteValue, refIPkey, refIPValue);
}
flag = checkRefField(key, value, refVidMemkey, refVidMemValue) && flag;//ip参数的vid必须在vid membership中
return flag;
} /**
* 描述:双CC情况下检验Hdlc的相关约束(可以不用检查,负荷分担模式IPOE相关参数也只能配一套).<br>
*
* @param
* @return true:满足约束
* false:不满足约束
*/
private boolean checkHdlc(String key, AttributeList attributeList) {
boolean flag = true;
String refHdlckey = "";
String refHdlcValue = "";
String srcPPPkey = "";
String srcPPPValue = "";
if ((StringUtils.contains(key, "1"))) {
refHdlckey = "//node[@radioMode='PLAT']/property[@excelName='HDLC link number1']";
srcPPPkey = "//node[@radioMode='PLAT']/property[@excelName='Used HDLC channel1']";
} else {
refHdlckey = "//node[@radioMode='PLAT']/property[@excelName='HDLC link number']";
srcPPPkey = "//node[@radioMode='PLAT']/property[@excelName='Used HDLC channel']";
}
refHdlcValue = attributeList.get(refHdlckey);
srcPPPValue = attributeList.get(srcPPPkey);
flag = checkRefField(srcPPPkey, srcPPPValue, refHdlckey, refHdlcValue) && flag;
return flag;
}
}
TL 重构的更多相关文章
- 深度原理与框架-图像超分辨重构-tensorlayer
图像超分辨重构的原理,输入一张像素点少,像素较低的图像, 输出一张像素点多,像素较高的图像 而在作者的文章中,作者使用downsample_up, 使用imresize(img, []) 将图像的像素 ...
- 最近关于css样式重构的一点心得体会
之前的项目一直都是基于bootstrap,elementUI这些已经很成熟的框架进行二次开发,要么就是一些很小的宣传页面,h5页面,或者结构相对简单的移动端.一直都没有机会对css的整体进行一个思考, ...
- GAN生成式对抗网络(四)——SRGAN超高分辨率图片重构
论文pdf 地址:https://arxiv.org/pdf/1609.04802v1.pdf 我的实际效果 清晰度距离我的期待有距离. 颜色上面存在差距. 解决想法 增加一个颜色判别器.将颜色值反馈 ...
- Re:《Unity Shader入门精要》13.3全局雾效--如何从深度纹理重构世界坐标
如何从深度纹理重构世界坐标 游戏特效,后处理是必不可少的,而后处理经常需要我们得到当前画面的像素对应世界空间的所有信息. 思路 通过深度纹理取得NDC坐标,然后再通过NDC坐标还原成世界空间坐标 // ...
- 记一次.NET代码重构
好久没写代码了,终于好不容易接到了开发任务,一看时间还挺充足的,我就慢慢整吧,若是遇上赶进度,基本上直接是功能优先,完全不考虑设计.你可以认为我完全没有追求,当身后有鞭子使劲赶的时候,神马设计都是浮云 ...
- CSharpGL(17)重构CSharpGL
CSharpGL(17)重构CSharpGL CSharpGL用起来我自己都觉得繁琐了,这是到了重构的时候. 下载 CSharpGL已在GitHub开源,欢迎对OpenGL有兴趣的同学加入(https ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(58)-DAL层重构
系列目录 前言:这是对本文系统一次重要的革新,很久就想要重构数据访问层了,数据访问层重复代码太多.主要集中增删该查每个模块都有,所以本次是为封装相同接口方法 如果你想了解怎么重构普通的接口DAL层请查 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(59)-BLL层重构
系列目录 前言: 这应该是本系统最后一次重构,将重构BLL层和Model层.来完全取代代码生成器生成的BLL层和DAL层.完全废掉了代码生成器的DAL,BLL,MODEL层. 全自动生成增,删,改 ...
- 原生JS实现全屏切换以及导航栏滑动隐藏及显示——重构前
思路分析: 向后滚动鼠标滚轮,页面向下全屏切换:向前滚动滚轮,页面向上全屏切换.切换过程为动画效果. 第一屏时,导航栏固定在页面顶部,切换到第二屏时,导航条向左滑动隐藏.切换回第一屏时,导航栏向右滑动 ...
随机推荐
- 如何远程运行PowerShell命令?
首先, 被remote运行PowerShell的windows必须已经join了domain. 其次, 该Windows的PowerShell必须开启对remote command的接受, 运行下面的 ...
- Pascal's Triangle II Leetcode java
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return ...
- 构建配置 Enable multidex
官方文档 配置方法数超过 64K 的应用 随着 Android 平台的持续成长,Android 应用的大小也在增加.当您的应用及其引用的库达到特定大小时,您会遇到构建错误,指明您的应用已达到 Andr ...
- C#操作json类型数据
将对象序列化为 JavaScript 对象表示法 (JSON),并将 JSON 数据反序列化为对象. 此类不能继承. // msdn 例子: namespace SL_DataContractJson ...
- Qt OpenGL:学习现代3D图形编程之四,透视投影浅析
一.非真实的世界 与之前几篇文章不同的是,这里要画12个三角形,这个12个三角形构造一个方形棱柱(这里为长方体).棱柱的每个四边形表面由两个三角形组成.这两个三角形其中的一条边重合,而且它们的六个顶点 ...
- NLP--自然语言处理与机器学习会议
http://blog.csdn.net/ice110956/article/details/17090061 整理至11月中旬在重庆参加的自然语言处理与机器学习会议,第一讲为自然语言处理. 由基本理 ...
- Mac下brew/memcached/nginx/iterm/zsh的安装
brew https://www.cnblogs.com/fireworld/p/8609190.html memcached https://blog.csdn.net/whereismatrix ...
- Direct2D教程VII——变换几何(TransformedGeometry)对象
目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...
- (纪录片)光的故事 BBC Light Fantastic (2004)
简介: 导演: Jeremy Turner主演: Simon Schaffer / Dimitri Andreas ... Al Hazen / Edmund Dehn ... Priest/Old ...
- phpmyadmin误删表后如何恢复
用mysqlbinlog php处理代码: 将mysql-bin.xxxxxx文件导出为可读文本: <?php //导出mysql-bin.000xxx文件为可读性txt文本 //0为执行成功, ...