use of teammates.common.exception.EnrollException in project teammates by TEAMMATES.
the class StudentAttributesFactoryTest method testMakeStudent.
@Test
public void testMakeStudent() throws EnrollException {
StudentAttributesFactory saf = new StudentAttributesFactory();
String line = null;
String courseId = null;
StudentAttributes studentCreated;
______TS("Failure case: empty row");
line = "";
courseId = "SAFT.courseId";
try {
saf.makeStudent(line, courseId);
signalFailureToDetectException();
} catch (EnrollException e) {
assertEquals(StudentAttributesFactory.ERROR_ENROLL_LINE_EMPTY, e.getMessage());
}
______TS("Failure case: too few columns");
line = "name|email";
try {
saf.makeStudent(line, courseId);
signalFailureToDetectException();
} catch (EnrollException e) {
assertEquals(StudentAttributesFactory.ERROR_ENROLL_LINE_TOOFEWPARTS, e.getMessage());
}
______TS("Typical case: normal column order with comment");
saf = new StudentAttributesFactory("TEAMS|Names|Email|comments");
line = "team 1|SAFT.name|SAFT@email.com|some comment...";
studentCreated = saf.makeStudent(line, courseId);
assertEquals(studentCreated.team, "team 1");
assertEquals(studentCreated.name, "SAFT.name");
assertEquals(studentCreated.email, "SAFT@email.com");
assertEquals(studentCreated.comments, "some comment...");
line = "team 2|SAFT.name2|SAFT2@email.com";
studentCreated = saf.makeStudent(line, courseId);
assertEquals(studentCreated.team, "team 2");
assertEquals(studentCreated.name, "SAFT.name2");
assertEquals(studentCreated.email, "SAFT2@email.com");
assertEquals(studentCreated.comments, "");
______TS("Typical case: different column order without comment");
saf = new StudentAttributesFactory("Name|emails|teams");
line = "SAFT.name|SAFT@email.com|team 1";
studentCreated = saf.makeStudent(line, courseId);
assertEquals(studentCreated.team, "team 1");
assertEquals(studentCreated.name, "SAFT.name");
assertEquals(studentCreated.email, "SAFT@email.com");
assertEquals(studentCreated.comments, "");
______TS("Typical case: different column order, contains empty columns");
saf = new StudentAttributesFactory("email \t name \t \t team");
line = "SAFT@email.com \t SAFT.name \t \t team 1";
studentCreated = saf.makeStudent(line, courseId);
assertEquals(studentCreated.team, "team 1");
assertEquals(studentCreated.name, "SAFT.name");
assertEquals(studentCreated.email, "SAFT@email.com");
assertEquals(studentCreated.comments, "");
______TS("Typical case: no header specified, assume default column order");
saf = new StudentAttributesFactory();
line = "section 1| team 1|SAFT.name|SAFT@email.com|comment";
studentCreated = saf.makeStudent(line, courseId);
assertEquals(studentCreated.section, "section 1");
assertEquals(studentCreated.team, "team 1");
assertEquals(studentCreated.name, "SAFT.name");
assertEquals(studentCreated.email, "SAFT@email.com");
assertEquals(studentCreated.comments, "comment");
line = "section 2| team 2|SAFT.name2|SAFT2@email.com";
studentCreated = saf.makeStudent(line, courseId);
assertEquals(studentCreated.section, "section 2");
assertEquals(studentCreated.team, "team 2");
assertEquals(studentCreated.name, "SAFT.name2");
assertEquals(studentCreated.email, "SAFT2@email.com");
assertEquals(studentCreated.comments, "");
}
use of teammates.common.exception.EnrollException in project teammates by TEAMMATES.
the class InstructorCourseStudentDetailsEditSaveAction method execute.
@Override
public ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENT_EMAIL, studentEmail);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
if (student == null) {
return redirectWithError(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_EDIT, "Student <span class=\"bold\">" + studentEmail + "</span> in " + "Course <span class=\"bold\">[" + courseId + "]</span> not found.", courseId);
}
student.name = getRequestParamValue(Const.ParamsNames.STUDENT_NAME);
student.email = getRequestParamValue(Const.ParamsNames.NEW_STUDENT_EMAIL);
student.team = getRequestParamValue(Const.ParamsNames.TEAM_NAME);
student.section = getRequestParamValue(Const.ParamsNames.SECTION_NAME);
student.comments = getRequestParamValue(Const.ParamsNames.COMMENTS);
boolean hasSection = logic.hasIndicatedSections(courseId);
student.name = SanitizationHelper.sanitizeName(student.name);
student.email = SanitizationHelper.sanitizeEmail(student.email);
student.team = SanitizationHelper.sanitizeName(student.team);
student.section = SanitizationHelper.sanitizeName(student.section);
student.comments = SanitizationHelper.sanitizeTextField(student.comments);
try {
StudentAttributes originalStudentAttribute = logic.getStudentForEmail(courseId, studentEmail);
student.updateWithExistingRecord(originalStudentAttribute);
boolean isSectionChanged = student.isSectionChanged(originalStudentAttribute);
boolean isTeamChanged = student.isTeamChanged(originalStudentAttribute);
boolean isEmailChanged = student.isEmailChanged(originalStudentAttribute);
if (isSectionChanged) {
logic.validateSectionsAndTeams(Arrays.asList(student), courseId);
} else if (isTeamChanged) {
logic.validateTeams(Arrays.asList(student), courseId);
}
logic.updateStudent(studentEmail, student);
boolean isSessionSummarySendEmail = getRequestParamAsBoolean(Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK);
if (isEmailChanged) {
logic.resetStudentGoogleId(student.email, courseId);
if (isSessionSummarySendEmail) {
try {
EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(courseId, student);
emailSender.sendEmail(email);
} catch (Exception e) {
log.severe("Error while sending session summary email" + TeammatesException.toStringWithStackTrace(e));
}
}
}
statusToUser.add(new StatusMessage(isSessionSummarySendEmail && isEmailChanged ? Const.StatusMessages.STUDENT_EDITED_AND_EMAIL_SENT : Const.StatusMessages.STUDENT_EDITED, StatusMessageColor.SUCCESS));
statusToAdmin = "Student <span class=\"bold\">" + studentEmail + "'s</span> details in " + "Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Email: " + student.email + "<br>New Team: " + student.team + "<br>" + "Comments: " + student.comments;
RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE);
result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
return result;
} catch (InvalidParametersException | EnrollException e) {
setStatusForException(e);
String newEmail = student.email;
student.email = studentEmail;
boolean isOpenOrPublishedEmailSentForTheCourse = logic.isOpenOrPublishedEmailSentForTheCourse(courseId);
InstructorCourseStudentDetailsEditPageData data = new InstructorCourseStudentDetailsEditPageData(account, sessionToken, student, newEmail, hasSection, isOpenOrPublishedEmailSentForTheCourse);
return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, data);
}
}
use of teammates.common.exception.EnrollException in project teammates by TEAMMATES.
the class InstructorCourseEnrollSaveAction method enrollAndProcessResultForDisplay.
private List<StudentAttributes>[] enrollAndProcessResultForDisplay(String studentsInfo, String courseId) throws EnrollException, EntityDoesNotExistException, InvalidParametersException, EntityAlreadyExistsException {
CourseEnrollmentResult enrollResult = logic.enrollStudents(studentsInfo, courseId);
List<StudentAttributes> students = enrollResult.studentList;
// Adjust submissions for all feedback responses within the course
List<FeedbackSessionAttributes> feedbackSessions = logic.getFeedbackSessionsForCourse(courseId);
for (FeedbackSessionAttributes session : feedbackSessions) {
// Schedule adjustment of submissions for feedback session in course
taskQueuer.scheduleFeedbackResponseAdjustmentForCourse(courseId, session.getFeedbackSessionName(), enrollResult.enrollmentList);
}
students.sort(Comparator.comparing(obj -> obj.updateStatus.numericRepresentation));
return separateStudents(students);
}
Aggregations