Search in sources :

Example 71 with InvalidParametersException

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

the class FeedbackQuestionsDb method updateFeedbackQuestion.

/**
 * Updates the feedback question identified by `{@code newAttributes.getId()}
 * For the remaining parameters, the existing value is preserved
 *   if the parameter is null (due to 'keep existing' policy).<br>
 * The timestamp for {@code updatedAt} is independent of the {@code newAttributes}
 *   and depends on the value of {@code keepUpdateTimestamp}
 * Preconditions: <br>
 * * {@code newAttributes.getId()} is non-null and
 *  correspond to an existing feedback question. <br>
 */
public void updateFeedbackQuestion(FeedbackQuestionAttributes newAttributes, boolean keepUpdateTimestamp) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newAttributes);
    if (!newAttributes.isValid()) {
        throw new InvalidParametersException(newAttributes.getInvalidityInfo());
    }
    FeedbackQuestion fq = getEntity(newAttributes);
    if (fq == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + newAttributes.toString());
    }
    fq.setQuestionNumber(newAttributes.questionNumber);
    fq.setQuestionText(newAttributes.questionMetaData);
    fq.setQuestionDescription(newAttributes.questionDescription);
    fq.setQuestionType(newAttributes.questionType);
    fq.setGiverType(newAttributes.giverType);
    fq.setRecipientType(newAttributes.recipientType);
    fq.setShowResponsesTo(newAttributes.showResponsesTo);
    fq.setShowGiverNameTo(newAttributes.showGiverNameTo);
    fq.setShowRecipientNameTo(newAttributes.showRecipientNameTo);
    fq.setNumberOfEntitiesToGiveFeedbackTo(newAttributes.numberOfEntitiesToGiveFeedbackTo);
    // set true to prevent changes to last update timestamp
    fq.keepUpdateTimestamp = keepUpdateTimestamp;
    saveEntity(fq, newAttributes);
}
Also used : FeedbackQuestion(teammates.storage.entity.FeedbackQuestion) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 72 with InvalidParametersException

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

the class FeedbackResponseCommentsDb method updateFeedbackResponseComment.

/**
 * Preconditions: <br>
 * * All parameters are non-null.
 */
public FeedbackResponseCommentAttributes updateFeedbackResponseComment(FeedbackResponseCommentAttributes newAttributes) throws InvalidParametersException, EntityDoesNotExistException {
    Assumption.assertNotNull(Const.StatusCodes.DBLEVEL_NULL_INPUT, newAttributes);
    newAttributes.sanitizeForSaving();
    if (!newAttributes.isValid()) {
        throw new InvalidParametersException(newAttributes.getInvalidityInfo());
    }
    FeedbackResponseComment frc = getEntity(newAttributes);
    if (frc == null) {
        throw new EntityDoesNotExistException(ERROR_UPDATE_NON_EXISTENT + newAttributes.toString());
    }
    frc.setCommentText(newAttributes.commentText);
    frc.setGiverSection(newAttributes.giverSection);
    frc.setReceiverSection(newAttributes.receiverSection);
    frc.setShowCommentTo(newAttributes.showCommentTo);
    frc.setShowGiverNameTo(newAttributes.showGiverNameTo);
    frc.setIsVisibilityFollowingFeedbackQuestion(false);
    frc.setLastEditorEmail(newAttributes.giverEmail);
    frc.setLastEditedAt(newAttributes.createdAt);
    if (newAttributes.feedbackResponseId != null) {
        frc.setFeedbackResponseId(newAttributes.feedbackResponseId);
    }
    saveEntity(frc, newAttributes);
    return makeAttributes(frc);
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) FeedbackResponseComment(teammates.storage.entity.FeedbackResponseComment) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 73 with InvalidParametersException

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

the class FeedbackSessionsDb method addStudentRespondents.

// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void addStudentRespondents(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.getRespondingStudentList().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 74 with InvalidParametersException

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

the class FeedbackSessionsDb method clearInstructorRespondents.

public void clearInstructorRespondents(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.getRespondingInstructorList().clear();
    saveEntity(fs, feedbackSession);
}
Also used : FeedbackSession(teammates.storage.entity.FeedbackSession) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 75 with InvalidParametersException

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

the class FeedbackSessionsDb method deleteInstructorRespondent.

// The objectify library does not support throwing checked exceptions inside transactions
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public void deleteInstructorRespondent(String email, FeedbackSessionAttributes feedbackSession) throws InvalidParametersException, EntityDoesNotExistException {
    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.getRespondingInstructorList().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)

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