/** * @param question the current question-reply question * @param users list of users to notify * @throws QuestionReplyException */ private void notifyTemplateReply(Question question, Reply reply, UserDetail[] users) throws QuestionReplyException { try { UserDetail user = getUserDetail(getUserId()); String senderName = user.getFirstName() + " " + user.getLastName(); String subject = getString("questionReply.notification") + getComponentLabel(); // String message = senderName + intro + " \n" + content + "\n \n"; // Get default resource bundle String resource = "com.stratelia.webactiv.survey.multilang.surveyBundle"; ResourceLocator message = new ResourceLocator(resource, I18NHelper.defaultLanguage); // Initialize templates Map<String, SilverpeasTemplate> templates = new HashMap<String, SilverpeasTemplate>(); NotificationMetaData notifMetaData = new NotificationMetaData(NotificationParameters.NORMAL, subject, templates, "reply"); List<String> languages = DisplayI18NHelper.getLanguages(); for (String language : languages) { // initialize new resource locator message = new ResourceLocator(resource, language); // Create a new silverpeas template SilverpeasTemplate template = getNewTemplate(); template.setAttribute("UserDetail", user); template.setAttribute("userName", senderName); template.setAttribute("QuestionDetail", question); template.setAttribute("ReplyDetail", reply); template.setAttribute("replyTitle", reply.getTitle()); template.setAttribute("replyContent", reply.getContent()); templates.put(language, template); notifMetaData.addLanguage( language, message.getString("questionReply.notification", "") + getComponentLabel(), ""); } notifMetaData.setSender(getUserId()); notifMetaData.addUserRecipients(users); notifMetaData.setSource(getSpaceLabel() + " - " + getComponentLabel()); // notifMetaData.setLink(question._getURL()); getNotificationSender().notifyUser(notifMetaData); } catch (Exception e) { throw new QuestionReplyException( "QuestionReplySessionController.notify()", SilverpeasException.ERROR, "questionReply.EX_NOTIFICATION_MANAGER_FAILED", "", e); } }
/** * Returns the string value of this field : the user names (FirstName LastName,FirstName * LastName,FirstName LastName, ...) */ public String getValue() { String theUserCardIds = getUserCardIds(); // userCardId-userId,userCardId-userId // .... if (!StringUtil.isDefined(theUserCardIds)) { return theUserCardIds; } try { theUserCardIds += ","; String userCardIdUserId = null; int index = -1; String userCardId = null; String userId = null; UserDetail user = null; StringBuffer names = new StringBuffer(""); int begin = 0; int end = 0; end = theUserCardIds.indexOf(',', begin); while (end != -1) { userCardIdUserId = theUserCardIds.substring(begin, end); // userCardId-userId index = userCardIdUserId.indexOf("-"); userCardId = userCardIdUserId.substring(0, index); userId = userCardIdUserId.substring(index + 1); user = organizationController.getUserDetail(userId); if (user == null) { names.append("userCardId(").append(userCardId).append(")"); } else { names.append(user.getFirstName()).append(" ").append(user.getLastName()); } names.append(","); begin = end + 1; end = theUserCardIds.indexOf(',', begin); } if (!names.toString().equals("")) { names = names.deleteCharAt(names.length() - 1); } return names.toString(); } catch (Exception e) { SilverTrace.error("form", "PdcUserField.getValue", "root.MSG_GEN_PARAM_VALUE", "", e); return null; } }