Search in sources :

Example 26 with EmailWrapper

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

the class AdminSendEmailWorkerAction method execute.

@Override
public void execute() {
    String receiverEmail = getRequestParamValue(ParamsNames.ADMIN_EMAIL_RECEIVER);
    Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_RECEIVER, receiverEmail);
    String emailContent = getRequestParamValue(ParamsNames.ADMIN_EMAIL_CONTENT);
    String emailSubject = getRequestParamValue(ParamsNames.ADMIN_EMAIL_SUBJECT);
    if (emailContent == null || emailSubject == null) {
        String emailId = getRequestParamValue(ParamsNames.ADMIN_EMAIL_ID);
        Assumption.assertPostParamNotNull(ParamsNames.ADMIN_EMAIL_ID, emailId);
        log.info("Sending large email. Going to retrieve email content and subject from datastore.");
        AdminEmailAttributes adminEmail = logic.getAdminEmailById(emailId);
        Assumption.assertNotNull(adminEmail);
        emailContent = adminEmail.getContentValue();
        emailSubject = adminEmail.getSubject();
    }
    Assumption.assertNotNull(emailContent);
    Assumption.assertNotNull(emailSubject);
    try {
        EmailWrapper email = new EmailGenerator().generateAdminEmail(emailContent, emailSubject, receiverEmail);
        emailSender.sendEmail(email);
        log.info("Email sent to " + receiverEmail);
    } catch (Exception e) {
        log.severe("Unexpected error while sending admin emails: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) TeammatesException(teammates.common.exception.TeammatesException) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 27 with EmailWrapper

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

the class CompileLogsAction method sendEmail.

private void sendEmail(List<AppLogLine> logs) {
    // Do not send any emails if there are no severe logs; prevents spamming
    if (!logs.isEmpty()) {
        EmailWrapper message = new EmailGenerator().generateCompiledLogsEmail(logs);
        emailSender.sendReport(message);
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailWrapper(teammates.common.util.EmailWrapper)

Example 28 with EmailWrapper

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

the class FeedbackSessionClosingRemindersAction method execute.

@Override
public void execute() {
    List<FeedbackSessionAttributes> sessions = logic.getFeedbackSessionsClosingWithinTimeLimit();
    for (FeedbackSessionAttributes session : sessions) {
        List<EmailWrapper> emailsToBeSent = new EmailGenerator().generateFeedbackSessionClosingEmails(session);
        try {
            taskQueuer.scheduleEmailsForSending(emailsToBeSent);
            session.setSentClosingEmail(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 29 with EmailWrapper

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

the class FeedbackSessionPublishedEmailWorkerAction 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().generateFeedbackSessionPublishedEmails(session);
    try {
        taskQueuer.scheduleEmailsForSending(emailsToBeSent);
        session.setSentPublishedEmail(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 30 with EmailWrapper

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

the class FeedbackSessionRemindEmailWorkerAction method execute.

@Override
public void execute() {
    String feedbackSessionName = getRequestParamValue(ParamsNames.SUBMISSION_FEEDBACK);
    Assumption.assertPostParamNotNull(ParamsNames.SUBMISSION_FEEDBACK, feedbackSessionName);
    String courseId = getRequestParamValue(ParamsNames.SUBMISSION_COURSE);
    Assumption.assertPostParamNotNull(ParamsNames.SUBMISSION_COURSE, courseId);
    String instructorId = getRequestParamValue(ParamsNames.USER_ID);
    Assumption.assertPostParamNotNull(ParamsNames.USER_ID, instructorId);
    try {
        FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
        List<StudentAttributes> studentList = logic.getStudentsForCourse(courseId);
        List<InstructorAttributes> instructorList = logic.getInstructorsForCourse(courseId);
        InstructorAttributes instructorToNotify = logic.getInstructorForGoogleId(courseId, instructorId);
        List<StudentAttributes> studentsToRemindList = new ArrayList<>();
        for (StudentAttributes student : studentList) {
            if (!logic.isFeedbackSessionCompletedByStudent(session, student.email)) {
                studentsToRemindList.add(student);
            }
        }
        // Filter out instructors who have submitted the feedback session
        List<InstructorAttributes> instructorsToRemindList = new ArrayList<>();
        for (InstructorAttributes instructor : instructorList) {
            if (!logic.isFeedbackSessionCompletedByInstructor(session, instructor.email)) {
                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)

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