Search in sources :

Example 6 with DutySchedule

use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.

the class GroupManager method isGroupOnDuty.

/**
     * Determines if a group is on duty at a given time. If a group has no duty schedules
     * listed in the configuration file, that group is assumed to always be on duty.
     *
     * @param group the group whose duty schedule we want
     * @param time the time to check for a duty schedule
     * @return boolean, true if the group is on duty, false otherwise.
     * @throws java.io.IOException if any.
     */
public boolean isGroupOnDuty(String group, Calendar time) throws IOException {
    update();
    //if the group has no duty schedules then it is on duty
    if (!m_dutySchedules.containsKey(group)) {
        return true;
    }
    List<DutySchedule> dutySchedules = m_dutySchedules.get(group);
    for (DutySchedule curSchedule : dutySchedules) {
        if (curSchedule.isInSchedule(time)) {
            return true;
        }
    }
    return false;
}
Also used : DutySchedule(org.opennms.netmgt.config.users.DutySchedule)

Example 7 with DutySchedule

use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.

the class GroupManager method buildDutySchedules.

/**
     * Builds a mapping between groups and duty schedules. These are used when
     * determining to send a notice to a given group. This helps speed up the decision process.
     * @param groups the map of groups parsed from the XML configuration file
     */
private static void buildDutySchedules(Map<String, Group> groups) {
    m_dutySchedules = new HashMap<String, List<DutySchedule>>();
    for (final Entry<String, Group> entry : groups.entrySet()) {
        final String key = entry.getKey();
        final Group curGroup = entry.getValue();
        if (curGroup.getDutySchedules().size() > 0) {
            final List<DutySchedule> dutyList = new ArrayList<DutySchedule>();
            for (final String duty : curGroup.getDutySchedules()) {
                dutyList.add(new DutySchedule(duty));
            }
            m_dutySchedules.put(key, dutyList);
        }
    }
}
Also used : Group(org.opennms.netmgt.config.groups.Group) OnmsGroup(org.opennms.netmgt.model.OnmsGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) OnmsGroupList(org.opennms.netmgt.model.OnmsGroupList) List(java.util.List) DutySchedule(org.opennms.netmgt.config.users.DutySchedule)

Example 8 with DutySchedule

use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.

the class GroupManager method groupNextOnDuty.

/**
     * Determines when a group is next on duty. If a group has no duty schedules
     * listed in the configuration file, that group is assumed to always be on duty.
     *
     * @param group the group whose duty schedule we want
     * @param time the time to check for a duty schedule
     * @return long, the time in milliseconds until the group is next on duty
     * @throws java.io.IOException if any.
     */
public long groupNextOnDuty(String group, Calendar time) throws IOException {
    long next = -1;
    update();
    //if the group has no duty schedules then it is on duty
    if (!m_dutySchedules.containsKey(group)) {
        return 0;
    }
    List<DutySchedule> dutySchedules = m_dutySchedules.get(group);
    for (int i = 0; i < dutySchedules.size(); i++) {
        DutySchedule curSchedule = dutySchedules.get(i);
        long tempnext = curSchedule.nextInSchedule(time);
        if (tempnext < next || next == -1) {
            LOG.debug("isGroupOnDuty: On duty in {} millisec from schedule {}", i, tempnext);
            next = tempnext;
        }
    }
    return next;
}
Also used : DutySchedule(org.opennms.netmgt.config.users.DutySchedule)

Example 9 with DutySchedule

use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.

the class UserManager method isUserOnDuty.

/**
     * Determines if a user is on duty at a given time. If a user has no duty
     * schedules listed in the configuration file, that user is assumed to always be on
     * duty.
     *
     * @param user
     *            the user id
     * @param time
     *            the time to check for a duty schedule
     * @return boolean, true if the user is on duty, false otherwise.
     * @throws java.io.IOException if any.
     */
public boolean isUserOnDuty(final String user, final Calendar time) throws IOException {
    update();
    m_readLock.lock();
    try {
        // if the user has no duty schedules then he is on duty
        if (!m_dutySchedules.containsKey(user))
            return true;
        for (final DutySchedule curSchedule : m_dutySchedules.get(user)) {
            if (curSchedule.isInSchedule(time)) {
                return true;
            }
        }
    } finally {
        m_readLock.unlock();
    }
    return false;
}
Also used : DutySchedule(org.opennms.netmgt.config.users.DutySchedule)

Example 10 with DutySchedule

use of org.opennms.netmgt.config.users.DutySchedule in project opennms by OpenNMS.

the class RemoveGroupDutySchedulesServlet method doPost.

/** {@inheritDoc} */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(true);
    Group group = (Group) userSession.getAttribute("group.modifyGroup.jsp");
    GroupInfo groupInfo = group.getGroupInfo();
    List<DutySchedule> dutySchedules = groupInfo.getDutySchedules();
    int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
    for (int i = 0; i < dutyCount; i++) {
        String curDuty = request.getParameter("deleteDuty" + i);
        if (curDuty != null) {
            dutySchedules.remove(i);
        }
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/groups/modifyGroup.jsp");
    dispatcher.forward(request, response);
}
Also used : Group(org.opennms.web.admin.groups.parsers.Group) GroupInfo(org.opennms.web.admin.groups.parsers.GroupInfo) HttpSession(javax.servlet.http.HttpSession) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

DutySchedule (org.opennms.netmgt.config.users.DutySchedule)14 HttpSession (javax.servlet.http.HttpSession)7 Vector (java.util.Vector)5 RequestDispatcher (javax.servlet.RequestDispatcher)5 ChoiceFormat (java.text.ChoiceFormat)4 ArrayList (java.util.ArrayList)4 Group (org.opennms.netmgt.config.groups.Group)3 User (org.opennms.netmgt.config.users.User)3 List (java.util.List)2 WebGroup (org.opennms.web.group.WebGroup)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ServletException (javax.servlet.ServletException)1 Contact (org.opennms.netmgt.config.users.Contact)1 Password (org.opennms.netmgt.config.users.Password)1 OnmsGroup (org.opennms.netmgt.model.OnmsGroup)1 OnmsGroupList (org.opennms.netmgt.model.OnmsGroupList)1 OnmsUser (org.opennms.netmgt.model.OnmsUser)1 OnmsUserList (org.opennms.netmgt.model.OnmsUserList)1 Group (org.opennms.web.admin.groups.parsers.Group)1 GroupInfo (org.opennms.web.admin.groups.parsers.GroupInfo)1