use of teammates.common.datatransfer.CourseDetailsBundle in project teammates by TEAMMATES.
the class CoursesLogic method getCourseStudentListAsCsv.
/**
* Returns a CSV for the details (name, email, status) of all students belonging to a given course.
*/
public String getCourseStudentListAsCsv(String courseId, String googleId) throws EntityDoesNotExistException {
Map<String, CourseDetailsBundle> courses = getCourseSummariesForInstructor(googleId, false);
CourseDetailsBundle course = courses.get(courseId);
boolean hasSection = hasIndicatedSections(courseId);
StringBuilder export = new StringBuilder(100);
String courseInfo = "Course ID," + SanitizationHelper.sanitizeForCsv(courseId) + System.lineSeparator() + "Course Name," + SanitizationHelper.sanitizeForCsv(course.course.getName()) + System.lineSeparator() + System.lineSeparator() + System.lineSeparator();
export.append(courseInfo);
String header = (hasSection ? "Section," : "") + "Team,Full Name,Last Name,Status,Email" + System.lineSeparator();
export.append(header);
for (SectionDetailsBundle section : course.sections) {
for (TeamDetailsBundle team : section.teams) {
for (StudentAttributes student : team.students) {
String studentStatus = null;
if (student.googleId == null || student.googleId.isEmpty()) {
studentStatus = Const.STUDENT_COURSE_STATUS_YET_TO_JOIN;
} else {
studentStatus = Const.STUDENT_COURSE_STATUS_JOINED;
}
if (hasSection) {
export.append(SanitizationHelper.sanitizeForCsv(section.name)).append(',');
}
export.append(SanitizationHelper.sanitizeForCsv(team.name) + ',' + SanitizationHelper.sanitizeForCsv(StringHelper.removeExtraSpace(student.name)) + ',' + SanitizationHelper.sanitizeForCsv(StringHelper.removeExtraSpace(student.lastName)) + ',' + SanitizationHelper.sanitizeForCsv(studentStatus) + ',' + SanitizationHelper.sanitizeForCsv(student.email) + System.lineSeparator());
}
}
}
return export.toString();
}
use of teammates.common.datatransfer.CourseDetailsBundle in project teammates by TEAMMATES.
the class CoursesLogicTest method testGetCourseSummary.
private void testGetCourseSummary() throws Exception {
______TS("typical case");
CourseAttributes course = dataBundle.courses.get("typicalCourse1");
CourseDetailsBundle courseSummary = coursesLogic.getCourseSummary(course.getId());
assertEquals(course.getId(), courseSummary.course.getId());
assertEquals(course.getName(), courseSummary.course.getName());
assertEquals(2, courseSummary.stats.teamsTotal);
assertEquals(5, courseSummary.stats.studentsTotal);
assertEquals(0, courseSummary.stats.unregisteredTotal);
assertEquals(1, courseSummary.sections.get(0).teams.size());
assertEquals("Team 1.1</td></div>'\"", courseSummary.sections.get(0).teams.get(0).name);
______TS("course without students");
StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "Asia/Singapore");
courseSummary = coursesLogic.getCourseSummary("course1");
assertEquals("course1", courseSummary.course.getId());
assertEquals("course 1", courseSummary.course.getName());
assertEquals("Asia/Singapore", courseSummary.course.getTimeZone().getId());
assertEquals(0, courseSummary.stats.teamsTotal);
assertEquals(0, courseSummary.stats.studentsTotal);
assertEquals(0, courseSummary.stats.unregisteredTotal);
assertEquals(0, courseSummary.sections.size());
coursesLogic.deleteCourseCascade("course1");
accountsDb.deleteAccount("instructor1");
______TS("non-existent");
try {
coursesLogic.getCourseSummary("non-existent-course");
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("The course does not exist:", e.getMessage());
}
______TS("null parameter");
try {
coursesLogic.getCourseSummary((CourseAttributes) null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
try {
coursesLogic.getCourseSummary((String) null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
}
use of teammates.common.datatransfer.CourseDetailsBundle in project teammates by TEAMMATES.
the class CoursesLogicTest method testGetCourseDetails.
private void testGetCourseDetails() throws Exception {
______TS("typical case");
CourseAttributes course = dataBundle.courses.get("typicalCourse1");
CourseDetailsBundle courseDetails = coursesLogic.getCourseSummary(course.getId());
assertEquals(course.getId(), courseDetails.course.getId());
assertEquals(course.getName(), courseDetails.course.getName());
assertEquals(course.getTimeZone(), courseDetails.course.getTimeZone());
assertEquals(2, courseDetails.stats.teamsTotal);
assertEquals(5, courseDetails.stats.studentsTotal);
assertEquals(0, courseDetails.stats.unregisteredTotal);
assertEquals(1, courseDetails.sections.get(0).teams.size());
assertEquals("Team 1.1</td></div>'\"", courseDetails.sections.get(0).teams.get(0).name);
______TS("course without students");
StudentProfileAttributes spa = StudentProfileAttributes.builder("instructor1").build();
AccountsLogic.inst().createAccount(AccountAttributes.builder().withGoogleId("instructor1").withName("Instructor 1").withEmail("instructor@email.tmt").withInstitute("TEAMMATES Test Institute 1").withIsInstructor(true).withStudentProfileAttributes(spa).build());
coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1", "Australia/Adelaide");
courseDetails = coursesLogic.getCourseSummary("course1");
assertEquals("course1", courseDetails.course.getId());
assertEquals("course 1", courseDetails.course.getName());
assertEquals("Australia/Adelaide", courseDetails.course.getTimeZone().getId());
assertEquals(0, courseDetails.stats.teamsTotal);
assertEquals(0, courseDetails.stats.studentsTotal);
assertEquals(0, courseDetails.stats.unregisteredTotal);
assertEquals(0, courseDetails.sections.size());
coursesLogic.deleteCourseCascade("course1");
accountsDb.deleteAccount("instructor1");
______TS("non-existent");
try {
coursesLogic.getCourseSummary("non-existent-course");
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("The course does not exist:", e.getMessage());
}
______TS("null parameter");
try {
coursesLogic.getCourseSummary((String) null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
}
use of teammates.common.datatransfer.CourseDetailsBundle in project teammates by TEAMMATES.
the class CoursesLogicTest method testGetCourseDetailsListForStudent.
private void testGetCourseDetailsListForStudent() throws Exception {
______TS("student having multiple evaluations in multiple courses");
CourseAttributes expectedCourse1 = dataBundle.courses.get("typicalCourse1");
// This student is in both course 1 and 2
StudentAttributes studentInBothCourses = dataBundle.students.get("student2InCourse1");
// Get course details for student
List<CourseDetailsBundle> courseList = coursesLogic.getCourseDetailsListForStudent(studentInBothCourses.googleId);
// Verify number of courses received
assertEquals(2, courseList.size());
CourseDetailsBundle actualCourse1 = courseList.get(0);
assertEquals(expectedCourse1.getId(), actualCourse1.course.getId());
assertEquals(expectedCourse1.getName(), actualCourse1.course.getName());
// student with no courses is not applicable
______TS("non-existent student");
try {
coursesLogic.getCourseDetailsListForStudent("non-existent-student");
signalFailureToDetectException();
} catch (EntityDoesNotExistException e) {
AssertHelper.assertContains("does not exist", e.getMessage());
}
______TS("null parameter");
try {
coursesLogic.getCourseDetailsListForStudent(null);
signalFailureToDetectException();
} catch (AssertionError e) {
assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
}
}
use of teammates.common.datatransfer.CourseDetailsBundle in project teammates by TEAMMATES.
the class InstructorCourseDetailsPageDataTest method testAll.
@Test
public void testAll() {
______TS("test typical case");
AccountAttributes instructorAccount = dataBundle.accounts.get("instructor1OfCourse1");
InstructorCourseDetailsPageData pageData = new InstructorCourseDetailsPageData(instructorAccount, dummySessionToken);
InstructorAttributes curInstructor = dataBundle.instructors.get("instructor1OfCourse1");
List<InstructorAttributes> instructors = new ArrayList<>();
for (InstructorAttributes instructor : dataBundle.instructors.values()) {
if ("idOfTypicalCourse1".equals(instructor.courseId)) {
instructors.add(instructor);
}
}
CourseDetailsBundle courseDetails = new CourseDetailsBundle(dataBundle.courses.get("typicalCourse1"));
courseDetails.sections = new ArrayList<>();
SectionDetailsBundle sampleSection = new SectionDetailsBundle();
sampleSection.name = "Sample section name";
courseDetails.sections.add(sampleSection);
pageData.init(curInstructor, courseDetails, instructors);
assertEquals(instructors.size(), pageData.getInstructors().size());
assertNotNull(pageData.getCourseRemindButton());
assertFalse(pageData.getCourseRemindButton().getAttributes().isEmpty());
assertNull(pageData.getCourseRemindButton().getContent());
assertNotNull(pageData.getCourseDetails());
assertNotNull(pageData.getCurrentInstructor());
assertTrue(pageData.isHasSection());
assertEquals(1, pageData.getSections().size());
______TS("test data bundle with no section");
courseDetails.sections = new ArrayList<>();
sampleSection = new SectionDetailsBundle();
sampleSection.name = "None";
courseDetails.sections.add(sampleSection);
pageData.init(curInstructor, courseDetails, instructors);
assertFalse(pageData.isHasSection());
assertEquals(1, pageData.getSections().size());
______TS("test current instructor doesn't have any permission for the course");
String[] allPrivileges = { Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS };
for (String privilege : allPrivileges) {
curInstructor.privileges.updatePrivilege(privilege, false);
}
pageData.init(curInstructor, courseDetails, instructors);
assertEquals(instructors.size(), pageData.getInstructors().size());
assertNotNull(pageData.getCourseRemindButton());
assertFalse(pageData.getCourseRemindButton().getAttributes().isEmpty());
assertNull(pageData.getCourseRemindButton().getContent());
assertNotNull(pageData.getCourseDetails());
assertNotNull(pageData.getCurrentInstructor());
}
Aggregations