Search in sources :

Example 51 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class AccountsLogic method verifyStudentJoinCourseRequest.

private void verifyStudentJoinCourseRequest(String encryptedKey, String googleId) throws JoinCourseException {
    StudentAttributes studentRole = studentsLogic.getStudentForRegistrationKey(encryptedKey);
    if (studentRole == null) {
        throw new JoinCourseException(Const.StatusCodes.INVALID_KEY, "You have used an invalid join link: %s");
    } else if (studentRole.isRegistered()) {
        if (studentRole.googleId.equals(googleId)) {
            throw new JoinCourseException(Const.StatusCodes.ALREADY_JOINED, "You (" + googleId + ") have already joined this course");
        }
        throw new JoinCourseException(Const.StatusCodes.KEY_BELONGS_TO_DIFFERENT_USER, String.format(Const.StatusMessages.JOIN_COURSE_KEY_BELONGS_TO_DIFFERENT_USER, StringHelper.obscure(studentRole.googleId)));
    }
    StudentAttributes existingStudent = studentsLogic.getStudentForCourseIdAndGoogleId(studentRole.course, googleId);
    if (existingStudent != null) {
        throw new JoinCourseException(String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, googleId));
    }
}
Also used : JoinCourseException(teammates.common.exception.JoinCourseException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 52 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class AccountsLogic method joinCourseForInstructorWithInstitute.

/**
 * Institute is set only if it is not null. If it is null, this instructor
 * is given the institute of an existing instructor of the same course.
 */
private void joinCourseForInstructorWithInstitute(String encryptedKey, String googleId, String institute) throws JoinCourseException, InvalidParametersException, EntityDoesNotExistException {
    confirmValidJoinCourseRequest(encryptedKey, googleId);
    InstructorAttributes instructor = instructorsLogic.getInstructorForRegistrationKey(encryptedKey);
    AccountAttributes account = accountsDb.getAccount(googleId);
    String instituteToSave = institute == null ? getCourseInstitute(instructor.courseId) : institute;
    if (account == null) {
        createAccount(AccountAttributes.builder().withGoogleId(googleId).withName(instructor.name).withEmail(instructor.email).withInstitute(instituteToSave).withIsInstructor(true).withDefaultStudentProfileAttributes(googleId).build());
    } else {
        makeAccountInstructor(googleId);
    }
    instructor.googleId = googleId;
    instructorsLogic.updateInstructorByEmail(instructor.email, instructor);
    // Update the goolgeId of the student entity for the instructor which was created from sampleData.
    StudentAttributes student = studentsLogic.getStudentForEmail(instructor.courseId, instructor.email);
    if (student != null) {
        student.googleId = googleId;
        studentsLogic.updateStudentCascade(instructor.email, student);
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 53 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes 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 54 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes 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 55 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class CoursesLogic method hasIndicatedSections.

public boolean hasIndicatedSections(String courseId) throws EntityDoesNotExistException {
    verifyCourseIsPresent(courseId);
    List<StudentAttributes> studentList = studentsLogic.getStudentsForCourse(courseId);
    for (StudentAttributes student : studentList) {
        if (!student.section.equals(Const.DEFAULT_SECTION)) {
            return true;
        }
    }
    return false;
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Aggregations

StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)241 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)85 Test (org.testng.annotations.Test)80 ArrayList (java.util.ArrayList)55 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)33 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)33 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)30 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)27 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)22 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)17 ShowPageResult (teammates.ui.controller.ShowPageResult)15 HashMap (java.util.HashMap)14 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)14 InvalidParametersException (teammates.common.exception.InvalidParametersException)14 EmailWrapper (teammates.common.util.EmailWrapper)13 RedirectResult (teammates.ui.controller.RedirectResult)12 List (java.util.List)11 StatusMessage (teammates.common.util.StatusMessage)10 HashSet (java.util.HashSet)9 StudentEnrollDetails (teammates.common.datatransfer.StudentEnrollDetails)9