Search in sources :

Example 96 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class CoursesLogic method getCourseDetailsListForStudent.

/**
 * Returns a list of {@link CourseDetailsBundle} for all
 * courses a given student is enrolled in.
 *
 * @param googleId The Google ID of the student
 */
public List<CourseDetailsBundle> getCourseDetailsListForStudent(String googleId) throws EntityDoesNotExistException {
    List<CourseAttributes> courseList = getCoursesForStudentAccount(googleId);
    CourseAttributes.sortById(courseList);
    List<CourseDetailsBundle> courseDetailsList = new ArrayList<>();
    for (CourseAttributes c : courseList) {
        StudentAttributes s = studentsLogic.getStudentForCourseIdAndGoogleId(c.getId(), googleId);
        if (s == null) {
            // TODO Remove excessive logging after the reason why s can be null is found
            StringBuilder logMsgBuilder = new StringBuilder();
            String logMsg = "Student is null in CoursesLogic.getCourseDetailsListForStudent(String googleId)" + "<br> Student Google ID: " + googleId + "<br> Course: " + c.getId() + "<br> All Courses Retrieved using the Google ID:";
            logMsgBuilder.append(logMsg);
            for (CourseAttributes course : courseList) {
                logMsgBuilder.append("<br>").append(course.getId());
            }
            log.severe(logMsgBuilder.toString());
            // TODO Failing might not be the best course of action here.
            // Maybe throw a custom exception and tell user to wait due to eventual consistency?
            Assumption.fail("Student should not be null at this point.");
        }
        // Skip the course existence check since the course ID is obtained from a
        // valid CourseAttributes resulting from query
        List<FeedbackSessionAttributes> feedbackSessionList = feedbackSessionsLogic.getFeedbackSessionsForUserInCourseSkipCheck(c.getId(), s.email);
        CourseDetailsBundle cdd = new CourseDetailsBundle(c);
        for (FeedbackSessionAttributes fs : feedbackSessionList) {
            cdd.feedbackSessions.add(new FeedbackSessionDetailsBundle(fs));
        }
        courseDetailsList.add(cdd);
    }
    return courseDetailsList;
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) ArrayList(java.util.ArrayList) FeedbackSessionDetailsBundle(teammates.common.datatransfer.FeedbackSessionDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 97 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes 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 98 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class EmailGenerator method generateFeedbackSessionOpeningEmails.

/**
 * Generates the feedback session opening emails for the given {@code session}.
 */
public List<EmailWrapper> generateFeedbackSessionOpeningEmails(FeedbackSessionAttributes session) {
    String template = EmailTemplates.USER_FEEDBACK_SESSION;
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    boolean isEmailNeeded = fsLogic.isFeedbackSessionForStudentsToAnswer(session);
    List<InstructorAttributes> instructors = isEmailNeeded ? instructorsLogic.getInstructorsForCourse(session.getCourseId()) : new ArrayList<InstructorAttributes>();
    List<StudentAttributes> students = isEmailNeeded ? studentsLogic.getStudentsForCourse(session.getCourseId()) : new ArrayList<StudentAttributes>();
    List<EmailWrapper> emails = generateFeedbackSessionEmailBases(course, session, students, instructors, template, EmailType.FEEDBACK_OPENING.getSubject());
    for (EmailWrapper email : emails) {
        email.setContent(email.getContent().replace("${status}", FEEDBACK_STATUS_SESSION_OPENING));
    }
    return emails;
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 99 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes 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)

Example 100 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes in project teammates by TEAMMATES.

the class InstructorCoursesPageAction method execute.

@Override
public ActionResult execute() {
    /* Explanation: First, we extract any parameters from the request object.
         * e.g., idOfCourseToDelete = getRequestParam(Const.ParamsNames.COURSE_ID);
         * After that, we may verify parameters.
         * e.g. Assumption.assertNotNull(courseId);
         * In this Action, there are no parameters.*/
    /* Explanation: Next, check if the user has rights to execute the action.*/
    gateKeeper.verifyInstructorPrivileges(account);
    /* Explanation: This is a 'show page' type action. Therefore, we
         * prepare the matching PageData object, accessing the Logic
         * component if necessary.*/
    InstructorCoursesPageData data = new InstructorCoursesPageData(account, sessionToken);
    String isUsingAjax = getRequestParamValue(Const.ParamsNames.IS_USING_AJAX);
    data.setUsingAjax(isUsingAjax != null);
    Map<String, InstructorAttributes> instructorsForCourses = new HashMap<>();
    List<CourseAttributes> allCourses = new ArrayList<>();
    List<CourseAttributes> activeCourses = new ArrayList<>();
    List<CourseAttributes> archivedCourses = new ArrayList<>();
    if (data.isUsingAjax()) {
        // Get list of InstructorAttributes that belong to the user.
        List<InstructorAttributes> instructorList = logic.getInstructorsForGoogleId(data.account.googleId);
        for (InstructorAttributes instructor : instructorList) {
            instructorsForCourses.put(instructor.courseId, instructor);
        }
        // Get corresponding courses of the instructors.
        allCourses = logic.getCoursesForInstructor(instructorList);
        List<String> archivedCourseIds = logic.getArchivedCourseIds(allCourses, instructorsForCourses);
        for (CourseAttributes course : allCourses) {
            if (archivedCourseIds.contains(course.getId())) {
                archivedCourses.add(course);
            } else {
                activeCourses.add(course);
            }
        }
        // Sort CourseDetailsBundle lists by course id
        CourseAttributes.sortById(activeCourses);
        CourseAttributes.sortById(archivedCourses);
    }
    data.init(activeCourses, archivedCourses, instructorsForCourses);
    /* Explanation: Set any status messages that should be shown to the user.*/
    if (data.isUsingAjax() && allCourses.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_EMPTY, StatusMessageColor.WARNING));
    }
    /* Explanation: We must set this variable. It is the text that will
         * represent this particular execution of this action in the
         * 'admin activity log' page.*/
    statusToAdmin = "instructorCourse Page Load<br>Total courses: " + allCourses.size();
    /* Explanation: Create the appropriate result object and return it.*/
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSES, data);
}
Also used : InstructorCoursesPageData(teammates.ui.pagedata.InstructorCoursesPageData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)106 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 Test (org.testng.annotations.Test)40 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)33 ArrayList (java.util.ArrayList)31 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)19 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)16 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)15 EmailWrapper (teammates.common.util.EmailWrapper)15 HashMap (java.util.HashMap)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)10 EmailGenerator (teammates.logic.api.EmailGenerator)10 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)6 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)4 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)4 InstructorCoursesPageData (teammates.ui.pagedata.InstructorCoursesPageData)4 InstructorFeedbackSessionsPageData (teammates.ui.pagedata.InstructorFeedbackSessionsPageData)4