Search in sources :

Example 26 with InvalidParametersException

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);
}
Also used : StudentProfile(teammates.storage.entity.StudentProfile) Account(teammates.storage.entity.Account) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 27 with InvalidParametersException

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);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) AdminEmail(teammates.storage.entity.AdminEmail) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 28 with InvalidParametersException

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);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 29 with InvalidParametersException

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;
    }
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) VoidWork(com.googlecode.objectify.VoidWork) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 30 with InvalidParametersException

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);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

InvalidParametersException (teammates.common.exception.InvalidParametersException)83 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)37 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 StatusMessage (teammates.common.util.StatusMessage)21 Test (org.testng.annotations.Test)19 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)19 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)13 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)12 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 Text (com.google.appengine.api.datastore.Text)8 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)8 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)6 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)6 ArrayList (java.util.ArrayList)5 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)5 VoidWork (com.googlecode.objectify.VoidWork)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 PageData (teammates.ui.pagedata.PageData)4 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)3