Search in sources :

Example 41 with StatusMessage

use of teammates.common.util.StatusMessage 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 42 with StatusMessage

use of teammates.common.util.StatusMessage 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 43 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class StudentProfilePictureEditAction method validatePostParameters.

/**
 * Checks that the information given via POST is valid.
 */
private boolean validatePostParameters() {
    if (leftXString.isEmpty() || topYString.isEmpty() || rightXString.isEmpty() || bottomYString.isEmpty()) {
        isError = true;
        statusToUser.add(new StatusMessage("Given crop locations were not valid. Please try again", StatusMessageColor.DANGER));
        statusToAdmin = Const.ACTION_RESULT_FAILURE + " : One or more of the given coords were empty.";
        return false;
    } else if (heightString.isEmpty() || widthString.isEmpty()) {
        isError = true;
        statusToUser.add(new StatusMessage("Given crop locations were not valid. Please try again", StatusMessageColor.DANGER));
        statusToAdmin = Const.ACTION_RESULT_FAILURE + " : One or both of the image dimensions were empty.";
        return false;
    } else if (Double.parseDouble(widthString) == 0 || Double.parseDouble(heightString) == 0) {
        isError = true;
        statusToUser.add(new StatusMessage("Given crop locations were not valid. Please try again", StatusMessageColor.DANGER));
        statusToAdmin = Const.ACTION_RESULT_FAILURE + " : One or both of the image dimensions were zero.";
        return false;
    }
    return true;
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 44 with StatusMessage

use of teammates.common.util.StatusMessage 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 45 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class StudentProfilePictureUploadAction method updateStatusesForBlobstoreFailure.

private void updateStatusesForBlobstoreFailure() {
    statusToAdmin += Const.ACTION_RESULT_FAILURE + " : Could not delete profile picture for account (" + account.googleId + ")" + System.lineSeparator();
    statusToUser.clear();
    statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_PIC_SERVICE_DOWN, StatusMessageColor.DANGER));
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Aggregations

StatusMessage (teammates.common.util.StatusMessage)81 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)34 InvalidParametersException (teammates.common.exception.InvalidParametersException)20 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)18 ArrayList (java.util.ArrayList)14 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)9 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)9 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)7 List (java.util.List)6 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)6 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)6 HashMap (java.util.HashMap)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)3 PageData (teammates.ui.pagedata.PageData)3 BlobInfo (com.google.appengine.api.blobstore.BlobInfo)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)2 BlobstoreFailureException (com.google.appengine.api.blobstore.BlobstoreFailureException)2 Text (com.google.appengine.api.datastore.Text)2 AppLogLine (com.google.appengine.api.log.AppLogLine)2