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);
}
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);
}
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;
}
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);
}
}
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);
}
Aggregations