Search in sources :

Example 6 with EnrollException

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, "");
}
Also used : EnrollException(teammates.common.exception.EnrollException) StudentAttributesFactory(teammates.common.datatransfer.StudentAttributesFactory) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Example 7 with EnrollException

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);
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EnrollException(teammates.common.exception.EnrollException) InstructorCourseStudentDetailsEditPageData(teammates.ui.pagedata.InstructorCourseStudentDetailsEditPageData) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EnrollException(teammates.common.exception.EnrollException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) TeammatesException(teammates.common.exception.TeammatesException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) StatusMessage(teammates.common.util.StatusMessage)

Example 8 with EnrollException

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);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) CourseEnrollmentResult(teammates.common.datatransfer.CourseEnrollmentResult) EnrollException(teammates.common.exception.EnrollException) SanitizationHelper(teammates.common.util.SanitizationHelper) StatusMessageColor(teammates.common.util.StatusMessageColor) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) ArrayList(java.util.ArrayList) List(java.util.List) StudentUpdateStatus(teammates.common.datatransfer.StudentUpdateStatus) InstructorCourseEnrollResultPageData(teammates.ui.pagedata.InstructorCourseEnrollResultPageData) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorCourseEnrollPageData(teammates.ui.pagedata.InstructorCourseEnrollPageData) Assumption(teammates.common.util.Assumption) StatusMessage(teammates.common.util.StatusMessage) Comparator(java.util.Comparator) Logger(teammates.common.util.Logger) InvalidParametersException(teammates.common.exception.InvalidParametersException) CourseEnrollmentResult(teammates.common.datatransfer.CourseEnrollmentResult) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Aggregations

EnrollException (teammates.common.exception.EnrollException)8 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 ArrayList (java.util.ArrayList)5 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)4 CourseEnrollmentResult (teammates.common.datatransfer.CourseEnrollmentResult)3 StudentAttributesFactory (teammates.common.datatransfer.StudentAttributesFactory)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)3 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 StatusMessage (teammates.common.util.StatusMessage)3 List (java.util.List)2 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)2 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)2 InstructorCourseEnrollPageData (teammates.ui.pagedata.InstructorCourseEnrollPageData)2 InstructorCourseEnrollResultPageData (teammates.ui.pagedata.InstructorCourseEnrollResultPageData)2 Text (com.google.appengine.api.datastore.Text)1 Comparator (java.util.Comparator)1 Test (org.testng.annotations.Test)1 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)1 StudentEnrollDetails (teammates.common.datatransfer.StudentEnrollDetails)1 StudentUpdateStatus (teammates.common.datatransfer.StudentUpdateStatus)1