use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class StudentsLogic method enrollStudents.
private CourseEnrollmentResult enrollStudents(String enrollLines, String courseId, boolean hasDocument) throws EntityDoesNotExistException, EnrollException, InvalidParametersException, EntityAlreadyExistsException {
if (!coursesLogic.isCoursePresent(courseId)) {
throw new EntityDoesNotExistException("Course does not exist :" + courseId);
}
if (enrollLines.isEmpty()) {
throw new EnrollException(Const.StatusMessages.ENROLL_LINE_EMPTY);
}
List<StudentAttributes> studentList = createStudents(enrollLines, courseId);
ArrayList<StudentAttributes> returnList = new ArrayList<>();
ArrayList<StudentEnrollDetails> enrollmentList = new ArrayList<>();
verifyIsWithinSizeLimitPerEnrollment(studentList);
validateSectionsAndTeams(studentList, courseId);
// enroll all students
for (StudentAttributes student : studentList) {
StudentEnrollDetails enrollmentDetails;
enrollmentDetails = enrollStudent(student, hasDocument);
student.updateStatus = enrollmentDetails.updateStatus;
enrollmentList.add(enrollmentDetails);
returnList.add(student);
}
// add to return list students not included in the enroll list.
List<StudentAttributes> studentsInCourse = getStudentsForCourse(courseId);
for (StudentAttributes student : studentsInCourse) {
if (!isInEnrollList(student, returnList)) {
student.updateStatus = StudentUpdateStatus.NOT_IN_ENROLL_LIST;
returnList.add(student);
}
}
return new CourseEnrollmentResult(returnList, enrollmentList);
}
use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class AccountsDb method updateAccount.
/**
* Preconditions:
* <br> * {@code accountToAdd} is not null and has valid data.
*/
public void updateAccount(AccountAttributes a, boolean updateStudentProfile) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, a);
if (!a.isValid()) {
throw new InvalidParametersException(a.getInvalidityInfo());
}
Account accountToUpdate = getAccountEntity(a.googleId, updateStudentProfile);
if (accountToUpdate == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + a.googleId + ThreadHelper.getCurrentThreadStack());
}
a.sanitizeForSaving();
accountToUpdate.setName(a.name);
accountToUpdate.setEmail(a.email);
accountToUpdate.setIsInstructor(a.isInstructor);
accountToUpdate.setInstitute(a.institute);
if (updateStudentProfile) {
StudentProfile existingProfile = accountToUpdate.getStudentProfile();
if (existingProfile == null) {
existingProfile = new StudentProfile(a.studentProfile.googleId);
}
StudentProfileAttributes existingProfileAttributes = StudentProfileAttributes.valueOf(existingProfile);
a.studentProfile.modifiedDate = existingProfileAttributes.modifiedDate;
// this is to maintain integrity of the modified date.
if (!existingProfileAttributes.toString().equals(a.studentProfile.toString())) {
StudentProfile updatedProfile = a.studentProfile.toEntity();
accountToUpdate.setStudentProfile(updatedProfile);
profilesDb.saveEntity(updatedProfile);
}
}
saveEntity(accountToUpdate, a);
}
use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class AdminEmailsDb method updateAdminEmailById.
public void updateAdminEmailById(AdminEmailAttributes newAdminEmail, String emailId) throws InvalidParametersException, EntityDoesNotExistException {
if (!newAdminEmail.isValid()) {
throw new InvalidParametersException(newAdminEmail.getInvalidityInfo());
}
AdminEmail adminEmailToUpdate = getAdminEmailEntity(emailId);
if (adminEmailToUpdate == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + "with Id : " + emailId + ThreadHelper.getCurrentThreadStack());
}
newAdminEmail.sanitizeForSaving();
adminEmailToUpdate.setContent(newAdminEmail.content);
adminEmailToUpdate.setAddressReceiver(newAdminEmail.addressReceiver);
adminEmailToUpdate.setGroupReceiver(newAdminEmail.groupReceiver);
adminEmailToUpdate.setSubject(newAdminEmail.subject);
adminEmailToUpdate.setIsInTrashBin(newAdminEmail.isInTrashBin);
adminEmailToUpdate.setSendDate(newAdminEmail.sendDate);
saveEntity(adminEmailToUpdate, newAdminEmail);
}
use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class FeedbackSessionsDb method clearStudentRespondents.
public void clearStudentRespondents(FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString());
}
fs.getRespondingStudentList().clear();
saveEntity(fs, feedbackSession);
}
use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.
the class FeedbackSessionsDb method addInstructorRespondents.
// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void addInstructorRespondents(List<String> emails, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, emails);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, feedbackSession);
feedbackSession.sanitizeForSaving();
if (!feedbackSession.isValid()) {
throw new InvalidParametersException(feedbackSession.getInvalidityInfo());
}
try {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
FeedbackSession fs = getEntity(feedbackSession);
if (fs == null) {
throw new RuntimeException(new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + feedbackSession.toString()));
}
fs.getRespondingInstructorList().addAll(emails);
saveEntity(fs, feedbackSession);
}
});
} catch (RuntimeException e) {
if (e.getCause() instanceof EntityDoesNotExistException) {
throw (EntityDoesNotExistException) e.getCause();
}
throw e;
}
}
Aggregations