Search in sources :

Example 16 with CourseAttributes

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

the class InstructorCourseAddAction method execute.

@Override
public ActionResult execute() {
    String newCourseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, newCourseId);
    String newCourseName = getRequestParamValue(Const.ParamsNames.COURSE_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_NAME, newCourseName);
    String newCourseTimeZone = getRequestParamValue(Const.ParamsNames.COURSE_TIME_ZONE);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_TIME_ZONE, newCourseTimeZone);
    /* Check if user has the right to execute the action */
    gateKeeper.verifyInstructorPrivileges(account);
    /* Create a new course in the database */
    data = new InstructorCoursesPageData(account, sessionToken);
    createCourse(newCourseId, newCourseName, newCourseTimeZone);
    /* Prepare data for the refreshed page after executing the adding action */
    Map<String, InstructorAttributes> instructorsForCourses = new HashMap<>();
    List<CourseAttributes> activeCourses = new ArrayList<>();
    List<CourseAttributes> archivedCourses = new ArrayList<>();
    // 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.
    List<CourseAttributes> 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);
    String courseIdToShowParam = "";
    String courseNameToShowParam = "";
    if (isError) {
        // there is error in adding the course
        courseIdToShowParam = SanitizationHelper.sanitizeForHtml(newCourseId);
        courseNameToShowParam = SanitizationHelper.sanitizeForHtml(newCourseName);
        List<String> statusMessageTexts = new ArrayList<>();
        for (StatusMessage msg : statusToUser) {
            statusMessageTexts.add(msg.getText());
        }
        statusToAdmin = StringHelper.toString(statusMessageTexts, "<br>");
    } else {
        statusToAdmin = "Course added : " + newCourseId;
        statusToAdmin += "<br>Total courses: " + allCourses.size();
    }
    data.init(activeCourses, archivedCourses, instructorsForCourses, courseIdToShowParam, courseNameToShowParam);
    return isError ? createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSES, data) : createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE);
}
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)

Example 17 with CourseAttributes

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

the class InstructorFeedbackAddAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getNonNullRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertNotEmpty(courseId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    String feedbackSessionName = SanitizationHelper.sanitizeTitle(getNonNullRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME));
    FeedbackSessionAttributes fs = extractFeedbackSessionData(feedbackSessionName, courseId, instructor.email);
    String feedbackSessionType = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_TYPE);
    InstructorFeedbackSessionsPageData data = new InstructorFeedbackSessionsPageData(account, sessionToken);
    try {
        validateTimeData(fs);
        logic.createFeedbackSession(fs);
        try {
            createTemplateFeedbackQuestions(fs.getCourseId(), fs.getFeedbackSessionName(), fs.getCreatorEmail(), feedbackSessionType);
        } catch (InvalidParametersException e) {
            // Failed to create feedback questions for specified template/feedback session type.
            // TODO: let the user know an error has occurred? delete the feedback session?
            log.severe(TeammatesException.toStringWithStackTrace(e));
        }
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_ADDED, StatusMessageColor.SUCCESS));
        statusToAdmin = "New Feedback Session <span class=\"bold\">(" + fs.getFeedbackSessionName() + ")</span> for Course " + "<span class=\"bold\">[" + fs.getCourseId() + "]</span> created.<br>" + "<span class=\"bold\">From:</span> " + fs.getStartTime() + "<span class=\"bold\"> to</span> " + fs.getEndTime() + "<br>" + "<span class=\"bold\">Session visible from:</span> " + fs.getSessionVisibleFromTime() + "<br>" + "<span class=\"bold\">Results visible from:</span> " + fs.getResultsVisibleFromTime() + "<br><br>" + "<span class=\"bold\">Instructions:</span> " + fs.getInstructions();
        // (similar to the one below)
        return createRedirectResult(data.getInstructorFeedbackEditLink(fs.getCourseId(), fs.getFeedbackSessionName()));
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.FEEDBACK_SESSION_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    // isError == true if an exception occurred above
    boolean shouldOmitArchived = true;
    Map<String, InstructorAttributes> instructors = loadCourseInstructorMap(shouldOmitArchived);
    List<InstructorAttributes> instructorList = new ArrayList<>(instructors.values());
    List<CourseAttributes> courses = loadCoursesList(instructorList);
    List<FeedbackSessionAttributes> feedbackSessions = loadFeedbackSessionsList(instructorList);
    FeedbackSessionAttributes.sortFeedbackSessionsByCreationTimeDescending(feedbackSessions);
    if (feedbackSessions.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_ADD_DB_INCONSISTENCY, StatusMessageColor.WARNING));
    }
    data.initWithoutHighlightedRow(courses, courseId, feedbackSessions, instructors, fs, feedbackSessionType);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SESSIONS, data);
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) ArrayList(java.util.ArrayList) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackSessionsPageData(teammates.ui.pagedata.InstructorFeedbackSessionsPageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 18 with CourseAttributes

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

the class InstructorFeedbackEditCopyPageAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    List<InstructorAttributes> instructors = logic.getInstructorsForGoogleId(account.googleId);
    Assumption.assertNotNull(instructors);
    List<CourseAttributes> allCourses = logic.getCoursesForInstructor(account.googleId);
    List<CourseAttributes> coursesToAddToData = new ArrayList<>();
    // Only add courses to data if the course is not archived and instructor has sufficient permissions
    for (CourseAttributes course : allCourses) {
        InstructorAttributes instructor = logic.getInstructorForGoogleId(course.getId(), account.googleId);
        boolean isAllowedToMakeSession = instructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
        if (!instructor.isArchived && isAllowedToMakeSession) {
            coursesToAddToData.add(course);
        }
    }
    CourseAttributes.sortByCreatedDate(coursesToAddToData);
    InstructorFeedbackEditCopyPageData data = new InstructorFeedbackEditCopyPageData(account, sessionToken, coursesToAddToData, courseId, feedbackSessionName);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_COPY_MODAL, data);
}
Also used : InstructorFeedbackEditCopyPageData(teammates.ui.pagedata.InstructorFeedbackEditCopyPageData) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 19 with CourseAttributes

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

the class InstructorFeedbackSessionsPageAction method execute.

@Override
protected ActionResult execute() {
    // This can be null. Non-null value indicates the page is being loaded
    // to add a feedback to the specified course
    String courseIdForNewSession = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionToHighlight = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    String isUsingAjax = getRequestParamValue(Const.ParamsNames.IS_USING_AJAX);
    gateKeeper.verifyInstructorPrivileges(account);
    if (courseIdForNewSession != null) {
        gateKeeper.verifyAccessible(logic.getInstructorForGoogleId(courseIdForNewSession, account.googleId), logic.getCourse(courseIdForNewSession), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    }
    InstructorFeedbackSessionsPageData data = new InstructorFeedbackSessionsPageData(account, sessionToken);
    data.setUsingAjax(isUsingAjax != null);
    // TODO: implement as a request parameter
    boolean shouldOmitArchived = true;
    // HashMap with courseId as key and InstructorAttributes as value
    Map<String, InstructorAttributes> instructors = loadCourseInstructorMap(shouldOmitArchived);
    List<InstructorAttributes> instructorList = new ArrayList<>(instructors.values());
    List<CourseAttributes> courses = loadCoursesList(instructorList);
    List<FeedbackSessionAttributes> existingFeedbackSessions;
    if (courses.isEmpty() || !data.isUsingAjax()) {
        existingFeedbackSessions = new ArrayList<>();
    } else {
        existingFeedbackSessions = loadFeedbackSessionsList(instructorList);
        if (existingFeedbackSessions.isEmpty()) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SESSION_EMPTY, StatusMessageColor.WARNING));
        }
    }
    if (courses.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_EMPTY_IN_INSTRUCTOR_FEEDBACKS.replace("${user}", "?user=" + account.googleId), StatusMessageColor.WARNING));
    }
    statusToAdmin = "Number of feedback sessions: " + existingFeedbackSessions.size();
    data.initWithoutDefaultFormValues(courses, courseIdForNewSession, existingFeedbackSessions, instructors, feedbackSessionToHighlight);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SESSIONS, data);
}
Also used : ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorFeedbackSessionsPageData(teammates.ui.pagedata.InstructorFeedbackSessionsPageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 20 with CourseAttributes

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

the class InstructorCourseRemindAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    CourseAttributes course = logic.getCourse(courseId);
    if (course == null) {
        throw new EntityDoesNotExistException("Course with ID " + courseId + " does not exist!");
    }
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    boolean isSendingToStudent = studentEmail != null;
    boolean isSendingToInstructor = instructorEmail != null;
    if (isSendingToStudent) {
        gateKeeper.verifyAccessible(instructor, course, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    } else if (isSendingToInstructor) {
        gateKeeper.verifyAccessible(instructor, course, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
    } else {
        // this is sending registration emails to all students in the course and we will check if the instructor
        // canmodifystudent for course level since for modifystudent privilege there is only course level setting for now
        gateKeeper.verifyAccessible(instructor, course, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    }
    /* Process sending emails and setup status to be shown to user and admin */
    Map<String, JoinEmailData> emailDataMap = new TreeMap<>();
    String redirectUrl = "";
    if (isSendingToStudent) {
        taskQueuer.scheduleCourseRegistrationInviteToStudent(courseId, studentEmail, false);
        StudentAttributes studentData = logic.getStudentForEmail(courseId, studentEmail);
        if (studentData == null) {
            throw new EntityDoesNotExistException("Student with email " + studentEmail + " does not exist " + "in course " + courseId + "!");
        }
        emailDataMap.put(studentEmail, new JoinEmailData(studentData.getName(), extractStudentRegistrationKey(studentData)));
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_REMINDER_SENT_TO + studentEmail, StatusMessageColor.SUCCESS));
        redirectUrl = Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE;
    } else if (isSendingToInstructor) {
        taskQueuer.scheduleCourseRegistrationInviteToInstructor(loggedInUser.googleId, instructorEmail, courseId);
        InstructorAttributes instructorData = logic.getInstructorForEmail(courseId, instructorEmail);
        if (instructorData == null) {
            throw new EntityDoesNotExistException("Instructor with email " + instructorEmail + " does not exist " + "in course " + courseId + "!");
        }
        emailDataMap.put(instructorEmail, new JoinEmailData(instructorData.getName(), StringHelper.encrypt(instructorData.key)));
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_REMINDER_SENT_TO + instructorEmail, StatusMessageColor.SUCCESS));
        redirectUrl = Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE;
    } else {
        List<StudentAttributes> studentDataList = logic.getUnregisteredStudentsForCourse(courseId);
        for (StudentAttributes student : studentDataList) {
            taskQueuer.scheduleCourseRegistrationInviteToStudent(course.getId(), student.getEmail(), false);
            emailDataMap.put(student.getEmail(), new JoinEmailData(student.getName(), extractStudentRegistrationKey(student)));
        }
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_REMINDERS_SENT, StatusMessageColor.SUCCESS));
        redirectUrl = Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE;
    }
    statusToAdmin = generateStatusToAdmin(emailDataMap, courseId);
    /* Create redirection with URL based on type of sending email */
    RedirectResult response = createRedirectResult(redirectUrl);
    response.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    return response;
}
Also used : List(java.util.List) TreeMap(java.util.TreeMap) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) 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