Search in sources :

Example 6 with EmailWrapper

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

the class AdminInstructorAccountAddAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminHomePageData data = new AdminHomePageData(account, sessionToken);
    data.instructorName = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME).trim();
    data.instructorEmail = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL).trim();
    data.instructorInstitution = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION).trim();
    data.isInstructorAddingResultForAjax = true;
    data.statusForAjax = "";
    data.instructorName = data.instructorName.trim();
    data.instructorEmail = data.instructorEmail.trim();
    data.instructorInstitution = data.instructorInstitution.trim();
    try {
        logic.verifyInputForAdminHomePage(data.instructorName, data.instructorInstitution, data.instructorEmail);
    } catch (InvalidParametersException e) {
        data.statusForAjax = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
        data.isInstructorAddingResultForAjax = false;
        statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.DANGER));
        return createAjaxResult(data);
    }
    String courseId = null;
    try {
        courseId = importDemoData(data);
    } catch (Exception e) {
        String retryUrl = Const.ActionURIs.ADMIN_INSTRUCTORACCOUNT_ADD;
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_NAME, data.instructorName);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_EMAIL, data.instructorEmail);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_INSTITUTION, data.instructorInstitution);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.SESSION_TOKEN, data.getSessionToken());
        StringBuilder errorMessage = new StringBuilder(100);
        String retryLink = "<a href=" + retryUrl + ">Exception in Importing Data, Retry</a>";
        errorMessage.append(retryLink);
        statusToUser.add(new StatusMessage(errorMessage.toString(), StatusMessageColor.DANGER));
        String message = "<span class=\"text-danger\">Servlet Action failure in AdminInstructorAccountAddAction" + "<br>" + e.getClass() + ": " + TeammatesException.toStringWithStackTrace(e) + "<br></span>";
        errorMessage.append("<br>").append(message);
        statusToUser.add(new StatusMessage("<br>" + message, StatusMessageColor.DANGER));
        statusToAdmin = message;
        data.isInstructorAddingResultForAjax = false;
        data.statusForAjax = errorMessage.toString();
        return createAjaxResult(data);
    }
    List<InstructorAttributes> instructorList = logic.getInstructorsForCourse(courseId);
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructorList.get(0).key)).withInstructorInstitution(data.instructorInstitution).toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorList.get(0).email, data.instructorName, joinLink);
    try {
        emailSender.sendEmail(email);
    } catch (EmailSendingException e) {
        log.severe("Instructor welcome email failed to send: " + TeammatesException.toStringWithStackTrace(e));
    }
    data.statusForAjax = "Instructor " + SanitizationHelper.sanitizeForHtml(data.instructorName) + " has been successfully created " + "<a href=" + joinLink + ">" + Const.JOIN_LINK + "</a>";
    statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.SUCCESS));
    statusToAdmin = "A New Instructor <span class=\"bold\">" + SanitizationHelper.sanitizeForHtmlTag(data.instructorName) + "</span> has been created.<br>" + "<span class=\"bold\">Id: </span>" + "ID will be assigned when the verification link was clicked and confirmed" + "<br>" + "<span class=\"bold\">Email: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorEmail) + "<span class=\"bold\">Institution: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorInstitution);
    return createAjaxResult(data);
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AdminHomePageData(teammates.ui.pagedata.AdminHomePageData) EmailSendingException(teammates.common.exception.EmailSendingException) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) EmailSendingException(teammates.common.exception.EmailSendingException) TeammatesException(teammates.common.exception.TeammatesException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 7 with EmailWrapper

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

the class CourseJoinAuthenticatedAbstractAction method sendCourseRegisteredEmail.

protected void sendCourseRegisteredEmail(String name, String emailAddress, boolean isInstructor, String courseId) {
    CourseAttributes course = logic.getCourse(courseId);
    EmailWrapper email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, account.googleId, isInstructor, course);
    try {
        emailSender.sendEmail(email);
    } catch (EmailSendingException e) {
        log.severe("User course register email failed to send: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailSendingException(teammates.common.exception.EmailSendingException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 8 with EmailWrapper

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

the class EmailGenerator method generateUserCourseRegisteredEmail.

/**
 * Generates the course registered email for the user with the given details in {@code course}.
 */
public EmailWrapper generateUserCourseRegisteredEmail(String name, String emailAddress, String googleId, boolean isInstructor, CourseAttributes course) {
    String emailBody = Templates.populateTemplate(EmailTemplates.USER_COURSE_REGISTER, "${userName}", SanitizationHelper.sanitizeForHtml(name), "${userType}", isInstructor ? "an instructor" : "a student", "${courseId}", SanitizationHelper.sanitizeForHtml(course.getId()), "${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()), "${googleId}", SanitizationHelper.sanitizeForHtml(googleId), "${supportEmail}", Config.SUPPORT_EMAIL);
    EmailWrapper email = getEmptyEmailAddressedToEmail(emailAddress);
    email.setSubject(String.format(EmailType.USER_COURSE_REGISTER.getSubject(), course.getName(), course.getId()));
    email.setContent(emailBody);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 9 with EmailWrapper

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

the class EmailGenerator method generateFeedbackSessionReminderEmails.

/**
 * Generates the feedback session reminder emails for the given {@code session} for {@code students}
 * and {@code instructorsToRemind}. In addition, the emails will also be forwarded to {@code instructorsToNotify}.
 */
public List<EmailWrapper> generateFeedbackSessionReminderEmails(FeedbackSessionAttributes session, List<StudentAttributes> students, List<InstructorAttributes> instructorsToRemind, InstructorAttributes instructorToNotify) {
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    String template = EmailTemplates.USER_FEEDBACK_SESSION.replace("${status}", FEEDBACK_STATUS_SESSION_OPEN);
    String additionalContactInformation = HTML_NO_ACTION_REQUIRED + getAdditionalContactInformationFragment(course);
    List<InstructorAttributes> instructorToNotifyAsList = new ArrayList<>();
    instructorToNotifyAsList.add(instructorToNotify);
    List<EmailWrapper> emails = generateFeedbackSessionEmailBasesForInstructorReminders(course, session, instructorsToRemind, template, EmailType.FEEDBACK_SESSION_REMINDER.getSubject(), additionalContactInformation);
    emails.addAll(generateFeedbackSessionEmailBases(course, session, students, instructorToNotifyAsList, template, EmailType.FEEDBACK_SESSION_REMINDER.getSubject(), FEEDBACK_ACTION_SUBMIT, additionalContactInformation));
    return emails;
}
Also used : ArrayList(java.util.ArrayList) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 10 with EmailWrapper

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

the class EmailGenerator method generateInstructorCourseJoinEmail.

/**
 * Generates the course join email for the given {@code instructor} in {@code course}.
 * Also specifies contact information of {@code inviter}.
 */
public EmailWrapper generateInstructorCourseJoinEmail(AccountAttributes inviter, InstructorAttributes instructor, CourseAttributes course) {
    String emailBody = Templates.populateTemplate(fillUpInstructorJoinFragment(instructor, EmailTemplates.USER_COURSE_JOIN), "${userName}", SanitizationHelper.sanitizeForHtml(instructor.getName()), "${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()), "${inviterName}", SanitizationHelper.sanitizeForHtml(inviter.getName()), "${inviterEmail}", SanitizationHelper.sanitizeForHtml(inviter.getEmail()), "${supportEmail}", Config.SUPPORT_EMAIL);
    EmailWrapper email = getEmptyEmailAddressedToEmail(instructor.getEmail());
    email.setSubject(String.format(EmailType.INSTRUCTOR_COURSE_JOIN.getSubject(), course.getName(), course.getId()));
    email.setContent(emailBody);
    return email;
}
Also used : 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