Search in sources :

Example 6 with TeamDetailsBundle

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

the class StudentsLogic method getTeamDetailsForStudent.

public TeamDetailsBundle getTeamDetailsForStudent(StudentAttributes student) {
    if (student != null) {
        TeamDetailsBundle teamResult = new TeamDetailsBundle();
        teamResult.name = student.team;
        teamResult.students = getStudentsForTeam(student.team, student.course);
        StudentAttributes.sortByNameAndThenByEmail(teamResult.students);
        return teamResult;
    }
    return null;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle)

Example 7 with TeamDetailsBundle

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

the class StudentsLogicTest method testGetTeamForStudent.

/*
     * NOTE: enrollStudents() tested in SubmissionsAdjustmentTest.
     * This is because it uses Task Queues for scheduling and therefore has to be
     * tested in a separate class.
     */
private void testGetTeamForStudent() {
    ______TS("Typical case: get team of existing student");
    String courseId = "idOfTypicalCourse1";
    String googleId = "student1InCourse1";
    StudentAttributes student = StudentsLogic.inst().getStudentForCourseIdAndGoogleId(courseId, googleId);
    TeamDetailsBundle team = StudentsLogic.inst().getTeamDetailsForStudent(student);
    assertEquals("Team 1.1</td></div>'\"", team.name);
    assertNotNull(team.students);
    assertEquals(4, team.students.size());
    ______TS("Typical case: get team of non-existing student");
    courseId = "idOfTypicalCourse1";
    googleId = "idOfNonExistingStudent";
    student = StudentsLogic.inst().getStudentForCourseIdAndGoogleId(courseId, googleId);
    team = StudentsLogic.inst().getTeamDetailsForStudent(student);
    assertNull(team);
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 8 with TeamDetailsBundle

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

the class CoursesLogicTest method testGetTeamsForCourse.

private void testGetTeamsForCourse() throws Exception {
    ______TS("typical case");
    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    List<TeamDetailsBundle> teams = coursesLogic.getTeamsForCourse(course.getId());
    assertEquals(2, teams.size());
    assertEquals("Team 1.1</td></div>'\"", teams.get(0).name);
    assertEquals("Team 1.2", teams.get(1).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", "UTC");
    teams = coursesLogic.getTeamsForCourse("course1");
    assertEquals(0, teams.size());
    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");
    ______TS("non-existent");
    try {
        coursesLogic.getTeamsForCourse("non-existent-course");
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("does not exist", e.getMessage());
    }
    ______TS("null parameter");
    try {
        coursesLogic.getTeamsForCourse(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 9 with TeamDetailsBundle

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

the class CoursesLogic method getSectionsForCourseWithoutStats.

/**
 * Returns a list of {@link SectionDetailsBundle} for a given course using courseId.
 */
public List<SectionDetailsBundle> getSectionsForCourseWithoutStats(String courseId) throws EntityDoesNotExistException {
    verifyCourseIsPresent(courseId);
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(courseId);
    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);
        if (section == null) {
            // First student of first section
            section = new SectionDetailsBundle();
            section.name = s.section;
            section.teams.add(new TeamDetailsBundle());
            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());
                section.teams.get(teamIndexWithinSection).name = s.team;
                section.teams.get(teamIndexWithinSection).students.add(s);
            }
        } else {
            // first student of subsequent section
            sections.add(section);
            teamIndexWithinSection = 0;
            section = new SectionDetailsBundle();
            section.name = s.section;
            section.teams.add(new TeamDetailsBundle());
            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);
        }
    }
    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 10 with TeamDetailsBundle

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

the class FeedbackMsqQuestionDetails method generateOptionList.

private List<String> generateOptionList(String courseId) {
    List<String> optionList = new ArrayList<>();
    switch(generateOptionsFor) {
        case NONE:
            optionList = msqChoices;
            break;
        case STUDENTS:
        // fallthrough
        case STUDENTS_EXCLUDING_SELF:
            List<StudentAttributes> studentList = StudentsLogic.inst().getStudentsForCourse(courseId);
            if (generateOptionsFor == FeedbackParticipantType.STUDENTS_EXCLUDING_SELF) {
                studentList.removeIf(studentInList -> studentInList.email.equals(studentDoingQuestion.email));
            }
            for (StudentAttributes student : studentList) {
                optionList.add(student.name + " (" + student.team + ")");
            }
            optionList.sort(null);
            break;
        case TEAMS:
        // fallthrough
        case TEAMS_EXCLUDING_SELF:
            try {
                List<TeamDetailsBundle> teamList = CoursesLogic.inst().getTeamsForCourse(courseId);
                if (generateOptionsFor == FeedbackParticipantType.TEAMS_EXCLUDING_SELF) {
                    teamList.removeIf(teamInList -> teamInList.name.equals(studentDoingQuestion.team));
                }
                for (TeamDetailsBundle team : teamList) {
                    optionList.add(team.name);
                }
                optionList.sort(null);
            } catch (EntityDoesNotExistException e) {
                Assumption.fail("Course disappeared");
            }
            break;
        case INSTRUCTORS:
            List<InstructorAttributes> instructorList = InstructorsLogic.inst().getInstructorsForCourse(courseId);
            for (InstructorAttributes instructor : instructorList) {
                optionList.add(instructor.name);
            }
            optionList.sort(null);
            break;
        default:
            Assumption.fail("Trying to generate options for neither students, teams nor instructors");
            break;
    }
    return optionList;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

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