use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class AdminInstructorAccountAddAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminHomePageData data = new AdminHomePageData(account, sessionToken);
data.instructorName = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME).trim();
data.instructorEmail = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL).trim();
data.instructorInstitution = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION).trim();
data.isInstructorAddingResultForAjax = true;
data.statusForAjax = "";
data.instructorName = data.instructorName.trim();
data.instructorEmail = data.instructorEmail.trim();
data.instructorInstitution = data.instructorInstitution.trim();
try {
logic.verifyInputForAdminHomePage(data.instructorName, data.instructorInstitution, data.instructorEmail);
} catch (InvalidParametersException e) {
data.statusForAjax = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
data.isInstructorAddingResultForAjax = false;
statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.DANGER));
return createAjaxResult(data);
}
String courseId = null;
try {
courseId = importDemoData(data);
} catch (Exception e) {
String retryUrl = Const.ActionURIs.ADMIN_INSTRUCTORACCOUNT_ADD;
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_NAME, data.instructorName);
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_EMAIL, data.instructorEmail);
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_INSTITUTION, data.instructorInstitution);
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.SESSION_TOKEN, data.getSessionToken());
StringBuilder errorMessage = new StringBuilder(100);
String retryLink = "<a href=" + retryUrl + ">Exception in Importing Data, Retry</a>";
errorMessage.append(retryLink);
statusToUser.add(new StatusMessage(errorMessage.toString(), StatusMessageColor.DANGER));
String message = "<span class=\"text-danger\">Servlet Action failure in AdminInstructorAccountAddAction" + "<br>" + e.getClass() + ": " + TeammatesException.toStringWithStackTrace(e) + "<br></span>";
errorMessage.append("<br>").append(message);
statusToUser.add(new StatusMessage("<br>" + message, StatusMessageColor.DANGER));
statusToAdmin = message;
data.isInstructorAddingResultForAjax = false;
data.statusForAjax = errorMessage.toString();
return createAjaxResult(data);
}
List<InstructorAttributes> instructorList = logic.getInstructorsForCourse(courseId);
String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructorList.get(0).key)).withInstructorInstitution(data.instructorInstitution).toAbsoluteString();
EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorList.get(0).email, data.instructorName, joinLink);
try {
emailSender.sendEmail(email);
} catch (EmailSendingException e) {
log.severe("Instructor welcome email failed to send: " + TeammatesException.toStringWithStackTrace(e));
}
data.statusForAjax = "Instructor " + SanitizationHelper.sanitizeForHtml(data.instructorName) + " has been successfully created " + "<a href=" + joinLink + ">" + Const.JOIN_LINK + "</a>";
statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.SUCCESS));
statusToAdmin = "A New Instructor <span class=\"bold\">" + SanitizationHelper.sanitizeForHtmlTag(data.instructorName) + "</span> has been created.<br>" + "<span class=\"bold\">Id: </span>" + "ID will be assigned when the verification link was clicked and confirmed" + "<br>" + "<span class=\"bold\">Email: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorEmail) + "<span class=\"bold\">Institution: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorInstitution);
return createAjaxResult(data);
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class AdminStudentGoogleIdResetAction method execute.
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
gateKeeper.verifyAdminPrivileges(account);
String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
String studentCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
String wrongGoogleId = getRequestParamValue(Const.ParamsNames.STUDENT_ID);
AdminStudentGoogleIdResetPageData data = new AdminStudentGoogleIdResetPageData(account, sessionToken);
if (studentEmail != null && studentCourseId != null) {
try {
logic.resetStudentGoogleId(studentEmail, studentCourseId);
taskQueuer.scheduleCourseRegistrationInviteToStudent(studentCourseId, studentEmail, true);
} catch (InvalidParametersException e) {
statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL, StatusMessageColor.DANGER));
statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId + "<br>" + "Failed with error<br>" + e.getMessage();
isError = true;
}
StudentAttributes updatedStudent = logic.getStudentForEmail(studentCourseId, studentEmail);
if (updatedStudent.googleId == null || updatedStudent.googleId.isEmpty()) {
statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET, StatusMessageColor.SUCCESS));
statusToUser.add(new StatusMessage("Email : " + studentEmail, StatusMessageColor.SUCCESS));
statusToUser.add(new StatusMessage("CourseId : " + studentCourseId, StatusMessageColor.SUCCESS));
statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId;
data.statusForAjax = Const.StatusMessages.STUDENT_GOOGLEID_RESET + "<br>" + "Email : " + studentEmail + "<br>" + "CourseId : " + studentCourseId;
data.isGoogleIdReset = true;
deleteAccountIfNeeded(wrongGoogleId);
} else {
data.isGoogleIdReset = false;
statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL, StatusMessageColor.DANGER));
statusToAdmin = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email: " + studentEmail + "<br>" + "CourseId: " + studentCourseId + "<br>";
data.statusForAjax = Const.StatusMessages.STUDENT_GOOGLEID_RESET_FAIL + "<br>" + "Email : " + studentEmail + "<br>" + "CourseId : " + studentCourseId;
}
isError = false;
return createAjaxResult(data);
}
isError = true;
return createAjaxResult(data);
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class FeedbackSubmissionEditSaveAction method updateResponses.
private void updateResponses(List<FeedbackResponseAttributes> responsesToUpdate) throws EntityDoesNotExistException {
for (FeedbackResponseAttributes response : responsesToUpdate) {
try {
logic.updateFeedbackResponse(response);
hasValidResponse = true;
} catch (EntityAlreadyExistsException | InvalidParametersException e) {
setStatusForException(e);
}
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorCourseAddAction method createCourse.
private void createCourse(String newCourseId, String newCourseName, String newCourseTimeZone) {
try {
logic.createCourseAndInstructor(data.account.googleId, newCourseId, newCourseName, newCourseTimeZone);
String statusMessage = Const.StatusMessages.COURSE_ADDED.replace("${courseEnrollLink}", data.getInstructorCourseEnrollLink(newCourseId)).replace("${courseEditLink}", data.getInstructorCourseEditLink(newCourseId));
statusToUser.add(new StatusMessage(statusMessage, StatusMessageColor.SUCCESS));
isError = false;
} catch (EntityAlreadyExistsException e) {
setStatusForException(e, Const.StatusMessages.COURSE_EXISTS);
} catch (InvalidParametersException e) {
setStatusForException(e);
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorFeedbackAbstractAction method validateTimeData.
protected void validateTimeData(FeedbackSessionAttributes attributes) throws InvalidParametersException {
FieldValidator validator = new FieldValidator();
// Stop if invalid or fixed offset time zone is detected
String paramTimeZone = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_TIMEZONE);
String timeZoneErrorMessage = validator.getInvalidityInfoForTimeZone(paramTimeZone);
if (!timeZoneErrorMessage.isEmpty()) {
// Collect other errors before throwing an exception
List<String> errors = new ArrayList<>(attributes.getInvalidityInfo());
errors.add(timeZoneErrorMessage);
throw new InvalidParametersException(errors);
}
// The time zone is valid at this point and can be used for future calculations
ZoneId timeZone = attributes.getTimeZone();
// Warn if ambiguity of time fields (brought about by DST) is detected
validateLocalDateTimeUnambiguity(inputStartTimeLocal, attributes.getStartTime(), timeZone, FieldValidator.SESSION_START_TIME_FIELD_NAME);
validateLocalDateTimeUnambiguity(inputEndTimeLocal, attributes.getEndTime(), timeZone, FieldValidator.SESSION_END_TIME_FIELD_NAME);
validateLocalDateTimeUnambiguity(inputVisibleTimeLocal, attributes.getSessionVisibleFromTime(), timeZone, FieldValidator.SESSION_VISIBLE_TIME_FIELD_NAME);
validateLocalDateTimeUnambiguity(inputPublishTimeLocal, attributes.getResultsVisibleFromTime(), timeZone, FieldValidator.RESULTS_VISIBLE_TIME_FIELD_NAME);
}
Aggregations