@Override public void commit() throws Exception { Set<UUID> userIDs = new HashSet<UUID>(); // Users Integer userCount = getParameterInteger("users"); for (int i = 0; i < userCount; i++) { Pair<String, String> kvp = getParameterTypeAhead("user_" + i); if (kvp != null && !Util.isEmpty(kvp.getKey())) { User u = UserStore.getInstance().loadByLoginName(kvp.getKey()); if (u != null) { userIDs.add(u.getID()); } } } // Groups Integer groupCount = getParameterInteger("groups"); for (int i = 0; i < groupCount; i++) { Pair<String, String> kvp = getParameterTypeAhead("group_" + i); if (kvp != null && !Util.isEmpty(kvp.getKey())) { UserGroup lg = UserGroupStore.getInstance().loadByName(kvp.getKey()); if (lg != null) { userIDs.addAll(UserUserGroupLinkStore.getInstance().getUsersForGroup(lg.getID())); } } } // Content String subject = getParameterString("subject"); String body = getParameterString("body"); Map<String, String> notifParams = new ParameterMap(AdHocNotif.PARAM_SUBJECT, subject).plus(AdHocNotif.PARAM_BODY, body); // Send Server fed = ServerStore.getInstance().loadFederation(); Date date = getParameterDate("date"); this.messageCount = new HashMap<String, Integer>(); for (String channel : Channel.getPush()) { if (isParameter(channel) == true && fed.isChannelEnabled(channel) == true) { for (UUID userID : userIDs) { Notifier.send(channel, date, userID, null, AdHocNotif.COMMAND, notifParams); // !$! Consider delayed schedule Integer count = this.messageCount.get(channel); if (count == null) { this.messageCount.put(channel, 1); } else { this.messageCount.put(channel, (1 + count)); } } } } }
@Override public void validate() throws Exception { int countAddressees = 0; // Users Integer userCount = getParameterInteger("users"); for (int i = 0; i < userCount; i++) { Pair<String, String> kvp = getParameterTypeAhead("user_" + i); if (kvp != null && !Util.isEmpty(kvp.getKey())) { User u = UserStore.getInstance().loadByLoginName(kvp.getKey()); if (u == null) { throw new WebFormException( "user_" + i, getString("admin:AdHocMessage.InvalidLoginName", kvp.getValue())); } countAddressees++; } } // Groups Integer groupCount = getParameterInteger("groups"); for (int i = 0; i < groupCount; i++) { Pair<String, String> kvp = getParameterTypeAhead("group_" + i); if (kvp != null && !Util.isEmpty(kvp.getKey())) { UserGroup lg = UserGroupStore.getInstance().loadByName(kvp.getKey()); if (lg == null) { throw new WebFormException( "group_" + i, getString("admin:AdHocMessage.InvalidGroupName", kvp.getValue())); } countAddressees++; } } // Check number of recipients if (countAddressees == 0) { throw new WebFormException( new String[] {"groups", "users"}, getString("admin:AdHocMessage.NoRecipients")); } // Channels int countChannels = 0; for (String channel : Channel.getAll()) { if (isParameter(channel)) { countChannels++; } } if (countChannels == 0) { throw new WebFormException(Channel.getAll(), getString("common:Errors.MissingField")); } // Subject and body boolean mandateSubject = isParameter(Channel.EMAIL); validateParameterString("subject", mandateSubject ? 1 : 0, 128); String html = getParameterRichEdit("body"); if (Util.isEmptyHTML(html)) { throw new WebFormException("body", getString("common:Errors.MissingField")); } // Date validateParameterDate("date"); }