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));
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations