use of teammates.common.exception.InvalidParametersException 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.InvalidParametersException 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.InvalidParametersException 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.InvalidParametersException 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;
}
}
use of teammates.common.exception.InvalidParametersException in project teammates by TEAMMATES.
the class FeedbackSessionsDb method updateInstructorRespondent.
public void updateInstructorRespondent(String oldEmail, String newEmail, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, oldEmail);
Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newEmail);
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());
}
if (fs.getRespondingInstructorList().contains(oldEmail)) {
fs.getRespondingInstructorList().remove(oldEmail);
fs.getRespondingInstructorList().add(newEmail);
}
saveEntity(fs, feedbackSession);
}
Aggregations