Esempio n. 1
0
  // / <summary>
  // / 根据用户的Profile检查用户权限——规则为必须所有的RuleItem都满足才算成功
  // / </summary>
  // / <param name="up"></param>
  // / <returns></returns>
  public boolean CheckUser(UserProfile up) throws Exception {
    for (RuleItem ri : ruleItems) {
      if (!ri.CheckUser(up)) return false;
    }

    return true;
  }
Esempio n. 2
0
  public static RuleLine Parse(String s) {
    int i = s.indexOf(':');
    if (i <= 0) throw new RuntimeException("Invalid RuleLine=" + s);

    RuleLine rl = new RuleLine();

    String t = s.substring(0, i).trim().toLowerCase();
    if ("include".equals(t)) rl.exeType = ExeType.include;
    else if ("exclude".equals(t)) rl.exeType = ExeType.exclude;
    else throw new RuntimeException("Invalid RuleLine=" + s + "  unknown ExeType=" + t);

    s = s.substring(i + 1);

    String[] ss = s.split("&");
    for (String tmps : ss) {
      String ts = tmps.trim();
      if (ts == null || ts.equals("")) continue;

      RuleItem ri = RuleItem.Parse(ts);
      rl.ruleItems.add(ri);
    }

    if (rl.ruleItems.size() == 0)
      throw new RuntimeException("Invalid RuleLine=" + s + " no RuleItem String found!");

    return rl;
  }
Esempio n. 3
0
  public void generateRuleItemList(BaseRuleConfigManager manager, Model model) {
    Collection<Rule> rules = manager.getMonitorRules().getRules().values();
    List<RuleItem> ruleItems = new ArrayList<RuleItem>();

    for (Rule rule : rules) {
      String id = rule.getId();
      List<MetricItem> items = rule.getMetricItems();

      if (items.size() > 0) {
        MetricItem item = items.get(0);
        String productText = item.getProductText();
        String metricText = item.getMetricItemText();
        RuleItem ruleItem = new RuleItem(id, productText, metricText);

        ruleItem.setMonitorCount(item.isMonitorCount());
        ruleItem.setMonitorAvg(item.isMonitorAvg());
        ruleItem.setMonitorSum(item.isMonitorSum());

        ruleItems.add(ruleItem);
      }
    }
    model.setRuleItems(ruleItems);
  }
Esempio n. 4
0
  public HashSet<String> GetFitUserNames() throws Exception {
    HashSet<String> rets = null;
    for (RuleItem ri : ruleItems) {
      HashSet<String> hs = ri.getFitUserNames();
      if (hs == null || hs.size() <= 0) return null;

      if (rets == null) {
        rets = hs;
        continue;
      }

      if (rets.size() <= 0) return null;
      // 交集运算
      HashSet<String> tmphs = new HashSet<String>();
      for (String s : hs) {
        if (rets.contains(s)) tmphs.add(s);
      }

      rets = tmphs;
    }

    return rets;
  }
 public synchronized boolean equals(java.lang.Object obj) {
   if (!(obj instanceof RuleItem)) return false;
   RuleItem other = (RuleItem) obj;
   if (obj == null) return false;
   if (this == obj) return true;
   if (__equalsCalc != null) {
     return (__equalsCalc == obj);
   }
   __equalsCalc = obj;
   boolean _equals;
   _equals =
       true
           && ((this.dateRuleItem == null && other.getDateRuleItem() == null)
               || (this.dateRuleItem != null && this.dateRuleItem.equals(other.getDateRuleItem())))
           && ((this.numberRuleItem == null && other.getNumberRuleItem() == null)
               || (this.numberRuleItem != null
                   && this.numberRuleItem.equals(other.getNumberRuleItem())))
           && ((this.stringRuleItem == null && other.getStringRuleItem() == null)
               || (this.stringRuleItem != null
                   && this.stringRuleItem.equals(other.getStringRuleItem())));
   __equalsCalc = null;
   return _equals;
 }