Search in sources :

Example 1 with TeamDetailsBundle

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

the class CoursesLogic method getTeamsForCourse.

/**
 * Returns Teams for a particular courseId.<br>
 * <b>Note:</b><br>
 * This method does not returns any Loner information presently,<br>
 * Loner information must be returned as we decide to support loners<br>in future.
 */
public List<TeamDetailsBundle> getTeamsForCourse(String courseId) throws EntityDoesNotExistException {
    if (getCourse(courseId) == null) {
        throw new EntityDoesNotExistException("The course " + courseId + " does not exist");
    }
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(courseId);
    StudentAttributes.sortByTeamName(students);
    List<TeamDetailsBundle> teams = new ArrayList<>();
    TeamDetailsBundle team = null;
    for (int i = 0; i < students.size(); i++) {
        StudentAttributes s = students.get(i);
        // first student of first team
        if (team == null) {
            team = new TeamDetailsBundle();
            team.name = s.team;
            team.students.add(s);
        } else if (s.team.equals(team.name)) {
            // student in the same team as the previous student
            team.students.add(s);
        } else {
            // first student of subsequent teams (not the first team)
            teams.add(team);
            team = new TeamDetailsBundle();
            team.name = s.team;
            team.students.add(s);
        }
        // if last iteration
        if (i == students.size() - 1) {
            teams.add(team);
        }
    }
    return teams;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 2 with TeamDetailsBundle

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

use of teammates.common.datatransfer.TeamDetailsBundle 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 4 with TeamDetailsBundle

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

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

the class StudentCourseDetailsPageDataTest method test.

@Test
public void test() {
    ______TS("typical success case");
    AccountAttributes account = dataBundle.accounts.get("student1InCourse1");
    StudentCourseDetailsPageData pageData = new StudentCourseDetailsPageData(account, dummySessionToken);
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseDetailsBundle courseDetails = new CourseDetailsBundle(course);
    List<InstructorAttributes> instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructor1OfCourse1"));
    instructors.add(dataBundle.instructors.get("instructor2OfCourse1"));
    instructors.add(dataBundle.instructors.get("helperOfCourse1"));
    TeamDetailsBundle team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    List<InstructorAttributes> courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    List<StudentAttributes> teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(1).name, courseInstructors.get(1).name);
    assertEquals(instructors.get(2).name, courseInstructors.get(2).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(instructors.get(1).displayedName, courseInstructors.get(1).displayedName);
    assertEquals(instructors.get(2).displayedName, courseInstructors.get(2).displayedName);
    assertEquals(team.students.size(), teammates.size());
    ______TS("student in unregistered course");
    student = dataBundle.students.get("student1InUnregisteredCourse");
    course = dataBundle.courses.get("unregisteredCourse");
    courseDetails = new CourseDetailsBundle(course);
    instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructor5"));
    team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(team.students.size(), teammates.size());
    ______TS("student in archived course");
    student = dataBundle.students.get("student1InArchivedCourse");
    course = dataBundle.courses.get("archivedCourse");
    courseDetails = new CourseDetailsBundle(course);
    instructors = new ArrayList<>();
    instructors.add(dataBundle.instructors.get("instructorOfArchivedCourse"));
    team = new TeamDetailsBundle();
    team.name = student.team;
    // Get team members of student
    for (Entry<String, StudentAttributes> entry : dataBundle.students.entrySet()) {
        StudentAttributes currStudent = entry.getValue();
        if (currStudent.team.equals(team.name)) {
            team.students.add(currStudent);
        }
    }
    pageData.init(courseDetails, instructors, student, team);
    courseInstructors = pageData.getStudentCourseDetailsPanel().getInstructors();
    teammates = pageData.getStudentCourseDetailsPanel().getTeammates();
    assertEquals(courseDetails.course.getName(), pageData.getStudentCourseDetailsPanel().getCourseName());
    assertEquals(courseDetails.course.getId(), pageData.getStudentCourseDetailsPanel().getCourseId());
    assertFalse(courseInstructors.isEmpty());
    assertFalse(teammates.isEmpty());
    assertEquals(student.email, pageData.getStudentCourseDetailsPanel().getStudentEmail());
    assertEquals(student.name, pageData.getStudentCourseDetailsPanel().getStudentName());
    assertEquals(team.name, pageData.getStudentCourseDetailsPanel().getStudentTeam());
    assertEquals(instructors.size(), courseInstructors.size());
    assertEquals(instructors.get(0).name, courseInstructors.get(0).name);
    assertEquals(instructors.get(0).displayedName, courseInstructors.get(0).displayedName);
    assertEquals(team.students.size(), teammates.size());
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ArrayList(java.util.ArrayList) StudentCourseDetailsPageData(teammates.ui.pagedata.StudentCourseDetailsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Aggregations

TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)16 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)13 ArrayList (java.util.ArrayList)8 SectionDetailsBundle (teammates.common.datatransfer.SectionDetailsBundle)7 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)6 HashMap (java.util.HashMap)5 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)5 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)3 Map (java.util.Map)2 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)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 FeedbackParticipantType (teammates.common.datatransfer.FeedbackParticipantType)1 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)1