Search in sources :

Example 36 with StatusMessage

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

the class InstructorCourseDeleteAction method execute.

@Override
public ActionResult execute() {
    String idOfCourseToDelete = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, idOfCourseToDelete);
    gateKeeper.verifyAccessible(logic.getInstructorForGoogleId(idOfCourseToDelete, account.googleId), logic.getCourse(idOfCourseToDelete), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE);
    /* Delete the course and setup status to be shown to user and admin */
    logic.deleteCourse(idOfCourseToDelete);
    String statusMessage = String.format(Const.StatusMessages.COURSE_DELETED, idOfCourseToDelete);
    statusToUser.add(new StatusMessage(statusMessage, StatusMessageColor.SUCCESS));
    statusToAdmin = "Course deleted: " + idOfCourseToDelete;
    if (isRedirectedToHomePage()) {
        return createRedirectResult(Const.ActionURIs.INSTRUCTOR_HOME_PAGE);
    }
    return createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE);
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 37 with StatusMessage

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

the class InstructorCourseEnrollSaveAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String studentsInfo = getRequestParamValue(Const.ParamsNames.STUDENTS_ENROLLMENT_INFO);
    String sanitizedStudentsInfo = SanitizationHelper.sanitizeForHtml(studentsInfo);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, studentsInfo);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    /* Process enrollment list and setup data for page result */
    try {
        List<StudentAttributes>[] students = enrollAndProcessResultForDisplay(studentsInfo, courseId);
        boolean hasSection = hasSections(students);
        InstructorCourseEnrollResultPageData pageData = new InstructorCourseEnrollResultPageData(account, sessionToken, courseId, students, hasSection, studentsInfo);
        statusToAdmin = "Students Enrolled in Course <span class=\"bold\">[" + courseId + "]:</span><br>" + sanitizedStudentsInfo.replace("\n", "<br>");
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL_RESULT, pageData);
    } catch (EnrollException | InvalidParametersException e) {
        setStatusForException(e);
        statusToAdmin += "<br>Enrollment string entered by user:<br>" + sanitizedStudentsInfo.replace("\n", "<br>");
        InstructorCourseEnrollPageData pageData = new InstructorCourseEnrollPageData(account, sessionToken, courseId, studentsInfo);
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageData);
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e);
        statusToUser.add(new StatusMessage("The enrollment failed, possibly because some students were re-enrolled before " + "the previous enrollment action was still being processed by TEAMMATES database " + "servers. Please try again after about 10 minutes. If the problem persists, " + "please contact TEAMMATES support", StatusMessageColor.DANGER));
        InstructorCourseEnrollPageData pageData = new InstructorCourseEnrollPageData(account, sessionToken, courseId, studentsInfo);
        log.severe("Entity already exists exception occurred when updating student: " + e.getMessage());
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageData);
    }
}
Also used : EnrollException(teammates.common.exception.EnrollException) InstructorCourseEnrollResultPageData(teammates.ui.pagedata.InstructorCourseEnrollResultPageData) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InstructorCourseEnrollPageData(teammates.ui.pagedata.InstructorCourseEnrollPageData) ArrayList(java.util.ArrayList) List(java.util.List) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 38 with StatusMessage

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

the class InstructorCourseInstructorAddAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String instructorName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_NAME, instructorName);
    String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
    InstructorAttributes instructorToAdd = extractCompleteInstructor(courseId, instructorName, instructorEmail);
    /* Process adding the instructor and setup status to be shown to user and admin */
    try {
        logic.createInstructor(instructorToAdd);
        taskQueuer.scheduleCourseRegistrationInviteToInstructor(loggedInUser.googleId, instructorEmail, courseId);
        statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_ADDED, instructorName, instructorEmail), StatusMessageColor.SUCCESS));
        statusToAdmin = "New instructor (<span class=\"bold\"> " + instructorEmail + "</span>)" + " for Course <span class=\"bold\">[" + courseId + "]</span> created.<br>";
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.COURSE_INSTRUCTOR_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    RedirectResult redirectResult = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
    redirectResult.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    return redirectResult;
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 39 with StatusMessage

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

the class InstructorCourseInstructorDeleteAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
    /* Process deleting an instructor and setup status to be shown to user and admin */
    if (hasAlternativeInstructor(courseId, instructorEmail)) {
        logic.deleteInstructor(courseId, instructorEmail);
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Instructor <span class=\"bold\"> " + instructorEmail + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> deleted.<br>";
    } else {
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_INSTRUCTOR_DELETE_NOT_ALLOWED, StatusMessageColor.DANGER));
        statusToAdmin = "Instructor <span class=\"bold\"> " + instructorEmail + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> could not be deleted " + "as there is only one instructor left to be able to modify instructors.<br>";
    }
    /* Create redirection. It will redirect back to 'Courses' page if the instructor deletes himself */
    RedirectResult result = null;
    if (logic.isInstructorOfCourse(account.googleId, courseId)) {
        result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
        result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    } else {
        result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE);
    }
    return result;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 40 with StatusMessage

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

the class StudentCourseJoinAuthenticatedAction method addStatusMessageToUser.

private void addStatusMessageToUser() throws EntityDoesNotExistException {
    CourseAttributes course = logic.getCourse(getStudent().course);
    String courseDisplayText = "[" + course.getId() + "] " + SanitizationHelper.sanitizeForHtml(course.getName());
    statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL, courseDisplayText), StatusMessageColor.SUCCESS));
    List<FeedbackSessionAttributes> fsa = logic.getFeedbackSessionsForUserInCourse(getStudent().course, getStudent().email);
    if (fsa.isEmpty()) {
        statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT, courseDisplayText), StatusMessageColor.INFO));
        StudentProfileAttributes spa = logic.getStudentProfile(account.googleId);
        String updateProfileMessage = spa.generateUpdateMessageForStudent();
        if (!updateProfileMessage.isEmpty()) {
            statusToUser.add(new StatusMessage(updateProfileMessage, StatusMessageColor.INFO));
        }
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) 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