Search in sources :

Example 51 with EmailWrapper

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

the class FeedbackSessionClosedRemindersAction method execute.

@Override
public void execute() {
    List<FeedbackSessionAttributes> sessions = logic.getFeedbackSessionsClosedWithinThePastHour();
    for (FeedbackSessionAttributes session : sessions) {
        List<EmailWrapper> emailsToBeSent = new EmailGenerator().generateFeedbackSessionClosedEmails(session);
        try {
            taskQueuer.scheduleEmailsForSending(emailsToBeSent);
            session.setSentClosedEmail(true);
            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 52 with EmailWrapper

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

the class FeedbackSessionOpeningRemindersAction method execute.

@Override
public void execute() {
    List<FeedbackSessionAttributes> sessions = logic.getFeedbackSessionsWhichNeedOpenEmailsToBeSent();
    for (FeedbackSessionAttributes session : sessions) {
        List<EmailWrapper> emailsToBeSent = new EmailGenerator().generateFeedbackSessionOpeningEmails(session);
        try {
            taskQueuer.scheduleEmailsForSending(emailsToBeSent);
            session.setSentOpenEmail(true);
            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 53 with EmailWrapper

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

the class FeedbackSessionRemindParticularUsersEmailWorkerAction method execute.

@Override
public void execute() {
    String feedbackSessionName = getNonNullRequestParamValue(ParamsNames.SUBMISSION_FEEDBACK);
    String courseId = getNonNullRequestParamValue(ParamsNames.SUBMISSION_COURSE);
    String[] usersToRemind = getNonNullRequestParamValues(ParamsNames.SUBMISSION_REMIND_USERLIST);
    String googleIdOfInstructorToNotify = getNonNullRequestParamValue(ParamsNames.USER_ID);
    try {
        FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
        List<StudentAttributes> studentsToRemindList = new ArrayList<>();
        List<InstructorAttributes> instructorsToRemindList = new ArrayList<>();
        InstructorAttributes instructorToNotify = logic.getInstructorForGoogleId(courseId, googleIdOfInstructorToNotify);
        for (String userEmail : usersToRemind) {
            StudentAttributes student = logic.getStudentForEmail(courseId, userEmail);
            if (student != null) {
                studentsToRemindList.add(student);
            }
            InstructorAttributes instructor = logic.getInstructorForEmail(courseId, userEmail);
            if (instructor != null) {
                instructorsToRemindList.add(instructor);
            }
        }
        List<EmailWrapper> emails = new EmailGenerator().generateFeedbackSessionReminderEmails(session, studentsToRemindList, instructorsToRemindList, instructorToNotify);
        taskQueuer.scheduleEmailsForSending(emails);
    } catch (Exception e) {
        log.severe("Unexpected error while sending emails: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EmailGenerator(teammates.logic.api.EmailGenerator) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) TeammatesException(teammates.common.exception.TeammatesException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 54 with EmailWrapper

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

the class InstructorCourseJoinEmailWorkerAction method execute.

@Override
public void execute() {
    String inviterId = getRequestParamValue(ParamsNames.INVITER_ID);
    Assumption.assertPostParamNotNull(ParamsNames.INVITER_ID, inviterId);
    String courseId = getRequestParamValue(ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(ParamsNames.COURSE_ID, courseId);
    String instructorEmail = getRequestParamValue(ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    AccountAttributes inviter = logic.getAccount(inviterId);
    Assumption.assertNotNull(inviter);
    CourseAttributes course = logic.getCourse(courseId);
    Assumption.assertNotNull(course);
    InstructorAttributes instructor = logic.getInstructorForEmail(courseId, instructorEmail);
    Assumption.assertNotNull(instructor);
    EmailWrapper email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor, course);
    try {
        emailSender.sendEmail(email);
    } catch (Exception e) {
        Assumption.fail("Unexpected error while sending email" + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) TeammatesException(teammates.common.exception.TeammatesException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 55 with EmailWrapper

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

the class SendEmailWorkerAction method execute.

@Override
public void execute() {
    String emailSubject = getRequestParamValue(ParamsNames.EMAIL_SUBJECT);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_SUBJECT, emailSubject);
    String emailContent = getRequestParamValue(ParamsNames.EMAIL_CONTENT);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_CONTENT, emailContent);
    String emailSenderEmail = getRequestParamValue(ParamsNames.EMAIL_SENDER);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_SENDER, emailSenderEmail);
    String emailSenderName = getRequestParamValue(ParamsNames.EMAIL_SENDERNAME);
    String emailReceiver = getRequestParamValue(ParamsNames.EMAIL_RECEIVER);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_RECEIVER, emailReceiver);
    String emailReply = getRequestParamValue(ParamsNames.EMAIL_REPLY_TO_ADDRESS);
    Assumption.assertPostParamNotNull(ParamsNames.EMAIL_REPLY_TO_ADDRESS, emailReply);
    EmailWrapper message = new EmailWrapper();
    message.setRecipient(emailReceiver);
    message.setSenderEmail(emailSenderEmail);
    if (emailSenderName != null) {
        message.setSenderName(emailSenderName);
    }
    message.setContent(emailContent);
    message.setSubject(emailSubject);
    message.setReplyTo(emailReply);
    try {
        emailSender.sendEmail(message);
    } catch (Exception e) {
        log.severe("Error while sending email via servlet: " + TeammatesException.toStringWithStackTrace(e));
        setForRetry();
    }
}
Also used : TeammatesException(teammates.common.exception.TeammatesException) 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