Search in sources :

Example 1 with EntityAlreadyExistsException

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

the class FeedbackSubmissionEditSaveAction method updateResponses.

private void updateResponses(List<FeedbackResponseAttributes> responsesToUpdate) throws EntityDoesNotExistException {
    for (FeedbackResponseAttributes response : responsesToUpdate) {
        try {
            logic.updateFeedbackResponse(response);
            hasValidResponse = true;
        } catch (EntityAlreadyExistsException | InvalidParametersException e) {
            setStatusForException(e);
        }
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException)

Example 2 with EntityAlreadyExistsException

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

the class InstructorCourseAddAction method createCourse.

private void createCourse(String newCourseId, String newCourseName, String newCourseTimeZone) {
    try {
        logic.createCourseAndInstructor(data.account.googleId, newCourseId, newCourseName, newCourseTimeZone);
        String statusMessage = Const.StatusMessages.COURSE_ADDED.replace("${courseEnrollLink}", data.getInstructorCourseEnrollLink(newCourseId)).replace("${courseEditLink}", data.getInstructorCourseEditLink(newCourseId));
        statusToUser.add(new StatusMessage(statusMessage, StatusMessageColor.SUCCESS));
        isError = false;
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.COURSE_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage)

Example 3 with EntityAlreadyExistsException

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

the class InstructorFeedbackAddAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getNonNullRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertNotEmpty(courseId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    String feedbackSessionName = SanitizationHelper.sanitizeTitle(getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME));
    FeedbackSessionAttributes fs = extractFeedbackSessionData(feedbackSessionName, courseId, instructor.email);
    String feedbackSessionType = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_TYPE);
    InstructorFeedbackSessionsPageData data = new InstructorFeedbackSessionsPageData(account, sessionToken);
    try {
        validateTimeData(fs);
        logic.createFeedbackSession(fs);
        try {
            createTemplateFeedbackQuestions(fs.getCourseId(), fs.getFeedbackSessionName(), fs.getCreatorEmail(), feedbackSessionType);
        } catch (InvalidParametersException e) {
            // Failed to create feedback questions for specified template/feedback session type.
            // TODO: let the user know an error has occurred? delete the feedback session?
            log.severe(TeammatesException.toStringWithStackTrace(e));
        }
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_ADDED, StatusMessageColor.SUCCESS));
        statusToAdmin = "New Feedback Session <span class=\"bold\">(" + fs.getFeedbackSessionName() + ")</span> for Course " + "<span class=\"bold\">[" + fs.getCourseId() + "]</span> created.<br>" + "<span class=\"bold\">From:</span> " + fs.getStartTime() + "<span class=\"bold\"> to</span> " + fs.getEndTime() + "<br>" + "<span class=\"bold\">Session visible from:</span> " + fs.getSessionVisibleFromTime() + "<br>" + "<span class=\"bold\">Results visible from:</span> " + fs.getResultsVisibleFromTime() + "<br><br>" + "<span class=\"bold\">Instructions:</span> " + fs.getInstructions();
        // (similar to the one below)
        return createRedirectResult(data.getInstructorFeedbackEditLink(fs.getCourseId(), fs.getFeedbackSessionName()));
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.FEEDBACK_SESSION_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    // isError == true if an exception occurred above
    boolean shouldOmitArchived = true;
    Map<String, InstructorAttributes> instructors = loadCourseInstructorMap(shouldOmitArchived);
    List<InstructorAttributes> instructorList = new ArrayList<>(instructors.values());
    List<CourseAttributes> courses = loadCoursesList(instructorList);
    List<FeedbackSessionAttributes> feedbackSessions = loadFeedbackSessionsList(instructorList);
    FeedbackSessionAttributes.sortFeedbackSessionsByCreationTimeDescending(feedbackSessions);
    if (feedbackSessions.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_ADD_DB_INCONSISTENCY, StatusMessageColor.WARNING));
    }
    data.initWithoutHighlightedRow(courses, courseId, feedbackSessions, instructors, fs, feedbackSessionType);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SESSIONS, data);
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) ArrayList(java.util.ArrayList) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackSessionsPageData(teammates.ui.pagedata.InstructorFeedbackSessionsPageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 4 with EntityAlreadyExistsException

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

the class InstructorFeedbackCopyAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String copiedFeedbackSessionName = getRequestParamValue(Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME);
    String copiedCourseId = getRequestParamValue(Const.ParamsNames.COPIED_COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, copiedFeedbackSessionName);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COPIED_COURSE_ID, copiedCourseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    try {
        FeedbackSessionAttributes fs = logic.copyFeedbackSession(copiedFeedbackSessionName.trim(), copiedCourseId, feedbackSessionName, courseId, instructor.email);
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_COPIED, StatusMessageColor.SUCCESS));
        statusToAdmin = "New Feedback Session <span class=\"bold\">(" + fs.getFeedbackSessionName() + ")</span> " + "for Course <span class=\"bold\">[" + fs.getCourseId() + "]</span> created.<br>" + "<span class=\"bold\">From:</span> " + fs.getStartTime() + "<span class=\"bold\"> to</span> " + fs.getEndTime() + "<br>" + "<span class=\"bold\">Session visible from:</span> " + fs.getSessionVisibleFromTime() + "<br>" + "<span class=\"bold\">Results visible from:</span> " + fs.getResultsVisibleFromTime() + "<br><br>" + "<span class=\"bold\">Instructions:</span> " + fs.getInstructions();
        // (similar to the one below)
        return createRedirectResult(new PageData(account, sessionToken).getInstructorFeedbackEditLink(fs.getCourseId(), fs.getFeedbackSessionName()));
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.FEEDBACK_SESSION_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    RedirectResult redirectResult = createRedirectResult(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE);
    redirectResult.responseParams.put(Const.ParamsNames.USER_ID, account.googleId);
    return redirectResult;
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) PageData(teammates.ui.pagedata.PageData) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 5 with EntityAlreadyExistsException

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

the class InstructorCourseEnrollSaveAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String studentsInfo = getRequestParamValue(Const.ParamsNames.STUDENTS_ENROLLMENT_INFO);
    String sanitizedStudentsInfo = SanitizationHelper.sanitizeForHtml(studentsInfo);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, studentsInfo);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    /* Process enrollment list and setup data for page result */
    try {
        List<StudentAttributes>[] students = enrollAndProcessResultForDisplay(studentsInfo, courseId);
        boolean hasSection = hasSections(students);
        InstructorCourseEnrollResultPageData pageData = new InstructorCourseEnrollResultPageData(account, sessionToken, courseId, students, hasSection, studentsInfo);
        statusToAdmin = "Students Enrolled in Course <span class=\"bold\">[" + courseId + "]:</span><br>" + sanitizedStudentsInfo.replace("\n", "<br>");
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL_RESULT, pageData);
    } catch (EnrollException | InvalidParametersException e) {
        setStatusForException(e);
        statusToAdmin += "<br>Enrollment string entered by user:<br>" + sanitizedStudentsInfo.replace("\n", "<br>");
        InstructorCourseEnrollPageData pageData = new InstructorCourseEnrollPageData(account, sessionToken, courseId, studentsInfo);
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageData);
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e);
        statusToUser.add(new StatusMessage("The enrollment failed, possibly because some students were re-enrolled before " + "the previous enrollment action was still being processed by TEAMMATES database " + "servers. Please try again after about 10 minutes. If the problem persists, " + "please contact TEAMMATES support", StatusMessageColor.DANGER));
        InstructorCourseEnrollPageData pageData = new InstructorCourseEnrollPageData(account, sessionToken, courseId, studentsInfo);
        log.severe("Entity already exists exception occurred when updating student: " + e.getMessage());
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageData);
    }
}
Also used : EnrollException(teammates.common.exception.EnrollException) InstructorCourseEnrollResultPageData(teammates.ui.pagedata.InstructorCourseEnrollResultPageData) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InstructorCourseEnrollPageData(teammates.ui.pagedata.InstructorCourseEnrollPageData) ArrayList(java.util.ArrayList) List(java.util.List) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

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