Search in sources :

Example 61 with StatusMessage

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

the class InstructorCourseStudentDetailsEditSaveAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENT_EMAIL, studentEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
    if (student == null) {
        return redirectWithError(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_EDIT, "Student <span class=\"bold\">" + studentEmail + "</span> in " + "Course <span class=\"bold\">[" + courseId + "]</span> not found.", courseId);
    }
    student.name = getRequestParamValue(Const.ParamsNames.STUDENT_NAME);
    student.email = getRequestParamValue(Const.ParamsNames.NEW_STUDENT_EMAIL);
    student.team = getRequestParamValue(Const.ParamsNames.TEAM_NAME);
    student.section = getRequestParamValue(Const.ParamsNames.SECTION_NAME);
    student.comments = getRequestParamValue(Const.ParamsNames.COMMENTS);
    boolean hasSection = logic.hasIndicatedSections(courseId);
    student.name = SanitizationHelper.sanitizeName(student.name);
    student.email = SanitizationHelper.sanitizeEmail(student.email);
    student.team = SanitizationHelper.sanitizeName(student.team);
    student.section = SanitizationHelper.sanitizeName(student.section);
    student.comments = SanitizationHelper.sanitizeTextField(student.comments);
    try {
        StudentAttributes originalStudentAttribute = logic.getStudentForEmail(courseId, studentEmail);
        student.updateWithExistingRecord(originalStudentAttribute);
        boolean isSectionChanged = student.isSectionChanged(originalStudentAttribute);
        boolean isTeamChanged = student.isTeamChanged(originalStudentAttribute);
        boolean isEmailChanged = student.isEmailChanged(originalStudentAttribute);
        if (isSectionChanged) {
            logic.validateSectionsAndTeams(Arrays.asList(student), courseId);
        } else if (isTeamChanged) {
            logic.validateTeams(Arrays.asList(student), courseId);
        }
        logic.updateStudent(studentEmail, student);
        boolean isSessionSummarySendEmail = getRequestParamAsBoolean(Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK);
        if (isEmailChanged) {
            logic.resetStudentGoogleId(student.email, courseId);
            if (isSessionSummarySendEmail) {
                try {
                    EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(courseId, student);
                    emailSender.sendEmail(email);
                } catch (Exception e) {
                    log.severe("Error while sending session summary email" + TeammatesException.toStringWithStackTrace(e));
                }
            }
        }
        statusToUser.add(new StatusMessage(isSessionSummarySendEmail && isEmailChanged ? Const.StatusMessages.STUDENT_EDITED_AND_EMAIL_SENT : Const.StatusMessages.STUDENT_EDITED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Student <span class=\"bold\">" + studentEmail + "'s</span> details in " + "Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Email: " + student.email + "<br>New Team: " + student.team + "<br>" + "Comments: " + student.comments;
        RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE);
        result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
        return result;
    } catch (InvalidParametersException | EnrollException e) {
        setStatusForException(e);
        String newEmail = student.email;
        student.email = studentEmail;
        boolean isOpenOrPublishedEmailSentForTheCourse = logic.isOpenOrPublishedEmailSentForTheCourse(courseId);
        InstructorCourseStudentDetailsEditPageData data = new InstructorCourseStudentDetailsEditPageData(account, sessionToken, student, newEmail, hasSection, isOpenOrPublishedEmailSentForTheCourse);
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, data);
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EnrollException(teammates.common.exception.EnrollException) InstructorCourseStudentDetailsEditPageData(teammates.ui.pagedata.InstructorCourseStudentDetailsEditPageData) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EnrollException(teammates.common.exception.EnrollException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) TeammatesException(teammates.common.exception.TeammatesException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) StatusMessage(teammates.common.util.StatusMessage)

Example 62 with StatusMessage

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

the class InstructorCoursesPageAction method execute.

@Override
public ActionResult execute() {
    /* Explanation: First, we extract any parameters from the request object.
         * e.g., idOfCourseToDelete = getRequestParam(Const.ParamsNames.COURSE_ID);
         * After that, we may verify parameters.
         * e.g. Assumption.assertNotNull(courseId);
         * In this Action, there are no parameters.*/
    /* Explanation: Next, check if the user has rights to execute the action.*/
    gateKeeper.verifyInstructorPrivileges(account);
    /* Explanation: This is a 'show page' type action. Therefore, we
         * prepare the matching PageData object, accessing the Logic
         * component if necessary.*/
    InstructorCoursesPageData data = new InstructorCoursesPageData(account, sessionToken);
    String isUsingAjax = getRequestParamValue(Const.ParamsNames.IS_USING_AJAX);
    data.setUsingAjax(isUsingAjax != null);
    Map<String, InstructorAttributes> instructorsForCourses = new HashMap<>();
    List<CourseAttributes> allCourses = new ArrayList<>();
    List<CourseAttributes> activeCourses = new ArrayList<>();
    List<CourseAttributes> archivedCourses = new ArrayList<>();
    if (data.isUsingAjax()) {
        // Get list of InstructorAttributes that belong to the user.
        List<InstructorAttributes> instructorList = logic.getInstructorsForGoogleId(data.account.googleId);
        for (InstructorAttributes instructor : instructorList) {
            instructorsForCourses.put(instructor.courseId, instructor);
        }
        // Get corresponding courses of the instructors.
        allCourses = logic.getCoursesForInstructor(instructorList);
        List<String> archivedCourseIds = logic.getArchivedCourseIds(allCourses, instructorsForCourses);
        for (CourseAttributes course : allCourses) {
            if (archivedCourseIds.contains(course.getId())) {
                archivedCourses.add(course);
            } else {
                activeCourses.add(course);
            }
        }
        // Sort CourseDetailsBundle lists by course id
        CourseAttributes.sortById(activeCourses);
        CourseAttributes.sortById(archivedCourses);
    }
    data.init(activeCourses, archivedCourses, instructorsForCourses);
    /* Explanation: Set any status messages that should be shown to the user.*/
    if (data.isUsingAjax() && allCourses.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_EMPTY, StatusMessageColor.WARNING));
    }
    /* Explanation: We must set this variable. It is the text that will
         * represent this particular execution of this action in the
         * 'admin activity log' page.*/
    statusToAdmin = "instructorCourse Page Load<br>Total courses: " + allCourses.size();
    /* Explanation: Create the appropriate result object and return it.*/
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSES, data);
}
Also used : InstructorCoursesPageData(teammates.ui.pagedata.InstructorCoursesPageData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 63 with StatusMessage

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

the class AdminEmailComposeSaveAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
    String emailContent = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_CONTENT);
    String subject = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_SUBJECT);
    String addressReceiverListString = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
    String groupReceiverListFileKey = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_FILE_KEY);
    String emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
    addressReceiver.add(addressReceiverListString);
    if (groupReceiverListFileKey != null && !groupReceiverListFileKey.isEmpty()) {
        groupReceiver.add(groupReceiverListFileKey);
    }
    boolean isNewDraft = emailId == null;
    if (isNewDraft) {
        // this is a new email draft, so create a new admin email entity
        createAndSaveNewDraft(subject, addressReceiver, groupReceiver, emailContent);
    } else {
        // currently editing a previous email draft, so we need to update the previous draft
        // instead of creating a new admin email entity
        // retrieve the previous draft email
        AdminEmailAttributes previousDraft = logic.getAdminEmailById(emailId);
        if (previousDraft == null) {
            // the previous draft is not found (eg. deleted by accident when editing)
            createAndSaveNewDraft(subject, addressReceiver, groupReceiver, emailContent);
        } else {
            // the previous draft exists so simply update it with the latest email info
            updatePreviousEmailDraft(previousDraft.getEmailId(), subject, addressReceiver, groupReceiver, emailContent);
        }
    }
    if (isError) {
        data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
    } else {
        statusToAdmin = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: " + SanitizationHelper.sanitizeForHtml(subject);
        statusToUser.add(new StatusMessage(Const.StatusMessages.EMAIL_DRAFT_SAVED, StatusMessageColor.SUCCESS));
    }
    return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
Also used : Text(com.google.appengine.api.datastore.Text) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 64 with StatusMessage

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

the class AdminEmailComposeSendAction method moveJobToGroupModeTaskQueue.

private void moveJobToGroupModeTaskQueue() {
    if (!isGroupModeOn) {
        return;
    }
    taskQueuer.scheduleAdminEmailPreparationInGroupMode(emailId, groupReceiverListFileKey, 0, 0);
    statusToAdmin += "<br/>" + "Group receiver's list " + groupReceiverListFileKey;
    statusToUser.add(new StatusMessage("Email will be sent within an hour to uploaded group receiver's list.", StatusMessageColor.SUCCESS));
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 65 with StatusMessage

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

the class AdminEmailComposeSendAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
    String emailContent = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_CONTENT);
    String subject = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_SUBJECT);
    addressReceiverListString = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
    isAddressModeOn = addressReceiverListString != null && !addressReceiverListString.isEmpty();
    emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
    groupReceiverListFileKey = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_FILE_KEY);
    isGroupModeOn = groupReceiverListFileKey != null && !groupReceiverListFileKey.isEmpty();
    if (isGroupModeOn) {
        try {
            groupReceiver.add(groupReceiverListFileKey);
            GoogleCloudStorageHelper.getGroupReceiverList(new BlobKey(groupReceiverListFileKey));
        } catch (Exception e) {
            isError = true;
            setStatusForException(e, "An error occurred when retrieving receiver list, please try again");
        }
    }
    if (isAddressModeOn) {
        addressReceiver.add(addressReceiverListString);
        try {
            checkAddressReceiverString(addressReceiverListString);
        } catch (InvalidParametersException e) {
            isError = true;
            setStatusForException(e);
        }
    }
    if (!isAddressModeOn && !isGroupModeOn) {
        isError = true;
        statusToAdmin = "Error : No receiver address or file given";
        statusToUser.add(new StatusMessage("Error : No receiver address or file given", StatusMessageColor.DANGER));
    }
    if (isError) {
        data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
        return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
    }
    boolean isEmailDraft = emailId != null && !emailId.isEmpty();
    if (isEmailDraft) {
        updateDraftEmailToSent(emailId, subject, addressReceiver, groupReceiver, emailContent);
    } else {
        recordNewSentEmail(subject, addressReceiver, groupReceiver, emailContent);
    }
    if (isError) {
        data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
    }
    return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) InvalidParametersException(teammates.common.exception.InvalidParametersException) Text(com.google.appengine.api.datastore.Text) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

StatusMessage (teammates.common.util.StatusMessage)81 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)34 InvalidParametersException (teammates.common.exception.InvalidParametersException)20 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)18 ArrayList (java.util.ArrayList)14 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)9 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)9 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)7 List (java.util.List)6 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)6 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)6 HashMap (java.util.HashMap)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)3 PageData (teammates.ui.pagedata.PageData)3 BlobInfo (com.google.appengine.api.blobstore.BlobInfo)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)2 BlobstoreFailureException (com.google.appengine.api.blobstore.BlobstoreFailureException)2 Text (com.google.appengine.api.datastore.Text)2 AppLogLine (com.google.appengine.api.log.AppLogLine)2