Search in sources :

Example 1 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 2 with DutySchedule

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

the class GroupInfo method toString.

/**
 * Returns a String representation of the group, used primarily for
 * debugging.
 *
 * @return a string representation
 */
@Override
public String toString() {
    final StringBuilder buffer = new StringBuilder();
    buffer.append("name     = " + m_groupName + "\n");
    buffer.append("comments = " + m_groupComments + "\n");
    buffer.append("users:\n");
    for (String user : m_users) {
        buffer.append("\t" + user + "\n");
    }
    for (DutySchedule dutySchedule : m_dutySchedules) {
        buffer.append(dutySchedule.toString() + "\n");
    }
    return buffer.toString();
}
Also used : DutySchedule(org.opennms.netmgt.config.users.DutySchedule)

Example 3 with DutySchedule

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

the class UpdateUserServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    if (userSession != null) {
        User newUser = (User) userSession.getAttribute("user.modifyUser.jsp");
        try {
            UserFactory.init();
        } catch (Throwable e) {
            throw new ServletException("UpdateUserServlet:init Error initialising UserFactory " + e);
        }
        // get the rest of the user information from the form
        newUser.setFullName(request.getParameter("fullName"));
        newUser.setUserComments(request.getParameter("userComments"));
        String password = request.getParameter("password");
        if (password != null && !password.trim().equals("")) {
            final Password pass = new Password();
            pass.setEncryptedPassword(UserFactory.getInstance().encryptedPassword(password, true));
            pass.setSalt(true);
            newUser.setPassword(pass);
        }
        String tuiPin = request.getParameter("tuiPin");
        if (tuiPin != null && !tuiPin.trim().equals("")) {
            newUser.setTuiPin(tuiPin);
        }
        String email = request.getParameter(ContactType.email.toString());
        String pagerEmail = request.getParameter("pemail");
        String xmppAddress = request.getParameter(ContactType.xmppAddress.toString());
        String microblog = request.getParameter(ContactType.microblog.toString());
        String numericPage = request.getParameter("numericalService");
        String numericPin = request.getParameter("numericalPin");
        String textPage = request.getParameter("textService");
        String textPin = request.getParameter("textPin");
        String workPhone = request.getParameter(ContactType.workPhone.toString());
        String mobilePhone = request.getParameter(ContactType.mobilePhone.toString());
        String homePhone = request.getParameter(ContactType.homePhone.toString());
        newUser.clearContacts();
        Contact tmpContact = new Contact();
        tmpContact.setInfo(email);
        tmpContact.setType(ContactType.email.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(pagerEmail);
        tmpContact.setType(ContactType.pagerEmail.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(xmppAddress);
        tmpContact.setType(ContactType.xmppAddress.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(microblog);
        tmpContact.setType(ContactType.microblog.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(numericPin);
        tmpContact.setServiceProvider(numericPage);
        tmpContact.setType(ContactType.numericPage.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(textPin);
        tmpContact.setServiceProvider(textPage);
        tmpContact.setType(ContactType.textPage.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(workPhone);
        tmpContact.setType(ContactType.workPhone.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(mobilePhone);
        tmpContact.setType(ContactType.mobilePhone.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(homePhone);
        tmpContact.setType(ContactType.homePhone.toString());
        newUser.addContact(tmpContact);
        // build the duty schedule data structure
        List<Boolean> newSchedule = new ArrayList<Boolean>(7);
        ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
        Collection<String> dutySchedules = getDutySchedulesForUser(newUser);
        dutySchedules.clear();
        int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
        for (int duties = 0; duties < dutyCount; duties++) {
            newSchedule.clear();
            String deleteFlag = request.getParameter("deleteDuty" + duties);
            // don't save any duties that were marked for deletion
            if (deleteFlag == null) {
                for (int i = 0; i < 7; i++) {
                    String curDayFlag = request.getParameter("duty" + duties + days.format(i));
                    newSchedule.add(Boolean.valueOf(curDayFlag != null));
                }
                int startTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "Begin"));
                int stopTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "End"));
                DutySchedule newDuty = new DutySchedule(newSchedule, startTime, stopTime);
                dutySchedules.add(newDuty.toString());
            }
        }
        // The new list of roles will override the existing one.
        // If the new list is empty or null, that means the user should not have roles, and the existing ones should be removed.
        newUser.getRoles().clear();
        String[] configuredRoles = request.getParameterValues("configuredRoles");
        if (configuredRoles != null && configuredRoles.length > 0) {
            newUser.getRoles().clear();
            for (String role : configuredRoles) {
                newUser.addRole(role);
            }
        }
        userSession.setAttribute("user.modifyUser.jsp", newUser);
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(request.getParameter("redirect"));
    dispatcher.forward(request, response);
}
Also used : User(org.opennms.netmgt.config.users.User) HttpSession(javax.servlet.http.HttpSession) ChoiceFormat(java.text.ChoiceFormat) ArrayList(java.util.ArrayList) RequestDispatcher(javax.servlet.RequestDispatcher) Contact(org.opennms.netmgt.config.users.Contact) ServletException(javax.servlet.ServletException) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Password(org.opennms.netmgt.config.users.Password)

Example 4 with DutySchedule

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

the class AddGroupDutySchedulesServlet 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");
    Vector<Object> newSchedule = new Vector<>();
    int dutyAddCount = WebSecurityUtils.safeParseInt(request.getParameter("numSchedules"));
    for (int j = 0; j < dutyAddCount; j++) {
        // add 7 false boolean values for each day of the week
        for (int i = 0; i < 7; i++) {
            newSchedule.addElement(Boolean.FALSE);
        }
        // add two strings for the begin and end time
        newSchedule.addElement("0");
        newSchedule.addElement("0");
        group.addDutySchedule((new DutySchedule(newSchedule)).toString());
    }
    // 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.netmgt.config.groups.Group) HttpSession(javax.servlet.http.HttpSession) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Vector(java.util.Vector) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 5 with DutySchedule

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

the class GroupController method updateGroup.

private void updateGroup(HttpServletRequest request, WebGroup newGroup) {
    String[] users = request.getParameterValues("selectedUsers");
    List<String> userList = users == null ? Collections.<String>emptyList() : Arrays.asList(users);
    newGroup.setUsers(new ArrayList<String>(userList));
    String[] selectedCategories = request.getParameterValues("selectedCategories");
    List<String> categoryList = selectedCategories == null ? Collections.<String>emptyList() : Arrays.asList(selectedCategories);
    newGroup.setAuthorizedCategories(new ArrayList<String>(categoryList));
    Vector<Object> newSchedule = new Vector<>();
    ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
    Collection<String> dutySchedules = newGroup.getDutySchedules();
    dutySchedules.clear();
    int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
    for (int duties = 0; duties < dutyCount; duties++) {
        newSchedule.clear();
        String deleteFlag = request.getParameter("deleteDuty" + duties);
        // don't save any duties that were marked for deletion
        if (deleteFlag == null) {
            for (int i = 0; i < 7; i++) {
                String curDayFlag = request.getParameter("duty" + duties + days.format(i));
                if (curDayFlag != null) {
                    newSchedule.addElement(Boolean.TRUE);
                } else {
                    newSchedule.addElement(Boolean.FALSE);
                }
            }
            newSchedule.addElement(request.getParameter("duty" + duties + "Begin"));
            newSchedule.addElement(request.getParameter("duty" + duties + "End"));
            DutySchedule newDuty = new DutySchedule(newSchedule);
            dutySchedules.add(newDuty.toString());
        }
    }
}
Also used : ChoiceFormat(java.text.ChoiceFormat) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Vector(java.util.Vector)

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