Search in sources :

Example 71 with InstructorAttributes

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

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

the class InstructorEditInstructorFeedbackPageAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    String instructorUnderModerationEmail = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_MODERATED_PERSON);
    gateKeeper.verifyAccessible(logic.getInstructorForGoogleId(courseId, account.googleId), logic.getFeedbackSession(feedbackSessionName, courseId), false, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION);
    InstructorAttributes instructorUnderModeration = logic.getInstructorForEmail(courseId, instructorUnderModerationEmail);
    // If the instructor doesn't exist
    if (instructorUnderModeration == null) {
        throw new EntityDoesNotExistException("Instructor Email " + instructorUnderModerationEmail + " does not exist in " + courseId + ".");
    }
    String moderatedQuestionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_MODERATED_QUESTION_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_MODERATED_PERSON, instructorUnderModerationEmail);
    FeedbackSubmissionEditPageData data = new FeedbackSubmissionEditPageData(account, student, sessionToken);
    data.bundle = logic.getFeedbackSessionQuestionsBundleForInstructor(feedbackSessionName, courseId, instructorUnderModeration.email);
    Assumption.assertNotNull(data.bundle);
    data.setSessionOpenForSubmission(true);
    data.setModeration(true);
    data.setHeaderHidden(true);
    data.setPreviewInstructor(instructorUnderModeration);
    data.setSubmitAction(Const.ActionURIs.INSTRUCTOR_EDIT_INSTRUCTOR_FEEDBACK_SAVE);
    if (moderatedQuestionId != null) {
        data.setModeratedQuestionId(moderatedQuestionId);
    }
    statusToAdmin = "Moderating feedback session for instructor (" + instructorUnderModeration.email + ")<br>" + "Session Name: " + feedbackSessionName + "<br>" + "Course ID: " + courseId;
    data.bundle.hideUnmoderatableQuestions();
    data.init(courseId);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_SUBMISSION_EDIT, data);
}
Also used : FeedbackSubmissionEditPageData(teammates.ui.pagedata.FeedbackSubmissionEditPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 73 with InstructorAttributes

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

the class InstructorEditInstructorFeedbackSaveAction method checkAdditionalConstraints.

/**
 * Checks if the instructor only submitted responses that he/she should be submitting when moderating.
 */
@Override
protected void checkAdditionalConstraints() {
    // check the instructor did not submit responses to questions that he/she should not be able when moderating
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    int numOfQuestionsToGet = data.bundle.questionResponseBundle.size();
    for (int questionIndx = 1; questionIndx <= numOfQuestionsToGet; questionIndx++) {
        String paramMapKey = Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx;
        String questionId = getRequestParamValue(paramMapKey);
        if (questionId == null) {
            // we do not throw an error if the question was not present on the page for instructors to edit
            continue;
        }
        FeedbackQuestionAttributes questionAttributes = data.bundle.getQuestionAttributes(questionId);
        if (questionAttributes == null) {
            statusToUser.add(new StatusMessage("The feedback session or questions may have changed " + "while you were submitting. Please check your responses " + "to make sure they are saved correctly.", StatusMessageColor.WARNING));
            isError = true;
            log.warning("Question not found in Feedback Session [" + feedbackSessionName + "] " + "of Course ID [" + courseId + "]." + "(deleted or invalid id passed?) id: " + questionId + " index: " + questionIndx);
            continue;
        }
        checkSessionQuestionAccessPermission(instructor, questionAttributes);
    }
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 74 with InstructorAttributes

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

the class InstructorFeedbackAbstractAction method loadCourseInstructorMap.

/**
 * Gets a Map with courseId as key, and InstructorAttributes as value.
 */
protected Map<String, InstructorAttributes> loadCourseInstructorMap(boolean omitArchived) {
    HashMap<String, InstructorAttributes> courseInstructorMap = new HashMap<>();
    List<InstructorAttributes> instructors = logic.getInstructorsForGoogleId(account.googleId, omitArchived);
    for (InstructorAttributes instructor : instructors) {
        courseInstructorMap.put(instructor.courseId, instructor);
    }
    return courseInstructorMap;
}
Also used : HashMap(java.util.HashMap) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 75 with InstructorAttributes

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

Aggregations

InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)325 Test (org.testng.annotations.Test)127 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)84 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)77 ArrayList (java.util.ArrayList)58 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)47 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)46 RedirectResult (teammates.ui.controller.RedirectResult)46 StatusMessage (teammates.common.util.StatusMessage)34 ShowPageResult (teammates.ui.controller.ShowPageResult)31 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)30 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)29 HashMap (java.util.HashMap)25 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)24 InvalidParametersException (teammates.common.exception.InvalidParametersException)24 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)20 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)18 EmailWrapper (teammates.common.util.EmailWrapper)15 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)14 DataBundle (teammates.common.datatransfer.DataBundle)13