Search in sources :

Example 21 with EntityAlreadyExistsException

use of teammates.common.exception.EntityAlreadyExistsException 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)

Example 22 with EntityAlreadyExistsException

use of teammates.common.exception.EntityAlreadyExistsException in project teammates by TEAMMATES.

the class FeedbackResponsesLogic method updateFeedbackResponsesForChangingEmail.

/**
 * Updates responses for a student when his email changes.
 */
// TODO: cascade the update to response comments
public void updateFeedbackResponsesForChangingEmail(String courseId, String oldEmail, String newEmail) throws InvalidParametersException, EntityDoesNotExistException {
    List<FeedbackResponseAttributes> responsesFromUser = getFeedbackResponsesFromGiverForCourse(courseId, oldEmail);
    for (FeedbackResponseAttributes response : responsesFromUser) {
        response.giver = newEmail;
        try {
            updateFeedbackResponse(response);
        } catch (EntityAlreadyExistsException e) {
            Assumption.fail("Feedback response failed to update successfully" + "as email was already in use.");
        }
    }
    List<FeedbackResponseAttributes> responsesToUser = getFeedbackResponsesForReceiverForCourse(courseId, oldEmail);
    for (FeedbackResponseAttributes response : responsesToUser) {
        response.recipient = newEmail;
        try {
            updateFeedbackResponse(response);
        } catch (EntityAlreadyExistsException e) {
            Assumption.fail("Feedback response failed to update successfully" + "as email was already in use.");
        }
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException)

Example 23 with EntityAlreadyExistsException

use of teammates.common.exception.EntityAlreadyExistsException in project teammates by TEAMMATES.

the class StudentsDb method recreateStudentWithNewEmail.

@SuppressWarnings("PMD.PreserveStackTrace")
private void recreateStudentWithNewEmail(CourseStudent newCourseStudent, String lastName, CourseStudent courseStudent, boolean hasDocument, boolean keepUpdateTimestamp, String courseId, String email) throws InvalidParametersException {
    newCourseStudent.setLastName(lastName);
    newCourseStudent.setCreatedAt(courseStudent.getCreatedAt());
    if (keepUpdateTimestamp) {
        newCourseStudent.setLastUpdate(courseStudent.getUpdatedAt());
    }
    StudentAttributes newCourseStudentAttributes = makeAttributes(newCourseStudent);
    try {
        createStudent(newCourseStudentAttributes, hasDocument);
    } catch (EntityAlreadyExistsException e) {
        CourseStudent existingStudent = getEntity(newCourseStudentAttributes);
        String error = ERROR_UPDATE_EMAIL_ALREADY_USED + existingStudent.getName() + "/" + existingStudent.getEmail();
        throw new InvalidParametersException(error);
    }
    deleteStudent(courseId, email);
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) CourseStudent(teammates.storage.entity.CourseStudent) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Aggregations

EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)23 InvalidParametersException (teammates.common.exception.InvalidParametersException)19 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)10 Test (org.testng.annotations.Test)7 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)7 StatusMessage (teammates.common.util.StatusMessage)7 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)4 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)4 ArrayList (java.util.ArrayList)3 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)3 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)3 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)3 Text (com.google.appengine.api.datastore.Text)2 List (java.util.List)2 EnrollException (teammates.common.exception.EnrollException)2 InstructorCourseEnrollPageData (teammates.ui.pagedata.InstructorCourseEnrollPageData)2 InstructorCourseEnrollResultPageData (teammates.ui.pagedata.InstructorCourseEnrollResultPageData)2 Comparator (java.util.Comparator)1 CourseEnrollmentResult (teammates.common.datatransfer.CourseEnrollmentResult)1