Search in sources :

Example 1 with CourseDetailsBundle

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();
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 2 with CourseDetailsBundle

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());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 3 with CourseDetailsBundle

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());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 4 with CourseDetailsBundle

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());
    }
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 5 with CourseDetailsBundle

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());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) InstructorCourseDetailsPageData(teammates.ui.pagedata.InstructorCourseDetailsPageData) ArrayList(java.util.ArrayList) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)21 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)8 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)8 ArrayList (java.util.ArrayList)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)6 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)6 HashMap (java.util.HashMap)5 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)5 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 Test (org.testng.annotations.Test)3 SectionDetailsBundle (teammates.common.datatransfer.SectionDetailsBundle)3 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)3 FeedbackSessionDetailsBundle (teammates.common.datatransfer.FeedbackSessionDetailsBundle)2 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)2 StatusMessage (teammates.common.util.StatusMessage)2 InstructorCourseDetailsPageData (teammates.ui.pagedata.InstructorCourseDetailsPageData)2 StudentHomePageData (teammates.ui.pagedata.StudentHomePageData)2 CourseTable (teammates.ui.template.CourseTable)2 Text (com.google.appengine.api.datastore.Text)1 CourseEnrollmentResult (teammates.common.datatransfer.CourseEnrollmentResult)1