Search in sources :

Example 41 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException 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)

Example 42 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsDb method updateFeedbackSession.

/**
 * Updates the feedback session identified by {@code newAttributes.feedbackSesionName}
 * and {@code newAttributes.courseId}.
 * For the remaining parameters, the existing value is preserved
 *   if the parameter is null (due to 'keep existing' policy).<br>
 * Preconditions: <br>
 * * {@code newAttributes.feedbackSesionName} and {@code newAttributes.courseId}
 *  are non-null and correspond to an existing feedback session. <br>
 */
public void updateFeedbackSession(FeedbackSessionAttributes newAttributes) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newAttributes);
    newAttributes.sanitizeForSaving();
    if (!newAttributes.isValid()) {
        throw new InvalidParametersException(newAttributes.getInvalidityInfo());
    }
    FeedbackSession fs = getEntity(newAttributes);
    if (fs == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + newAttributes.toString());
    }
    fs.setInstructions(newAttributes.getInstructions());
    fs.setStartTime(newAttributes.getStartTime());
    fs.setEndTime(newAttributes.getEndTime());
    fs.setSessionVisibleFromTime(newAttributes.getSessionVisibleFromTime());
    fs.setResultsVisibleFromTime(newAttributes.getResultsVisibleFromTime());
    fs.setTimeZone(newAttributes.getTimeZone().getId());
    fs.setGracePeriod(newAttributes.getGracePeriodMinutes());
    fs.setFeedbackSessionType(newAttributes.getFeedbackSessionType());
    fs.setSentOpenEmail(newAttributes.isSentOpenEmail());
    fs.setSentClosingEmail(newAttributes.isSentClosingEmail());
    fs.setSentClosedEmail(newAttributes.isSentClosedEmail());
    fs.setSentPublishedEmail(newAttributes.isSentPublishedEmail());
    fs.setIsOpeningEmailEnabled(newAttributes.isOpeningEmailEnabled());
    fs.setSendClosingEmail(newAttributes.isClosingEmailEnabled());
    fs.setSendPublishedEmail(newAttributes.isPublishedEmailEnabled());
    saveEntity(fs, newAttributes);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 43 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsDb method updateStudentRespondent.

public void updateStudentRespondent(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.getRespondingStudentList().contains(oldEmail)) {
        fs.getRespondingStudentList().remove(oldEmail);
        fs.getRespondingStudentList().add(newEmail);
    }
    saveEntity(fs, feedbackSession);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 44 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsDb method deleteStudentRespondent.

// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void deleteStudentRespondent(String email, FeedbackSessionAttributes feedbackSession) throws EntityDoesNotExistException, InvalidParametersException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, email);
    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.getRespondingStudentList().remove(email);
                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 45 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class InstructorsDb method updateInstructorByEmail.

/**
 * Updates the instructor. Cannot modify Course ID or email.
 */
public void updateInstructorByEmail(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 = getInstructorEntityForEmail(instructorAttributesToUpdate.courseId, instructorAttributesToUpdate.email);
    if (instructorToUpdate == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT_ACCOUNT + instructorAttributesToUpdate.email + ThreadHelper.getCurrentThreadStack());
    }
    instructorToUpdate.setGoogleId(instructorAttributesToUpdate.googleId);
    instructorToUpdate.setName(instructorAttributesToUpdate.name);
    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);
}
Also used : Instructor(teammates.storage.entity.Instructor) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4