static Map<String, MatchPair> parseNameAndValueListString2Condition( Map<String, String> params, Map<String, String> notParams) { Map<String, MatchPair> condition = new HashMap<String, RouteRule.MatchPair>(); for (Entry<String, String> entry : params.entrySet()) { String valueListString = entry.getValue(); if (StringUtils.isBlank(valueListString)) { continue; } String[] list = VALUE_LIST_SEPARATOR.split(valueListString); Set<String> set = new HashSet<String>(); for (String item : list) { if (StringUtils.isBlank(item)) { continue; } set.add(item.trim()); } if (set.isEmpty()) { continue; } String key = entry.getKey(); MatchPair matchPair = condition.get(key); if (null == matchPair) { matchPair = new MatchPair(); condition.put(key, matchPair); } matchPair.matches = set; } for (Entry<String, String> entry : notParams.entrySet()) { String valueListString = entry.getValue(); if (StringUtils.isBlank(valueListString)) { continue; } String[] list = VALUE_LIST_SEPARATOR.split(valueListString); Set<String> set = new HashSet<String>(); for (String item : list) { if (StringUtils.isBlank(item)) { continue; } set.add(item.trim()); } if (set.isEmpty()) { continue; } String key = entry.getKey(); MatchPair matchPair = condition.get(key); if (null == matchPair) { matchPair = new MatchPair(); condition.put(key, matchPair); } matchPair.unmatches = set; } return condition; }
@Override public UserTradeBaseVo getUserWholeInfoByToken(String token) { if (StringUtils.isBlank(token)) { return null; } return cacheService.getUserWholeInfoByToken(token); }
public static RouteRule parse(String rule) throws ParseException { if (StringUtils.isBlank(rule)) { throw new ParseException("Illegal blank route rule", 0); } final Matcher matcher = CONDITION_SEPERATOR.matcher(rule); if (!matcher.matches()) throw new ParseException("condition seperator => not found!", 0); return parse(matcher.group(1), matcher.group(2)); }
private AccountDept convertldapOrgToDeptEntity(LdapOrg ldapOrg) { // 部门编码必填 if (StringUtils.isBlank(ldapOrg.getDeptcode())) { return null; } AccountDept accountDept = new AccountDept(); accountDept.setDeptcode(ldapOrg.getDeptcode()); accountDept.setDeptname(ldapOrg.getDeptname()); accountDept.setFatherdept(ldapOrg.getFatherdept()); accountDept.setOrgcode(ldapOrg.getOrgcode()); accountDept.setOrgname(ldapOrg.getOrgname()); accountDept.setPkdept(ldapOrg.getPkdept()); accountDept.setPkfatherdept(ldapOrg.getPkfatherdept()); accountDept.setPkorg(ldapOrg.getPkorg()); return accountDept; }
public static Map<String, MatchPair> parseRule(String rule) throws ParseException { Map<String, MatchPair> condition = new HashMap<String, RouteRule.MatchPair>(); if (StringUtils.isBlank(rule)) { return condition; } // 匹配或不匹配Key-Value对 MatchPair pair = null; // 多个Value值 Set<String> values = null; final Matcher matcher = ROUTE_PATTERN.matcher(rule); while (matcher.find()) { // 逐个匹配 String separator = matcher.group(1); String content = matcher.group(2); // 表达式开始 if (separator == null || separator.length() == 0) { pair = new MatchPair(); condition.put(content, pair); } // KV开始 else if ("&".equals(separator)) { if (condition.get(content) == null) { pair = new MatchPair(); condition.put(content, pair); } else { condition.put(content, pair); } } // KV的Value部分开始 else if ("=".equals(separator)) { if (pair == null) throw new ParseException( "Illegal route rule \"" + rule + "\", The error char '" + separator + "' at index " + matcher.start() + " before \"" + content + "\".", matcher.start()); values = pair.matches; values.add(content); } // KV的Value部分开始 else if ("!=".equals(separator)) { if (pair == null) throw new ParseException( "Illegal route rule \"" + rule + "\", The error char '" + separator + "' at index " + matcher.start() + " before \"" + content + "\".", matcher.start()); values = pair.unmatches; values.add(content); } // KV的Value部分的多个条目 else if (",".equals(separator)) { // 如果为逗号表示 if (values == null || values.size() == 0) throw new ParseException( "Illegal route rule \"" + rule + "\", The error char '" + separator + "' at index " + matcher.start() + " before \"" + content + "\".", matcher.start()); values.add(content); } else { throw new ParseException( "Illegal route rule \"" + rule + "\", The error char '" + separator + "' at index " + matcher.start() + " before \"" + content + "\".", matcher.start()); } } return condition; }