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;
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations