Search in sources :

Example 1 with AdminStudentGoogleIdResetPageData

use of teammates.ui.pagedata.AdminStudentGoogleIdResetPageData in project teammates by TEAMMATES.

the class AdminStudentGoogleIdResetAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    gateKeeper.verifyAdminPrivileges(account);
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    String studentCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String wrongGoogleId = getRequestParamValue(Const.ParamsNames.STUDENT_ID);
    AdminStudentGoogleIdResetPageData data = new AdminStudentGoogleIdResetPageData(account, sessionToken);
    if (studentEmail != null && studentCourseId != null) {
        try {
            logic.resetStudentGoogleId(studentEmail, studentCourseId);
            taskQueuer.scheduleCourseRegistrationInviteToStudent(studentCourseId, studentEmail, true);
        } catch (InvalidParametersException e) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL, StatusMessageColor.DANGER));
            statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId + "<br>" + "Failed with error<br>" + e.getMessage();
            isError = true;
        }
        StudentAttributes updatedStudent = logic.getStudentForEmail(studentCourseId, studentEmail);
        if (updatedStudent.googleId == null || updatedStudent.googleId.isEmpty()) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET, StatusMessageColor.SUCCESS));
            statusToUser.add(new StatusMessage("Email : " + studentEmail, StatusMessageColor.SUCCESS));
            statusToUser.add(new StatusMessage("CourseId : " + studentCourseId, StatusMessageColor.SUCCESS));
            statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId;
            data.statusForAjax = Const.StatusMessages.STUDENT_GOOGLEID_RESET + "<br>" + "Email : " + studentEmail + "<br>" + "CourseId : " + studentCourseId;
            data.isGoogleIdReset = true;
            deleteAccountIfNeeded(wrongGoogleId);
        } else {
            data.isGoogleIdReset = false;
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL, StatusMessageColor.DANGER));
            statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId + "<br>";
            data.statusForAjax = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email : " + studentEmail + "<br>" + "CourseId : " + studentCourseId;
        }
        isError = false;
        return createAjaxResult(data);
    }
    isError = true;
    return createAjaxResult(data);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) AdminStudentGoogleIdResetPageData(teammates.ui.pagedata.AdminStudentGoogleIdResetPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 InvalidParametersException (teammates.common.exception.InvalidParametersException)1 StatusMessage (teammates.common.util.StatusMessage)1 AdminStudentGoogleIdResetPageData (teammates.ui.pagedata.AdminStudentGoogleIdResetPageData)1