Пример #1
0
 public void updatePrivilege(Privilege pvlg) throws EntityExistException {
   updator.updateByIdColumns(pvlg);
   if (pvlg.getType() == Privilege.BUSINESS_PRIVILEGE) {
     businessPrivilegeTreeChanged = true;
   } else if (pvlg.getType() == Privilege.NON_ROLE_PRIVILEGE) {
     nonRolePrivilegeTreeChanged = true;
   }
 }
Пример #2
0
  public void movePrivilege(Privilege privilege, Privilege target, int newOrderNum) {
    try {
      if (privilege.getId() <= 0) {
        throw new RalasafeException("Cannot move reserved privilege.");
      }

      privilege = getPrivilege(privilege.getId());
      target = getPrivilege(target.getId());
      if (privilege.getType() != target.getType()) {
        throw new RalasafeException("Cannot move privilege out of the tree.");
      }
      if (target.getIsLeaf()) {
        throw new RalasafeException("Canot move privilege to a leaf node.");
      }
      if (privilege == target || isCascadeChild(privilege.getId(), target.getId())) {
        throw new RalasafeException("This move will produce a cycle.");
      }

      Collection children = getChildren(target);
      ArrayList list = new ArrayList();
      if (children != null) {
        list.addAll(children);
      }

      // If it still be a child of the original parent node
      if (privilege.getPid() == target.getId()) {
        list.remove(privilege);
      }

      privilege.setPid(target.getId());

      // reset orderNum(s), and update to db
      list.add(newOrderNum, privilege);
      for (int i = 0, size = list.size(); i < size; i++) {
        Privilege p = (Privilege) list.get(i);
        p.setOrderNum(i);

        updator.updateByIdColumns(p);
      }

      if (target.getType() == Privilege.BUSINESS_PRIVILEGE) {
        businessPrivilegeTreeChanged = true;
      } else if (target.getType() == Privilege.NON_ROLE_PRIVILEGE) {
        nonRolePrivilegeTreeChanged = true;
      }
    } catch (EntityExistException e) {
      throw new DBLevelException(e);
    }
  }