for(String[] names : then_names) {
then_name2valueList.put(names[0], (String)context.get(names[1]));
notThen_name2valueList.put(names[0], (String)context.get(names[2]));
}
RouteRule routeRule = RouteRule.createFromNameAndValueListString(
when_name2valueList, notWhen_name2valueList,
then_name2valueList, notThen_name2valueList);
RouteRule result = null;
if(black){
RouteRule.MatchPair matchPair = routeRule.getThenCondition().get("black");
Map<String, RouteRule.MatchPair> then = null;
if(null == matchPair) {
matchPair = new RouteRule.MatchPair();
then = new HashMap<String, RouteRule.MatchPair>();
then.put("black", matchPair);
}else{
matchPair.getMatches().clear();
}
matchPair.getMatches().add(String.valueOf(black));
result = RouteRule.copyWithReplace(routeRule, null, then);
}
if(result == null){
result = routeRule;
}
if (result.getThenCondition().isEmpty()) {
context.put("message", getMessage("Update route error! then is empty."));
return false;
}
String matchRule = result.getWhenConditionString();
String filterRule = result.getThenConditionString();
//限制表达式的长度
if (matchRule.length() > MAX_RULE_LENGTH) {
context.put("message", getMessage("When rule is too long!"));
return false;
}
if (filterRule.length() > MAX_RULE_LENGTH) {
context.put("message", getMessage("Then rule is too long!"));
return false;
}
int priority = 0;
if (StringUtils.isNotEmpty((String)context.get("priority"))) {
priority = Integer.parseInt((String)context.get("priority"));
}
Route route = new Route();
route.setRule(result.toString());
route.setService(service);
route.setPriority(priority);
route.setName((String)context.get("name"));
route.setUsername((String)context.get("operator"));
route.setOperator((String)context.get("operatorAddress"));