use of teammates.ui.pagedata.FeedbackSubmissionEditPageData in project teammates by TEAMMATES.
the class InstructorFeedbackPreviewAsStudentAction method execute.
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
String previewStudentEmail = getRequestParamValue(Const.ParamsNames.PREVIEWAS);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
Assumption.assertPostParamNotNull(Const.ParamsNames.PREVIEWAS, previewStudentEmail);
gateKeeper.verifyAccessible(logic.getInstructorForGoogleId(courseId, account.googleId), logic.getFeedbackSession(feedbackSessionName, courseId), false, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
StudentAttributes previewStudent = logic.getStudentForEmail(courseId, previewStudentEmail);
if (previewStudent == null) {
throw new EntityDoesNotExistException("Student Email " + previewStudentEmail + " does not exist in " + courseId + ".");
}
FeedbackSubmissionEditPageData data = new FeedbackSubmissionEditPageData(account, previewStudent, sessionToken);
data.bundle = logic.getFeedbackSessionQuestionsBundleForStudent(feedbackSessionName, courseId, previewStudent.email);
data.setSessionOpenForSubmission(true);
data.setPreview(true);
data.setHeaderHidden(true);
data.setStudentToViewPageAs(previewStudent);
data.setSubmitAction(Const.ActionURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT_SAVE);
data.bundle.resetAllResponses();
statusToAdmin = "Preview feedback session as student (" + previewStudent.email + ")<br>" + "Session Name: " + feedbackSessionName + "<br>" + "Course ID: " + courseId;
data.init("", "", courseId);
return createShowPageResult(Const.ViewURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT, data);
}
use of teammates.ui.pagedata.FeedbackSubmissionEditPageData in project teammates by TEAMMATES.
the class FeedbackSubmissionEditSaveAction method execute.
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
setAdditionalParameters();
verifyAccessibleForSpecificUser();
String userEmailForCourse = getUserEmailForCourse();
data = new FeedbackSubmissionEditPageData(account, student, sessionToken);
data.bundle = getDataBundle(userEmailForCourse);
Assumption.assertNotNull("Feedback session " + feedbackSessionName + " does not exist in " + courseId + ".", data.bundle);
checkAdditionalConstraints();
setStatusToAdmin();
if (!isSessionOpenForSpecificUser(data.bundle.feedbackSession)) {
isError = true;
statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SUBMISSIONS_NOT_OPEN, StatusMessageColor.WARNING));
return createSpecificRedirectResult();
}
String userTeamForCourse = getUserTeamForCourse();
String userSectionForCourse = getUserSectionForCourse();
int numOfQuestionsToGet = data.bundle.questionResponseBundle.size();
for (int questionIndx = 1; questionIndx <= numOfQuestionsToGet; questionIndx++) {
String totalResponsesForQuestion = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-" + questionIndx);
if (totalResponsesForQuestion == null) {
// question has been skipped (not displayed).
continue;
}
List<FeedbackResponseAttributes> responsesForQuestion = new ArrayList<>();
String questionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx);
FeedbackQuestionAttributes questionAttributes = data.bundle.getQuestionAttributes(questionId);
if (questionAttributes == null) {
statusToUser.add(new StatusMessage("The feedback session or questions may have changed " + "while you were submitting. Please check your responses " + "to make sure they are saved correctly.", StatusMessageColor.WARNING));
isError = true;
log.warning("Question not found. (deleted or invalid id passed?) id: " + questionId + " index: " + questionIndx);
continue;
}
FeedbackQuestionDetails questionDetails = questionAttributes.getQuestionDetails();
int numOfResponsesToGet = Integer.parseInt(totalResponsesForQuestion);
Set<String> emailSet = data.bundle.getRecipientEmails(questionAttributes.getId());
emailSet.add("");
emailSet = SanitizationHelper.desanitizeFromHtml(emailSet);
ArrayList<String> responsesRecipients = new ArrayList<>();
List<String> errors = new ArrayList<>();
for (int responseIndx = 0; responseIndx < numOfResponsesToGet; responseIndx++) {
FeedbackResponseAttributes response = extractFeedbackResponseData(requestParameters, questionIndx, responseIndx, questionAttributes);
if (response.feedbackQuestionType != questionAttributes.questionType) {
errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_WRONG_QUESTION_TYPE, questionIndx));
}
boolean isExistingResponse = response.getId() != null;
// came from the original set of existing responses loaded on the submission page
if (isExistingResponse && !isExistingResponseValid(response)) {
errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_INVALID_ID, questionIndx));
continue;
}
responsesRecipients.add(response.recipient);
// if the answer is not empty but the recipient is empty
if (response.recipient.isEmpty() && !response.responseMetaData.getValue().isEmpty()) {
errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_MISSING_RECIPIENT, questionIndx));
}
if (response.responseMetaData.getValue().isEmpty()) {
// deletes the response since answer is empty
addToPendingResponses(response);
} else {
response.giver = questionAttributes.giverType.isTeam() ? userTeamForCourse : userEmailForCourse;
response.giverSection = userSectionForCourse;
responsesForQuestion.add(response);
}
}
List<String> questionSpecificErrors = questionDetails.validateResponseAttributes(responsesForQuestion, data.bundle.recipientList.get(questionId).size());
errors.addAll(questionSpecificErrors);
if (!emailSet.containsAll(responsesRecipients)) {
errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSE_INVALID_RECIPIENT, questionIndx));
}
if (errors.isEmpty()) {
for (FeedbackResponseAttributes response : responsesForQuestion) {
addToPendingResponses(response);
}
} else {
List<StatusMessage> errorMessages = new ArrayList<>();
for (String error : errors) {
errorMessages.add(new StatusMessage(error, StatusMessageColor.DANGER));
}
statusToUser.addAll(errorMessages);
isError = true;
}
}
saveNewReponses(responsesToSave);
deleteResponses(responsesToDelete);
updateResponses(responsesToUpdate);
if (!isError) {
statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, StatusMessageColor.SUCCESS));
}
if (isUserRespondentOfSession()) {
appendRespondent();
} else {
removeRespondent();
}
boolean isSubmissionEmailRequested = "on".equals(getRequestParamValue(Const.ParamsNames.SEND_SUBMISSION_EMAIL));
if (!isError && isSendSubmissionEmail && isSubmissionEmailRequested) {
FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
Assumption.assertNotNull(session);
String user = account == null ? null : account.googleId;
String unregisteredStudentEmail = student == null ? null : student.email;
String unregisteredStudentRegisterationKey = student == null ? null : student.key;
StudentAttributes student = null;
InstructorAttributes instructor = null;
if (user != null) {
student = logic.getStudentForGoogleId(courseId, user);
instructor = logic.getInstructorForGoogleId(courseId, user);
}
if (student == null && unregisteredStudentEmail != null) {
student = StudentAttributes.builder("", unregisteredStudentEmail, unregisteredStudentEmail).withKey(unregisteredStudentRegisterationKey).build();
}
Assumption.assertFalse(student == null && instructor == null);
try {
EmailWrapper email = instructor == null ? new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student, Instant.now()) : new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor, Instant.now());
emailSender.sendEmail(email);
} catch (EmailSendingException e) {
log.severe("Submission confirmation email failed to send: " + TeammatesException.toStringWithStackTrace(e));
}
}
// TODO: Refactor to AjaxResult so status messages do not have to be passed by session
return createSpecificRedirectResult();
}
Aggregations