Search in sources :

Example 76 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException 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 77 with EntityDoesNotExistException

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

Example 78 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException 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 79 with EntityDoesNotExistException

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

the class InstructorCourseInstructorAbstractAction method updateInstructorWithSectionLevelPrivileges.

/**
 * Updates section and session level privileges for the instructor.
 *
 * @param courseId   Course that the instructor is being added to.
 * @param instructor Instructor that will be added.
 *                       This will be modified within the method.
 */
protected void updateInstructorWithSectionLevelPrivileges(String courseId, InstructorAttributes instructor) {
    List<String> sectionNames = null;
    try {
        sectionNames = logic.getSectionNamesForCourse(courseId);
    } catch (EntityDoesNotExistException e) {
        return;
    }
    HashMap<String, Boolean> isSectionSpecialMappings = new HashMap<>();
    for (String sectionName : sectionNames) {
        isSectionSpecialMappings.put(sectionName, false);
    }
    List<String> feedbackNames = new ArrayList<>();
    List<FeedbackSessionAttributes> feedbacks = logic.getFeedbackSessionsForCourse(courseId);
    for (FeedbackSessionAttributes feedback : feedbacks) {
        feedbackNames.add(feedback.getFeedbackSessionName());
    }
    Map<String, List<String>> sectionNamesMap = getSectionsWithSpecialPrivilegesFromParameters(instructor, sectionNames, isSectionSpecialMappings);
    sectionNamesMap.forEach((sectionGroupName, specialSectionsInSectionGroup) -> {
        updateInstructorPrivilegesForSectionInSectionLevel(sectionGroupName, specialSectionsInSectionGroup, instructor);
        // check if session-specific permissions are to be used
        String setSessionsStr = getRequestParamValue("is" + sectionGroupName + "sessionsset");
        boolean isSessionsForSectionGroupSpecial = Boolean.parseBoolean(setSessionsStr);
        if (isSessionsForSectionGroupSpecial) {
            updateInstructorPrivilegesForSectionInSessionLevel(sectionGroupName, specialSectionsInSectionGroup, feedbackNames, instructor);
        } else {
            removeSessionLevelPrivileges(instructor, specialSectionsInSectionGroup);
        }
    });
    isSectionSpecialMappings.forEach((sectionNameToBeChecked, isSectionSpecial) -> {
        if (!isSectionSpecial) {
            instructor.privileges.removeSectionLevelPrivileges(sectionNameToBeChecked);
        }
    });
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 80 with EntityDoesNotExistException

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

the class Action method executeAndPostProcess.

/**
 * ------------------------------------------------
 */
/**
 * Executes the action (as implemented by a child class). Before passing
 * the result to the caller, it does some post processing: <br>
 * 1. If the original request contained a URL to redirect after performing
 *    the action, the result will be replaced with a new 'redirect' type
 *    result. Note: Redirection is not allowed to third-party destinations. <br>
 * 2. User ID, error flag, and the status message will be added to the response,
 *    to be encoded into the URL. The error flag is also added to the
 *    {@code isError} flag in the {@link ActionResult} object.
 */
public ActionResult executeAndPostProcess() {
    if (!isValidUser()) {
        return createRedirectResult(getAuthenticationRedirectUrl());
    }
    // get the result from the child class.
    ActionResult response;
    try {
        response = execute();
    } catch (EntityDoesNotExistException e) {
        throw new EntityNotFoundException(e);
    }
    // set error flag of the result
    response.isError = isError;
    // Set the common parameters for the response
    if (gateKeeper.getCurrentUser() != null) {
        response.responseParams.put(Const.ParamsNames.USER_ID, account.googleId);
    }
    if (regkey != null) {
        response.responseParams.put(Const.ParamsNames.REGKEY, getRegkeyFromRequest());
        if (student != null) {
            response.responseParams.put(Const.ParamsNames.STUDENT_EMAIL, student.email);
            response.responseParams.put(Const.ParamsNames.COURSE_ID, student.course);
        }
        if (getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME) != null) {
            response.responseParams.put(Const.ParamsNames.FEEDBACK_SESSION_NAME, getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME));
        }
    }
    response.responseParams.put(Const.ParamsNames.ERROR, Boolean.toString(response.isError));
    // Pass status message using session to prevent XSS attack
    if (!response.getStatusMessage().isEmpty()) {
        putStatusMessageToSession(response);
    }
    return response;
}
Also used : EntityNotFoundException(teammates.common.exception.EntityNotFoundException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4