use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorCourseJoinAuthenticatedAction method execute.
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
Assumption.assertNotNull(regkey);
String institute = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION);
gateKeeper.verifyLoggedInUserPrivileges();
/* Process authentication for the instructor to join course */
try {
if (institute == null) {
logic.joinCourseForInstructor(regkey, account.googleId);
} else {
logic.joinCourseForInstructor(regkey, account.googleId, institute);
}
} catch (JoinCourseException | InvalidParametersException e) {
// Does not sanitize for html to allow insertion of mailto link
setStatusForException(e, e.getMessage());
log.info(e.getMessage());
}
/* Set status to be shown to admin */
StringBuffer joinedCourseMsg = new StringBuffer(100);
joinedCourseMsg.append("Action Instructor Joins Course<br>Google ID: ").append(account.googleId);
try {
joinedCourseMsg.append("<br>Key : ").append(StringHelper.decrypt(regkey));
} catch (InvalidParametersException e) {
joinedCourseMsg.append("<br>Key could not be decrypted.");
// no need to do setStatusForException and logging, as this case is already caught above
}
if (statusToAdmin == null) {
statusToAdmin = joinedCourseMsg.toString();
} else {
statusToAdmin += "<br><br>" + joinedCourseMsg.toString();
}
/* Create redirection to instructor's homepage */
RedirectResult response = createRedirectResult(Const.ActionURIs.INSTRUCTOR_HOME_PAGE);
InstructorAttributes instructor = logic.getInstructorForRegistrationKey(regkey);
if (instructor != null) {
response.addResponseParam(Const.ParamsNames.CHECK_PERSISTENCE_COURSE, instructor.courseId);
sendCourseRegisteredEmail(instructor.name, instructor.email, true, instructor.courseId);
}
return response;
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorCourseStudentDetailsEditSaveAction method execute.
@Override
public ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENT_EMAIL, studentEmail);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
if (student == null) {
return redirectWithError(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_EDIT, "Student <span class=\"bold\">" + studentEmail + "</span> in " + "Course <span class=\"bold\">[" + courseId + "]</span> not found.", courseId);
}
student.name = getRequestParamValue(Const.ParamsNames.STUDENT_NAME);
student.email = getRequestParamValue(Const.ParamsNames.NEW_STUDENT_EMAIL);
student.team = getRequestParamValue(Const.ParamsNames.TEAM_NAME);
student.section = getRequestParamValue(Const.ParamsNames.SECTION_NAME);
student.comments = getRequestParamValue(Const.ParamsNames.COMMENTS);
boolean hasSection = logic.hasIndicatedSections(courseId);
student.name = SanitizationHelper.sanitizeName(student.name);
student.email = SanitizationHelper.sanitizeEmail(student.email);
student.team = SanitizationHelper.sanitizeName(student.team);
student.section = SanitizationHelper.sanitizeName(student.section);
student.comments = SanitizationHelper.sanitizeTextField(student.comments);
try {
StudentAttributes originalStudentAttribute = logic.getStudentForEmail(courseId, studentEmail);
student.updateWithExistingRecord(originalStudentAttribute);
boolean isSectionChanged = student.isSectionChanged(originalStudentAttribute);
boolean isTeamChanged = student.isTeamChanged(originalStudentAttribute);
boolean isEmailChanged = student.isEmailChanged(originalStudentAttribute);
if (isSectionChanged) {
logic.validateSectionsAndTeams(Arrays.asList(student), courseId);
} else if (isTeamChanged) {
logic.validateTeams(Arrays.asList(student), courseId);
}
logic.updateStudent(studentEmail, student);
boolean isSessionSummarySendEmail = getRequestParamAsBoolean(Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK);
if (isEmailChanged) {
logic.resetStudentGoogleId(student.email, courseId);
if (isSessionSummarySendEmail) {
try {
EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(courseId, student);
emailSender.sendEmail(email);
} catch (Exception e) {
log.severe("Error while sending session summary email" + TeammatesException.toStringWithStackTrace(e));
}
}
}
statusToUser.add(new StatusMessage(isSessionSummarySendEmail && isEmailChanged ? Const.StatusMessages.STUDENT_EDITED_AND_EMAIL_SENT : Const.StatusMessages.STUDENT_EDITED, StatusMessageColor.SUCCESS));
statusToAdmin = "Student <span class=\"bold\">" + studentEmail + "'s</span> details in " + "Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Email: " + student.email + "<br>New Team: " + student.team + "<br>" + "Comments: " + student.comments;
RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE);
result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
return result;
} catch (InvalidParametersException | EnrollException e) {
setStatusForException(e);
String newEmail = student.email;
student.email = studentEmail;
boolean isOpenOrPublishedEmailSentForTheCourse = logic.isOpenOrPublishedEmailSentForTheCourse(courseId);
InstructorCourseStudentDetailsEditPageData data = new InstructorCourseStudentDetailsEditPageData(account, sessionToken, student, newEmail, hasSection, isOpenOrPublishedEmailSentForTheCourse);
return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, data);
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class AdminEmailComposeSendAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
String emailContent = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_CONTENT);
String subject = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_SUBJECT);
addressReceiverListString = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS);
isAddressModeOn = addressReceiverListString != null && !addressReceiverListString.isEmpty();
emailId = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
groupReceiverListFileKey = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_GROUP_RECEIVER_LIST_FILE_KEY);
isGroupModeOn = groupReceiverListFileKey != null && !groupReceiverListFileKey.isEmpty();
if (isGroupModeOn) {
try {
groupReceiver.add(groupReceiverListFileKey);
GoogleCloudStorageHelper.getGroupReceiverList(new BlobKey(groupReceiverListFileKey));
} catch (Exception e) {
isError = true;
setStatusForException(e, "An error occurred when retrieving receiver list, please try again");
}
}
if (isAddressModeOn) {
addressReceiver.add(addressReceiverListString);
try {
checkAddressReceiverString(addressReceiverListString);
} catch (InvalidParametersException e) {
isError = true;
setStatusForException(e);
}
}
if (!isAddressModeOn && !isGroupModeOn) {
isError = true;
statusToAdmin = "Error : No receiver address or file given";
statusToUser.add(new StatusMessage("Error : No receiver address or file given", StatusMessageColor.DANGER));
}
if (isError) {
data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
boolean isEmailDraft = emailId != null && !emailId.isEmpty();
if (isEmailDraft) {
updateDraftEmailToSent(emailId, subject, addressReceiver, groupReceiver, emailContent);
} else {
recordNewSentEmail(subject, addressReceiver, groupReceiver, emailContent);
}
if (isError) {
data.emailToEdit = AdminEmailAttributes.builder(subject, addressReceiver, groupReceiver, new Text(emailContent)).withEmailId(emailId).build();
}
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
use of teammates.common.exception.InvalidParametersException 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();
}
use of teammates.common.exception.InvalidParametersException 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);
}
Aggregations