Search in sources :

Example 1 with Contact

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

the class BroadcastEventProcessor method userHasContactType.

boolean userHasContactType(User user, String contactType, boolean allowEmpty) {
    ConfigUtils.assertNotEmpty(user, "user");
    ConfigUtils.assertNotEmpty(contactType, "contactType");
    boolean retVal = false;
    for (Contact c : user.getContacts()) {
        if (contactType.equalsIgnoreCase(c.getType())) {
            if (allowEmpty || !"".equals(c.getInfo())) {
                retVal = true;
            }
        }
    }
    return retVal;
}
Also used : Contact(org.opennms.netmgt.config.users.Contact)

Example 2 with Contact

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

the class BroadcastEventProcessor method makeEmailTask.

/**
     * 
     */
NotificationTask makeEmailTask(long sendTime, Map<String, String> parameters, int noticeId, String address, String[] commandList, List<NotificationTask> siblings, String autoNotify) throws IOException {
    NotificationTask task = null;
    task = new NotificationTask(getNotificationManager(), getUserManager(), sendTime, parameters, siblings, autoNotify);
    User user = new User();
    user.setUserId(address);
    Contact contact = new Contact();
    contact.setType("email");
    LOG.debug("email address = {}, using contact type {}", address, contact.getType());
    contact.setInfo(address);
    user.addContact(contact);
    Command[] commands = new Command[commandList.length];
    for (int i = 0; i < commandList.length; i++) {
        commands[i] = getNotificationCommandManager().getCommand(commandList[i]);
    }
    task.setUser(user);
    task.setCommands(commands);
    task.setNoticeId(noticeId);
    task.setAutoNotify(autoNotify);
    return task;
}
Also used : User(org.opennms.netmgt.config.users.User) Command(org.opennms.netmgt.config.notificationCommands.Command) Contact(org.opennms.netmgt.config.users.Contact)

Example 3 with Contact

use of org.opennms.netmgt.config.users.Contact 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 Contact

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

the class UserManager method _setContact.

private void _setContact(final User user, final ContactType contactType, final String value) {
    if (user != null && !StringUtils.isEmpty(value)) {
        Contact contact = _getContact(user.getUserId(), contactType);
        if (contact == null) {
            contact = new Contact();
            user.addContact(contact);
        }
        contact.setInfo(value);
        contact.setType(contactType.name());
    }
}
Also used : Contact(org.opennms.netmgt.config.users.Contact)

Example 5 with Contact

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

the class NotificationsITCase method anticipateNotificationsForUsers.

protected long anticipateNotificationsForUsers(String[] users, String subject, String textMsg, long startTime, long interval) throws IOException {
    long expectedTime = startTime;
    for (int i = 0; i < users.length; i++) {
        User user = m_userManager.getUser(users[i]);
        Contact[] contacts = user.getContacts().toArray(new Contact[0]);
        for (int j = 0; j < contacts.length; j++) {
            Contact contact = contacts[j];
            if ("email".equals(contact.getType())) {
                m_anticipator.anticipateNotification(createMockNotification(expectedTime, subject, textMsg, contact.getInfo().orElse(null)));
            }
        }
        expectedTime += interval;
    }
    return expectedTime - interval;
}
Also used : User(org.opennms.netmgt.config.users.User) Contact(org.opennms.netmgt.config.users.Contact)

Aggregations

Contact (org.opennms.netmgt.config.users.Contact)5 User (org.opennms.netmgt.config.users.User)3 ChoiceFormat (java.text.ChoiceFormat)1 ArrayList (java.util.ArrayList)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletException (javax.servlet.ServletException)1 HttpSession (javax.servlet.http.HttpSession)1 Command (org.opennms.netmgt.config.notificationCommands.Command)1 DutySchedule (org.opennms.netmgt.config.users.DutySchedule)1 Password (org.opennms.netmgt.config.users.Password)1