/** * Sends a newly created notification message to the specific user. * * @param apiKey the API key * @param title the title * @param message the message details * @param uri the uri */ public void sendNotifcationToUser( String apiKey, String username, String title, String message, String uri, boolean save) { log.debug("sendNotifcationToUser()..."); Random random = new Random(); String id = Integer.toHexString(random.nextInt()); IQ notificationIQ = createNotificationIQ(id, apiKey, title, message, uri); ClientSession session = sessionManager.getSession(username); if (session != null) { if (session.getPresence().isAvailable()) { notificationIQ.setTo(session.getAddress()); session.deliver(notificationIQ); } } try { User user = userService.getUserByUsername(username); if (user != null && save) { saveNotification(id, apiKey, username, title, message, uri); } } catch (UserNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public List<Map<String, String>> getUserInfo() { Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(); List<Map<String, String>> list = new ArrayList<Map<String, String>>(); Map<String, String> u = null; for (ClientSession s : sessions) { if (s.getAuthToken() == null) continue; u = new HashMap<String, String>(); try { @SuppressWarnings("unchecked") List<UserGroup> groups = ((List<UserGroup>) s.getSessionData("groups")); if (groups != null && groups.size() > 0) { String gname = ""; for (UserGroup ug : groups) { gname += ug.getSGroupName() + ","; } if (gname.length() > 0) { gname = gname.substring(0, gname.length() - 1); } u.put("ugroup", gname); } else { u.put("ugroup", ""); } u.put("username", s.getUsername()); u.put("ip", s.getHostName()); u.put("id", s.getStreamID()); list.add(u); } catch (UserNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return list; }