Search in sources :

Example 66 with InvalidParametersException

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

the class InstructorFeedbackResponseCommentAddAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    String feedbackQuestionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_ID, feedbackQuestionId);
    String feedbackResponseId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_ID, feedbackResponseId);
    String commentId = getRequestParamValue(Const.ParamsNames.COMMENT_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COMMENT_ID, commentId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
    FeedbackResponseAttributes response = logic.getFeedbackResponse(feedbackResponseId);
    Assumption.assertNotNull(response);
    boolean isCreatorOnly = true;
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly, response.giverSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly, response.recipientSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
    InstructorFeedbackResponseCommentAjaxPageData data = new InstructorFeedbackResponseCommentAjaxPageData(account, sessionToken);
    String giverEmail = response.giver;
    String recipientEmail = response.recipient;
    FeedbackSessionResultsBundle bundle = logic.getFeedbackSessionResultsForInstructor(feedbackSessionName, courseId, instructor.email);
    String giverName = bundle.getGiverNameForResponse(response);
    String giverTeamName = bundle.getTeamNameForEmail(giverEmail);
    data.giverName = bundle.appendTeamNameToName(giverName, giverTeamName);
    String recipientName = bundle.getRecipientNameForResponse(response);
    String recipientTeamName = bundle.getTeamNameForEmail(recipientEmail);
    data.recipientName = bundle.appendTeamNameToName(recipientName, recipientTeamName);
    // Set up comment text
    String commentText = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT, commentText);
    if (commentText.trim().isEmpty()) {
        data.errorMessage = Const.StatusMessages.FEEDBACK_RESPONSE_COMMENT_EMPTY;
        data.isError = true;
        return createAjaxResult(data);
    }
    FeedbackResponseCommentAttributes feedbackResponseComment = FeedbackResponseCommentAttributes.builder(courseId, feedbackSessionName, instructor.email, new Text(commentText)).withFeedbackQuestionId(feedbackQuestionId).withFeedbackResponseId(feedbackResponseId).withCreatedAt(Instant.now()).withGiverSection(response.giverSection).withReceiverSection(response.recipientSection).build();
    // Set up visibility settings
    String showCommentTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWCOMMENTSTO);
    String showGiverNameTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWGIVERTO);
    feedbackResponseComment.showCommentTo = new ArrayList<>();
    if (showCommentTo != null && !showCommentTo.isEmpty()) {
        String[] showCommentToArray = showCommentTo.split(",");
        for (String viewer : showCommentToArray) {
            feedbackResponseComment.showCommentTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    feedbackResponseComment.showGiverNameTo = new ArrayList<>();
    if (showGiverNameTo != null && !showGiverNameTo.isEmpty()) {
        String[] showGiverNameToArray = showGiverNameTo.split(",");
        for (String viewer : showGiverNameToArray) {
            feedbackResponseComment.showGiverNameTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    FeedbackResponseCommentAttributes createdComment = null;
    try {
        createdComment = logic.createFeedbackResponseComment(feedbackResponseComment);
        logic.putDocument(createdComment);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
        data.errorMessage = e.getMessage();
        data.isError = true;
    }
    if (!data.isError) {
        statusToAdmin += "InstructorFeedbackResponseCommentAddAction:<br>" + "Adding comment to response: " + feedbackResponseComment.feedbackResponseId + "<br>" + "in course/feedback session: " + feedbackResponseComment.courseId + "/" + feedbackResponseComment.feedbackSessionName + "<br>" + "by: " + feedbackResponseComment.giverEmail + " at " + feedbackResponseComment.createdAt + "<br>" + "comment text: " + feedbackResponseComment.commentText.getValue();
    }
    if (createdComment == null) {
        data.showCommentToString = "";
        data.showGiverNameToString = "";
    } else {
        data.showCommentToString = StringHelper.toString(createdComment.showCommentTo, ",");
        data.showGiverNameToString = StringHelper.toString(createdComment.showGiverNameTo, ",");
    }
    data.comment = createdComment;
    data.commentId = commentId;
    data.instructorEmailNameTable = bundle.instructorEmailNameTable;
    data.question = logic.getFeedbackQuestion(feedbackQuestionId);
    data.sessionTimeZone = session.getTimeZone();
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_RESPONSE_COMMENTS_ADD, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorFeedbackResponseCommentAjaxPageData(teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle)

Example 67 with InvalidParametersException

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

the class InstructorFeedbackResponseCommentEditAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    String feedbackResponseId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_ID, feedbackResponseId);
    String feedbackResponseCommentId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_ID, feedbackResponseCommentId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
    FeedbackResponseAttributes response = logic.getFeedbackResponse(feedbackResponseId);
    Assumption.assertNotNull(response);
    FeedbackResponseCommentAttributes frc = logic.getFeedbackResponseComment(Long.parseLong(feedbackResponseCommentId));
    Assumption.assertNotNull("FeedbackResponseComment should not be null", frc);
    verifyAccessibleForInstructorToFeedbackResponseComment(feedbackResponseCommentId, instructor, session, response);
    InstructorFeedbackResponseCommentAjaxPageData data = new InstructorFeedbackResponseCommentAjaxPageData(account, sessionToken);
    // Edit comment text
    String commentText = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT, commentText);
    if (commentText.trim().isEmpty()) {
        data.errorMessage = Const.StatusMessages.FEEDBACK_RESPONSE_COMMENT_EMPTY;
        data.isError = true;
        return createAjaxResult(data);
    }
    FeedbackResponseCommentAttributes feedbackResponseComment = FeedbackResponseCommentAttributes.builder(courseId, feedbackSessionName, instructor.email, new Text(commentText)).withCreatedAt(Instant.now()).withGiverSection(response.giverSection).withReceiverSection(response.recipientSection).build();
    feedbackResponseComment.setId(Long.parseLong(feedbackResponseCommentId));
    // Edit visibility settings
    String showCommentTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWCOMMENTSTO);
    String showGiverNameTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWGIVERTO);
    feedbackResponseComment.showCommentTo = new ArrayList<>();
    if (showCommentTo != null && !showCommentTo.isEmpty()) {
        String[] showCommentToArray = showCommentTo.split(",");
        for (String viewer : showCommentToArray) {
            feedbackResponseComment.showCommentTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    feedbackResponseComment.showGiverNameTo = new ArrayList<>();
    if (showGiverNameTo != null && !showGiverNameTo.isEmpty()) {
        String[] showGiverNameToArray = showGiverNameTo.split(",");
        for (String viewer : showGiverNameToArray) {
            feedbackResponseComment.showGiverNameTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    FeedbackResponseCommentAttributes updatedComment = null;
    try {
        updatedComment = logic.updateFeedbackResponseComment(feedbackResponseComment);
        // TODO: move putDocument to task queue
        logic.putDocument(updatedComment);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
        data.errorMessage = e.getMessage();
        data.isError = true;
    }
    if (!data.isError) {
        statusToAdmin += "InstructorFeedbackResponseCommentEditAction:<br>" + "Editing feedback response comment: " + feedbackResponseComment.getId() + "<br>" + "in course/feedback session: " + feedbackResponseComment.courseId + "/" + feedbackResponseComment.feedbackSessionName + "<br>" + "by: " + feedbackResponseComment.giverEmail + "<br>" + "comment text: " + feedbackResponseComment.commentText.getValue();
        String commentGiverName = logic.getInstructorForEmail(courseId, frc.giverEmail).name;
        String commentEditorName = instructor.name;
        // createdAt and lastEditedAt fields in updatedComment as well as sessionTimeZone
        // are required to generate timestamps in editedCommentDetails
        data.comment = updatedComment;
        data.sessionTimeZone = session.getTimeZone();
        data.editedCommentDetails = data.createEditedCommentDetails(commentGiverName, commentEditorName);
    }
    return createAjaxResult(data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorFeedbackResponseCommentAjaxPageData(teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 68 with InvalidParametersException

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

the class InstructorCourseEditSaveAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String courseName = getRequestParamValue(Const.ParamsNames.COURSE_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_NAME, courseName);
    String courseTimeZone = getRequestParamValue(Const.ParamsNames.COURSE_TIME_ZONE);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE);
    try {
        logic.updateCourse(courseId, courseName, courseTimeZone);
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_EDITED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Updated Course <span class=\"bold\">[" + courseId + "]</span> details:<br>" + "Name: " + courseName + "<br>" + "Time zone: " + courseTimeZone;
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
    result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    return result;
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 69 with InvalidParametersException

use of teammates.common.exception.InvalidParametersException 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 70 with InvalidParametersException

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

the class FeedbackResponsesLogic method deleteFeedbackResponsesForQuestionAndCascade.

public void deleteFeedbackResponsesForQuestionAndCascade(String feedbackQuestionId, boolean hasResponseRateUpdate) {
    List<FeedbackResponseAttributes> responsesForQuestion = getFeedbackResponsesForQuestion(feedbackQuestionId);
    Set<String> emails = new HashSet<>();
    for (FeedbackResponseAttributes response : responsesForQuestion) {
        this.deleteFeedbackResponseAndCascade(response);
        emails.add(response.giver);
    }
    if (!hasResponseRateUpdate) {
        return;
    }
    try {
        FeedbackQuestionAttributes question = fqLogic.getFeedbackQuestion(feedbackQuestionId);
        boolean isInstructor = question.giverType == FeedbackParticipantType.SELF || question.giverType == FeedbackParticipantType.INSTRUCTORS;
        for (String email : emails) {
            boolean hasResponses = hasGiverRespondedForSession(email, question.feedbackSessionName, question.courseId);
            if (!hasResponses) {
                if (isInstructor) {
                    fsLogic.deleteInstructorRespondent(email, question.feedbackSessionName, question.courseId);
                } else {
                    fsLogic.deleteStudentFromRespondentList(email, question.feedbackSessionName, question.courseId);
                }
            }
        }
    } catch (InvalidParametersException | EntityDoesNotExistException e) {
        Assumption.fail("Fail to delete respondent");
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InvalidParametersException(teammates.common.exception.InvalidParametersException) HashSet(java.util.HashSet) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

InvalidParametersException (teammates.common.exception.InvalidParametersException)83 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)37 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 StatusMessage (teammates.common.util.StatusMessage)21 Test (org.testng.annotations.Test)19 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)19 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)13 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)12 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 Text (com.google.appengine.api.datastore.Text)8 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)8 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)6 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)6 ArrayList (java.util.ArrayList)5 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)5 VoidWork (com.googlecode.objectify.VoidWork)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 PageData (teammates.ui.pagedata.PageData)4 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)3