Search in sources :

Example 1 with InstructorFeedbackEditCopyData

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

the class InstructorFeedbackEditCopyActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = dataBundle.instructors.get("teammates.test.instructor2");
    String instructorId = instructor.googleId;
    FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("openSession");
    CourseAttributes course = dataBundle.courses.get("course");
    gaeSimulation.loginAsInstructor(instructorId);
    String expectedString = "";
    ______TS("Failure case: No parameters");
    verifyAssumptionFailure();
    ______TS("Failure case: Courses not passed in, instructor home page");
    String[] params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    InstructorFeedbackEditCopyAction a = getAction(params);
    AjaxResult ajaxResult = getAjaxResult(a);
    InstructorFeedbackEditCopyData editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: Courses not passed in, instructor feedbacks page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: Courses not passed in, instructor feedback copy page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: Courses not passed in, instructor feedback edit page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: copying non-existing fs");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "non.existing.fs", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name", Const.ParamsNames.COPIED_COURSES_ID, course.getId() };
    a = getAction(params);
    try {
        ajaxResult = getAjaxResult(a);
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException uae) {
        assertEquals("Trying to access system using a non-existent feedback session entity", uae.getMessage());
    }
    ______TS("Failure case: copying to non-existing course");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name", Const.ParamsNames.COPIED_COURSES_ID, "non.existing.course" };
    a = getAction(params);
    try {
        ajaxResult = getAjaxResult(a);
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException uae) {
        assertEquals("Trying to access system using a non-existent instructor entity", uae.getMessage());
    }
    ______TS("Failure case: course already has feedback session with same name, instructor home page");
    CourseAttributes course6 = dataBundle.courses.get("course6");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: course already has feedback session with same name, instructor feedbacks page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: course already has feedback session with same name, instructor feedback copy page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: course already has feedback session with same name, instructor feedback edit page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: empty name, instructor home page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Failure case: empty name, instructor feedbacks page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Failure case: empty name, instructor feedback copy page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Failure case: empty name, instructor feedback edit page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Successful case");
    CourseAttributes course7 = dataBundle.courses.get("course7");
    String copiedCourseName = "Session with valid name";
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, copiedCourseName, Const.ParamsNames.COPIED_COURSES_ID, course6.getId(), Const.ParamsNames.COPIED_COURSES_ID, course7.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    expectedString = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, instructor.googleId);
    assertEquals(expectedString, editCopyData.redirectUrl);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||" + "true|||Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||" + "tmms.instr@gmail.tmt|||Copying to multiple feedback sessions.<br>" + "New Feedback Session <span class=\"bold\">(Session with valid name)</span> " + "for Courses: <br>FeedbackEditCopy.CS2103R,FeedbackEditCopy.CS2102<br>" + "<span class=\"bold\">From:</span> 2012-04-01T21:59:00Z<span class=\"bold\"> " + "to</span> 2026-04-30T21:59:00Z<br><span class=\"bold\">Session visible from:</span> " + "2012-04-01T21:59:00Z<br><span class=\"bold\">Results visible from:</span> " + "2026-05-01T21:59:00Z<br><br><span class=\"bold\">Instructions:</span> " + "<Text: Instructions for first session><br>Copied from " + "<span class=\"bold\">(First Session)</span> " + "for Course <span class=\"bold\">[FeedbackEditCopy.CS2104]</span> created.<br>|||" + "/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AjaxResult(teammates.ui.controller.AjaxResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) InstructorFeedbackEditCopyData(teammates.ui.pagedata.InstructorFeedbackEditCopyData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorFeedbackEditCopyAction(teammates.ui.controller.InstructorFeedbackEditCopyAction) Test(org.testng.annotations.Test)

Example 2 with InstructorFeedbackEditCopyData

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

the class InstructorFeedbackEditCopyAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String newFeedbackSessionName = getRequestParamValue(Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME);
    String[] coursesIdToCopyTo = getRequestParamValues(Const.ParamsNames.COPIED_COURSES_ID);
    String originalFeedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    String originalCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String nextUrl = getRequestParamValue(Const.ParamsNames.NEXT_URL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, originalCourseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, originalFeedbackSessionName);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, newFeedbackSessionName);
    if (nextUrl == null) {
        nextUrl = Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE;
    }
    if (coursesIdToCopyTo == null || coursesIdToCopyTo.length == 0) {
        return createAjaxResultWithErrorMessage(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED);
    }
    InstructorAttributes instructor = logic.getInstructorForGoogleId(originalCourseId, account.googleId);
    FeedbackSessionAttributes fsa = logic.getFeedbackSession(originalFeedbackSessionName, originalCourseId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(originalCourseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS);
    gateKeeper.verifyAccessible(instructor, fsa, false);
    try {
        // Check if there are no conflicting feedback sessions in all the courses
        List<String> conflictCourses = filterConflictsInCourses(newFeedbackSessionName, coursesIdToCopyTo);
        if (!conflictCourses.isEmpty()) {
            String commaSeparatedListOfCourses = StringHelper.toString(conflictCourses, ",");
            String errorToUser = String.format(Const.StatusMessages.FEEDBACK_SESSION_COPY_ALREADYEXISTS, newFeedbackSessionName, commaSeparatedListOfCourses);
            return createAjaxResultWithErrorMessage(errorToUser);
        }
        FeedbackSessionAttributes fs = null;
        // TODO: consider doing this as a batch insert
        for (String courseIdToCopyTo : coursesIdToCopyTo) {
            InstructorAttributes instructorForCourse = logic.getInstructorForGoogleId(courseIdToCopyTo, account.googleId);
            gateKeeper.verifyAccessible(instructorForCourse, logic.getCourse(courseIdToCopyTo), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
            fs = logic.copyFeedbackSession(newFeedbackSessionName, courseIdToCopyTo, originalFeedbackSessionName, originalCourseId, instructor.email);
        }
        List<String> courses = Arrays.asList(coursesIdToCopyTo);
        String commaSeparatedListOfCourses = StringHelper.toString(courses, ",");
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_COPIED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Copying to multiple feedback sessions.<br>" + "New Feedback Session <span class=\"bold\">(" + fs.getFeedbackSessionName() + ")</span> " + "for Courses: <br>" + commaSeparatedListOfCourses + "<br>" + "<span class=\"bold\">From:</span> " + fs.getStartTime() + "<span class=\"bold\"> to</span> " + fs.getEndTime() + "<br>" + "<span class=\"bold\">Session visible from:</span> " + fs.getSessionVisibleFromTime() + "<br>" + "<span class=\"bold\">Results visible from:</span> " + fs.getResultsVisibleFromTime() + "<br><br>" + "<span class=\"bold\">Instructions:</span> " + fs.getInstructions() + "<br>" + "Copied from <span class=\"bold\">(" + originalFeedbackSessionName + ")</span> for Course " + "<span class=\"bold\">[" + originalCourseId + "]</span> created.<br>";
        // so that the instructor can see the new feedback sessions
        return createAjaxResultWithoutClearingStatusMessage(new InstructorFeedbackEditCopyData(account, sessionToken, Config.getAppUrl(nextUrl).withParam(Const.ParamsNames.ERROR, Boolean.FALSE.toString()).withParam(Const.ParamsNames.USER_ID, account.googleId)));
    } catch (EntityAlreadyExistsException e) {
        // If conflicts are checked above, this will only occur via race condition
        setStatusForException(e, Const.StatusMessages.FEEDBACK_SESSION_EXISTS);
        return createAjaxResultWithErrorMessage(Const.StatusMessages.FEEDBACK_SESSION_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
        return createAjaxResultWithErrorMessage(e.getMessage());
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InstructorFeedbackEditCopyData(teammates.ui.pagedata.InstructorFeedbackEditCopyData) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)2 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)2 InstructorFeedbackEditCopyData (teammates.ui.pagedata.InstructorFeedbackEditCopyData)2 Test (org.testng.annotations.Test)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)1 InvalidParametersException (teammates.common.exception.InvalidParametersException)1 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)1 StatusMessage (teammates.common.util.StatusMessage)1 AjaxResult (teammates.ui.controller.AjaxResult)1 InstructorFeedbackEditCopyAction (teammates.ui.controller.InstructorFeedbackEditCopyAction)1