Example #1
0
  /**
   * 检查配置项的关联关系<br>
   * 在配置项更新时调用
   *
   * @param oldInfo 原配置项
   * @return null表示成功,失败时返回错误描述
   */
  protected String checkRelations(CIInfo oldInfo) {
    Map m = new HashMap();
    if (oldInfo != null) {
      List l2 = CIManager.getCIRelations(oldInfo.getOid(), -1, true);
      for (int i = 0; i < l2.size(); i++) {
        RelationInfo r = (RelationInfo) l2.get(i);
        if (r.getObjectB() == oldInfo) {
          int n = r.getType().getReverseOid();
          if (n > 0) {
            List l0 = (List) m.get("" + n);
            if (l0 == null) {
              l0 = new ArrayList();
              m.put("" + n, l0);
            }
            l0.add("" + r.getObjectA().getOid());
          }
        }
      }
    }
    String str = getRelationDesc();
    if (str.length() > 0) {
      String[] vals = str.split(";");
      for (int i = 0, pos; i < vals.length; i++) {
        if (vals[i].length() == 0) continue;
        String s = vals[i];
        if ((pos = s.lastIndexOf("-")) == -1) continue;
        int a = Integer.parseInt(s.substring(0, pos));
        int b = Integer.parseInt(s.substring(pos + 1));
        if (b == this.oid || (oldInfo != null && oldInfo.getOid() == b)) return "不能和自己进行关联";
        CIInfo item = CIManager.getCIByOid(b);
        RelationTypeInfo rtInfo = CIManager.getRelationTypeByOid(a);
        if (item != null && rtInfo != null) {
          List l0 = (List) m.get("" + a);
          if (l0 == null) {
            l0 = new ArrayList();
            m.put("" + a, l0);
          }
          for (int j = 0; j < l0.size(); j++) {
            if (l0.get(j).equals("" + b)) return "重复的关联关系:" + rtInfo.getCaption(item);
          }
          l0.add("" + b);
          if (l0.size() > 1 && rtInfo.getFlag().endsWith("1"))
            return "关联关系只能一对一进行:" + rtInfo.getCaption(item);
        }
      }
    }

    return null;
  }
Example #2
0
 /**
  * 获取配置项的关联关系
  *
  * @see CIManager#getCIRelations(int, int, boolean)
  * @param type 关联关系类型
  * @param includeRev 是否包括逆向的关系
  * @return 返回配置项的关联关系 List<RelationInfo>
  */
 public List getRelations(int type, boolean includeRev) {
   return CIManager.getCIRelations(this.oid, type, includeRev);
 }
Example #3
0
 /**
  * 获取此配置项所有的关联关系类别
  *
  * @return 返回此类别的配置项所有的关联关系List<RelationTypeInfo>
  * @see CICategoryInfo#getRelationTypes
  */
 public List getRelationTypes() {
   CICategoryInfo info = CIManager.getCICategoryByOid(this.getType());
   return info.getRelationTypes();
 }