Search in sources :

Example 41 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class TaskQueuer method scheduleEmailsForSending.

/**
 * Schedules for the given list of emails to be sent.
 *
 * @param emails the list of emails to be sent
 */
public void scheduleEmailsForSending(List<EmailWrapper> emails) {
    if (emails.isEmpty()) {
        return;
    }
    // Equally spread out the emails to be sent over 1 hour
    // Sets interval to a maximum of 5 seconds if the interval is too large
    int oneHourInMillis = 60 * 60 * 1000;
    int emailIntervalMillis = Math.min(5000, oneHourInMillis / emails.size());
    int numberOfEmailsSent = 0;
    for (EmailWrapper email : emails) {
        long emailDelayTimer = numberOfEmailsSent * emailIntervalMillis;
        scheduleEmailForSending(email, emailDelayTimer);
        numberOfEmailsSent++;
    }
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 42 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method generateStudentCourseJoinEmail.

/**
 * Generates the course join email for the given {@code student} in {@code course}.
 */
public EmailWrapper generateStudentCourseJoinEmail(CourseAttributes course, StudentAttributes student) {
    String emailBody = Templates.populateTemplate(fillUpStudentJoinFragment(student, EmailTemplates.USER_COURSE_JOIN), "${userName}", SanitizationHelper.sanitizeForHtml(student.name), "${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()), "${coOwnersEmails}", generateCoOwnersEmailsLine(course.getId()), "${supportEmail}", Config.SUPPORT_EMAIL);
    EmailWrapper email = getEmptyEmailAddressedToEmail(student.email);
    email.setSubject(String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId()));
    email.setContent(emailBody);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 43 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method generateSubmissionConfirmationEmail.

private EmailWrapper generateSubmissionConfirmationEmail(CourseAttributes course, FeedbackSessionAttributes session, String submitUrl, String userName, String userEmail, Instant timestamp) {
    String template = EmailTemplates.USER_FEEDBACK_SUBMISSION_CONFIRMATION;
    String subject = EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject();
    String additionalContactInformation = getAdditionalContactInformationFragment(course);
    String emailBody = Templates.populateTemplate(template, "${userName}", SanitizationHelper.sanitizeForHtml(userName), "${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()), "${courseId}", SanitizationHelper.sanitizeForHtml(course.getId()), "${feedbackSessionName}", SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName()), "${deadline}", SanitizationHelper.sanitizeForHtml(session.getEndTimeString()), "${submitUrl}", submitUrl, "${timeStamp}", SanitizationHelper.sanitizeForHtml(TimeHelper.formatDateTimeForSessions(timestamp, session.getTimeZone())), "${additionalContactInformation}", additionalContactInformation);
    EmailWrapper email = getEmptyEmailAddressedToEmail(userEmail);
    email.setSubject(String.format(subject, course.getName(), session.getFeedbackSessionName()));
    email.setContent(emailBody);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 44 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method generateFeedbackSessionEmailBaseForInstructorReminders.

private EmailWrapper generateFeedbackSessionEmailBaseForInstructorReminders(CourseAttributes course, FeedbackSessionAttributes session, InstructorAttributes instructor, String template, String subject, String additionalContactInformation) {
    String submitUrl = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SUBMISSION_EDIT_PAGE).withCourseId(course.getId()).withSessionName(session.getFeedbackSessionName()).toAbsoluteString();
    String reportUrl = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_FEEDBACK_RESULTS_PAGE).withCourseId(course.getId()).withSessionName(session.getFeedbackSessionName()).toAbsoluteString();
    String emailBody = Templates.populateTemplate(template, "${userName}", SanitizationHelper.sanitizeForHtml(instructor.name), "${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()), "${courseId}", SanitizationHelper.sanitizeForHtml(course.getId()), "${feedbackSessionName}", SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName()), "${deadline}", SanitizationHelper.sanitizeForHtml(session.getEndTimeString()), "${instructorFragment}", "", "${sessionInstructions}", session.getInstructionsString(), "${submitUrl}", submitUrl, "${reportUrl}", reportUrl, "${feedbackAction}", FEEDBACK_ACTION_SUBMIT, "${additionalContactInformation}", additionalContactInformation);
    EmailWrapper email = getEmptyEmailAddressedToEmail(instructor.email);
    email.setSubject(String.format(subject, course.getName(), session.getFeedbackSessionName()));
    email.setContent(emailBody);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 45 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method generateFeedbackSessionOpeningEmails.

/**
 * Generates the feedback session opening emails for the given {@code session}.
 */
public List<EmailWrapper> generateFeedbackSessionOpeningEmails(FeedbackSessionAttributes session) {
    String template = EmailTemplates.USER_FEEDBACK_SESSION;
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    boolean isEmailNeeded = fsLogic.isFeedbackSessionForStudentsToAnswer(session);
    List<InstructorAttributes> instructors = isEmailNeeded ? instructorsLogic.getInstructorsForCourse(session.getCourseId()) : new ArrayList<InstructorAttributes>();
    List<StudentAttributes> students = isEmailNeeded ? studentsLogic.getStudentsForCourse(session.getCourseId()) : new ArrayList<StudentAttributes>();
    List<EmailWrapper> emails = generateFeedbackSessionEmailBases(course, session, students, instructors, template, EmailType.FEEDBACK_OPENING.getSubject());
    for (EmailWrapper email : emails) {
        email.setContent(email.getContent().replace("${status}", FEEDBACK_STATUS_SESSION_OPENING));
    }
    return emails;
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Aggregations

EmailWrapper (teammates.common.util.EmailWrapper)55 EmailGenerator (teammates.logic.api.EmailGenerator)24 Test (org.testng.annotations.Test)20 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)15 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)13 TeammatesException (teammates.common.exception.TeammatesException)13 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)12 ArrayList (java.util.ArrayList)6 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)3 EmailSendingException (teammates.common.exception.EmailSendingException)3 NullPostParameterException (teammates.common.exception.NullPostParameterException)3 StatusMessage (teammates.common.util.StatusMessage)3 RedirectResult (teammates.ui.controller.RedirectResult)3 Instant (java.time.Instant)2 DataBundle (teammates.common.datatransfer.DataBundle)2 FeedbackNumericalScaleQuestionDetails (teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2