use of teammates.ui.pagedata.InstructorCoursesPageData in project teammates by TEAMMATES.
the class InstructorCourseAddAction method execute.
@Override
public ActionResult execute() {
String newCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, newCourseId);
String newCourseName = getRequestParamValue(Const.ParamsNames.COURSE_NAME);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_NAME, newCourseName);
String newCourseTimeZone = getRequestParamValue(Const.ParamsNames.COURSE_TIME_ZONE);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_TIME_ZONE, newCourseTimeZone);
/* Check if user has the right to execute the action */
gateKeeper.verifyInstructorPrivileges(account);
/* Create a new course in the database */
data = new InstructorCoursesPageData(account, sessionToken);
createCourse(newCourseId, newCourseName, newCourseTimeZone);
/* Prepare data for the refreshed page after executing the adding action */
Map<String, InstructorAttributes> instructorsForCourses = new HashMap<>();
List<CourseAttributes> activeCourses = new ArrayList<>();
List<CourseAttributes> archivedCourses = new ArrayList<>();
// Get list of InstructorAttributes that belong to the user.
List<InstructorAttributes> instructorList = logic.getInstructorsForGoogleId(data.account.googleId);
for (InstructorAttributes instructor : instructorList) {
instructorsForCourses.put(instructor.courseId, instructor);
}
// Get corresponding courses of the instructors.
List<CourseAttributes> allCourses = logic.getCoursesForInstructor(instructorList);
List<String> archivedCourseIds = logic.getArchivedCourseIds(allCourses, instructorsForCourses);
for (CourseAttributes course : allCourses) {
if (archivedCourseIds.contains(course.getId())) {
archivedCourses.add(course);
} else {
activeCourses.add(course);
}
}
// Sort CourseDetailsBundle lists by course id
CourseAttributes.sortById(activeCourses);
CourseAttributes.sortById(archivedCourses);
String courseIdToShowParam = "";
String courseNameToShowParam = "";
if (isError) {
// there is error in adding the course
courseIdToShowParam = SanitizationHelper.sanitizeForHtml(newCourseId);
courseNameToShowParam = SanitizationHelper.sanitizeForHtml(newCourseName);
List<String> statusMessageTexts = new ArrayList<>();
for (StatusMessage msg : statusToUser) {
statusMessageTexts.add(msg.getText());
}
statusToAdmin = StringHelper.toString(statusMessageTexts, "<br>");
} else {
statusToAdmin = "Course added : " + newCourseId;
statusToAdmin += "<br>Total courses: " + allCourses.size();
}
data.init(activeCourses, archivedCourses, instructorsForCourses, courseIdToShowParam, courseNameToShowParam);
return isError ? createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSES, data) : createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE);
}
use of teammates.ui.pagedata.InstructorCoursesPageData in project teammates by TEAMMATES.
the class InstructorCoursesPageDataTest method testAll.
@Test
public void testAll() {
______TS("test no course");
AccountAttributes instructorAccountWithoutCourses = dataBundle.accounts.get("instructorWithoutCourses");
InstructorCoursesPageData pageData = new InstructorCoursesPageData(instructorAccountWithoutCourses, dummySessionToken);
List<CourseAttributes> activeCourses = new ArrayList<>();
List<CourseAttributes> archivedCourses = new ArrayList<>();
Map<String, InstructorAttributes> instructorForCourses = new HashMap<>();
pageData.init(activeCourses, archivedCourses, instructorForCourses);
assertNotNull(pageData.getActiveCourses());
assertNotNull(pageData.getActiveCourses().getRows());
assertEquals(0, pageData.getActiveCourses().getRows().size());
assertNotNull(pageData.getArchivedCourses());
assertNotNull(pageData.getArchivedCourses().getRows());
assertEquals(0, pageData.getArchivedCourses().getRows().size());
assertEquals("", pageData.getCourseIdToShow());
assertEquals("", pageData.getCourseNameToShow());
______TS("test 1 active course");
AccountAttributes instructorAccountWithOneActiveCourse = dataBundle.accounts.get("instructor1OfCourse1");
pageData = new InstructorCoursesPageData(instructorAccountWithOneActiveCourse, dummySessionToken);
activeCourses = new ArrayList<>();
activeCourses.add(dataBundle.courses.get("typicalCourse1"));
archivedCourses = new ArrayList<>();
instructorForCourses = new HashMap<>();
instructorForCourses.put("idOfTypicalCourse1", dataBundle.instructors.get("instructor1OfCourse1"));
pageData.init(activeCourses, archivedCourses, instructorForCourses);
assertNotNull(pageData.getActiveCourses());
assertNotNull(pageData.getActiveCourses().getRows());
assertEquals(1, pageData.getActiveCourses().getRows().size());
assertNotNull(pageData.getArchivedCourses());
assertNotNull(pageData.getArchivedCourses().getRows());
assertEquals(0, pageData.getArchivedCourses().getRows().size());
assertEquals("", pageData.getCourseIdToShow());
assertEquals("", pageData.getCourseNameToShow());
______TS("test 2 active courses");
AccountAttributes instructorAccountWithTwoActiveCourses = dataBundle.accounts.get("instructor3");
pageData = new InstructorCoursesPageData(instructorAccountWithTwoActiveCourses, dummySessionToken);
activeCourses = new ArrayList<>();
activeCourses.add(dataBundle.courses.get("typicalCourse1"));
activeCourses.add(dataBundle.courses.get("typicalCourse2"));
archivedCourses = new ArrayList<>();
instructorForCourses = new HashMap<>();
instructorForCourses.put("idOfTypicalCourse1", dataBundle.instructors.get("instructor3OfCourse1"));
instructorForCourses.put("idOfTypicalCourse2", dataBundle.instructors.get("instructor3OfCourse2"));
pageData.init(activeCourses, archivedCourses, instructorForCourses, "Id to show", "Name to show");
assertNotNull(pageData.getActiveCourses());
assertNotNull(pageData.getActiveCourses().getRows());
assertEquals(2, pageData.getActiveCourses().getRows().size());
assertNotNull(pageData.getArchivedCourses());
assertNotNull(pageData.getArchivedCourses().getRows());
assertEquals(0, pageData.getArchivedCourses().getRows().size());
assertEquals("Id to show", pageData.getCourseIdToShow());
assertEquals("Name to show", pageData.getCourseNameToShow());
______TS("test 1 archived course");
AccountAttributes instructorAccountWithOneArchivedCourse = dataBundle.accounts.get("instructorOfArchivedCourse");
pageData = new InstructorCoursesPageData(instructorAccountWithOneArchivedCourse, dummySessionToken);
activeCourses = new ArrayList<>();
archivedCourses = new ArrayList<>();
archivedCourses.add(dataBundle.courses.get("archivedCourse"));
instructorForCourses = new HashMap<>();
instructorForCourses.put("idOfArchivedCourse", dataBundle.instructors.get("instructorOfArchivedCourse"));
pageData.init(activeCourses, archivedCourses, instructorForCourses);
assertNotNull(pageData.getActiveCourses());
assertNotNull(pageData.getActiveCourses().getRows());
assertEquals(0, pageData.getActiveCourses().getRows().size());
assertNotNull(pageData.getArchivedCourses());
assertNotNull(pageData.getArchivedCourses().getRows());
assertEquals(1, pageData.getArchivedCourses().getRows().size());
assertEquals("", pageData.getCourseIdToShow());
assertEquals("", pageData.getCourseNameToShow());
}
use of teammates.ui.pagedata.InstructorCoursesPageData in project teammates by TEAMMATES.
the class InstructorCoursesPageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
// TODO: find a way to test status message from session
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
String instructorId = instructor1OfCourse1.googleId;
String[] submissionParams = new String[] { Const.ParamsNames.IS_USING_AJAX, "true" };
InstructorAttributes instructor1ofCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
/* Explanation: If the action is supposed to verify parameters,
* we should check here the correctness of parameter verification.
* e.g.
______TS("Invalid parameters");
//both parameters missing.
verifyAssumptionFailure(new String[] {});
//null student email, only course ID is set
String[] invalidParams = new String[] {
Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId
};
verifyAssumptionFailure(invalidParams);
* In this action, there is no parameter verification.
*/
______TS("Typical case, 2 courses");
if (CoursesLogic.inst().isCoursePresent("new-course")) {
CoursesLogic.inst().deleteCourseCascade("new-course");
}
CoursesLogic.inst().createCourseAndInstructor(instructorId, "new-course", "New course", "UTC");
gaeSimulation.loginAsInstructor(instructorId);
InstructorCoursesPageAction a = getAction(submissionParams);
ShowPageResult r = getShowPageResult(a);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSES, false, "idOfInstructor1OfCourse1"), r.getDestinationWithParams());
assertFalse(r.isError);
assertEquals("", r.getStatusMessage());
InstructorCoursesPageData pageData = (InstructorCoursesPageData) r.data;
assertEquals(instructorId, pageData.account.googleId);
assertEquals(2, pageData.getActiveCourses().getRows().size() + pageData.getArchivedCourses().getRows().size());
assertEquals(0, pageData.getArchivedCourses().getRows().size());
assertEquals("", pageData.getCourseIdToShow());
assertEquals("", pageData.getCourseNameToShow());
String expectedLogMessage = "TEAMMATESLOG|||instructorCoursesPage|||instructorCoursesPage" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1" + "|||instr1@course1.tmt|||instructorCourse Page Load<br>Total courses: 2" + "|||/page/instructorCoursesPage";
AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
______TS("Masquerade mode, 0 courses");
String adminUserId = "admin.user";
gaeSimulation.loginAsAdmin(adminUserId);
CoursesLogic.inst().deleteCourseCascade(instructor1ofCourse1.courseId);
CoursesLogic.inst().deleteCourseCascade("new-course");
a = getAction(addUserIdToParams(instructorId, submissionParams));
r = getShowPageResult(a);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSES, false, "idOfInstructor1OfCourse1"), r.getDestinationWithParams());
assertEquals("You have not created any courses yet. Use the form above to create a course.", r.getStatusMessage());
assertFalse(r.isError);
pageData = (InstructorCoursesPageData) r.data;
assertEquals(instructorId, pageData.account.googleId);
assertEquals(0, pageData.getArchivedCourses().getRows().size());
assertEquals(0, pageData.getActiveCourses().getRows().size());
assertEquals("", pageData.getCourseIdToShow());
assertEquals("", pageData.getCourseNameToShow());
expectedLogMessage = "TEAMMATESLOG|||instructorCoursesPage|||instructorCoursesPage" + "|||true|||Instructor(M)|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1" + "|||instr1@course1.tmt|||instructorCourse Page Load<br>Total courses: 0" + "|||/page/instructorCoursesPage";
AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, a.getLogMessage(), adminUserId);
}
use of teammates.ui.pagedata.InstructorCoursesPageData in project teammates by TEAMMATES.
the class InstructorCourseAddActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
String instructorId = instructor1OfCourse1.googleId;
String adminUserId = "admin.user";
gaeSimulation.loginAsInstructor(instructorId);
______TS("Not enough parameters");
verifyAssumptionFailure();
verifyAssumptionFailure(Const.ParamsNames.COURSE_NAME, "ticac tac name");
______TS("Error: Invalid parameter for Course ID");
String invalidCourseId = "ticac,tpa1,id";
InstructorCourseAddAction addAction = getAction(Const.ParamsNames.COURSE_ID, invalidCourseId, Const.ParamsNames.COURSE_NAME, "ticac tpa1 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
ShowPageResult pageResult = getShowPageResult(addAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSES, true, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
assertTrue(pageResult.isError);
assertEquals(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, invalidCourseId, FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), pageResult.getStatusMessage());
InstructorCoursesPageData pageData = (InstructorCoursesPageData) pageResult.data;
assertEquals(1, pageData.getActiveCourses().getRows().size() + pageData.getArchivedCourses().getRows().size());
String expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, invalidCourseId, FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH) + "|||/page/instructorCourseAdd";
AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
______TS("Typical case, 1 existing course");
addAction = getAction(Const.ParamsNames.COURSE_ID, "ticac.tpa1.id", Const.ParamsNames.COURSE_NAME, "ticac tpa1 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
RedirectResult redirectResult = getRedirectResult(addAction);
List<CourseAttributes> courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
assertEquals(2, courseList.size());
expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course added : ticac.tpa1.id<br>Total courses: 2|||/page/instructorCourseAdd";
AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
String expected = Const.StatusMessages.COURSE_ADDED.replace("${courseEnrollLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_ENROLL_PAGE, "ticac.tpa1.id", "idOfInstructor1OfCourse1")).replace("${courseEditLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, "ticac.tpa1.id", "idOfInstructor1OfCourse1"));
assertEquals(expected, redirectResult.getStatusMessage());
______TS("Error: Try to add the same course again");
addAction = getAction(Const.ParamsNames.COURSE_ID, "ticac.tpa1.id", Const.ParamsNames.COURSE_NAME, "ticac tpa1 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
pageResult = getShowPageResult(addAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSES, true, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
assertTrue(pageResult.isError);
assertEquals(Const.StatusMessages.COURSE_EXISTS, pageResult.getStatusMessage());
pageData = (InstructorCoursesPageData) pageResult.data;
assertEquals(2, pageData.getActiveCourses().getRows().size() + pageData.getArchivedCourses().getRows().size());
expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "A course by the same ID already exists in the system, possibly created by another " + "user. Please choose a different course ID|||/page/instructorCourseAdd";
AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
______TS("Masquerade mode, 0 courses");
CoursesLogic.inst().deleteCourseCascade(instructor1OfCourse1.courseId);
CoursesLogic.inst().deleteCourseCascade("ticac.tpa1.id");
gaeSimulation.loginAsAdmin(adminUserId);
addAction = getAction(Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, "ticac.tpa2.id", Const.ParamsNames.COURSE_NAME, "ticac tpa2 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
redirectResult = getRedirectResult(addAction);
String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1");
assertEquals(expectedDestination, redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
String expectedStatus = "The course has been added. Click <a href=\"/page/instructorCourseEnrollPage?" + "courseid=ticac.tpa2.id&user=idOfInstructor1OfCourse1\">here</a> to add students " + "to the course or click <a href=\"/page/instructorCourseEditPage?" + "courseid=ticac.tpa2.id&user=idOfInstructor1OfCourse1\">here</a> to add other " + "instructors.<br>If you don't see the course in the list below, please refresh " + "the page after a few moments.";
assertEquals(expectedStatus, redirectResult.getStatusMessage());
courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
assertEquals(1, courseList.size());
expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course added : ticac.tpa2.id<br>Total courses: 1|||/page/instructorCourseAdd";
AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, addAction.getLogMessage(), adminUserId);
// delete the new course
CoursesLogic.inst().deleteCourseCascade("ticac.tpa2.id");
______TS("Test archived Courses");
InstructorAttributes instructorOfArchivedCourse = typicalBundle.instructors.get("instructorOfArchivedCourse");
instructorId = instructorOfArchivedCourse.googleId;
gaeSimulation.loginAsInstructor(instructorId);
addAction = getAction(Const.ParamsNames.COURSE_ID, "ticac.tpa2.id", Const.ParamsNames.COURSE_NAME, "ticac tpa2 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
redirectResult = getRedirectResult(addAction);
courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
assertEquals(2, courseList.size());
expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "InstructorOfArchiveCourse name|||idOfInstructorOfArchivedCourse|||" + "instructorOfArchiveCourse@archiveCourse.tmt|||Course added : ticac.tpa2.id<br>" + "Total courses: 2|||/page/instructorCourseAdd";
AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
expected = Const.StatusMessages.COURSE_ADDED.replace("${courseEnrollLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_ENROLL_PAGE, "ticac.tpa2.id", "idOfInstructorOfArchivedCourse")).replace("${courseEditLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, "ticac.tpa2.id", "idOfInstructorOfArchivedCourse"));
assertEquals(expected, redirectResult.getStatusMessage());
}
use of teammates.ui.pagedata.InstructorCoursesPageData in project teammates by TEAMMATES.
the class InstructorCoursesPageAction method execute.
@Override
public ActionResult execute() {
/* Explanation: First, we extract any parameters from the request object.
* e.g., idOfCourseToDelete = getRequestParam(Const.ParamsNames.COURSE_ID);
* After that, we may verify parameters.
* e.g. Assumption.assertNotNull(courseId);
* In this Action, there are no parameters.*/
/* Explanation: Next, check if the user has rights to execute the action.*/
gateKeeper.verifyInstructorPrivileges(account);
/* Explanation: This is a 'show page' type action. Therefore, we
* prepare the matching PageData object, accessing the Logic
* component if necessary.*/
InstructorCoursesPageData data = new InstructorCoursesPageData(account, sessionToken);
String isUsingAjax = getRequestParamValue(Const.ParamsNames.IS_USING_AJAX);
data.setUsingAjax(isUsingAjax != null);
Map<String, InstructorAttributes> instructorsForCourses = new HashMap<>();
List<CourseAttributes> allCourses = new ArrayList<>();
List<CourseAttributes> activeCourses = new ArrayList<>();
List<CourseAttributes> archivedCourses = new ArrayList<>();
if (data.isUsingAjax()) {
// Get list of InstructorAttributes that belong to the user.
List<InstructorAttributes> instructorList = logic.getInstructorsForGoogleId(data.account.googleId);
for (InstructorAttributes instructor : instructorList) {
instructorsForCourses.put(instructor.courseId, instructor);
}
// Get corresponding courses of the instructors.
allCourses = logic.getCoursesForInstructor(instructorList);
List<String> archivedCourseIds = logic.getArchivedCourseIds(allCourses, instructorsForCourses);
for (CourseAttributes course : allCourses) {
if (archivedCourseIds.contains(course.getId())) {
archivedCourses.add(course);
} else {
activeCourses.add(course);
}
}
// Sort CourseDetailsBundle lists by course id
CourseAttributes.sortById(activeCourses);
CourseAttributes.sortById(archivedCourses);
}
data.init(activeCourses, archivedCourses, instructorsForCourses);
/* Explanation: Set any status messages that should be shown to the user.*/
if (data.isUsingAjax() && allCourses.isEmpty()) {
statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_EMPTY, StatusMessageColor.WARNING));
}
/* Explanation: We must set this variable. It is the text that will
* represent this particular execution of this action in the
* 'admin activity log' page.*/
statusToAdmin = "instructorCourse Page Load<br>Total courses: " + allCourses.size();
/* Explanation: Create the appropriate result object and return it.*/
return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSES, data);
}
Aggregations