Search in sources :

Example 31 with EmailWrapper

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

the class FeedbackSessionUnpublishedEmailWorkerAction method execute.

@Override
public void execute() {
    String feedbackSessionName = getRequestParamValue(ParamsNames.EMAIL_FEEDBACK);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_FEEDBACK, feedbackSessionName);
    String courseId = getRequestParamValue(ParamsNames.EMAIL_COURSE);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_COURSE, courseId);
    FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
    if (session == null) {
        log.severe("Feedback session object for feedback session name: " + feedbackSessionName + " for course: " + courseId + " could not be fetched.");
        return;
    }
    List<EmailWrapper> emailsToBeSent = new EmailGenerator().generateFeedbackSessionUnpublishedEmails(session);
    try {
        taskQueuer.scheduleEmailsForSending(emailsToBeSent);
        session.setSentPublishedEmail(false);
        logic.updateFeedbackSession(session);
    } catch (Exception e) {
        log.severe("Unexpected error: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EmailGenerator(teammates.logic.api.EmailGenerator) TeammatesException(teammates.common.exception.TeammatesException) EmailWrapper(teammates.common.util.EmailWrapper)

Example 32 with EmailWrapper

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

the class EmailGeneratorTest method testGenerateStudentCourseJoinEmail.

@Test
public void testGenerateStudentCourseJoinEmail() throws IOException {
    ______TS("student course join email");
    CourseAttributes course = CourseAttributes.builder("idOfTypicalCourse1", "Course Name", ZoneId.of("UTC")).build();
    StudentAttributes student = StudentAttributes.builder("", "Student Name", "student@email.tmt").withKey("skxxxxxxxxxks").build();
    EmailWrapper email = new EmailGenerator().generateStudentCourseJoinEmail(course, student);
    String subject = String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithCoOwnersJoinEmail.html");
    ______TS("student course with co-owners join email after Google ID reset");
    email = new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student);
    subject = String.format(EmailType.STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithCoOwnersRejoinAfterGoogleIdResetEmail.html");
    ______TS("student course (without co-owners) join email");
    course = CourseAttributes.builder("course-id", "Course Name", ZoneId.of("UTC")).build();
    email = new EmailGenerator().generateStudentCourseJoinEmail(course, student);
    subject = String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithoutCoOwnersJoinEmail.html");
    ______TS("student course (without-co-owners) join email after Google ID reset");
    email = new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student);
    subject = String.format(EmailType.STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student.email, subject, "/studentCourseWithoutCoOwnersRejoinAfterGoogleIdResetEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 33 with EmailWrapper

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

the class EmailGeneratorTest method testGenerateStudentCourseJoinEmail_testSanitization.

@Test
public void testGenerateStudentCourseJoinEmail_testSanitization() throws IOException {
    ______TS("student course join email: sanitization required");
    CourseAttributes course = coursesLogic.getCourse("idOfTestingSanitizationCourse");
    StudentAttributes student1 = studentsLogic.getStudentForEmail(course.getId(), "normal@sanitization.tmt");
    EmailWrapper email = new EmailGenerator().generateStudentCourseJoinEmail(course, student1);
    String subject = String.format(EmailType.STUDENT_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/studentCourseJoinEmailTestingSanitization.html");
    ______TS("student course join email after Google ID reset: sanitization required");
    email = new EmailGenerator().generateStudentCourseRejoinEmailAfterGoogleIdReset(course, student1);
    subject = String.format(EmailType.STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/studentCourseRejoinAfterGoogleIdResetEmailTestingSanitization.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 34 with EmailWrapper

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

the class EmailGeneratorTest method testGenerateFeedbackSessionEmails.

@Test
public void testGenerateFeedbackSessionEmails() throws IOException {
    FeedbackSessionAttributes session = fsLogic.getFeedbackSession("First feedback session", "idOfTypicalCourse1");
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    StudentAttributes student1 = studentsLogic.getStudentForEmail(course.getId(), "student1InCourse1@gmail.tmt");
    InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail(course.getId(), "instructor1@course1.tmt");
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(session.getCourseId());
    List<InstructorAttributes> instructors = instructorsLogic.getInstructorsForCourse(session.getCourseId());
    InstructorAttributes instructorToNotify = instructorsLogic.getInstructorForGoogleId(session.getCourseId(), instructor1.getGoogleId());
    ______TS("feedback session opening emails");
    List<EmailWrapper> emails = new EmailGenerator().generateFeedbackSessionOpeningEmails(session);
    assertEquals(10, emails.size());
    String subject = String.format(EmailType.FEEDBACK_OPENING.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionOpeningEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionOpeningEmailForInstructor.html");
    ______TS("feedback session reminders");
    emails = new EmailGenerator().generateFeedbackSessionReminderEmails(session, students, instructors, instructorToNotify);
    // (5 instructors, 5 students reminded) and (1 instructor to be notified)
    assertEquals(11, emails.size());
    subject = String.format(EmailType.FEEDBACK_SESSION_REMINDER.getSubject(), course.getName(), session.getFeedbackSessionName());
    String lineInEmailCopyToInstructor = "The email below has been sent to students of course:";
    // Verify the student reminder email
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionReminderEmailForStudent.html");
    // Verify the Student email copy send to the instructor
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionReminderEmailCopyToInstructor.html", lineInEmailCopyToInstructor);
    // Verify the instructor reminder email
    String lineInEmailToInstructor = "/page/instructorFeedbackSubmissionEditPage?courseid=idOfTypicalCourse1&fsname=First+feedback+session";
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionReminderEmailForInstructor.html", lineInEmailToInstructor);
    ______TS("feedback session closing alerts");
    emails = new EmailGenerator().generateFeedbackSessionClosingEmails(session);
    assertEquals(8, emails.size());
    subject = String.format(EmailType.FEEDBACK_CLOSING.getSubject(), course.getName(), session.getFeedbackSessionName());
    // student1 has completed the feedback session and closing alert is only sent for those who are
    // yet to complete, so we resort to student5
    StudentAttributes student5 = studentsLogic.getStudentForEmail(course.getId(), "student5InCourse1@gmail.tmt");
    for (EmailWrapper email : emails) {
        if (email.getRecipient().equals(student1.email)) {
            fail("student1 has completed the session and are not supposed to receive email");
        }
    }
    verifyEmailReceivedCorrectly(emails, student5.email, subject, "/sessionClosingEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionClosingEmailForInstructor.html");
    ______TS("feedback session closed alerts");
    emails = new EmailGenerator().generateFeedbackSessionClosedEmails(session);
    assertEquals(10, emails.size());
    subject = String.format(EmailType.FEEDBACK_CLOSED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionClosedEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionClosedEmailForInstructor.html");
    ______TS("feedback session published alerts");
    emails = new EmailGenerator().generateFeedbackSessionPublishedEmails(session);
    assertEquals(10, emails.size());
    subject = String.format(EmailType.FEEDBACK_PUBLISHED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionPublishedEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionPublishedEmailForInstructor.html");
    ______TS("feedback session unpublished alerts");
    emails = new EmailGenerator().generateFeedbackSessionUnpublishedEmails(session);
    assertEquals(10, emails.size());
    subject = String.format(EmailType.FEEDBACK_UNPUBLISHED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionUnpublishedEmailForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionUnpublishedEmailForInstructor.html");
    ______TS("send summary of all feedback sessions of course email");
    EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(session.getCourseId(), student1);
    subject = String.format(EmailType.STUDENT_EMAIL_CHANGED.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/summaryOfFeedbackSessionsOfCourseEmailForStudent.html");
    ______TS("feedback session submission email");
    Instant time = TimeHelper.parseInstant("2016-09-04 05:30 AM +0000");
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, student1.email, subject, "/sessionSubmissionConfirmationEmailPositiveTimeZone.html");
    setTimeZoneButMaintainLocalDate(session, ZoneId.of("Pacific/Marquesas"));
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, instructor1.email, subject, "/sessionSubmissionConfirmationEmailNegativeTimeZone.html");
    setTimeZoneButMaintainLocalDate(session, ZoneId.of("UTC"));
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, instructor1.email, subject, "/sessionSubmissionConfirmationEmailZeroTimeZone.html");
    ______TS("no email alerts sent for sessions not answerable/viewable for students");
    FeedbackSessionAttributes privateSession = fsLogic.getFeedbackSession("Private feedback session", "idOfTypicalCourse2");
    emails = new EmailGenerator().generateFeedbackSessionOpeningEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionClosingEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionClosedEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionPublishedEmails(privateSession);
    assertTrue(emails.isEmpty());
    emails = new EmailGenerator().generateFeedbackSessionUnpublishedEmails(privateSession);
    assertTrue(emails.isEmpty());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EmailGenerator(teammates.logic.api.EmailGenerator) Instant(java.time.Instant) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 35 with EmailWrapper

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

the class EmailGeneratorTest method testGenerateUserCourseRegisterEmail.

@Test
public void testGenerateUserCourseRegisterEmail() throws IOException {
    ______TS("student course register email");
    CourseAttributes course = CourseAttributes.builder("idOfTypicalCourse1", "Course Name", ZoneId.of("UTC")).build();
    String name = "User Name";
    String emailAddress = "user@email.tmt";
    String googleId = "user.googleid";
    EmailWrapper email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, googleId, false, course);
    String subject = String.format(EmailType.USER_COURSE_REGISTER.getSubject(), course.getName(), course.getId());
    verifyEmail(email, emailAddress, subject, "/studentCourseRegisterEmail.html");
    ______TS("instructor course register email");
    email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, googleId, true, course);
    subject = String.format(EmailType.USER_COURSE_REGISTER.getSubject(), course.getName(), course.getId());
    verifyEmail(email, emailAddress, subject, "/instructorCourseRegisterEmail.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

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