Ejemplo n.º 1
0
 /**
  * 复制指定配置项的所有属性
  *
  * @param oldCI 指定配置项
  * @throws DocumentException 复制时发生异常引发
  */
 public void cloneAttribute(CIInfo oldCI) throws DocumentException {
   if (oldCI == null) return;
   parse(
       oldCI.getOid(),
       oldCI.getParentOid(),
       oldCI.getId(),
       oldCI.getCreateTime(),
       oldCI.getLastUpdate(),
       oldCI.getStatus(),
       oldCI.getType(),
       oldCI.getAdmin(),
       oldCI.getName(),
       oldCI.getXmlData());
 }
Ejemplo n.º 2
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;
  }