Search in sources :

Example 81 with EntityDoesNotExistException

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

the class FeedbackQuestionsLogic method getCopiableFeedbackQuestionsForInstructor.

/**
 *  Gets a {@link List} of every FeedbackQuestion that the instructor can copy.
 */
public List<FeedbackQuestionAttributes> getCopiableFeedbackQuestionsForInstructor(String googleId) throws EntityDoesNotExistException {
    List<FeedbackQuestionAttributes> copiableQuestions = new ArrayList<>();
    List<CourseAttributes> courses = coursesLogic.getCoursesForInstructor(googleId);
    for (CourseAttributes course : courses) {
        List<FeedbackSessionAttributes> sessions = fsLogic.getFeedbackSessionsForCourse(course.getId());
        for (FeedbackSessionAttributes session : sessions) {
            List<FeedbackQuestionAttributes> questions = getFeedbackQuestionsForSession(session.getFeedbackSessionName(), course.getId());
            copiableQuestions.addAll(questions);
        }
    }
    copiableQuestions.sort(Comparator.comparing((FeedbackQuestionAttributes question) -> question.courseId).thenComparing(question -> question.feedbackSessionName).thenComparing(question -> question.getQuestionDetails().getQuestionTypeDisplayName()).thenComparing(question -> question.getQuestionDetails().getQuestionText()));
    return copiableQuestions;
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) Set(java.util.Set) HashMap(java.util.HashMap) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) FeedbackQuestionsDb(teammates.storage.api.FeedbackQuestionsDb) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) List(java.util.List) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackParticipantType(teammates.common.datatransfer.FeedbackParticipantType) Map(java.util.Map) Assumption(teammates.common.util.Assumption) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Comparator(java.util.Comparator) Logger(teammates.common.util.Logger) InvalidParametersException(teammates.common.exception.InvalidParametersException) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 82 with EntityDoesNotExistException

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

the class FeedbackQuestionsLogic method deleteFeedbackQuestionCascade.

/**
 * Deletes a question.<br> Question is identified by it's question number, and
 * the feedback session name and course ID of the question.<br>
 * Can be used when the question ID is unknown. <br>
 * Cascade the deletion of all existing responses for the question and then
 * shifts larger question numbers down by one to preserve number order.
 */
private void deleteFeedbackQuestionCascade(String feedbackSessionName, String courseId, int questionNumber, boolean hasResponseRateUpdate) {
    FeedbackQuestionAttributes questionToDelete = getFeedbackQuestion(feedbackSessionName, courseId, questionNumber);
    if (questionToDelete == null) {
        // Silently fail if question does not exist.
        return;
    }
    // Cascade delete responses for question.
    frLogic.deleteFeedbackResponsesForQuestionAndCascade(questionToDelete.getId(), hasResponseRateUpdate);
    List<FeedbackQuestionAttributes> questionsToShiftQnNumber = null;
    try {
        questionsToShiftQnNumber = getFeedbackQuestionsForSession(feedbackSessionName, courseId);
    } catch (EntityDoesNotExistException e) {
        Assumption.fail("Session disappeared.");
    }
    fqDb.deleteEntity(questionToDelete);
    if (questionToDelete.questionNumber < questionsToShiftQnNumber.size()) {
        shiftQuestionNumbersDown(questionToDelete.questionNumber, questionsToShiftQnNumber);
    }
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 83 with EntityDoesNotExistException

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

the class FeedbackQuestionsLogic method updateFeedbackQuestion.

private void updateFeedbackQuestion(FeedbackQuestionAttributes newAttributes, boolean hasResponseRateUpdate) throws InvalidParametersException, EntityDoesNotExistException {
    FeedbackQuestionAttributes oldQuestion = null;
    if (newAttributes.getId() == null) {
        oldQuestion = fqDb.getFeedbackQuestion(newAttributes.feedbackSessionName, newAttributes.courseId, newAttributes.questionNumber);
    } else {
        oldQuestion = fqDb.getFeedbackQuestion(newAttributes.getId());
    }
    if (oldQuestion == null) {
        throw new EntityDoesNotExistException("Trying to update a feedback question that does not exist.");
    }
    if (oldQuestion.areResponseDeletionsRequiredForChanges(newAttributes)) {
        frLogic.deleteFeedbackResponsesForQuestionAndCascade(oldQuestion.getId(), hasResponseRateUpdate);
    }
    oldQuestion.updateValues(newAttributes);
    newAttributes.removeIrrelevantVisibilityOptions();
    fqDb.updateFeedbackQuestion(newAttributes);
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 84 with EntityDoesNotExistException

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

the class FeedbackQuestionsLogic method getFeedbackQuestionsForInstructor.

/**
 * Gets a {@code List} of all questions for the given session for an
 * instructor to view/submit.
 */
public List<FeedbackQuestionAttributes> getFeedbackQuestionsForInstructor(String feedbackSessionName, String courseId, String userEmail) throws EntityDoesNotExistException {
    if (fsLogic.getFeedbackSession(feedbackSessionName, courseId) == null) {
        throw new EntityDoesNotExistException("Trying to get questions for a feedback session that does not exist.");
    }
    if (fsLogic.isCreatorOfSession(feedbackSessionName, courseId, userEmail)) {
        return getFeedbackQuestionsForCreatorInstructor(feedbackSessionName, courseId);
    }
    List<FeedbackQuestionAttributes> questions = new ArrayList<>();
    InstructorAttributes instructor = instructorsLogic.getInstructorForEmail(courseId, userEmail);
    boolean isInstructor = instructor != null;
    if (isInstructor) {
        questions.addAll(fqDb.getFeedbackQuestionsForGiverType(feedbackSessionName, courseId, FeedbackParticipantType.INSTRUCTORS));
    }
    questions.sort(null);
    return questions;
}
Also used : ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 85 with EntityDoesNotExistException

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

the class FeedbackQuestionsLogic method updateFeedbackQuestionNumber.

/**
 * Updates the feedback question number, shifts other questions up/down
 * depending on the change.
 */
public void updateFeedbackQuestionNumber(FeedbackQuestionAttributes newQuestion) throws InvalidParametersException, EntityDoesNotExistException {
    FeedbackQuestionAttributes oldQuestion = fqDb.getFeedbackQuestion(newQuestion.getId());
    if (oldQuestion == null) {
        throw new EntityDoesNotExistException("Trying to update a feedback question that does not exist.");
    }
    int oldQuestionNumber = oldQuestion.questionNumber;
    int newQuestionNumber = newQuestion.questionNumber;
    String feedbackSessionName = oldQuestion.feedbackSessionName;
    String courseId = oldQuestion.courseId;
    List<FeedbackQuestionAttributes> questions = null;
    try {
        questions = getFeedbackQuestionsForSession(feedbackSessionName, courseId);
    } catch (EntityDoesNotExistException e) {
        Assumption.fail("Session disappeared.");
    }
    adjustQuestionNumbers(oldQuestionNumber, newQuestionNumber, questions);
    updateFeedbackQuestion(newQuestion);
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) 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