/** {@inheritDoc} */ public void notifyCourseRequestRequester( String requestEmail, String supportEmailContent, String termTitle) { User currentUser = userDirectoryService.getCurrentUser(); String currentUserDisplayName = currentUser != null ? currentUser.getDisplayName() : ""; String currentUserDisplayId = currentUser != null ? currentUser.getDisplayId() : ""; String currentUserId = currentUser != null ? currentUser.getId() : ""; String currentUserEmail = currentUser != null ? currentUser.getEmail() : ""; ResourceLoader rb = new ResourceLoader(currentUserId, "UserNotificationProvider"); String from = requestEmail; String to = currentUserEmail; String headerTo = to; String replyTo = to; // message subject String message_subject = rb.getString("java.sitereqfrom") + " " + currentUserDisplayName + " " + rb.getString("java.for") + " " + termTitle; StringBuffer buf = new StringBuffer(); buf.append(rb.getString("java.isbeing") + " "); buf.append(rb.getString("java.meantime") + "\n\n"); buf.append(rb.getString("java.copy") + "\n\n"); buf.append(supportEmailContent); buf.append("\n" + rb.getString("java.wish") + " " + requestEmail); emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null); }
/** * Adds attendees to an existing event with a given role Common logic for addAttendeesToEvent and * addChairAttendeestoEvent * * @param vevent the VEvent to add the attendess too * @param attendees list of Users that have been invited to the event * @param role the role with which to add each user * @return the VEvent for the given event or null if there was an error */ protected VEvent addAttendeesToEventWithRole(VEvent vevent, List<User> attendees, Role role) { if (!isIcsEnabled()) { log.debug( "ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties"); return null; } // add attendees to event with 'required participant' role if (attendees != null) { for (User u : attendees) { Attendee a = new Attendee(createMailURI(u.getEmail())); a.getParameters().add(role); a.getParameters().add(new Cn(u.getDisplayName())); a.getParameters().add(PartStat.ACCEPTED); a.getParameters().add(Rsvp.FALSE); vevent.getProperties().add(a); } } if (log.isDebugEnabled()) { log.debug("VEvent with attendees:" + vevent); } return vevent; }
protected Map<String, String> getCurrentUserFields() { Map<String, String> rv = new HashMap<String, String>(); String userRef = developerHelperService.getCurrentUserReference(); if (userRef != null) { User user = (User) developerHelperService.fetchEntity(userRef); try { String email = user.getEmail(); if (email == null) email = ""; String first = user.getFirstName(); if (first == null) first = ""; String last = user.getLastName(); if (last == null) last = ""; rv.put(CURRENT_USER_EMAIL, email); rv.put(CURRENT_USER_FIRST_NAME, first); rv.put(CURRENT_USER_LAST_NAME, last); rv.put(CURRENT_USER_DISPLAY_NAME, user.getDisplayName()); rv.put(CURRENT_USER_DISPLAY_ID, user.getDisplayId()); rv.put("currentUserDispalyId", user.getDisplayId()); } catch (Exception e) { log.warn("Failed to get current user replacements: " + userRef, e); } } /*NoN user fields */ rv.put(LOCAL_SAKAI_NAME, serverConfigurationService.getString("ui.service", "Sakai")); rv.put( LOCAL_SAKAI_SUPPORT_MAIL, serverConfigurationService.getString( "support.email", "help@" + serverConfigurationService.getServerUrl())); rv.put(LOCAL_SAKAI_URL, serverConfigurationService.getServerUrl()); return rv; }
private String getCurrentUserEmailAddress() { User currentUser = userDirectoryService.getCurrentUser(); String email = currentUser != null ? currentUser.getEmail() : null; if (email == null || email.length() == 0) { email = getSetupRequestEmailAddress(); } return email; }
/** * Format the announcement notification from address. * * @param event The event that matched criteria to cause the notification. * @return the announcement notification from address. */ protected String getFromAddress(Event event) { Reference ref = EntityManager.newReference(event.getResource()); // SAK-14831, yorkadam, make site title reflected in 'From:' name instead of default // ServerConfigurationService.getString("ui.service", "Sakai"); String siteId = (getSite() != null) ? getSite() : ref.getContext(); String title = ""; try { Site site = SiteService.getSite(siteId); title = site.getTitle(); } catch (Exception ignore) { } String userEmail = "no-reply@" + ServerConfigurationService.getServerName(); String userDisplay = ServerConfigurationService.getString("ui.service", "Sakai"); // String no_reply = "From: \"" + userDisplay + "\" <" + userEmail + ">"; // String no_reply_withTitle = "From: \"" + title + "\" <" + userEmail + ">"; String from = "From: Sakai"; // fallback value if (title != null && !title.equals("")) { from = "From: \"" + title + "\" <" + userEmail + ">"; } else { String fromVal = getFrom(event); // should not return null but better safe than sorry if (fromVal != null) { from = fromVal; } } // get the message AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity(); String userId = msg.getAnnouncementHeader().getFrom().getDisplayId(); // checks if "from" email id has to be included? and whether the notification is a delayed // notification?. SAK-13512 // SAK-20988 - emailFromReplyable@org.sakaiproject.event.api.NotificationService is deprecated boolean notificationEmailFromReplyable = ServerConfigurationService.getBoolean("notify.email.from.replyable", false); if (notificationEmailFromReplyable && from.contains("no-reply@") && userId != null) { try { User u = UserDirectoryService.getUser(userId); userDisplay = u.getDisplayName(); userEmail = u.getEmail(); if ((userEmail != null) && (userEmail.trim().length()) == 0) userEmail = null; } catch (UserNotDefinedException e) { } // some fallback positions if (userEmail == null) userEmail = "no-reply@" + ServerConfigurationService.getServerName(); if (userDisplay == null) userDisplay = ServerConfigurationService.getString("ui.service", "Sakai"); from = "From: \"" + userDisplay + "\" <" + userEmail + ">"; } return from; }
/** @return return the current user */ public EmailUser getCurrentUser() { EmailUser euser = null; User curU = null; try { curU = m_userDirectoryService.getCurrentUser(); euser = new EmailUser(curU.getId(), curU.getDisplayName(), curU.getEmail()); } catch (Exception e) { log.debug("Exception: Mailtool.getCurrentUser(), " + e.getMessage()); } return euser; }
public void notifyNewUserEmail(User user, String newUserPassword, String siteTitle) { String from = getSetupRequestEmailAddress(); String productionSiteName = serverConfigurationService.getString("ui.service", ""); String newUserEmail = user.getEmail(); String to = newUserEmail; String headerTo = newUserEmail; String replyTo = newUserEmail; String content = ""; if (from != null && newUserEmail != null) { /* * $userName * $localSakaiName * $currentUserName * $localSakaiUrl */ Map<String, String> replacementValues = new HashMap<String, String>(); replacementValues.put("userName", user.getDisplayName()); replacementValues.put( "localSakaiName", serverConfigurationService.getString("ui.service", "")); replacementValues.put( "currentUserName", userDirectoryService.getCurrentUser().getDisplayName()); replacementValues.put("userEid", user.getEid()); replacementValues.put("localSakaiUrl", serverConfigurationService.getPortalUrl()); replacementValues.put("newPassword", newUserPassword); replacementValues.put("siteName", siteTitle); replacementValues.put("productionSiteName", productionSiteName); RenderedTemplate template = emailTemplateService.getRenderedTemplateForUser( NOTIFY_NEW_USER, user.getReference(), replacementValues); if (template == null) return; content = template.getRenderedMessage(); String message_subject = template.getRenderedSubject(); List<String> headers = new ArrayList<String>(); headers.add("Precedence: bulk"); emailService.send(from, to, message_subject, content, headerTo, replyTo, headers); } }
/** {@inheritDoc} */ public void notifyNewUserEmail(User user, String newUserPassword, Site site) { ResourceLoader rb = new ResourceLoader("UserNotificationProvider"); // set the locale to individual receipient's setting rb.setContextLocale(rb.getLocale(user.getId())); String from = getSetupRequestEmailAddress(); String productionSiteName = serverConfigurationService.getString("ui.service", ""); String productionSiteUrl = serverConfigurationService.getPortalUrl(); String newUserEmail = user.getEmail(); String to = newUserEmail; String headerTo = newUserEmail; // UVa: change Reply-To to be the From (collab support) address String replyTo = from; String message_subject = productionSiteName + " " + rb.getString("java.newusernoti"); String content = ""; if (from != null && newUserEmail != null) { StringBuilder buf = new StringBuilder(); buf.setLength(0); // email body buf.append(user.getDisplayName() + ":\n\n"); buf.append( rb.getString("java.addedto") + " " + productionSiteName + " (" + productionSiteUrl + ") "); buf.append(rb.getString("java.simpleby") + " "); buf.append(userDirectoryService.getCurrentUser().getDisplayName() + ". \n\n"); buf.append(rb.getString("java.passwordis1") + "\n" + newUserPassword + "\n\n"); buf.append(rb.getString("java.passwordis2") + "\n\n"); content = buf.toString(); emailService.send(from, to, message_subject, content, headerTo, replyTo, null); } }
/** * @see org.sakaiproject.api.common.edu.person.SakaiPersonManager#create(java.lang.String, * java.lang.String, org.sakaiproject.api.common.type.Type) */ public SakaiPerson create(String userId, Type recordType) { if (LOG.isDebugEnabled()) { LOG.debug("create(String " + userId + ", Type " + recordType + ")"); } if (userId == null || userId.length() < 1) throw new IllegalArgumentException("Illegal agentUuid argument passed!"); ; // a null uid is valid if (!isSupportedType(recordType)) throw new IllegalArgumentException("Illegal recordType argument passed!"); SakaiPersonImpl spi = new SakaiPersonImpl(); persistableHelper.createPersistableFields(spi); spi.setUuid(IdManager.createUuid()); spi.setAgentUuid(userId); spi.setUid(userId); spi.setTypeUuid(recordType.getUuid()); spi.setLocked(Boolean.valueOf(false)); this.getHibernateTemplate().save(spi); // log the event String ref = getReference(spi); eventTrackingService.post(eventTrackingService.newEvent("profile.new", ref, true)); // do not do this for system profiles if (serverConfigurationService.getBoolean("profile.updateUser", false)) { try { User u = userDirectoryService.getUser(userId); spi.setGivenName(u.getFirstName()); spi.setSurname(u.getLastName()); spi.setMail(u.getEmail()); } catch (UserNotDefinedException uue) { LOG.error("User " + userId + "doesn't exist"); } } LOG.debug("return spi;"); return spi; }
protected void processRoster( HttpServletRequest request, HttpServletResponse response, String lti_message_type, Site site, String siteId, String placement_id, Properties pitch, String user_id, Map<String, Object> theMap) throws java.io.IOException { // Check for permission in placement String allowRoster = pitch.getProperty(LTIService.LTI_ALLOWROSTER); if (!"on".equals(allowRoster)) { doError( request, response, theMap, "outcomes.invalid", "lti_message_type=" + lti_message_type, null); return; } String roleMapProp = pitch.getProperty("rolemap"); String releaseName = pitch.getProperty(LTIService.LTI_SENDNAME); String releaseEmail = pitch.getProperty(LTIService.LTI_SENDEMAILADDR); String assignment = pitch.getProperty("assignment"); String allowOutcomes = ServerConfigurationService.getString( SakaiBLTIUtil.BASICLTI_OUTCOMES_ENABLED, SakaiBLTIUtil.BASICLTI_OUTCOMES_ENABLED_DEFAULT); if (!"true".equals(allowOutcomes)) allowOutcomes = null; String maintainRole = site.getMaintainRole(); SakaiBLTIUtil.pushAdvisor(); boolean success = false; try { List<Map<String, Object>> lm = new ArrayList<Map<String, Object>>(); Set<Member> members = site.getMembers(); Map<String, String> roleMap = SakaiBLTIUtil.convertRoleMapPropToMap(roleMapProp); for (Member member : members) { Map<String, Object> mm = new TreeMap<String, Object>(); Role role = member.getRole(); String ims_user_id = member.getUserId(); mm.put("/user_id", ims_user_id); String ims_role = "Learner"; // If there is a role mapping, it has precedence over site.update if (roleMap.containsKey(role.getId())) { ims_role = roleMap.get(role.getId()); } else if (ComponentManager.get(AuthzGroupService.class) .isAllowed(ims_user_id, SiteService.SECURE_UPDATE_SITE, "/site/" + siteId)) { ims_role = "Instructor"; } // Using "/role" is inconsistent with to // http://developers.imsglobal.org/ext_membership.html. It // should be roles. If we can determine that nobody is using // the role tag, we should remove it. mm.put("/role", ims_role); mm.put("/roles", ims_role); User user = null; if ("true".equals(allowOutcomes) && assignment != null) { user = UserDirectoryService.getUser(ims_user_id); String placement_secret = pitch.getProperty(LTIService.LTI_PLACEMENTSECRET); String result_sourcedid = SakaiBLTIUtil.getSourceDID(user, placement_id, placement_secret); if (result_sourcedid != null) mm.put("/lis_result_sourcedid", result_sourcedid); } if ("on".equals(releaseName) || "on".equals(releaseEmail)) { if (user == null) user = UserDirectoryService.getUser(ims_user_id); if ("on".equals(releaseName)) { mm.put("/person_name_given", user.getFirstName()); mm.put("/person_name_family", user.getLastName()); mm.put("/person_name_full", user.getDisplayName()); } if ("on".equals(releaseEmail)) { mm.put("/person_contact_email_primary", user.getEmail()); mm.put("/person_sourcedid", user.getEid()); } } Collection groups = site.getGroupsWithMember(ims_user_id); if (groups.size() > 0) { List<Map<String, Object>> lgm = new ArrayList<Map<String, Object>>(); for (Iterator i = groups.iterator(); i.hasNext(); ) { Group group = (Group) i.next(); Map<String, Object> groupMap = new HashMap<String, Object>(); groupMap.put("/id", group.getId()); groupMap.put("/title", group.getTitle()); groupMap.put("/set", new HashMap(groupMap)); lgm.add(groupMap); } mm.put("/groups/group", lgm); } lm.add(mm); } theMap.put("/message_response/members/member", lm); success = true; } catch (Exception e) { doError(request, response, theMap, "memberships.fail", "", e); } finally { SakaiBLTIUtil.popAdvisor(); } if (!success) return; theMap.put("/message_response/statusinfo/codemajor", "Success"); theMap.put("/message_response/statusinfo/severity", "Status"); theMap.put("/message_response/statusinfo/codeminor", "fullsuccess"); String theXml = XMLMap.getXML(theMap, true); PrintWriter out = response.getWriter(); out.println(theXml); M_log.debug(theXml); }
/** {@inheritDoc} */ public boolean notifyCourseRequestAuthorizer( String instructorId, String requestEmail, String replyToEmail, String termTitle, String requestSectionInfo, String siteTitle, String siteId, String additionalInfo, String serverName) { try { User instructor = userDirectoryService.getUserByEid(instructorId); ResourceLoader rb = new ResourceLoader(instructorId, "UserNotificationProvider"); StringBuffer buf = new StringBuffer(); String to = instructor.getEmail(); String from = requestEmail; String headerTo = to; String replyTo = replyToEmail; User currentUser = userDirectoryService.getCurrentUser(); String currentUserDisplayName = currentUser != null ? currentUser.getDisplayName() : ""; // message subject String message_subject = rb.getString("java.sitereqfrom") + " " + currentUserDisplayName + " " + rb.getString("java.for") + " " + termTitle; buf.append(rb.getString("java.hello") + " \n\n"); buf.append(rb.getString("java.receiv") + " " + currentUserDisplayName + ", "); buf.append(rb.getString("java.who") + "\n"); if (!termTitle.isEmpty()) { buf.append(termTitle + "\n"); } // course section information buf.append(requestSectionInfo); buf.append(rb.getString("java.sitetitle") + "\t" + siteTitle + "\n"); buf.append(rb.getString("java.siteid") + "\t" + siteId + "\n\n"); buf.append(rb.getString("java.siteinstr") + "\n" + additionalInfo + "\n\n"); buf.append( rb.getString("java.according") + " " + currentUserDisplayName + " " + rb.getString("java.record")); buf.append( " " + rb.getString("java.canyou") + " " + currentUserDisplayName + " " + rb.getString("java.assoc") + "\n\n"); buf.append( rb.getString("java.respond") + " " + currentUserDisplayName + rb.getString("java.appoint") + "\n\n"); buf.append(rb.getString("java.thanks") + "\n"); buf.append(serverName + " " + rb.getString("java.support")); try { // send the email emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null); return true; } catch (Exception ee) { M_log.warn( this + " problem occurs with sending course request email to authorizer " + instructorId); return false; } } catch (Exception e) { M_log.warn(this + " cannot find user " + instructorId); return false; } }
public void notifyAddedParticipant(boolean newNonOfficialAccount, User user, String siteTitle) { String from = serverConfigurationService.getBoolean(NOTIFY_FROM_CURRENT_USER, false) ? getCurrentUserEmailAddress() : getSetupRequestEmailAddress(); // we need to get the template if (from != null) { String productionSiteName = serverConfigurationService.getString("ui.service", ""); String emailId = user.getEmail(); String to = emailId; String headerTo = emailId; String replyTo = emailId; Map<String, String> rv = new HashMap<String, String>(); rv.put("productionSiteName", productionSiteName); String content = ""; /* * $userName * $localSakaiName * $currentUserName * $localSakaiUrl */ Map<String, String> replacementValues = new HashMap<String, String>(); replacementValues.put("userName", user.getDisplayName()); replacementValues.put("userEid", user.getEid()); replacementValues.put( "localSakaiName", serverConfigurationService.getString("ui.service", "")); replacementValues.put( "currentUserName", userDirectoryService.getCurrentUser().getDisplayName()); replacementValues.put("localSakaiUrl", serverConfigurationService.getPortalUrl()); String nonOfficialAccountUrl = serverConfigurationService.getString("nonOfficialAccount.url", null); replacementValues.put( "hasNonOfficialAccountUrl", nonOfficialAccountUrl != null ? Boolean.TRUE.toString().toLowerCase() : Boolean.FALSE.toString().toLowerCase()); replacementValues.put("nonOfficialAccountUrl", nonOfficialAccountUrl); replacementValues.put("siteName", siteTitle); replacementValues.put("productionSiteName", productionSiteName); replacementValues.put( "newNonOfficialAccount", Boolean.valueOf(newNonOfficialAccount).toString().toLowerCase()); M_log.debug("getting template: sitemange.notifyAddedParticipant"); RenderedTemplate template = null; try { template = emailTemplateService.getRenderedTemplateForUser( NOTIFY_ADDED_PARTICIPANT, user.getReference(), replacementValues); if (template == null) return; } catch (Exception e) { e.printStackTrace(); return; } List<String> headers = new ArrayList<String>(); headers.add("Precedence: bulk"); content = template.getRenderedMessage(); emailService.send( from, to, template.getRenderedSubject(), content, headerTo, replyTo, headers); } // if }
/** {@inheritDoc} */ public String notifyCourseRequestSupport( String requestEmail, String serverName, String request, String termTitle, int requestListSize, String requestSectionInfo, String officialAccountName, String siteTitle, String siteId, String additionalInfo, boolean requireAuthorizer, String authorizerNotified, String authorizerNotNotified) { ResourceLoader rb = new ResourceLoader("UserNotificationProvider"); User currentUser = userDirectoryService.getCurrentUser(); String currentUserDisplayName = currentUser != null ? currentUser.getDisplayName() : ""; String currentUserDisplayId = currentUser != null ? currentUser.getDisplayId() : ""; String currentUserEmail = currentUser != null ? currentUser.getEmail() : ""; // To Support String from = currentUserEmail; String to = requestEmail; String headerTo = requestEmail; String replyTo = currentUserEmail; StringBuffer buf = new StringBuffer(); buf.append( rb.getString("java.to") + "\t\t" + serverName + " " + rb.getString("java.supp") + "\n"); buf.append("\n" + rb.getString("java.from") + "\t" + currentUserDisplayName + "\n"); if ("new".equals(request)) { buf.append(rb.getString("java.subj") + "\t" + rb.getString("java.sitereq") + "\n"); } else { buf.append(rb.getString("java.subj") + "\t" + rb.getString("java.sitechreq") + "\n"); } SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance()); dform.applyPattern("yyyy-MM-dd HH:mm:ss"); String dateDisplay = dform.format(new Date()); buf.append(rb.getString("java.date") + "\t" + dateDisplay + "\n\n"); if ("new".equals(request)) { buf.append( rb.getString("java.approval") + " " + serverName + " " + rb.getString("java.coursesite") + " "); } else { buf.append( rb.getString("java.approval2") + " " + serverName + " " + rb.getString("java.coursesite") + " "); } if (!termTitle.isEmpty()) { buf.append(termTitle); } if (requestListSize > 1) { buf.append( " " + rb.getString("java.forthese") + " " + requestListSize + " " + rb.getString("java.sections") + "\n\n"); } else { buf.append(" " + rb.getString("java.forthis") + "\n\n"); } // the course section information buf.append(requestSectionInfo); buf.append( rb.getString("java.name") + "\t" + currentUserDisplayName + " (" + officialAccountName + " " + currentUserDisplayId + ")\n"); buf.append(rb.getString("java.email") + "\t" + replyTo + "\n"); buf.append(rb.getString("java.sitetitle") + "\t" + siteTitle + "\n"); buf.append(rb.getString("java.siteid") + "\t" + siteId + "\n\n"); buf.append(rb.getString("java.siteinstr") + "\n" + additionalInfo + "\n\n"); if (requireAuthorizer) { // if authorizer is required if (!authorizerNotified.isEmpty()) { buf.append( rb.getString("java.authoriz") + " " + authorizerNotified + " " + rb.getString("java.asreq")); } if (!authorizerNotNotified.isEmpty()) { buf.append( rb.getString("java.thesiteemail") + " " + authorizerNotNotified + " " + rb.getString("java.asreq")); } } String content = buf.toString(); // message subject String message_subject = rb.getString("java.sitereqfrom") + " " + currentUserDisplayName + " " + rb.getString("java.for") + " " + termTitle; try { emailService.send(from, to, message_subject, content, headerTo, replyTo, null); return content; } catch (Exception e) { M_log.warn( this + " problem in send site request email to support for " + currentUserDisplayName); return ""; } }
/** {@inheritDoc} */ public void notifyAddedParticipant(boolean newNonOfficialAccount, User user, Site site) { ResourceLoader rb = new ResourceLoader(user.getId(), "UserNotificationProvider"); String from = serverConfigurationService.getBoolean(NOTIFY_FROM_CURRENT_USER, false) ? getCurrentUserEmailAddress() : getSetupRequestEmailAddress(); if (from != null) { String productionSiteName = serverConfigurationService.getString("ui.service", ""); String productionSiteUrl = serverConfigurationService.getPortalUrl(); String nonOfficialAccountUrl = serverConfigurationService.getString("nonOfficialAccount.url", null); String emailId = user.getEmail(); String to = emailId; String headerTo = emailId; // UVa: change Reply-To to be the user adding the new participant String replyTo = from; String message_subject = productionSiteName + " " + rb.getString("java.sitenoti"); String content = ""; StringBuilder buf = new StringBuilder(); buf.setLength(0); // email bnonOfficialAccounteen newly added nonOfficialAccount account // and other users buf.append(user.getDisplayName() + ":\n\n"); buf.append( rb.getString("java.following") + " " + productionSiteName + " " + rb.getString("java.simplesite") + "\n"); buf.append(site.getTitle() + "\n"); buf.append(rb.getString("java.simpleby") + " "); buf.append(userDirectoryService.getCurrentUser().getDisplayName() + ". \n\n"); if (newNonOfficialAccount) { buf.append(serverConfigurationService.getString("nonOfficialAccountInstru", "") + "\n"); if (nonOfficialAccountUrl != null) { buf.append(rb.getString("java.togeta1") + "\n" + nonOfficialAccountUrl + "\n"); buf.append(rb.getString("java.togeta2") + "\n\n"); } buf.append(rb.getString("java.once") + " " + productionSiteName + ": \n"); buf.append( rb.getString("java.loginhow1") + " " + productionSiteName + ": " + productionSiteUrl + "\n"); buf.append(rb.getString("java.loginhow2") + "\n"); buf.append(rb.getString("java.loginhow3") + "\n"); } else { buf.append(rb.getString("java.tolog") + "\n"); buf.append( rb.getString("java.loginhow1") + " " + productionSiteName + ": " + productionSiteUrl + "\n"); buf.append(rb.getString("java.loginhow2") + "\n"); buf.append(rb.getString("java.loginhow3u") + "\n"); } buf.append(rb.getString("java.tabscreen")); content = buf.toString(); emailService.send(from, to, message_subject, content, headerTo, replyTo, null); } // if }
public List /* EmailGroup */ getEmailGroupsByType(String roletypefilter) { List /* EmailGroup */ thegroups = new ArrayList(); List emailroles = this.getEmailRoles(); for (Iterator i = emailroles.iterator(); i.hasNext(); ) { EmailRole emailrole = (EmailRole) i.next(); if (emailrole.roletype.equals("role") && roletypefilter.equals("role")) { String realmid = emailrole.getRealmid(); AuthzGroup therealm = null; try { therealm = m_realmService.getAuthzGroup(realmid); } catch (GroupNotDefinedException e1) { log.debug("GroupNotDefinedException: Mailtool.getEmailGroups() #1, ", e1); return thegroups; } catch (Exception e2) { log.debug("Exception: Mailtool.getEmailGroups() #1, " + e2.getMessage()); return thegroups; } Set users = therealm.getUsersHasRole(emailrole.getRoleid()); List /* EmailUser */ mailusers = new ArrayList(); for (Iterator j = users.iterator(); j.hasNext(); ) { String userid = (String) j.next(); try { User theuser = m_userDirectoryService.getUser(userid); String firstname_for_display = ""; String lastname_for_display = ""; if (theuser.getFirstName().trim().equals("")) { if (theuser.getEmail().trim().equals("") && theuser.getLastName().trim().equals("")) firstname_for_display = theuser.getDisplayId(); // fix for SAK-7539 else firstname_for_display = theuser.getEmail(); // fix for SAK-7356 } else { firstname_for_display = theuser.getFirstName(); } lastname_for_display = theuser.getLastName(); EmailUser emailuser = new EmailUser( theuser.getId(), firstname_for_display, lastname_for_display, theuser.getEmail()); mailusers.add(emailuser); } catch (Exception e) { log.debug("Exception: OptionsBean.getEmailGroupsByType() #2, " + e.getMessage()); } } Collections.sort(mailusers); EmailGroup thegroup = new EmailGroup(emailrole, mailusers); thegroups.add(thegroup); } else if (emailrole.roletype.equals("group") && roletypefilter.equals("group")) { String sid = getSiteID(); Site currentSite = null; try { currentSite = siteService.getSite(sid); } catch (IdUnusedException e1) { log.debug("IdUnusedException: Mailtool.getEmailGroups() #3, ", e1); return thegroups; } catch (Exception e2) { log.debug("Exception: Mailtool.getEmailGroups() #3, " + e2.getMessage()); return thegroups; } Collection groups = currentSite.getGroups(); Group agroup = null; for (Iterator groupIterator = groups.iterator(); groupIterator.hasNext(); ) { agroup = (Group) groupIterator.next(); String groupname = agroup.getTitle(); if (emailrole.getRoleid().equals(groupname)) break; } Set users2 = agroup.getUsersHasRole(groupAwareRoleFound); List mailusers2 = new ArrayList(); for (Iterator k = users2.iterator(); k.hasNext(); ) { String userid2 = (String) k.next(); try { User theuser2 = m_userDirectoryService.getUser(userid2); String firstname_for_display = ""; String lastname_for_display = ""; if (theuser2.getFirstName().trim().equals("")) { if (theuser2.getEmail().trim().equals("") && theuser2.getLastName().trim().equals("")) firstname_for_display = theuser2.getDisplayId(); // fix for SAK-7539 else firstname_for_display = theuser2.getEmail(); // fix for SAK-7356 } else { firstname_for_display = theuser2.getFirstName(); } lastname_for_display = theuser2.getLastName(); EmailUser emailuser2 = new EmailUser( theuser2.getId(), firstname_for_display, lastname_for_display, theuser2.getEmail()); mailusers2.add(emailuser2); } catch (Exception e) { log.debug("Exception: OptionsBean.getEmailGroupsByType() #3-1, " + e.getMessage()); } } Collections.sort(mailusers2); EmailGroup thegroup2 = new EmailGroup(emailrole, mailusers2); thegroups.add(thegroup2); } // else else if (emailrole.roletype.equals("section") && roletypefilter.equals("section")) { String sid = getSiteID(); Site currentSite = null; try { currentSite = siteService.getSite(sid); } catch (IdUnusedException e1) { log.debug("IdUnusedException: Mailtool.getEmailGroups() #4, ", e1); return thegroups; } catch (Exception e2) { log.debug("Exception: Mailtool.getEmailGroups() #4, " + e2.getMessage()); return thegroups; } Collection groups = currentSite.getGroups(); Group agroup = null; for (Iterator groupIterator = groups.iterator(); groupIterator.hasNext(); ) { agroup = (Group) groupIterator.next(); String groupname = agroup.getTitle(); if (emailrole.getRoleid().equals(groupname)) break; } Set users2 = agroup.getUsersHasRole(groupAwareRoleFound); List mailusers2 = new ArrayList(); for (Iterator k = users2.iterator(); k.hasNext(); ) { String userid2 = (String) k.next(); try { User theuser2 = m_userDirectoryService.getUser(userid2); String firstname_for_display = ""; String lastname_for_display = ""; if (theuser2.getFirstName().trim().equals("")) { if (theuser2.getEmail().trim().equals("") && theuser2.getLastName().trim().equals("")) firstname_for_display = theuser2.getDisplayId(); // fix for SAK-7539 else firstname_for_display = theuser2.getEmail(); // fix for SAK-7356 } else { firstname_for_display = theuser2.getFirstName(); } lastname_for_display = theuser2.getLastName(); EmailUser emailuser2 = new EmailUser( theuser2.getId(), firstname_for_display, lastname_for_display, theuser2.getEmail()); mailusers2.add(emailuser2); } catch (Exception e) { log.debug("Exception: OptionsBean.getEmailGroupsByType() #4-1, " + e.getMessage()); } } Collections.sort(mailusers2); EmailGroup thegroup2 = new EmailGroup(emailrole, mailusers2); thegroups.add(thegroup2); } // else else if (emailrole.roletype.equals("role_groupaware") && roletypefilter.equals("role_groupaware")) { String realmid = emailrole.getRealmid(); AuthzGroup therealm = null; try { therealm = m_realmService.getAuthzGroup(realmid); } catch (GroupNotDefinedException e1) { log.debug("GroupNotDefinedException: Mailtool.getEmailGroupsByType() #5, ", e1); return thegroups; } catch (Exception e2) { log.debug("Exception: Mailtool.getEmailGroupsByType() #5, " + e2.getMessage()); return thegroups; } Set users = therealm.getUsersHasRole(emailrole.getRoleid()); List /* EmailUser */ mailusers = new ArrayList(); for (Iterator j = users.iterator(); j.hasNext(); ) { String userid = (String) j.next(); try { User theuser = m_userDirectoryService.getUser(userid); String firstname_for_display = ""; String lastname_for_display = ""; if (theuser.getFirstName().trim().equals("")) { if (theuser.getEmail().trim().equals("") && theuser.getLastName().trim().equals("")) firstname_for_display = theuser.getDisplayId(); // fix for SAK-7539 else firstname_for_display = theuser.getEmail(); // fix for SAK-7356 } else { firstname_for_display = theuser.getFirstName(); } lastname_for_display = theuser.getLastName(); EmailUser emailuser = new EmailUser( theuser.getId(), firstname_for_display, lastname_for_display, theuser.getEmail()); mailusers.add(emailuser); } catch (Exception e) { log.debug("Exception: OptionsBean.getEmailGroupsByType() #5-1, " + e.getMessage()); } } Collections.sort(mailusers); EmailGroup thegroup = new EmailGroup(emailrole, mailusers); thegroups.add(thegroup); } // else } return thegroups; }
public void sendRenderedMessages( String key, List<String> userReferences, Map<String, String> replacementValues, String fromEmail, String fromName) { Map<EmailTemplateLocaleUsers, RenderedTemplate> tMap = this.getRenderedTemplates(key, userReferences, replacementValues); Set<Entry<EmailTemplateLocaleUsers, RenderedTemplate>> set = tMap.entrySet(); Iterator<Entry<EmailTemplateLocaleUsers, RenderedTemplate>> it = set.iterator(); while (it.hasNext()) { Entry<EmailTemplateLocaleUsers, RenderedTemplate> entry = it.next(); RenderedTemplate rt = entry.getValue(); EmailTemplateLocaleUsers etlu = entry.getKey(); List<User> toAddress = getUsersEmail(etlu.getUserIds()); log.info( "sending template " + key + " for locale " + etlu.getLocale().toString() + " to " + toAddress.size() + " users"); StringBuilder message = new StringBuilder(); message.append(MIME_ADVISORY); if (rt.getRenderedMessage() != null) { message.append(BOUNDARY_LINE); message.append("Content-Type: text/plain; charset=iso-8859-1\n"); message.append(rt.getRenderedMessage()); } if (rt.getRenderedHtmlMessage() != null) { // append the HMTL part message.append(BOUNDARY_LINE); message.append("Content-Type: text/html; charset=iso-8859-1\n"); message.append(rt.getRenderedHtmlMessage()); } message.append(TERMINATION_LINE); // we need to manually construct the headers List<String> headers = new ArrayList<String>(); // the template may specify a from address if (StringUtils.isNotBlank(rt.getFrom())) { headers.add("From: \"" + rt.getFrom()); } else { headers.add("From: \"" + fromName + "\" <" + fromEmail + ">"); } // Add a To: header of either the recipient (if only 1), or the sender (if multiple) String toName = fromName; String toEmail = fromEmail; if (toAddress.size() == 1) { User u = toAddress.get(0); toName = u.getDisplayName(); toEmail = u.getEmail(); } headers.add("To: \"" + toName + "\" <" + toEmail + ">"); // SAK-21742 we need the rendered subject headers.add("Subject: " + rt.getRenderedSubject()); headers.add("Content-Type: multipart/alternative; boundary=\"" + MULTIPART_BOUNDARY + "\""); headers.add("Mime-Version: 1.0"); headers.add("Precedence: bulk"); String body = message.toString(); log.debug("message body " + body); emailService.sendToUsers(toAddress, headers, body); } }
/** {@inheritDoc} */ public void notifySiteCreation( Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail) { // send emails String id = site.getId(); String title = site.getTitle(); SimpleDateFormat dform = ((SimpleDateFormat) DateFormat.getDateInstance()); dform.applyPattern("yyyy-MM-dd HH:mm:ss"); String dateDisplay = dform.format(new Date()); User currentUser = userDirectoryService.getCurrentUser(); String currentUserName = currentUser.getDisplayName(); String currentUserId = currentUser.getId(); String currentUserEmail = currentUser.getEmail(); ResourceLoader rb = new ResourceLoader("UserNotificationProvider"); String message_subject = courseSite ? rb.getString("java.official") + " " + currentUserName + " " + rb.getString("java.for") + " " + termTitle : rb.getString("java.site.createdBy") + " " + currentUserName; String from = currentUser.getEmail(); String to = requestEmail; String headerTo = requestEmail; String replyTo = currentUserEmail; StringBuilder buf = new StringBuilder(); buf.append( "\n" + rb.getString("java.fromwork") + " " + serverConfigurationService.getServerName() + " " + rb.getString("java.supp") + ":\n\n"); buf.append(courseSite ? rb.getString("java.off") : rb.getString("java.site")); buf.append(" '" + title + "' (id " + id + "), " + rb.getString("java.wasset") + " "); buf.append( currentUserName + " (" + currentUserId + ", " + rb.getString("java.email2") + " " + replyTo + ") "); buf.append(rb.getString("java.on") + " " + dateDisplay); if (courseSite) { buf.append(rb.getString("java.for") + " " + termTitle + ", "); } if (notifySites != null) { int nbr_sections = notifySites.size(); if (nbr_sections > 1) { buf.append( rb.getString("java.withrost") + " " + Integer.toString(nbr_sections) + " " + rb.getString("java.sections") + "\n\n"); } else { buf.append(" " + rb.getString("java.withrost2") + "\n\n"); } for (int i = 0; i < nbr_sections; i++) { String course = (String) notifySites.get(i); buf.append(rb.getString("java.course2") + " " + course + "\n"); } } emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null); // send a confirmation email to site creator from = requestEmail; to = currentUserEmail; headerTo = currentUserEmail; replyTo = serverConfigurationService.getString( "setup.request", "no-reply@" + serverConfigurationService.getServerName()); String content = rb.getFormattedMessage( "java.siteCreation.confirmation", new Object[] {title, serverConfigurationService.getServerName()}); content += "\n\n" + buf.toString(); emailService.send(from, to, message_subject, content, headerTo, replyTo, null); }