Пример #1
0
    public void save() {
      try {
        Role role = (m_role == null ? new Role() : m_role);
        if (m_flags.get(DESCR)) {
          role.setDescription(super.getDescription());
        }
        if (m_flags.get(USER)) {
          role.setSupervisor(super.getDefaultUser().getName());
        }
        if (m_flags.get(GROUP)) {
          role.setMembershipGroup(super.getMembershipGroup().getName());
        }
        if (m_flags.get(NAME)) {
          role.setName(super.getName());
        }

        Collection<WebSchedEntry> newEntries = getNewEntries();
        for (WebSchedEntry entry : newEntries) {
          entry.update(role);
        }

        if (m_role != null) {
          m_groupManager.saveGroups();
        } else {
          m_groupManager.saveRole(role);
          m_role = role;
        }
      } catch (Throwable e) {
        throw new WebRolesException("Unable to save role " + getName() + ". " + e.getMessage(), e);
      }
    }
Пример #2
0
  /**
   * When this method is called group name is changed, so also is the group name belonging to the
   * view. Also overwrites the "groups.xml" file
   *
   * @param oldName a {@link java.lang.String} object.
   * @param newName a {@link java.lang.String} object.
   * @throws java.lang.Exception if any.
   */
  public synchronized void renameUser(String oldName, String newName) throws Exception {
    // Get the old data
    if (oldName == null || newName == null || oldName == "" || newName == "") {
      throw new Exception("Group Factory: Rename user.. no value ");
    } else {
      Map<String, Group> map = new LinkedHashMap<String, Group>();

      for (Group group : m_groups.values()) {
        for (ListIterator<String> userList = group.getUserCollection().listIterator();
            userList.hasNext(); ) {
          String name = userList.next();

          if (name.equals(oldName)) {
            userList.set(newName);
          }
        }
        map.put(group.getName(), group);
      }

      m_groups.clear();
      m_groups.putAll(map);

      for (Role role : m_roles.values()) {
        for (Schedule sched : role.getScheduleCollection()) {
          if (oldName.equals(sched.getName())) {
            sched.setName(newName);
          }
        }
      }

      saveGroups();
    }
  }
Пример #3
0
 ManagedRole(Role role) {
   super(role.getName());
   m_role = role;
   super.setDescription(role.getDescription());
   super.setDefaultUser(getWebUser(role.getSupervisor()));
   super.setMembershipGroup(getWebGroup(role.getMembershipGroup()));
 }
Пример #4
0
  private void initializeGroupsAndRoles(Groupinfo groupinfo) {
    Groups groups = groupinfo.getGroups();
    m_groups = new LinkedHashMap<String, Group>();
    m_oldHeader = groupinfo.getHeader();
    for (Group curGroup : groups.getGroupCollection()) {
      m_groups.put(curGroup.getName(), curGroup);
    }
    buildDutySchedules(m_groups);

    Roles roles = groupinfo.getRoles();
    m_roles = new LinkedHashMap<String, Role>();
    if (roles != null) {
      for (Role role : roles.getRoleCollection()) {
        m_roles.put(role.getName(), role);
      }
    }
  }
Пример #5
0
  /**
   * isUserScheduledForRole
   *
   * @param userId a {@link java.lang.String} object.
   * @param roleId a {@link java.lang.String} object.
   * @param time a {@link java.util.Date} object.
   * @return a boolean.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public boolean isUserScheduledForRole(String userId, String roleId, Date time)
      throws MarshalException, ValidationException, IOException {
    update();

    for (Schedule sched : getUserSchedulesForRole(userId, roleId)) {
      if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) {
        return true;
      }
    }

    // if no user is scheduled then the supervisor is schedule by default
    Role role = getRole(roleId);
    if (userId.equals(role.getSupervisor())) {
      for (Schedule sched : role.getScheduleCollection()) {
        if (BasicScheduleUtils.isTimeInSchedule(time, BasicScheduleUtils.getGroupSchedule(sched))) {
          // we found another scheduled user
          return false;
        }
      }
      return true;
    }
    return false;
  }
Пример #6
0
  /**
   * getRoleScheduleEntries
   *
   * @param roleid a {@link java.lang.String} object.
   * @param start a {@link java.util.Date} object.
   * @param end a {@link java.util.Date} object.
   * @return a {@link org.opennms.core.utils.OwnedIntervalSequence} object.
   * @throws org.exolab.castor.xml.MarshalException if any.
   * @throws org.exolab.castor.xml.ValidationException if any.
   * @throws java.io.IOException if any.
   */
  public OwnedIntervalSequence getRoleScheduleEntries(String roleid, Date start, Date end)
      throws MarshalException, ValidationException, IOException {
    update();

    OwnedIntervalSequence schedEntries = new OwnedIntervalSequence();
    Role role = getRole(roleid);
    for (int i = 0; i < role.getScheduleCount(); i++) {
      Schedule sched = (Schedule) role.getSchedule(i);
      Owner owner = new Owner(roleid, sched.getName(), i);
      schedEntries.addAll(
          BasicScheduleUtils.getIntervalsCovering(
              start, end, BasicScheduleUtils.getGroupSchedule(sched), owner));
    }

    OwnedIntervalSequence defaultEntries = new OwnedIntervalSequence(new OwnedInterval(start, end));
    defaultEntries.removeAll(schedEntries);
    Owner supervisor = new Owner(roleid, role.getSupervisor());
    for (Iterator<OwnedInterval> it = defaultEntries.iterator(); it.hasNext(); ) {
      OwnedInterval interval = it.next();
      interval.addOwner(supervisor);
    }
    schedEntries.addAll(defaultEntries);
    return schedEntries;
  }
Пример #7
0
  /**
   * Removes the user from the list of groups. Then overwrites to the "groups.xml"
   *
   * @param name a {@link java.lang.String} object.
   * @throws java.lang.Exception if any.
   */
  public synchronized void deleteUser(String name) throws Exception {
    // Check if the user exists
    if (name != null && !name.equals("")) {
      // Remove the user in the group.
      for (Group group : m_groups.values()) {
        group.removeUser(name);
      }

      for (Role role : m_roles.values()) {
        Iterator<Schedule> s = role.getScheduleCollection().iterator();
        while (s.hasNext()) {
          Schedule sched = s.next();
          if (name.equals(sched.getName())) {
            s.remove();
          }
        }
      }
    } else {
      throw new Exception("GroupFactory:delete Invalid user name:" + name);
    }

    // Saves into "groups.xml" file
    saveGroups();
  }
Пример #8
0
 /**
  * saveRole
  *
  * @param role a {@link org.opennms.netmgt.config.groups.Role} object.
  * @throws java.lang.Exception if any.
  */
 public void saveRole(Role role) throws Exception {
   m_roles.put(role.getName(), role);
   saveGroups();
 }
Пример #9
0
 public Schedule getSchedule(int schedIndex) {
   return m_role.getSchedule(schedIndex);
 }