Search in sources :

Example 1 with InstructorStudentListPageData

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

the class InstructorStudentListPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor3OfCourse1");
    String instructorId = instructor.googleId;
    String[] submissionParams = new String[] { Const.ParamsNames.SEARCH_KEY, "A search key", Const.ParamsNames.DISPLAY_ARCHIVE, "false" };
    ______TS("Typical case, student list view");
    gaeSimulation.loginAsInstructor(instructorId);
    InstructorStudentListPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST, false, instructorId), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    String expectedLogMessage = "TEAMMATESLOG|||instructorStudentListPage|||instructorStudentListPage" + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3" + "|||instr3@course1n2.tmt|||instructorStudentList Page Load<br>Total Courses: 2" + "|||/page/instructorStudentListPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    InstructorStudentListPageData islpd = (InstructorStudentListPageData) r.data;
    assertEquals(2, islpd.getNumOfCourses());
    ______TS("No courses");
    instructorId = typicalBundle.accounts.get("instructorWithoutCourses").googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST, false, "instructorWithoutCourses"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.INSTRUCTOR_NO_COURSE_AND_STUDENTS, r.getStatusMessage());
    islpd = (InstructorStudentListPageData) r.data;
    assertEquals(0, islpd.getNumOfCourses());
    expectedLogMessage = "TEAMMATESLOG|||instructorStudentListPage|||instructorStudentListPage" + "|||true|||Instructor|||Instructor Without Courses|||instructorWithoutCourses" + "|||iwc@yahoo.tmt|||instructorStudentList Page Load<br>Total Courses: 0" + "|||/page/instructorStudentListPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    instructor = typicalBundle.instructors.get("instructorOfArchivedCourse");
    instructorId = instructor.googleId;
    ______TS("Archived course, not displayed");
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST, false, "idOfInstructorOfArchivedCourse"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    islpd = (InstructorStudentListPageData) r.data;
    assertEquals(0, islpd.getNumOfCourses());
    expectedLogMessage = "TEAMMATESLOG|||instructorStudentListPage|||instructorStudentListPage" + "|||true|||Instructor|||InstructorOfArchiveCourse name|||idOfInstructorOfArchivedCourse" + "|||instructorOfArchiveCourse@archiveCourse.tmt" + "|||instructorStudentList Page Load<br>Total Courses: 1" + "|||/page/instructorStudentListPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    submissionParams = new String[] { Const.ParamsNames.SEARCH_KEY, "A search key", Const.ParamsNames.DISPLAY_ARCHIVE, "true" };
    ______TS("Archived course, displayed");
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST, false, "idOfInstructorOfArchivedCourse"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    islpd = (InstructorStudentListPageData) r.data;
    assertEquals(1, islpd.getNumOfCourses());
    expectedLogMessage = "TEAMMATESLOG|||instructorStudentListPage|||instructorStudentListPage" + "|||true|||Instructor|||InstructorOfArchiveCourse name|||idOfInstructorOfArchivedCourse" + "|||instructorOfArchiveCourse@archiveCourse.tmt" + "|||instructorStudentList Page Load<br>Total Courses: 1" + "|||/page/instructorStudentListPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorStudentListPageAction(teammates.ui.controller.InstructorStudentListPageAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData) Test(org.testng.annotations.Test)

Example 2 with InstructorStudentListPageData

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

the class InstructorStudentListPageAction method execute.

@Override
public ActionResult execute() {
    gateKeeper.verifyInstructorPrivileges(account);
    String searchKey = getRequestParamValue(Const.ParamsNames.SEARCH_KEY);
    Boolean displayArchive = getRequestParamAsBoolean(Const.ParamsNames.DISPLAY_ARCHIVE);
    Map<String, InstructorAttributes> instructors = new HashMap<>();
    List<CourseAttributes> courses = logic.getCoursesForInstructor(account.googleId);
    // Sort by creation date
    courses.sort(Comparator.comparing(course -> course.createdAt));
    // Get instructor attributes
    List<InstructorAttributes> instructorList = logic.getInstructorsForGoogleId(account.googleId);
    for (InstructorAttributes instructor : instructorList) {
        instructors.put(instructor.courseId, instructor);
    }
    if (courses.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_NO_COURSE_AND_STUDENTS, StatusMessageColor.WARNING));
    }
    statusToAdmin = "instructorStudentList Page Load<br>" + "Total Courses: " + courses.size();
    List<InstructorStudentListPageCourseData> coursesToDisplay = new ArrayList<>();
    for (CourseAttributes course : courses) {
        InstructorAttributes instructor = instructors.get(course.getId());
        boolean isInstructorAllowedToModify = instructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
        boolean isCourseDisplayed = displayArchive || !instructor.isArchived;
        if (isCourseDisplayed) {
            coursesToDisplay.add(new InstructorStudentListPageCourseData(course, instructor.isArchived, isInstructorAllowedToModify));
        }
    }
    InstructorStudentListPageData data = new InstructorStudentListPageData(account, sessionToken, searchKey, displayArchive, coursesToDisplay);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST, data);
}
Also used : List(java.util.List) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) Map(java.util.Map) InstructorStudentListPageCourseData(teammates.ui.datatransfer.InstructorStudentListPageCourseData) StatusMessage(teammates.common.util.StatusMessage) HashMap(java.util.HashMap) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) StatusMessageColor(teammates.common.util.StatusMessageColor) Comparator(java.util.Comparator) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) InstructorStudentListPageCourseData(teammates.ui.datatransfer.InstructorStudentListPageCourseData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData)

Example 3 with InstructorStudentListPageData

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

the class InstructorStudentListPageDataTest method initializeDataWithSearchKey.

private InstructorStudentListPageData initializeDataWithSearchKey() {
    acct = AccountAttributes.builder().withGoogleId(// only googleId is used
    "valid.id").build();
    searchKey = "<script>alert(\"A search key\");</script>";
    shouldDisplayArchive = false;
    // only course ID and name are used
    sampleCourse = CourseAttributes.builder("validCourseId", "Sample course name", ZoneId.of("UTC")).build();
    isCourseArchived = false;
    isInstructorAllowedToModify = true;
    coursesToDisplay = new ArrayList<>();
    coursesToDisplay.add(new InstructorStudentListPageCourseData(sampleCourse, isCourseArchived, isInstructorAllowedToModify));
    return new InstructorStudentListPageData(acct, dummySessionToken, searchKey, shouldDisplayArchive, coursesToDisplay);
}
Also used : InstructorStudentListPageCourseData(teammates.ui.datatransfer.InstructorStudentListPageCourseData) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData)

Aggregations

InstructorStudentListPageData (teammates.ui.pagedata.InstructorStudentListPageData)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)2 InstructorStudentListPageCourseData (teammates.ui.datatransfer.InstructorStudentListPageCourseData)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 Const (teammates.common.util.Const)1 StatusMessage (teammates.common.util.StatusMessage)1 StatusMessageColor (teammates.common.util.StatusMessageColor)1 InstructorStudentListPageAction (teammates.ui.controller.InstructorStudentListPageAction)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1