Search in sources :

Example 1 with EmailSendingException

use of teammates.common.exception.EmailSendingException 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 2 with EmailSendingException

use of teammates.common.exception.EmailSendingException 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 3 with EmailSendingException

use of teammates.common.exception.EmailSendingException in project teammates by TEAMMATES.

the class FeedbackSubmissionEditSaveAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    setAdditionalParameters();
    verifyAccessibleForSpecificUser();
    String userEmailForCourse = getUserEmailForCourse();
    data = new FeedbackSubmissionEditPageData(account, student, sessionToken);
    data.bundle = getDataBundle(userEmailForCourse);
    Assumption.assertNotNull("Feedback session " + feedbackSessionName + " does not exist in " + courseId + ".", data.bundle);
    checkAdditionalConstraints();
    setStatusToAdmin();
    if (!isSessionOpenForSpecificUser(data.bundle.feedbackSession)) {
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SUBMISSIONS_NOT_OPEN, StatusMessageColor.WARNING));
        return createSpecificRedirectResult();
    }
    String userTeamForCourse = getUserTeamForCourse();
    String userSectionForCourse = getUserSectionForCourse();
    int numOfQuestionsToGet = data.bundle.questionResponseBundle.size();
    for (int questionIndx = 1; questionIndx <= numOfQuestionsToGet; questionIndx++) {
        String totalResponsesForQuestion = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-" + questionIndx);
        if (totalResponsesForQuestion == null) {
            // question has been skipped (not displayed).
            continue;
        }
        List<FeedbackResponseAttributes> responsesForQuestion = new ArrayList<>();
        String questionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx);
        FeedbackQuestionAttributes questionAttributes = data.bundle.getQuestionAttributes(questionId);
        if (questionAttributes == null) {
            statusToUser.add(new StatusMessage("The feedback session or questions may have changed " + "while you were submitting. Please check your responses " + "to make sure they are saved correctly.", StatusMessageColor.WARNING));
            isError = true;
            log.warning("Question not found. (deleted or invalid id passed?) id: " + questionId + " index: " + questionIndx);
            continue;
        }
        FeedbackQuestionDetails questionDetails = questionAttributes.getQuestionDetails();
        int numOfResponsesToGet = Integer.parseInt(totalResponsesForQuestion);
        Set<String> emailSet = data.bundle.getRecipientEmails(questionAttributes.getId());
        emailSet.add("");
        emailSet = SanitizationHelper.desanitizeFromHtml(emailSet);
        ArrayList<String> responsesRecipients = new ArrayList<>();
        List<String> errors = new ArrayList<>();
        for (int responseIndx = 0; responseIndx < numOfResponsesToGet; responseIndx++) {
            FeedbackResponseAttributes response = extractFeedbackResponseData(requestParameters, questionIndx, responseIndx, questionAttributes);
            if (response.feedbackQuestionType != questionAttributes.questionType) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_WRONG_QUESTION_TYPE, questionIndx));
            }
            boolean isExistingResponse = response.getId() != null;
            // came from the original set of existing responses loaded on the submission page
            if (isExistingResponse && !isExistingResponseValid(response)) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_INVALID_ID, questionIndx));
                continue;
            }
            responsesRecipients.add(response.recipient);
            // if the answer is not empty but the recipient is empty
            if (response.recipient.isEmpty() && !response.responseMetaData.getValue().isEmpty()) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_MISSING_RECIPIENT, questionIndx));
            }
            if (response.responseMetaData.getValue().isEmpty()) {
                // deletes the response since answer is empty
                addToPendingResponses(response);
            } else {
                response.giver = questionAttributes.giverType.isTeam() ? userTeamForCourse : userEmailForCourse;
                response.giverSection = userSectionForCourse;
                responsesForQuestion.add(response);
            }
        }
        List<String> questionSpecificErrors = questionDetails.validateResponseAttributes(responsesForQuestion, data.bundle.recipientList.get(questionId).size());
        errors.addAll(questionSpecificErrors);
        if (!emailSet.containsAll(responsesRecipients)) {
            errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSE_INVALID_RECIPIENT, questionIndx));
        }
        if (errors.isEmpty()) {
            for (FeedbackResponseAttributes response : responsesForQuestion) {
                addToPendingResponses(response);
            }
        } else {
            List<StatusMessage> errorMessages = new ArrayList<>();
            for (String error : errors) {
                errorMessages.add(new StatusMessage(error, StatusMessageColor.DANGER));
            }
            statusToUser.addAll(errorMessages);
            isError = true;
        }
    }
    saveNewReponses(responsesToSave);
    deleteResponses(responsesToDelete);
    updateResponses(responsesToUpdate);
    if (!isError) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, StatusMessageColor.SUCCESS));
    }
    if (isUserRespondentOfSession()) {
        appendRespondent();
    } else {
        removeRespondent();
    }
    boolean isSubmissionEmailRequested = "on".equals(getRequestParamValue(Const.ParamsNames.SEND_SUBMISSION_EMAIL));
    if (!isError && isSendSubmissionEmail && isSubmissionEmailRequested) {
        FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
        Assumption.assertNotNull(session);
        String user = account == null ? null : account.googleId;
        String unregisteredStudentEmail = student == null ? null : student.email;
        String unregisteredStudentRegisterationKey = student == null ? null : student.key;
        StudentAttributes student = null;
        InstructorAttributes instructor = null;
        if (user != null) {
            student = logic.getStudentForGoogleId(courseId, user);
            instructor = logic.getInstructorForGoogleId(courseId, user);
        }
        if (student == null && unregisteredStudentEmail != null) {
            student = StudentAttributes.builder("", unregisteredStudentEmail, unregisteredStudentEmail).withKey(unregisteredStudentRegisterationKey).build();
        }
        Assumption.assertFalse(student == null && instructor == null);
        try {
            EmailWrapper email = instructor == null ? new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student, Instant.now()) : new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor, Instant.now());
            emailSender.sendEmail(email);
        } catch (EmailSendingException e) {
            log.severe("Submission confirmation email failed to send: " + TeammatesException.toStringWithStackTrace(e));
        }
    }
    // TODO: Refactor to AjaxResult so status messages do not have to be passed by session
    return createSpecificRedirectResult();
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) ArrayList(java.util.ArrayList) FeedbackSubmissionEditPageData(teammates.ui.pagedata.FeedbackSubmissionEditPageData) EmailSendingException(teammates.common.exception.EmailSendingException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Aggregations

EmailSendingException (teammates.common.exception.EmailSendingException)3 EmailWrapper (teammates.common.util.EmailWrapper)3 EmailGenerator (teammates.logic.api.EmailGenerator)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)2 StatusMessage (teammates.common.util.StatusMessage)2 ArrayList (java.util.ArrayList)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 FeedbackQuestionDetails (teammates.common.datatransfer.questions.FeedbackQuestionDetails)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 InvalidParametersException (teammates.common.exception.InvalidParametersException)1 TeammatesException (teammates.common.exception.TeammatesException)1 AdminHomePageData (teammates.ui.pagedata.AdminHomePageData)1 FeedbackSubmissionEditPageData (teammates.ui.pagedata.FeedbackSubmissionEditPageData)1