Search in sources :

Example 1 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class CoursesLogic method getSectionsForCourse.

/**
 * Returns a list of {@link SectionDetailsBundle} for a
 * given course using course attributes and course details bundle.
 *
 * @param course {@link CourseAttributes}
 * @param cdd {@link CourseDetailsBundle}
 */
public List<SectionDetailsBundle> getSectionsForCourse(CourseAttributes course, CourseDetailsBundle cdd) {
    Assumption.assertNotNull("Course is null", course);
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(course.getId());
    StudentAttributes.sortBySectionName(students);
    List<SectionDetailsBundle> sections = new ArrayList<>();
    SectionDetailsBundle section = null;
    int teamIndexWithinSection = 0;
    for (int i = 0; i < students.size(); i++) {
        StudentAttributes s = students.get(i);
        cdd.stats.studentsTotal++;
        if (!s.isRegistered()) {
            cdd.stats.unregisteredTotal++;
        }
        if (section == null) {
            // First student of first section
            section = new SectionDetailsBundle();
            section.name = s.section;
            section.teams.add(new TeamDetailsBundle());
            cdd.stats.teamsTotal++;
            section.teams.get(teamIndexWithinSection).name = s.team;
            section.teams.get(teamIndexWithinSection).students.add(s);
        } else if (s.section.equals(section.name)) {
            if (s.team.equals(section.teams.get(teamIndexWithinSection).name)) {
                section.teams.get(teamIndexWithinSection).students.add(s);
            } else {
                teamIndexWithinSection++;
                section.teams.add(new TeamDetailsBundle());
                cdd.stats.teamsTotal++;
                section.teams.get(teamIndexWithinSection).name = s.team;
                section.teams.get(teamIndexWithinSection).students.add(s);
            }
        } else {
            // first student of subsequent section
            sections.add(section);
            if (!section.name.equals(Const.DEFAULT_SECTION)) {
                cdd.stats.sectionsTotal++;
            }
            teamIndexWithinSection = 0;
            section = new SectionDetailsBundle();
            section.name = s.section;
            section.teams.add(new TeamDetailsBundle());
            cdd.stats.teamsTotal++;
            section.teams.get(teamIndexWithinSection).name = s.team;
            section.teams.get(teamIndexWithinSection).students.add(s);
        }
        boolean isLastStudent = i == students.size() - 1;
        if (isLastStudent) {
            sections.add(section);
            if (!section.name.equals(Const.DEFAULT_SECTION)) {
                cdd.stats.sectionsTotal++;
            }
        }
    }
    return sections;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle)

Example 2 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle 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 3 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle 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)

Example 4 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class InstructorStudentListAjaxPageDataTest method initializeData.

private InstructorStudentListAjaxPageData initializeData() {
    photoUrl = "validPhotoUrl";
    acct = AccountAttributes.builder().withGoogleId(// only googleId is needed
    "valid.id").build();
    sampleStudent = StudentAttributes.builder("valid course", "1+1@email.com", "<script>alert(\"Valid name\");</script>").build();
    sampleTeam = new TeamDetailsBundle();
    sampleTeam.students.add(sampleStudent);
    sampleTeam.name = "valid team name >.<";
    sampleSection = new SectionDetailsBundle();
    sampleSection.teams.add(sampleTeam);
    sampleSection.name = "<valid section name>";
    List<SectionDetailsBundle> sections = new ArrayList<>();
    sections.add(sampleSection);
    sectionPrivileges = new HashMap<>();
    Map<String, Boolean> sectionPrivilege = new HashMap<>();
    sectionPrivilege.put(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, true);
    sectionPrivilege.put(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, false);
    sectionPrivileges.put(sampleSection.name, sectionPrivilege);
    Map<String, String> emailPhotoUrlMapping = new HashMap<>();
    emailPhotoUrlMapping.put(sampleStudent.email, photoUrl);
    return new InstructorStudentListAjaxPageData(acct, dummySessionToken, "valid course id", 1, true, sections, sectionPrivileges, emailPhotoUrlMapping);
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorStudentListAjaxPageData(teammates.ui.pagedata.InstructorStudentListAjaxPageData) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle)

Example 5 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class CoursesLogic method getCourseSummary.

/**
 * Returns the {@link CourseDetailsBundle} course details for a course using {@link CourseAttributes}.
 */
public CourseDetailsBundle getCourseSummary(CourseAttributes cd) {
    Assumption.assertNotNull("Supplied parameter was null", cd);
    CourseDetailsBundle cdd = new CourseDetailsBundle(cd);
    cdd.sections = (ArrayList<SectionDetailsBundle>) getSectionsForCourse(cd, cdd);
    return cdd;
}
Also used : CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle)

Aggregations

SectionDetailsBundle (teammates.common.datatransfer.SectionDetailsBundle)9 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)7 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)3 Map (java.util.Map)2 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)2 InstructorStudentListAjaxPageData (teammates.ui.pagedata.InstructorStudentListAjaxPageData)2 StudentListSectionData (teammates.ui.template.StudentListSectionData)2 ZoneId (java.time.ZoneId)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)1 StudentSearchResultBundle (teammates.common.datatransfer.StudentSearchResultBundle)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1