Search in sources :

Example 61 with InvalidParametersException

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

the class InstructorCourseJoinAuthenticatedAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    Assumption.assertNotNull(regkey);
    String institute = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION);
    gateKeeper.verifyLoggedInUserPrivileges();
    /* Process authentication for the instructor to join course */
    try {
        if (institute == null) {
            logic.joinCourseForInstructor(regkey, account.googleId);
        } else {
            logic.joinCourseForInstructor(regkey, account.googleId, institute);
        }
    } catch (JoinCourseException | InvalidParametersException e) {
        // Does not sanitize for html to allow insertion of mailto link
        setStatusForException(e, e.getMessage());
        log.info(e.getMessage());
    }
    /* Set status to be shown to admin */
    StringBuffer joinedCourseMsg = new StringBuffer(100);
    joinedCourseMsg.append("Action Instructor Joins Course<br>Google ID: ").append(account.googleId);
    try {
        joinedCourseMsg.append("<br>Key : ").append(StringHelper.decrypt(regkey));
    } catch (InvalidParametersException e) {
        joinedCourseMsg.append("<br>Key could not be decrypted.");
    // no need to do setStatusForException and logging, as this case is already caught above
    }
    if (statusToAdmin == null) {
        statusToAdmin = joinedCourseMsg.toString();
    } else {
        statusToAdmin += "<br><br>" + joinedCourseMsg.toString();
    }
    /* Create redirection to instructor's homepage */
    RedirectResult response = createRedirectResult(Const.ActionURIs.INSTRUCTOR_HOME_PAGE);
    InstructorAttributes instructor = logic.getInstructorForRegistrationKey(regkey);
    if (instructor != null) {
        response.addResponseParam(Const.ParamsNames.CHECK_PERSISTENCE_COURSE, instructor.courseId);
        sendCourseRegisteredEmail(instructor.name, instructor.email, true, instructor.courseId);
    }
    return response;
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) JoinCourseException(teammates.common.exception.JoinCourseException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 62 with InvalidParametersException

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

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

the class AdminEmailComposeSendAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
    String emailContent = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_CONTENT);
    String subject = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_SUBJECT);
    addressReceiverListString = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
    isAddressModeOn = addressReceiverListString != null && !addressReceiverListString.isEmpty();
    emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
    groupReceiverListFileKey = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_FILE_KEY);
    isGroupModeOn = groupReceiverListFileKey != null && !groupReceiverListFileKey.isEmpty();
    if (isGroupModeOn) {
        try {
            groupReceiver.add(groupReceiverListFileKey);
            GoogleCloudStorageHelper.getGroupReceiverList(new BlobKey(groupReceiverListFileKey));
        } catch (Exception e) {
            isError = true;
            setStatusForException(e, "An error occurred when retrieving receiver list, please try again");
        }
    }
    if (isAddressModeOn) {
        addressReceiver.add(addressReceiverListString);
        try {
            checkAddressReceiverString(addressReceiverListString);
        } catch (InvalidParametersException e) {
            isError = true;
            setStatusForException(e);
        }
    }
    if (!isAddressModeOn && !isGroupModeOn) {
        isError = true;
        statusToAdmin = "Error : No receiver address or file given";
        statusToUser.add(new StatusMessage("Error : No receiver address or file given", StatusMessageColor.DANGER));
    }
    if (isError) {
        data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
        return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
    }
    boolean isEmailDraft = emailId != null && !emailId.isEmpty();
    if (isEmailDraft) {
        updateDraftEmailToSent(emailId, subject, addressReceiver, groupReceiver, emailContent);
    } else {
        recordNewSentEmail(subject, addressReceiver, groupReceiver, emailContent);
    }
    if (isError) {
        data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
    }
    return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) InvalidParametersException(teammates.common.exception.InvalidParametersException) Text(com.google.appengine.api.datastore.Text) AdminEmailComposePageData(teammates.ui.pagedata.AdminEmailComposePageData) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage)

Example 64 with InvalidParametersException

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

the class AdminEmailComposeSendAction method updateDraftEmailToSent.

private void updateDraftEmailToSent(String emailId, String subject, List<String> addressReceiver, List<String> groupReceiver, String content) {
    AdminEmailAttributes finalisedEmail = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(content)).withSendDate(Instant.now()).build();
    try {
        logic.updateAdminEmailById(finalisedEmail, emailId);
    } catch (InvalidParametersException | EntityDoesNotExistException e) {
        isError = true;
        setStatusForException(e);
        return;
    }
    moveJobToGroupModeTaskQueue();
    moveJobToAddressModeTaskQueue();
}
Also used : Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) AdminEmailAttributes(teammates.common.datatransfer.attributes.AdminEmailAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 65 with InvalidParametersException

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

the class AdminEmailTrashAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    String emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
    String redirect = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_TRASH_ACTION_REDIRECT);
    if (redirect == null) {
        redirect = Const.ActionURIs.ADMIN_EMAIL_TRASH_PAGE;
    }
    if (redirect.contains("sentpage")) {
        redirect = Const.ActionURIs.ADMIN_EMAIL_SENT_PAGE;
    } else if (redirect.contains("draftpage")) {
        redirect = Const.ActionURIs.ADMIN_EMAIL_DRAFT_PAGE;
    } else {
        redirect = Const.ActionURIs.ADMIN_EMAIL_TRASH_PAGE;
    }
    if (emailId == null || emailId.isEmpty()) {
        statusToAdmin = "Invalid parameter : email id cannot be null or empty";
        statusToUser.add(new StatusMessage("Invalid parameter : email id cannot be null or empty", StatusMessageColor.DANGER));
        return createRedirectResult(redirect);
    }
    if (requestUrl.contains(Const.ActionURIs.ADMIN_EMAIL_MOVE_TO_TRASH)) {
        try {
            logic.moveAdminEmailToTrashBin(emailId);
            statusToAdmin = "Email with id" + emailId + " has been moved to trash bin";
            statusToUser.add(new StatusMessage("The item has been moved to trash bin", StatusMessageColor.SUCCESS));
        } catch (InvalidParametersException | EntityDoesNotExistException e) {
            setStatusForException(e, "An error has occurred when moving email to trash bin");
        }
        return createRedirectResult(redirect);
    } else if (requestUrl.contains(Const.ActionURIs.ADMIN_EMAIL_MOVE_OUT_TRASH)) {
        try {
            logic.moveAdminEmailOutOfTrashBin(emailId);
            statusToAdmin = "Email with id" + emailId + " has been moved out of trash bin";
            statusToUser.add(new StatusMessage("The item has been moved out of trash bin", StatusMessageColor.SUCCESS));
        } catch (InvalidParametersException | EntityDoesNotExistException e) {
            setStatusForException(e, "An error has occurred when moving email out of trash bin");
        }
        return createRedirectResult(Const.ActionURIs.ADMIN_EMAIL_TRASH_PAGE);
    }
    return createRedirectResult(redirect);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage) 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