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());
}
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);
}
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);
}
Aggregations