Search in sources :

Example 26 with EntityDoesNotExistException

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

the class StudentFeedbackResultsPageAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    if (courseId == null || feedbackSessionName == null) {
        return createRedirectResult(Const.ActionURIs.STUDENT_HOME_PAGE);
    }
    if (!isJoinedCourse(courseId)) {
        return createPleaseJoinCourseResponse(courseId);
    }
    gateKeeper.verifyAccessible(getCurrentStudent(courseId), logic.getFeedbackSession(feedbackSessionName, courseId));
    StudentFeedbackResultsPageData data = new StudentFeedbackResultsPageData(account, student, sessionToken);
    data.student = getCurrentStudent(courseId);
    data.setBundle(logic.getFeedbackSessionResultsForStudent(feedbackSessionName, courseId, data.student.email));
    if (data.getBundle() == null) {
        // leave this here as a safety net on the off cases that GateKeeper fails to catch the Exception
        throw new EntityDoesNotExistException("Feedback session " + feedbackSessionName + " does not exist in " + courseId + ".");
    }
    if (!data.getBundle().feedbackSession.isPublished()) {
        throw new UnauthorizedAccessException("This feedback session is not yet visible.");
    }
    if (data.getBundle().isStudentHasSomethingNewToSee(data.student)) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESULTS_SOMETHINGNEW, StatusMessageColor.INFO));
    } else {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESULTS_NOTHINGNEW, StatusMessageColor.WARNING));
    }
    statusToAdmin = "Show student feedback result page<br>" + "Session Name: " + feedbackSessionName + "<br>" + "Course ID: " + courseId;
    Map<FeedbackQuestionAttributes, List<FeedbackResponseAttributes>> questionsWithResponses = data.getBundle().getQuestionResponseMapSortedByRecipient();
    data.init(questionsWithResponses);
    return createShowPageResult(Const.ViewURIs.STUDENT_FEEDBACK_RESULTS, data);
}
Also used : UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) List(java.util.List) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) StatusMessage(teammates.common.util.StatusMessage)

Example 27 with EntityDoesNotExistException

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

the class StudentHomePageAction method execute.

@Override
public ActionResult execute() {
    gateKeeper.verifyLoggedInUserPrivileges();
    String recentlyJoinedCourseId = getRequestParamValue(Const.ParamsNames.CHECK_PERSISTENCE_COURSE);
    List<CourseDetailsBundle> courses = new ArrayList<>();
    Map<FeedbackSessionAttributes, Boolean> sessionSubmissionStatusMap = new HashMap<>();
    try {
        courses = logic.getCourseDetailsListForStudent(account.googleId);
        sessionSubmissionStatusMap = generateFeedbackSessionSubmissionStatusMap(courses, account.googleId);
        CourseDetailsBundle.sortDetailedCoursesByCourseId(courses);
        statusToAdmin = "studentHome Page Load<br>" + "Total courses: " + courses.size();
        boolean isDataConsistent = isCourseIncluded(recentlyJoinedCourseId, courses);
        if (!isDataConsistent) {
            addPlaceholderCourse(courses, recentlyJoinedCourseId, sessionSubmissionStatusMap);
        }
        for (CourseDetailsBundle course : courses) {
            FeedbackSessionDetailsBundle.sortFeedbackSessionsByCreationTime(course.feedbackSessions);
        }
    } catch (EntityDoesNotExistException e) {
        if (recentlyJoinedCourseId == null) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_FIRST_TIME, StatusMessageColor.WARNING));
            statusToAdmin = Const.ACTION_RESULT_FAILURE + " :" + e.getMessage();
        } else {
            addPlaceholderCourse(courses, recentlyJoinedCourseId, sessionSubmissionStatusMap);
        }
    }
    StudentHomePageData data = new StudentHomePageData(account, sessionToken, courses, sessionSubmissionStatusMap);
    return createShowPageResult(Const.ViewURIs.STUDENT_HOME, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) HashMap(java.util.HashMap) StudentHomePageData(teammates.ui.pagedata.StudentHomePageData) ArrayList(java.util.ArrayList) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) StatusMessage(teammates.common.util.StatusMessage)

Example 28 with EntityDoesNotExistException

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

the class StudentProfilePictureUploadAction method execute.

/*
     * This class is not tested in ActionTests as it is difficult to
     * reproduce the upload action done by Google Blobstore API
     * without the server running.
     * This class is covered in UiTests.
     */
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    gateKeeper.verifyLoggedInUserPrivileges();
    String pictureKey = "";
    BlobKey blobKey = new BlobKey("");
    RedirectResult r = createRedirectResult(Const.ActionURIs.STUDENT_PROFILE_PAGE);
    try {
        BlobInfo blobInfo = extractProfilePictureKey();
        if (!isError) {
            blobKey = blobInfo.getBlobKey();
            pictureKey = renameFileToGoogleId(blobInfo);
            logic.updateStudentProfilePicture(account.googleId, pictureKey);
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_PICTURE_SAVED, StatusMessageColor.SUCCESS));
            r.addResponseParam(Const.ParamsNames.STUDENT_PROFILE_PHOTOEDIT, "true");
        }
    } catch (BlobstoreFailureException | IOException bfe) {
        deletePicture(blobKey);
        updateStatusesForBlobstoreFailure();
        isError = true;
    } catch (Exception e) {
        /*
             * This is for other exceptions like EntityNotFound, IllegalState, etc
             * that occur rarely and are handled higher up.
             */
        deletePicture(new BlobKey(pictureKey));
        statusToUser.clear();
        throw e;
    }
    return r;
}
Also used : BlobKey(com.google.appengine.api.blobstore.BlobKey) BlobstoreFailureException(com.google.appengine.api.blobstore.BlobstoreFailureException) BlobInfo(com.google.appengine.api.blobstore.BlobInfo) IOException(java.io.IOException) BlobstoreFailureException(com.google.appengine.api.blobstore.BlobstoreFailureException) IOException(java.io.IOException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) StatusMessage(teammates.common.util.StatusMessage)

Example 29 with EntityDoesNotExistException

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

the class FeedbackResponsesLogic method updateFeedbackResponse.

/**
 * Updates a {@link FeedbackResponse} using a {@link FeedbackResponseAttributes} <br>
 * If the giver/recipient field is changed, the {@link FeedbackResponse} is
 * updated by recreating the response<br>
 * in order to prevent an id clash if the previous email is reused later on.
 * @param oldResponseEntity  a FeedbackResponse retrieved from the database
 * @throws EntityAlreadyExistsException  if trying to prevent an id clash by recreating a response,
 *                                       a response with the same id already exist.
 */
public void updateFeedbackResponse(FeedbackResponseAttributes updatedResponse, FeedbackResponse oldResponseEntity) throws InvalidParametersException, EntityAlreadyExistsException, EntityDoesNotExistException {
    Assumption.assertNotNull(oldResponseEntity);
    // Create a copy.
    FeedbackResponseAttributes newResponse = new FeedbackResponseAttributes(updatedResponse);
    FeedbackResponseAttributes oldResponse = new FeedbackResponseAttributes(oldResponseEntity);
    // Copy values that cannot be changed to defensively avoid invalid
    // parameters.
    copyFixedValuesFromOldToNew(newResponse, oldResponse);
    if (newResponse.recipient.equals(oldResponse.recipient) && newResponse.giver.equals(oldResponse.giver)) {
        try {
            frDb.updateFeedbackResponseOptimized(newResponse, oldResponseEntity);
        } catch (EntityDoesNotExistException e) {
            Assumption.fail();
        }
    } else {
        // Recreate response to prevent possible future id conflict.
        recreateResponse(newResponse, oldResponse);
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 30 with EntityDoesNotExistException

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

the class FeedbackResponsesLogic method updateFeedbackResponse.

/**
 * Updates a {@link FeedbackResponse} based on it's {@code id}.<br>
 * If the giver/recipient field is changed, the {@link FeedbackResponse} is
 * updated by recreating the response<br>
 * in order to prevent an id clash if the previous email is reused later on.
 */
public void updateFeedbackResponse(FeedbackResponseAttributes responseToUpdate) throws InvalidParametersException, EntityDoesNotExistException, EntityAlreadyExistsException {
    // Create a copy.
    FeedbackResponseAttributes newResponse = new FeedbackResponseAttributes(responseToUpdate);
    FeedbackResponse oldResponseEntity = null;
    if (newResponse.getId() == null) {
        oldResponseEntity = frDb.getFeedbackResponseEntityWithCheck(newResponse.feedbackQuestionId, newResponse.giver, newResponse.recipient);
    } else {
        oldResponseEntity = frDb.getFeedbackResponseEntityWithCheck(newResponse.getId());
    }
    FeedbackResponseAttributes oldResponse = null;
    if (oldResponseEntity != null) {
        oldResponse = new FeedbackResponseAttributes(oldResponseEntity);
    }
    if (oldResponse == null) {
        throw new EntityDoesNotExistException("Trying to update a feedback response that does not exist.");
    }
    updateFeedbackResponse(newResponse, oldResponseEntity);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponse(teammates.storage.entity.FeedbackResponse) 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