Search in sources :

Example 1 with StudentFeedbackResultsPageData

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

the class StudentFeedbackResultsPageAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    if (courseId == null || feedbackSessionName == null) {
        return createRedirectResult(Const.ActionURIs.STUDENT_HOME_PAGE);
    }
    if (!isJoinedCourse(courseId)) {
        return createPleaseJoinCourseResponse(courseId);
    }
    gateKeeper.verifyAccessible(getCurrentStudent(courseId), logic.getFeedbackSession(feedbackSessionName, courseId));
    StudentFeedbackResultsPageData data = new StudentFeedbackResultsPageData(account, student, sessionToken);
    data.student = getCurrentStudent(courseId);
    data.setBundle(logic.getFeedbackSessionResultsForStudent(feedbackSessionName, courseId, data.student.email));
    if (data.getBundle() == null) {
        // leave this here as a safety net on the off cases that GateKeeper fails to catch the Exception
        throw new EntityDoesNotExistException("Feedback session " + feedbackSessionName + " does not exist in " + courseId + ".");
    }
    if (!data.getBundle().feedbackSession.isPublished()) {
        throw new UnauthorizedAccessException("This feedback session is not yet visible.");
    }
    if (data.getBundle().isStudentHasSomethingNewToSee(data.student)) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESULTS_SOMETHINGNEW, StatusMessageColor.INFO));
    } else {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESULTS_NOTHINGNEW, StatusMessageColor.WARNING));
    }
    statusToAdmin = "Show student feedback result page<br>" + "Session Name: " + feedbackSessionName + "<br>" + "Course ID: " + courseId;
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponses = data.getBundle().getQuestionResponseMapSortedByRecipient();
    data.init(questionsWithResponses);
    return createShowPageResult(Const.ViewURIs.STUDENT_FEEDBACK_RESULTS, data);
}
Also used : UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) List(java.util.List) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) StatusMessage(teammates.common.util.StatusMessage)

Example 2 with StudentFeedbackResultsPageData

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

the class StudentFeedbackResultsPageDataTest method testAll.

@Test
public void testAll() throws EntityDoesNotExistException {
    ______TS("typical success case");
    AccountAttributes account = dataBundle.accounts.get("student1InCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    assertNotNull(student);
    String dummyKey = "key123";
    student.key = dummyKey;
    Logic logic = new Logic();
    StudentFeedbackResultsPageData pageData = new StudentFeedbackResultsPageData(account, student, dummySessionToken);
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponses = new LinkedHashMap<>();
    FeedbackQuestionAttributes question1 = dataBundle.feedbackQuestions.get("qn1InSession1InCourse1");
    assertNotNull(question1);
    FeedbackQuestionAttributes question2 = dataBundle.feedbackQuestions.get("qn2InSession1InCourse1");
    assertNotNull(question2);
    List<FeedbackResponseAttributes> responsesForQ1 = new ArrayList<>();
    List<FeedbackResponseAttributes> responsesForQ2 = new ArrayList<>();
    /* Question 1 with responses */
    responsesForQ1.add(dataBundle.feedbackResponses.get("response1ForQ1S1C1"));
    questionsWithResponses.put(question1, responsesForQ1);
    /* Question 2 with responses */
    responsesForQ2.add(dataBundle.feedbackResponses.get("response1ForQ2S1C1"));
    responsesForQ2.add(dataBundle.feedbackResponses.get("response2ForQ2S1C1"));
    questionsWithResponses.put(question2, responsesForQ2);
    // need to obtain questionId and responseId as methods in FeedbackSessionResultsBundle require them
    questionsWithResponses = getActualQuestionsAndResponsesWithId(logic, questionsWithResponses);
    pageData.setBundle(logic.getFeedbackSessionResultsForStudent(question1.feedbackSessionName, question1.courseId, student.email));
    pageData.init(questionsWithResponses);
    StudentFeedbackResultsQuestionWithResponses questionBundle1 = pageData.getFeedbackResultsQuestionsWithResponses().get(0);
    StudentFeedbackResultsQuestionWithResponses questionBundle2 = pageData.getFeedbackResultsQuestionsWithResponses().get(1);
    assertNotNull(pageData.getFeedbackResultsQuestionsWithResponses());
    assertEquals(2, pageData.getFeedbackResultsQuestionsWithResponses().size());
    assertEquals("You are viewing feedback results as <span class='text-danger text-bold text-large'>" + "student1 In Course1</td></div>'\"</span>. You may submit feedback for sessions that are " + "currently open and view results without logging in. " + "To access other features you need <a href='/page/studentCourseJoinAuthentication?" + "key=" + StringHelper.encrypt(dummyKey) + "&studentemail=student1InCourse1%40gmail.tmt&courseid=idOfTypicalCourse1' class='link'>" + "to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
    assertNotNull(questionBundle1.getQuestionDetails());
    assertNotNull(questionBundle2.getQuestionDetails());
    assertEquals("1", questionBundle1.getQuestionDetails().getQuestionIndex());
    assertEquals("2", questionBundle2.getQuestionDetails().getQuestionIndex());
    assertEquals("", questionBundle1.getQuestionDetails().getAdditionalInfo());
    assertEquals("", questionBundle2.getQuestionDetails().getAdditionalInfo());
    assertNotNull(questionBundle1.getResponseTables());
    assertNotNull(questionBundle2.getResponseTables());
    assertEquals("You", questionBundle1.getResponseTables().get(0).getRecipientName());
    assertNotNull(questionBundle1.getResponseTables().get(0).getResponses());
    assertEquals("You", questionBundle1.getResponseTables().get(0).getResponses().get(0).getGiverName());
    assertEquals("Student 1 self feedback.", questionBundle1.getResponseTables().get(0).getResponses().get(0).getAnswer());
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    pageData = new StudentFeedbackResultsPageData(account, student, dummySessionToken);
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponsesUnregistered = new LinkedHashMap<>();
    pageData.init(questionsWithResponsesUnregistered);
    assertTrue(pageData.getFeedbackResultsQuestionsWithResponses().isEmpty());
    assertEquals("regKeyForStuNotYetJoinCourse", student.key);
    assertEquals("idOfUnregisteredCourse", student.course);
    assertEquals("student1InUnregisteredCourse@gmail.tmt", student.email);
    assertEquals("You are viewing feedback results as " + "<span class='text-danger text-bold text-large'>student1 In " + "unregisteredCourse</span>. You may submit feedback for sessions that are currently open " + "and view results without logging in. To access other features you need " + "<a href='/page/studentCourseJoinAuthentication?key=" + StringHelper.encrypt("regKeyForStuNotYetJoinCourse") + "&studentemail=student1InUnregisteredCourse%40gmail.tmt&courseid=idOfUnregisteredCourse' " + "class='link'>to login using a Google account</a> (recommended).", pageData.getRegisterMessage());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) LinkedHashMap(java.util.LinkedHashMap) StudentFeedbackResultsQuestionWithResponses(teammates.ui.template.StudentFeedbackResultsQuestionWithResponses) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) ArrayList(java.util.ArrayList) List(java.util.List) Logic(teammates.logic.api.Logic) Test(org.testng.annotations.Test)

Example 3 with StudentFeedbackResultsPageData

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

the class StudentFeedbackResultsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    FeedbackSessionAttributes session1InCourse1 = typicalBundle.feedbackSessions.get("session1InCourse1");
    FeedbackSessionAttributes emptySession = typicalBundle.feedbackSessions.get("empty.session");
    FeedbackSessionAttributes closedSession = typicalBundle.feedbackSessions.get("closedSession");
    FeedbackSessionAttributes gracePeriodSession = typicalBundle.feedbackSessions.get("gracePeriodSession");
    session1InCourse1.setResultsVisibleFromTime(session1InCourse1.getStartTime());
    FeedbackSessionsLogic.inst().updateFeedbackSession(session1InCourse1);
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    ______TS("invalid params");
    String[] submissionParams = new String[] {};
    verifyRedirectTo(Const.ActionURIs.STUDENT_HOME_PAGE, submissionParams);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId() };
    verifyRedirectTo(Const.ActionURIs.STUDENT_HOME_PAGE, submissionParams);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName() };
    verifyRedirectTo(Const.ActionURIs.STUDENT_HOME_PAGE, submissionParams);
    ______TS("results not viewable when not published");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName() };
    FeedbackSessionsLogic.inst().unpublishFeedbackSession(session1InCourse1);
    StudentFeedbackResultsPageAction pageAction = getAction(submissionParams);
    try {
        getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("This feedback session is not yet visible.", exception.getMessage());
    }
    ______TS("cannot access a private session");
    FeedbackSessionsLogic.inst().publishFeedbackSession(session1InCourse1);
    session1InCourse1.setFeedbackSessionType(FeedbackSessionType.PRIVATE);
    FeedbackSessionsLogic.inst().updateFeedbackSession(session1InCourse1);
    pageAction = getAction(submissionParams);
    try {
        getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("Feedback session [First feedback session] is not accessible to student " + "[" + student1InCourse1.email + "]", exception.getMessage());
    }
    session1InCourse1.setFeedbackSessionType(FeedbackSessionType.STANDARD);
    FeedbackSessionsLogic.inst().updateFeedbackSession(session1InCourse1);
    ______TS("access a empty session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, emptySession.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, emptySession.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    assertEquals(Const.ViewURIs.STUDENT_FEEDBACK_RESULTS, pageResult.destination);
    assertFalse(pageResult.isError);
    assertEquals("You have not received any new feedback but you may review your own submissions below.", pageResult.getStatusMessage());
    ______TS("access a gracePeriodSession session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, gracePeriodSession.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, gracePeriodSession.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    try {
        pageResult = getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("This feedback session is not yet visible.", exception.getMessage());
    }
    ______TS("access a closed session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, closedSession.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, closedSession.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    try {
        pageResult = getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("This feedback session is not yet visible.", exception.getMessage());
    }
    ______TS("access a non-existent session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, "non-existent session" };
    pageAction = getAction(submissionParams);
    try {
        pageResult = getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("Trying to access system using a non-existent feedback session entity", exception.getMessage());
    }
    ______TS("typical case");
    removeAndRestoreTypicalDataBundle();
    session1InCourse1 = FeedbackSessionsLogic.inst().getFeedbackSession(session1InCourse1.getFeedbackSessionName(), session1InCourse1.getCourseId());
    FeedbackSessionsLogic.inst().publishFeedbackSession(session1InCourse1);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    pageResult = getShowPageResult(pageAction);
    assertEquals(Const.ViewURIs.STUDENT_FEEDBACK_RESULTS, pageResult.destination);
    assertFalse(pageResult.isError);
    assertEquals("You have received feedback from others. Please see below.", pageResult.getStatusMessage());
    StudentFeedbackResultsPageData pageData = (StudentFeedbackResultsPageData) pageResult.data;
    // databundle time changed here because publishing sets resultsVisibleTime to now.
    typicalBundle.feedbackSessions.get("session1InCourse1").setResultsVisibleFromTime(Instant.now());
    /*
         * The above test can fail if the time elapsed between pageData... and dataBundle...
         * changes the time recorded by dataBundle up to the precision of seconds.
         * To solve that, verify that the time elapsed is less than one second (or else the test
         * fails after all) and if it does, change the value in the dataBundle to match.
         */
    Instant pageDataResultsVisibleFromTime = pageData.getBundle().feedbackSession.getResultsVisibleFromTime();
    Instant dataBundleResultsVisibleFromTime = typicalBundle.feedbackSessions.get("session1InCourse1").getResultsVisibleFromTime();
    Duration difference = Duration.between(pageDataResultsVisibleFromTime, dataBundleResultsVisibleFromTime);
    long toleranceTimeInMs = 1000;
    if (difference.compareTo(Duration.ofMillis(toleranceTimeInMs)) < 0) {
        // change to the value that will never make the test fail
        typicalBundle.feedbackSessions.get("session1InCourse1").setResultsVisibleFromTime(pageData.getBundle().feedbackSession.getResultsVisibleFromTime());
    }
    List<FeedbackSessionAttributes> expectedInfoList = new ArrayList<>();
    List<FeedbackSessionAttributes> actualInfoList = new ArrayList<>();
    expectedInfoList.add(typicalBundle.feedbackSessions.get("session1InCourse1"));
    actualInfoList.add(pageData.getBundle().feedbackSession);
    AssertHelper.assertSameContentIgnoreOrder(expectedInfoList, actualInfoList);
    assertEquals(student1InCourse1.googleId, pageData.account.googleId);
    assertEquals(student1InCourse1.getIdentificationString(), pageData.student.getIdentificationString());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) Duration(java.time.Duration) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) ShowPageResult(teammates.ui.controller.ShowPageResult) StudentFeedbackResultsPageAction(teammates.ui.controller.StudentFeedbackResultsPageAction) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) Test(org.testng.annotations.Test)

Aggregations

StudentFeedbackResultsPageData (teammates.ui.pagedata.StudentFeedbackResultsPageData)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.testng.annotations.Test)2 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)2 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)2 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)2 Duration (java.time.Duration)1 Instant (java.time.Instant)1 LinkedHashMap (java.util.LinkedHashMap)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 StatusMessage (teammates.common.util.StatusMessage)1 Logic (teammates.logic.api.Logic)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1 StudentFeedbackResultsPageAction (teammates.ui.controller.StudentFeedbackResultsPageAction)1 StudentFeedbackResultsQuestionWithResponses (teammates.ui.template.StudentFeedbackResultsQuestionWithResponses)1