use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class InstructorsDb method updateInstructorByGoogleId.
/**
* Updates the instructor. Cannot modify Course ID or google id.
*/
public void updateInstructorByGoogleId(InstructorAttributes instructorAttributesToUpdate) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, instructorAttributesToUpdate);
if (!instructorAttributesToUpdate.isValid()) {
throw new InvalidParametersException(instructorAttributesToUpdate.getInvalidityInfo());
}
instructorAttributesToUpdate.sanitizeForSaving();
Instructor instructorToUpdate = getInstructorEntityForGoogleId(instructorAttributesToUpdate.courseId, instructorAttributesToUpdate.googleId);
if (instructorToUpdate == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + instructorAttributesToUpdate.googleId + ThreadHelper.getCurrentThreadStack());
}
instructorToUpdate.setName(instructorAttributesToUpdate.name);
instructorToUpdate.setEmail(instructorAttributesToUpdate.email);
instructorToUpdate.setIsArchived(instructorAttributesToUpdate.isArchived);
instructorToUpdate.setRole(instructorAttributesToUpdate.role);
instructorToUpdate.setIsDisplayedToStudents(instructorAttributesToUpdate.isDisplayedToStudents);
instructorToUpdate.setDisplayedName(instructorAttributesToUpdate.displayedName);
instructorToUpdate.setInstructorPrivilegeAsText(instructorAttributesToUpdate.getTextFromInstructorPrivileges());
// TODO: make courseId+email the non-modifiable values
putDocument(makeAttributes(instructorToUpdate));
saveEntity(instructorToUpdate, instructorAttributesToUpdate);
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class StudentsDb method recreateStudentWithNewEmail.
@SuppressWarnings("PMD.PreserveStackTrace")
private void recreateStudentWithNewEmail(CourseStudent newCourseStudent, String lastName, CourseStudent courseStudent, boolean hasDocument, boolean keepUpdateTimestamp, String courseId, String email) throws InvalidParametersException {
newCourseStudent.setLastName(lastName);
newCourseStudent.setCreatedAt(courseStudent.getCreatedAt());
if (keepUpdateTimestamp) {
newCourseStudent.setLastUpdate(courseStudent.getUpdatedAt());
}
StudentAttributes newCourseStudentAttributes = makeAttributes(newCourseStudent);
try {
createStudent(newCourseStudentAttributes, hasDocument);
} catch (EntityAlreadyExistsException e) {
CourseStudent existingStudent = getEntity(newCourseStudentAttributes);
String error = ERROR_UPDATE_EMAIL_ALREADY_USED + existingStudent.getName() + "/" + existingStudent.getEmail();
throw new InvalidParametersException(error);
}
deleteStudent(courseId, email);
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class StudentsLogic method resetStudentGoogleId.
public void resetStudentGoogleId(String originalEmail, String courseId, boolean hasDocument) throws EntityDoesNotExistException, InvalidParametersException {
// Edit student uses KeepOriginal policy, where unchanged fields are set
// as null. Hence, we can't do isValid() for student here.
// After updateWithExistingRecordWithGoogleIdReset method called,
// the student should be valid
studentsDb.verifyStudentExists(courseId, originalEmail);
StudentAttributes originalStudent = getStudentForEmail(courseId, originalEmail);
originalStudent.googleId = null;
if (!originalStudent.isValid()) {
throw new InvalidParametersException(originalStudent.getInvalidityInfo());
}
studentsDb.updateStudent(originalStudent.course, originalEmail, originalStudent.name, originalStudent.team, originalStudent.section, originalStudent.email, originalStudent.googleId, originalStudent.comments, hasDocument, false);
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class StudentsLogic method updateStudentCascadeWithSubmissionAdjustmentScheduled.
public void updateStudentCascadeWithSubmissionAdjustmentScheduled(String originalEmail, StudentAttributes student, boolean hasDocument) throws EntityDoesNotExistException, InvalidParametersException {
// Edit student uses KeepOriginal policy, where unchanged fields are set
// as null. Hence, we can't do isValid() for student here.
// After updateWithReferenceToExistingStudentRecord method called,
// the student should be valid
// here is like a db access that can be avoided if we really want to optimize the code
studentsDb.verifyStudentExists(student.course, originalEmail);
StudentAttributes originalStudent = getStudentForEmail(student.course, originalEmail);
// prepare new student
student.updateWithExistingRecord(originalStudent);
if (!student.isValid()) {
throw new InvalidParametersException(student.getInvalidityInfo());
}
studentsDb.updateStudent(student.course, originalEmail, student.name, student.team, student.section, student.email, student.googleId, student.comments, hasDocument, false);
// cascade email change, if any
if (!originalEmail.equals(student.email)) {
frLogic.updateFeedbackResponsesForChangingEmail(student.course, originalEmail, student.email);
fsLogic.updateRespondentsForStudent(originalEmail, student.email, student.course);
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class AdminEmailsDb method updateAdminEmail.
public void updateAdminEmail(AdminEmailAttributes ae) throws InvalidParametersException, EntityDoesNotExistException {
if (!ae.isValid()) {
throw new InvalidParametersException(ae.getInvalidityInfo());
}
AdminEmail adminEmailToUpdate = getAdminEmailEntity(ae.emailId);
if (adminEmailToUpdate == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + ae.getSubject() + "/" + ae.getSendDate() + ThreadHelper.getCurrentThreadStack());
}
ae.sanitizeForSaving();
adminEmailToUpdate.setContent(ae.content);
adminEmailToUpdate.setAddressReceiver(ae.addressReceiver);
adminEmailToUpdate.setGroupReceiver(ae.groupReceiver);
adminEmailToUpdate.setSubject(ae.subject);
adminEmailToUpdate.setIsInTrashBin(ae.isInTrashBin);
adminEmailToUpdate.setSendDate(ae.sendDate);
saveEntity(adminEmailToUpdate, ae);
}
Aggregations