Search in sources :

Example 66 with EntityDoesNotExistException

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

the class CoursesLogic method getCoursesForStudentAccount.

/**
 * Returns a list of {@link CourseAttributes} for all courses a given student is enrolled in.
 *
 * @param googleId The Google ID of the student
 */
public List<CourseAttributes> getCoursesForStudentAccount(String googleId) throws EntityDoesNotExistException {
    List<StudentAttributes> studentDataList = studentsLogic.getStudentsForGoogleId(googleId);
    if (studentDataList.isEmpty()) {
        throw new EntityDoesNotExistException("Student with Google ID " + googleId + " does not exist");
    }
    List<String> courseIds = new ArrayList<>();
    for (StudentAttributes s : studentDataList) {
        courseIds.add(s.course);
    }
    return coursesDb.getCourses(courseIds);
}
Also used : ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 67 with EntityDoesNotExistException

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

the class FeedbackMsqQuestionDetails method generateOptionList.

private List<String> generateOptionList(String courseId) {
    List<String> optionList = new ArrayList<>();
    switch(generateOptionsFor) {
        case NONE:
            optionList = msqChoices;
            break;
        case STUDENTS:
        // fallthrough
        case STUDENTS_EXCLUDING_SELF:
            List<StudentAttributes> studentList = StudentsLogic.inst().getStudentsForCourse(courseId);
            if (generateOptionsFor == FeedbackParticipantType.STUDENTS_EXCLUDING_SELF) {
                studentList.removeIf(studentInList -> studentInList.email.equals(studentDoingQuestion.email));
            }
            for (StudentAttributes student : studentList) {
                optionList.add(student.name + " (" + student.team + ")");
            }
            optionList.sort(null);
            break;
        case TEAMS:
        // fallthrough
        case TEAMS_EXCLUDING_SELF:
            try {
                List<TeamDetailsBundle> teamList = CoursesLogic.inst().getTeamsForCourse(courseId);
                if (generateOptionsFor == FeedbackParticipantType.TEAMS_EXCLUDING_SELF) {
                    teamList.removeIf(teamInList -> teamInList.name.equals(studentDoingQuestion.team));
                }
                for (TeamDetailsBundle team : teamList) {
                    optionList.add(team.name);
                }
                optionList.sort(null);
            } catch (EntityDoesNotExistException e) {
                Assumption.fail("Course disappeared");
            }
            break;
        case INSTRUCTORS:
            List<InstructorAttributes> instructorList = InstructorsLogic.inst().getInstructorsForCourse(courseId);
            for (InstructorAttributes instructor : instructorList) {
                optionList.add(instructor.name);
            }
            optionList.sort(null);
            break;
        default:
            Assumption.fail("Trying to generate options for neither students, teams nor instructors");
            break;
    }
    return optionList;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 68 with EntityDoesNotExistException

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

the class FeedbackMcqQuestionDetails method generateOptionList.

private List<String> generateOptionList(String courseId) {
    List<String> optionList = new ArrayList<>();
    switch(generateOptionsFor) {
        case NONE:
            optionList = mcqChoices;
            break;
        case STUDENTS:
        // fallthrough
        case STUDENTS_EXCLUDING_SELF:
            List<StudentAttributes> studentList = StudentsLogic.inst().getStudentsForCourse(courseId);
            if (generateOptionsFor == FeedbackParticipantType.STUDENTS_EXCLUDING_SELF) {
                studentList.removeIf(studentInList -> studentInList.email.equals(studentDoingQuestion.email));
            }
            for (StudentAttributes student : studentList) {
                optionList.add(student.name + " (" + student.team + ")");
            }
            optionList.sort(null);
            break;
        case TEAMS:
        // fallthrough
        case TEAMS_EXCLUDING_SELF:
            try {
                List<TeamDetailsBundle> teamList = CoursesLogic.inst().getTeamsForCourse(courseId);
                if (generateOptionsFor == FeedbackParticipantType.TEAMS_EXCLUDING_SELF) {
                    teamList.removeIf(teamInList -> teamInList.name.equals(studentDoingQuestion.team));
                }
                for (TeamDetailsBundle team : teamList) {
                    optionList.add(team.name);
                }
                optionList.sort(null);
            } catch (EntityDoesNotExistException e) {
                Assumption.fail("Course disappeared");
            }
            break;
        case INSTRUCTORS:
            List<InstructorAttributes> instructorList = InstructorsLogic.inst().getInstructorsForCourse(courseId);
            for (InstructorAttributes instructor : instructorList) {
                optionList.add(instructor.name);
            }
            optionList.sort(null);
            break;
        default:
            Assumption.fail("Trying to generate options for neither students, teams nor instructors");
            break;
    }
    return optionList;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 69 with EntityDoesNotExistException

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

the class EmailGenerator method generateFeedbackSessionClosedEmails.

/**
 * Generates the feedback session closed emails for the given {@code session}.
 */
public List<EmailWrapper> generateFeedbackSessionClosedEmails(FeedbackSessionAttributes session) {
    if (session.isPrivateSession()) {
        return new ArrayList<>();
    }
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    boolean isEmailNeededForStudents = false;
    try {
        isEmailNeededForStudents = fsLogic.isFeedbackSessionHasQuestionForStudents(session.getFeedbackSessionName(), session.getCourseId());
    } catch (EntityDoesNotExistException e) {
        log.severe("Course " + session.getCourseId() + " does not exist or " + "session " + session.getFeedbackSessionName() + " does not exist");
    }
    List<InstructorAttributes> instructors = instructorsLogic.getInstructorsForCourse(session.getCourseId());
    List<StudentAttributes> students = isEmailNeededForStudents ? studentsLogic.getStudentsForCourse(session.getCourseId()) : new ArrayList<StudentAttributes>();
    String template = EmailTemplates.USER_FEEDBACK_SESSION.replace("${status}", FEEDBACK_STATUS_SESSION_CLOSED);
    String additionalContactInformation = getAdditionalContactInformationFragment(course);
    return generateFeedbackSessionEmailBases(course, session, students, instructors, template, EmailType.FEEDBACK_CLOSED.getSubject(), FEEDBACK_ACTION_VIEW, additionalContactInformation);
}
Also used : ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 70 with EntityDoesNotExistException

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

the class EmailGenerator method generateFeedbackSessionClosingEmails.

/**
 * Generates the feedback session closing emails for the given {@code session}.
 */
public List<EmailWrapper> generateFeedbackSessionClosingEmails(FeedbackSessionAttributes session) {
    List<StudentAttributes> students = new ArrayList<>();
    boolean isEmailNeeded = fsLogic.isFeedbackSessionForStudentsToAnswer(session);
    if (isEmailNeeded) {
        List<StudentAttributes> studentsForCourse = studentsLogic.getStudentsForCourse(session.getCourseId());
        for (StudentAttributes student : studentsForCourse) {
            try {
                if (!fsLogic.isFeedbackSessionFullyCompletedByStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email)) {
                    students.add(student);
                }
            } catch (EntityDoesNotExistException e) {
                log.severe("Course " + session.getCourseId() + " does not exist or " + "session " + session.getFeedbackSessionName() + " does not exist");
                // Do not waste time looping through all students
                break;
            }
        }
    }
    String template = EmailTemplates.USER_FEEDBACK_SESSION.replace("${status}", FEEDBACK_STATUS_SESSION_CLOSING);
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    List<InstructorAttributes> instructors = isEmailNeeded ? instructorsLogic.getInstructorsForCourse(session.getCourseId()) : new ArrayList<InstructorAttributes>();
    String additionalContactInformation = HTML_NO_ACTION_REQUIRED + getAdditionalContactInformationFragment(course);
    return generateFeedbackSessionEmailBases(course, session, students, instructors, template, EmailType.FEEDBACK_CLOSING.getSubject(), FEEDBACK_ACTION_SUBMIT, additionalContactInformation);
}
Also used : ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

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