(1)将excel相关的线程类划分到thread包下
(2)Ddos验证时如果协议为空,设置协议值为空字符串 (3)Ddos ip导入改为批量导入
This commit is contained in:
@@ -0,0 +1,318 @@
|
||||
package com.nis.util.excel.thread;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jets3t.service.ServiceException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.beust.jcommander.internal.Sets;
|
||||
import com.nis.domain.FunctionRegionDict;
|
||||
import com.nis.domain.FunctionServiceDict;
|
||||
import com.nis.domain.configuration.ComplexkeywordCfg;
|
||||
import com.nis.domain.configuration.DnsResStrategy;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.web.service.configuration.DnsResStrategyService;
|
||||
|
||||
public class CheckComplexStringFormatThread implements Callable<String>{
|
||||
private Logger logger=Logger.getLogger(CheckComplexStringFormatThread.class);
|
||||
private BlockingQueue<? extends Object> srcQueue;
|
||||
private BlockingQueue<ComplexkeywordCfg> destQueue;
|
||||
private Properties prop;
|
||||
private DnsResStrategyService dnsResStrategyService;
|
||||
private FunctionServiceDict serviceDict;
|
||||
private FunctionRegionDict regionDict;
|
||||
public CheckComplexStringFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<ComplexkeywordCfg> destQueue) {
|
||||
this.serviceDict=serviceDict;
|
||||
this.regionDict=regionDict;
|
||||
this.srcQueue=srcQueue;
|
||||
this.destQueue=destQueue;
|
||||
this.prop=prop;
|
||||
}
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
|
||||
String msg=null;
|
||||
while(!srcQueue.isEmpty()) {
|
||||
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
|
||||
if(regionDict.getRegionType().intValue()==3) {
|
||||
try {
|
||||
List<ComplexkeywordCfg> cfgs=this.checkComplexStringCfg(dataList);
|
||||
destQueue.addAll(cfgs);
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
msg=e.getMessage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
dataList.clear();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
public List<ComplexkeywordCfg> checkComplexStringCfg(
|
||||
List<?> list) throws ServiceException {
|
||||
logger.warn("start to validate complexString data...");
|
||||
long start=System.currentTimeMillis();
|
||||
List<ComplexkeywordCfg> stringList = new ArrayList<ComplexkeywordCfg>();
|
||||
String exprTypeP = regionDict.getConfigExprType();
|
||||
if (StringUtils.isBlank(exprTypeP)) {
|
||||
throw new RuntimeException("Found String region,but exprType is Empty");
|
||||
}
|
||||
String matchMethodP = regionDict.getConfigMatchMethod();
|
||||
if (StringUtils.isBlank(matchMethodP)) {
|
||||
throw new RuntimeException("Found String region,but matchMethod is Empty");
|
||||
}
|
||||
String hexP = regionDict.getConfigHex();
|
||||
if (StringUtils.isBlank(hexP)) {
|
||||
throw new RuntimeException("Found String region,but hex is Empty");
|
||||
}
|
||||
String mulityKeywordsP = regionDict.getConfigMultiKeywords();
|
||||
if (StringUtils.isBlank(mulityKeywordsP)) {
|
||||
throw new RuntimeException("Found String region,but mulityKeywords is Empty");
|
||||
}
|
||||
String dirtrictP = regionDict.getConfigDistrict();
|
||||
StringBuffer errTip = new StringBuffer();
|
||||
Pattern pattern = Pattern.compile("\t|\r|\n|\b|\f");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
StringBuffer errInfo = new StringBuffer();
|
||||
ComplexkeywordCfg baseStringCfg = new ComplexkeywordCfg();
|
||||
BeanUtils.copyProperties(list.get(i), baseStringCfg);
|
||||
if (regionDict.getRegionType().equals(3)) {
|
||||
if (regionDict.getFunctionId().equals(7)) {
|
||||
Long dnsStrategyId = baseStringCfg.getDnsStrategyId();
|
||||
if (dnsStrategyId != null&&dnsStrategyId>0) {
|
||||
List<DnsResStrategy> dnsStrategys = dnsResStrategyService.findDnsResStrategys(dnsStrategyId,
|
||||
Constants.VALID_YES, Constants.AUDIT_YES);
|
||||
if (dnsStrategys == null || dnsStrategys.size() == 0) {
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("dns_res_strategy")) + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
String keyword = baseStringCfg.getCfgKeywords();
|
||||
String district = baseStringCfg.getDistrict();
|
||||
if (StringUtils.isBlank(keyword)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("key_word") + " ") + ";");
|
||||
}
|
||||
if (StringUtils.isNotBlank(dirtrictP)) {
|
||||
if (StringUtils.isBlank(district)) {
|
||||
if (dirtrictP.indexOf(",") == -1) {
|
||||
baseStringCfg.setDistrict(dirtrictP);
|
||||
} else {
|
||||
// baseStringCfg.setDistrict(dirtrictP.split(",")[0]);
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("district") + " ")
|
||||
+ ";");
|
||||
}
|
||||
} else if (dirtrictP.indexOf(district) == -1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("district") + " ")
|
||||
+ ";");
|
||||
} else if (dirtrictP.indexOf("others")>-1&&district.equals("others")) {
|
||||
//不允许自定义匹配区域导入
|
||||
errInfo.append(prop.getProperty("district")+" "+
|
||||
String.format(prop.getProperty("can_not_be"), " 'others'")+ ";");
|
||||
}
|
||||
}
|
||||
if (mulityKeywordsP.equals("0")) {
|
||||
if (keyword.indexOf("\n") > -1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("not_multiple"), prop.getProperty("key_word")) + ";");
|
||||
}
|
||||
Matcher m = pattern.matcher(keyword);
|
||||
if (m.find()) {
|
||||
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
|
||||
prop.getProperty("key_word") + " '" + keyword + "'") + ";");
|
||||
}
|
||||
} else {
|
||||
boolean has = false;
|
||||
Set<String> keywordSet=Sets.newHashSet();
|
||||
|
||||
for (String key : keyword.split("\n")) {
|
||||
Matcher m = pattern.matcher(key);
|
||||
if (m.find()) {
|
||||
has = true;
|
||||
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
|
||||
prop.getProperty("key_word") + " '" + key + "'") + ";");
|
||||
break;
|
||||
}
|
||||
if(!keywordSet.contains(key)) {
|
||||
keywordSet.add(key);
|
||||
}else {
|
||||
errInfo.append(prop.getProperty("key_word") + " '" + key + "'"+" "+prop.getProperty("repeat") + ";");
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
if(keyword.replaceAll("\n","").length()>1024) {
|
||||
errInfo.append(String.format(prop.getProperty("most_keywords"),
|
||||
prop.getProperty("key_word")) + ";");
|
||||
}else {
|
||||
String reWord = keyword.replaceAll("\n", Constants.KEYWORD_EXPR);
|
||||
baseStringCfg.setCfgKeywords(reWord);
|
||||
}
|
||||
}
|
||||
}
|
||||
Integer exprType = baseStringCfg.getExprType();
|
||||
boolean has = false;
|
||||
if (exprType == null) {
|
||||
if (exprTypeP.indexOf(",") == -1) {
|
||||
if (mulityKeywordsP.equals("0") && exprTypeP.equals("1")) {
|
||||
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
|
||||
}
|
||||
baseStringCfg.setExprType(Integer.parseInt(exprTypeP));
|
||||
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("0")) {
|
||||
baseStringCfg.setExprType(0);
|
||||
} else if (exprTypeP.indexOf("1") > -1 && mulityKeywordsP.equals("1")
|
||||
&& keyword.indexOf("\n") > -1) {
|
||||
baseStringCfg.setExprType(1);
|
||||
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("1")
|
||||
&& keyword.indexOf("\n") == -1) {
|
||||
baseStringCfg.setExprType(0);
|
||||
} else {
|
||||
baseStringCfg.setExprType(Integer.parseInt(exprTypeP.split(",")[0]));
|
||||
}
|
||||
// errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
// prop.getProperty("expression_type"))+";");
|
||||
} else {
|
||||
for (String exp : exprTypeP.split(",")) {
|
||||
if (exp.equals(exprType.toString())) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("expression_type"))
|
||||
+ ";");
|
||||
}
|
||||
has = false;
|
||||
}
|
||||
exprType = baseStringCfg.getExprType();
|
||||
Integer matchMethod = baseStringCfg.getMatchMethod();
|
||||
if (matchMethod == null) {
|
||||
if (matchMethodP.indexOf(",") == -1) {
|
||||
if (exprTypeP.equals("1") && !matchMethodP.equals("0")) {
|
||||
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
|
||||
}
|
||||
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP));
|
||||
} else if (exprType != null && exprType.intValue() == 1) {
|
||||
if (matchMethodP.indexOf("0") > -1) {
|
||||
baseStringCfg.setMatchMethod(0);
|
||||
} else {
|
||||
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
|
||||
}
|
||||
|
||||
} else {
|
||||
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP.split(",")[0]));
|
||||
}
|
||||
// errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
// prop.getProperty("match_method"))+";");
|
||||
} else {
|
||||
for (String exp : matchMethodP.split(",")) {
|
||||
if (exp.equals(matchMethod.toString())) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("match_method"))
|
||||
+ ";");
|
||||
}
|
||||
}
|
||||
Integer isHex = baseStringCfg.getIsHex();
|
||||
Integer isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
|
||||
if (isHex == null || isCaseInsenstive == null) {
|
||||
if (isHex == null) {
|
||||
if (hexP.equals("0") || hexP.equals("2")) {
|
||||
baseStringCfg.setIsHex(0);
|
||||
} else if (hexP.equals("1")) {
|
||||
baseStringCfg.setIsHex(1);
|
||||
} else {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
}
|
||||
if (isCaseInsenstive == null) {
|
||||
if (hexP.equals("0") || hexP.equals("1")) {
|
||||
baseStringCfg.setIsCaseInsenstive(0);
|
||||
} else if (hexP.equals("2")) {
|
||||
baseStringCfg.setIsCaseInsenstive(1);
|
||||
} else {
|
||||
errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
prop.getProperty("is_case_insenstive")) + ";");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isHex.intValue() != 0 && isHex.intValue() != 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
if (isCaseInsenstive.intValue() != 0 && isCaseInsenstive.intValue() != 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
|
||||
+ ";");
|
||||
}
|
||||
if (hexP.indexOf("1") == -1 && isHex.intValue() == 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
if (hexP.equals("1") && isHex.intValue() == 0) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
if (hexP.indexOf("2") == -1 && isCaseInsenstive.intValue() == 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
|
||||
+ ";");
|
||||
}
|
||||
if (hexP.equals("2") && isCaseInsenstive.intValue() == 0) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
|
||||
+ ";");
|
||||
}
|
||||
}
|
||||
isHex = baseStringCfg.getIsHex();
|
||||
isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
|
||||
if (isHex != null && isCaseInsenstive != null) {
|
||||
if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 0) {
|
||||
baseStringCfg.setIsHexbin(0);
|
||||
} else if (isHex.intValue() == 1 && isCaseInsenstive.intValue() == 0) {
|
||||
baseStringCfg.setIsHexbin(1);
|
||||
} else if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 1) {
|
||||
baseStringCfg.setIsHexbin(2);
|
||||
}else {
|
||||
errInfo.append(prop.getProperty("hex_case_insensitive")+ ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errInfo.toString().length() > 0) {//
|
||||
errTip.append(String.format(prop.getProperty("line"), baseStringCfg.getIndex()) + ",");
|
||||
errTip.append(errInfo);
|
||||
errTip.append("<br>");
|
||||
}
|
||||
stringList.add(baseStringCfg);
|
||||
}
|
||||
if (errTip.toString().length() > 0) {
|
||||
throw new ServiceException(errTip.toString());
|
||||
}
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("validate complexString data finish,cost:"+(end-start));
|
||||
return stringList;
|
||||
}
|
||||
public DnsResStrategyService getDnsResStrategyService() {
|
||||
return dnsResStrategyService;
|
||||
}
|
||||
public void setDnsResStrategyService(DnsResStrategyService dnsResStrategyService) {
|
||||
this.dnsResStrategyService = dnsResStrategyService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.nis.util.excel.thread;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jets3t.service.ServiceException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.beust.jcommander.internal.Sets;
|
||||
import com.nis.domain.FunctionRegionDict;
|
||||
import com.nis.domain.FunctionServiceDict;
|
||||
import com.nis.domain.basics.PolicyGroupInfo;
|
||||
import com.nis.domain.configuration.ComplexkeywordCfg;
|
||||
import com.nis.domain.configuration.DnsResStrategy;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.web.service.basics.PolicyGroupInfoService;
|
||||
import com.nis.web.service.configuration.DnsResStrategyService;
|
||||
|
||||
public class CheckDnsResStrategyFormatThread implements Callable<String>{
|
||||
private Logger logger=Logger.getLogger(CheckDnsResStrategyFormatThread.class);
|
||||
private BlockingQueue<? extends Object> srcQueue;
|
||||
private BlockingQueue<DnsResStrategy> destQueue;
|
||||
private Properties prop;
|
||||
private DnsResStrategyService dnsResStrategyService;
|
||||
private FunctionServiceDict serviceDict;
|
||||
private FunctionRegionDict regionDict;
|
||||
private PolicyGroupInfoService policyGroupInfoService;
|
||||
public CheckDnsResStrategyFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<DnsResStrategy> destQueue) {
|
||||
this.serviceDict=serviceDict;
|
||||
this.regionDict=regionDict;
|
||||
this.srcQueue=srcQueue;
|
||||
this.destQueue=destQueue;
|
||||
this.prop=prop;
|
||||
}
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
|
||||
String msg=null;
|
||||
while(!srcQueue.isEmpty()) {
|
||||
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
|
||||
if(regionDict.getRegionType().intValue()==6) {
|
||||
try {
|
||||
List<DnsResStrategy> cfgs=this.checkDnsResStrategyCfg(dataList);
|
||||
destQueue.addAll(cfgs);
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
msg=e.getMessage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
dataList.clear();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
public List<DnsResStrategy> checkDnsResStrategyCfg(List<?> list)
|
||||
throws ServiceException {
|
||||
List<DnsResStrategy> dnsResStrategies=Lists.newArrayList();
|
||||
StringBuffer errTip = new StringBuffer();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
StringBuffer errInfo = new StringBuffer();
|
||||
DnsResStrategy dnsResStrategy=new DnsResStrategy();
|
||||
BeanUtils.copyProperties(list.get(i), dnsResStrategy);
|
||||
String groupName=dnsResStrategy.getCfgDesc();
|
||||
if(StringUtils.isBlank(groupName)) {
|
||||
errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
prop.getProperty("policy_name")) + ";");
|
||||
}
|
||||
Integer resGroup1Id=dnsResStrategy.getResGroup1Id();
|
||||
if(resGroup1Id==null) {
|
||||
errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
prop.getProperty("group")) + ";");
|
||||
}else {
|
||||
PolicyGroupInfo info=policyGroupInfoService.getById(resGroup1Id);
|
||||
if(info==null) {
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("group")) + ";");
|
||||
}
|
||||
}
|
||||
Integer resGroup1Num=dnsResStrategy.getResGroup1Num();
|
||||
if(resGroup1Num==null) {
|
||||
errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
prop.getProperty("res_group_num")) + ";");
|
||||
}
|
||||
String ttl=dnsResStrategy.getTtl();
|
||||
if(StringUtils.isBlank(ttl)) {
|
||||
errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
prop.getProperty("min_ttl")) + ";");
|
||||
}else {
|
||||
Pattern p=Constants.RANGE_PATTERN;
|
||||
Matcher m=p.matcher(ttl);
|
||||
if(!m.matches()) {
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("min_ttl")) + ";");
|
||||
}else {
|
||||
String minTtl=ttl.split("-")[0];
|
||||
String maxTtl=ttl.split("-")[1];
|
||||
Integer min=null,max=null;
|
||||
try {
|
||||
min=Integer.parseInt(minTtl);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("min_ttl")) + ";");
|
||||
}
|
||||
try {
|
||||
max=Integer.parseInt(maxTtl);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("min_ttl")) + ";");
|
||||
}
|
||||
if(min.intValue()>max.intValue())
|
||||
{errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("min_ttl")) + ";");
|
||||
}else {
|
||||
dnsResStrategy.setMinTtl(min);
|
||||
dnsResStrategy.setMaxTtl(max);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (errInfo.toString().length() > 0) {//
|
||||
errTip.append(String.format(prop.getProperty("line"), dnsResStrategy.getIndex()) + ",");
|
||||
errTip.append(errInfo);
|
||||
errTip.append("<br>");
|
||||
}
|
||||
dnsResStrategies.add(dnsResStrategy);
|
||||
}
|
||||
if (errTip.toString().length() > 0) {
|
||||
throw new ServiceException(errTip.toString());
|
||||
}
|
||||
return dnsResStrategies;
|
||||
}
|
||||
public DnsResStrategyService getDnsResStrategyService() {
|
||||
return dnsResStrategyService;
|
||||
}
|
||||
public void setDnsResStrategyService(DnsResStrategyService dnsResStrategyService) {
|
||||
this.dnsResStrategyService = dnsResStrategyService;
|
||||
}
|
||||
public PolicyGroupInfoService getPolicyGroupInfoService() {
|
||||
return policyGroupInfoService;
|
||||
}
|
||||
public void setPolicyGroupInfoService(PolicyGroupInfoService policyGroupInfoService) {
|
||||
this.policyGroupInfoService = policyGroupInfoService;
|
||||
}
|
||||
|
||||
}
|
||||
1048
src/main/java/com/nis/util/excel/thread/CheckIpFormatThread.java
Normal file
1048
src/main/java/com/nis/util/excel/thread/CheckIpFormatThread.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,330 @@
|
||||
package com.nis.util.excel.thread;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jets3t.service.ServiceException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.beust.jcommander.internal.Sets;
|
||||
import com.nis.domain.FunctionRegionDict;
|
||||
import com.nis.domain.FunctionServiceDict;
|
||||
import com.nis.domain.SysDataDictionaryItem;
|
||||
import com.nis.domain.configuration.BaseStringCfg;
|
||||
import com.nis.util.Constants;
|
||||
import com.nis.util.DictUtils;
|
||||
import com.nis.web.service.configuration.DnsResStrategyService;
|
||||
|
||||
public class CheckStringFormatThread implements Callable<String>{
|
||||
private Logger logger=Logger.getLogger(CheckStringFormatThread.class);
|
||||
private BlockingQueue<? extends Object> srcQueue;
|
||||
private BlockingQueue<BaseStringCfg<?>> destQueue;
|
||||
private Properties prop;
|
||||
private DnsResStrategyService dnsResStrategyService;
|
||||
private FunctionServiceDict serviceDict;
|
||||
private FunctionRegionDict regionDict;
|
||||
public CheckStringFormatThread(FunctionServiceDict serviceDict,FunctionRegionDict regionDict,Properties prop,BlockingQueue<? extends Object> srcQueue,BlockingQueue<BaseStringCfg<?>> destQueue) {
|
||||
this.serviceDict=serviceDict;
|
||||
this.regionDict=regionDict;
|
||||
this.srcQueue=srcQueue;
|
||||
this.destQueue=destQueue;
|
||||
this.prop=prop;
|
||||
}
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
List<Object> dataList=Lists.newArrayList(Constants.MAAT_JSON_SEND_SIZE);
|
||||
String msg=null;
|
||||
while(!srcQueue.isEmpty()) {
|
||||
int size=srcQueue.drainTo(dataList,Constants.MAAT_JSON_SEND_SIZE);
|
||||
if(regionDict.getRegionType().intValue()==2) {
|
||||
try {
|
||||
List<BaseStringCfg<?>> cfgs=this.checkStringCfg(dataList);
|
||||
destQueue.addAll(cfgs);
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
msg=e.getMessage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
dataList.clear();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public List<BaseStringCfg<?>> checkStringCfg(List<?> list) throws ServiceException {
|
||||
logger.warn("start to validate stringCfg data...");
|
||||
long start=System.currentTimeMillis();
|
||||
List<BaseStringCfg<?>> stringList = new ArrayList<BaseStringCfg<?>>();
|
||||
String exprTypeP = regionDict.getConfigExprType();
|
||||
if (StringUtils.isBlank(exprTypeP)) {
|
||||
throw new RuntimeException("Found String region,but exprType is Empty");
|
||||
}
|
||||
String matchMethodP = regionDict.getConfigMatchMethod();
|
||||
if (StringUtils.isBlank(matchMethodP)) {
|
||||
throw new RuntimeException("Found String region,but matchMethod is Empty");
|
||||
}
|
||||
String hexP = regionDict.getConfigHex();
|
||||
if (StringUtils.isBlank(hexP)) {
|
||||
throw new RuntimeException("Found String region,but hex is Empty");
|
||||
}
|
||||
String mulityKeywordsP = regionDict.getConfigMultiKeywords();
|
||||
if (StringUtils.isBlank(mulityKeywordsP)) {
|
||||
throw new RuntimeException("Found String region,but mulityKeywords is Empty");
|
||||
}
|
||||
StringBuffer errTip = new StringBuffer();
|
||||
Pattern pattern = Pattern.compile("\t|\r|\n|\b|\f");
|
||||
Pattern domainPattern = Pattern.compile(Constants.DOMAIN_REGEXP);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
StringBuffer errInfo = new StringBuffer();
|
||||
BaseStringCfg baseStringCfg = new BaseStringCfg();
|
||||
BeanUtils.copyProperties(list.get(i), baseStringCfg);
|
||||
if (regionDict.getRegionType().equals(2)) {
|
||||
if (regionDict.getFunctionId().equals(510) && "p2p_hash".equals(regionDict.getConfigServiceType())) {
|
||||
String userRegion1 = baseStringCfg.getUserRegion1();
|
||||
if (StringUtils.isNotBlank(userRegion1)) {
|
||||
List<SysDataDictionaryItem> hashs = DictUtils.getDictList("P2P_HASH_TYPE");
|
||||
boolean has = false;
|
||||
for (SysDataDictionaryItem hash : hashs) {
|
||||
if (hash.getItemCode().equals(userRegion1)) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"),
|
||||
prop.getProperty("p2p_hash_type") + " ") + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
String keyword = baseStringCfg.getCfgKeywords();
|
||||
if (!regionDict.getFunctionId().equals(403)) {
|
||||
if (StringUtils.isBlank(keyword)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("key_word") + " ") + ";");
|
||||
}
|
||||
if (mulityKeywordsP.equals("0")) {
|
||||
if (keyword.indexOf("\n") > -1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("not_multiple"), prop.getProperty("key_word")) + ";");
|
||||
}
|
||||
Matcher m = pattern.matcher(keyword);
|
||||
if (m.find()) {
|
||||
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
|
||||
prop.getProperty("key_word") + " '" + keyword + "'") + ";");
|
||||
}
|
||||
} else {
|
||||
boolean has = false;
|
||||
Set<String> keywordSet=Sets.newHashSet();
|
||||
for (String key : keyword.split("\n")) {
|
||||
Matcher m = pattern.matcher(key);
|
||||
if (m.find()) {
|
||||
has = true;
|
||||
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
|
||||
prop.getProperty("key_word") + " '" + key + "'") + ";");
|
||||
break;
|
||||
}
|
||||
if(!keywordSet.contains(key)) {
|
||||
keywordSet.add(key);
|
||||
}else {
|
||||
errInfo.append(prop.getProperty("key_word") + " '" + key + "'"+" "+prop.getProperty("repeat") + ";");
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
if(keyword.replaceAll("\n","").length()>1024) {
|
||||
errInfo.append(String.format(prop.getProperty("most_keywords"),
|
||||
prop.getProperty("key_word")) + ";");
|
||||
}else {
|
||||
String reWord = keyword.replaceAll("\n", Constants.KEYWORD_EXPR);
|
||||
baseStringCfg.setCfgKeywords(reWord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (StringUtils.isBlank(keyword)) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("domain_name") + " ") + ";");
|
||||
}else {
|
||||
Matcher m = pattern.matcher(keyword);
|
||||
if (m.find()) {
|
||||
errInfo.append(String.format(prop.getProperty("has_invisible_char"),
|
||||
prop.getProperty("domain_name") + " '" + keyword + "'") + ";");
|
||||
}else {
|
||||
m = domainPattern.matcher(keyword);
|
||||
if(!m.matches()) {
|
||||
errInfo.append(String.format(prop.getProperty("not_valid_domain"),
|
||||
prop.getProperty("domain_name") + " '" + keyword + "'") + ";");
|
||||
}else {
|
||||
baseStringCfg.setDomain(keyword);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Integer exprType = baseStringCfg.getExprType();
|
||||
boolean has = false;
|
||||
if (exprType == null) {
|
||||
if (exprTypeP.indexOf(",") == -1) {
|
||||
if (mulityKeywordsP.equals("0") && exprTypeP.equals("1")) {
|
||||
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
|
||||
}
|
||||
baseStringCfg.setExprType(Integer.parseInt(exprTypeP));
|
||||
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("0")) {
|
||||
baseStringCfg.setExprType(0);
|
||||
} else if (exprTypeP.indexOf("1") > -1 && mulityKeywordsP.equals("1")
|
||||
&& keyword.indexOf("\n") > -1) {
|
||||
baseStringCfg.setExprType(1);
|
||||
} else if (exprTypeP.indexOf("0") > -1 && mulityKeywordsP.equals("1")
|
||||
&& keyword.indexOf("\n") == -1) {
|
||||
baseStringCfg.setExprType(0);
|
||||
} else {
|
||||
baseStringCfg.setExprType(Integer.parseInt(exprTypeP.split(",")[0]));
|
||||
}
|
||||
// errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
// prop.getProperty("expression_type"))+";");
|
||||
} else {
|
||||
for (String exp : exprTypeP.split(",")) {
|
||||
if (exp.equals(exprType.toString())) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("expression_type"))
|
||||
+ ";");
|
||||
}
|
||||
has = false;
|
||||
}
|
||||
exprType = baseStringCfg.getExprType();
|
||||
Integer matchMethod = baseStringCfg.getMatchMethod();
|
||||
if (matchMethod == null) {
|
||||
if (matchMethodP.indexOf(",") == -1) {
|
||||
if (exprTypeP.equals("1") && !matchMethodP.equals("0")) {
|
||||
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
|
||||
}
|
||||
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP));
|
||||
} else if (exprType != null && exprType.intValue() == 1) {
|
||||
if (matchMethodP.indexOf("0") > -1) {
|
||||
baseStringCfg.setMatchMethod(0);
|
||||
} else {
|
||||
throw new RuntimeException("region dict config error,dict id is " + regionDict.getDictId());
|
||||
}
|
||||
|
||||
} else {
|
||||
baseStringCfg.setMatchMethod(Integer.parseInt(matchMethodP.split(",")[0]));
|
||||
}
|
||||
// errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
// prop.getProperty("match_method"))+";");
|
||||
} else {
|
||||
for (String exp : matchMethodP.split(",")) {
|
||||
if (exp.equals(matchMethod.toString())) {
|
||||
has = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!has) {
|
||||
errInfo.append(String.format(prop.getProperty("is_incorrect"), prop.getProperty("match_method"))
|
||||
+ ";");
|
||||
}
|
||||
}
|
||||
|
||||
Integer isHex = baseStringCfg.getIsHex();
|
||||
Integer isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
|
||||
if (isHex == null || isCaseInsenstive == null) {
|
||||
if (isHex == null) {
|
||||
if (hexP.equals("0") || hexP.equals("2")) {
|
||||
baseStringCfg.setIsHex(0);
|
||||
} else if (hexP.equals("1")) {
|
||||
baseStringCfg.setIsHex(1);
|
||||
} else {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("can_not_null"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
}
|
||||
if (isCaseInsenstive == null) {
|
||||
if (hexP.equals("0") || hexP.equals("1")) {
|
||||
baseStringCfg.setIsCaseInsenstive(0);
|
||||
} else if (hexP.equals("2")) {
|
||||
baseStringCfg.setIsCaseInsenstive(1);
|
||||
} else {
|
||||
errInfo.append(String.format(prop.getProperty("can_not_null"),
|
||||
prop.getProperty("is_case_insenstive")) + ";");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isHex.intValue() != 0 && isHex.intValue() != 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
if (isCaseInsenstive.intValue() != 0 && isCaseInsenstive.intValue() != 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
|
||||
+ ";");
|
||||
}
|
||||
if (hexP.indexOf("1") == -1 && isHex.intValue() == 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
if (hexP.equals("1") && isHex.intValue() == 0) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_hex")) + ";");
|
||||
}
|
||||
if (hexP.indexOf("2") == -1 && isCaseInsenstive.intValue() == 1) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
|
||||
+ ";");
|
||||
}
|
||||
if (hexP.equals("2") && isCaseInsenstive.intValue() == 0) {
|
||||
errInfo.append(
|
||||
String.format(prop.getProperty("is_incorrect"), prop.getProperty("is_case_insenstive"))
|
||||
+ ";");
|
||||
}
|
||||
}
|
||||
isHex = baseStringCfg.getIsHex();
|
||||
isCaseInsenstive = baseStringCfg.getIsCaseInsenstive();
|
||||
if (isHex != null && isCaseInsenstive != null) {
|
||||
if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 0) {
|
||||
baseStringCfg.setIsHexbin(0);
|
||||
} else if (isHex.intValue() == 1 && isCaseInsenstive.intValue() == 0) {
|
||||
baseStringCfg.setIsHexbin(1);
|
||||
} else if (isHex.intValue() == 0 && isCaseInsenstive.intValue() == 1) {
|
||||
baseStringCfg.setIsHexbin(2);
|
||||
}else {
|
||||
errInfo.append(prop.getProperty("hex_case_insensitive")+ ";");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (errInfo.toString().length() > 0) {//
|
||||
errTip.append(String.format(prop.getProperty("line"), baseStringCfg.getIndex()) + ",");
|
||||
errTip.append(errInfo);
|
||||
errTip.append("<br>");
|
||||
}
|
||||
stringList.add(baseStringCfg);
|
||||
}
|
||||
if (errTip.toString().length() > 0) {
|
||||
throw new ServiceException(errTip.toString());
|
||||
}
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("validate stringCfg data finish,cost:"+(end-start));
|
||||
return stringList;
|
||||
}
|
||||
|
||||
public DnsResStrategyService getDnsResStrategyService() {
|
||||
return dnsResStrategyService;
|
||||
}
|
||||
public void setDnsResStrategyService(DnsResStrategyService dnsResStrategyService) {
|
||||
this.dnsResStrategyService = dnsResStrategyService;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user