Search in sources :

Example 96 with InstructorAttributes

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

the class InstructorCourseEnrollSaveAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String studentsInfo = getRequestParamValue(Const.ParamsNames.STUDENTS_ENROLLMENT_INFO);
    String sanitizedStudentsInfo = SanitizationHelper.sanitizeForHtml(studentsInfo);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENTS_ENROLLMENT_INFO, studentsInfo);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    /* Process enrollment list and setup data for page result */
    try {
        List<StudentAttributes>[] students = enrollAndProcessResultForDisplay(studentsInfo, courseId);
        boolean hasSection = hasSections(students);
        InstructorCourseEnrollResultPageData pageData = new InstructorCourseEnrollResultPageData(account, sessionToken, courseId, students, hasSection, studentsInfo);
        statusToAdmin = "Students Enrolled in Course <span class=\"bold\">[" + courseId + "]:</span><br>" + sanitizedStudentsInfo.replace("\n", "<br>");
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL_RESULT, pageData);
    } catch (EnrollException | InvalidParametersException e) {
        setStatusForException(e);
        statusToAdmin += "<br>Enrollment string entered by user:<br>" + sanitizedStudentsInfo.replace("\n", "<br>");
        InstructorCourseEnrollPageData pageData = new InstructorCourseEnrollPageData(account, sessionToken, courseId, studentsInfo);
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageData);
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e);
        statusToUser.add(new StatusMessage("The enrollment failed, possibly because some students were re-enrolled before " + "the previous enrollment action was still being processed by TEAMMATES database " + "servers. Please try again after about 10 minutes. If the problem persists, " + "please contact TEAMMATES support", StatusMessageColor.DANGER));
        InstructorCourseEnrollPageData pageData = new InstructorCourseEnrollPageData(account, sessionToken, courseId, studentsInfo);
        log.severe("Entity already exists exception occurred when updating student: " + e.getMessage());
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_ENROLL, pageData);
    }
}
Also used : EnrollException(teammates.common.exception.EnrollException) InstructorCourseEnrollResultPageData(teammates.ui.pagedata.InstructorCourseEnrollResultPageData) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InstructorCourseEnrollPageData(teammates.ui.pagedata.InstructorCourseEnrollPageData) ArrayList(java.util.ArrayList) List(java.util.List) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 97 with InstructorAttributes

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

the class InstructorCourseInstructorAddAction method extractCompleteInstructor.

/**
 * Creates a new instructor with all information filled in, using request parameters.
 * This includes basic information as well as custom privileges (if applicable).
 *
 * @param courseId        Id of the course the instructor is being added to.
 * @param instructorName  Name of the instructor.
 * @param instructorEmail Email of the instructor.
 * @return An instructor with all relevant info filled in.
 */
private InstructorAttributes extractCompleteInstructor(String courseId, String instructorName, String instructorEmail) {
    String instructorRole = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ROLE_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_ROLE_NAME, instructorRole);
    boolean isDisplayedToStudents = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_IS_DISPLAYED_TO_STUDENT) != null;
    String displayedName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME);
    if (displayedName == null || displayedName.isEmpty()) {
        displayedName = InstructorAttributes.DEFAULT_DISPLAY_NAME;
    }
    instructorRole = SanitizationHelper.sanitizeName(instructorRole);
    displayedName = SanitizationHelper.sanitizeName(displayedName);
    InstructorAttributes instructorToAdd = createInstructorWithBasicAttributes(courseId, instructorName, instructorEmail, instructorRole, isDisplayedToStudents, displayedName);
    if (instructorRole.equals(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_CUSTOM)) {
        updateInstructorCourseLevelPrivileges(instructorToAdd);
    }
    updateInstructorWithSectionLevelPrivileges(courseId, instructorToAdd);
    instructorToAdd.privileges.validatePrivileges();
    return instructorToAdd;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 98 with InstructorAttributes

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

the class InstructorCourseInstructorAddAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String instructorName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_NAME, instructorName);
    String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
    InstructorAttributes instructorToAdd = extractCompleteInstructor(courseId, instructorName, instructorEmail);
    /* Process adding the instructor and setup status to be shown to user and admin */
    try {
        logic.createInstructor(instructorToAdd);
        taskQueuer.scheduleCourseRegistrationInviteToInstructor(loggedInUser.googleId, instructorEmail, courseId);
        statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_ADDED, instructorName, instructorEmail), StatusMessageColor.SUCCESS));
        statusToAdmin = "New instructor (<span class=\"bold\"> " + instructorEmail + "</span>)" + " for Course <span class=\"bold\">[" + courseId + "]</span> created.<br>";
    } catch (EntityAlreadyExistsException e) {
        setStatusForException(e, Const.StatusMessages.COURSE_INSTRUCTOR_EXISTS);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
    }
    RedirectResult redirectResult = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
    redirectResult.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    return redirectResult;
}
Also used : EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 99 with InstructorAttributes

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

the class InstructorCourseInstructorDeleteAction method execute.

@Override
protected ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
    /* Process deleting an instructor and setup status to be shown to user and admin */
    if (hasAlternativeInstructor(courseId, instructorEmail)) {
        logic.deleteInstructor(courseId, instructorEmail);
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Instructor <span class=\"bold\"> " + instructorEmail + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> deleted.<br>";
    } else {
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_INSTRUCTOR_DELETE_NOT_ALLOWED, StatusMessageColor.DANGER));
        statusToAdmin = "Instructor <span class=\"bold\"> " + instructorEmail + "</span>" + " in Course <span class=\"bold\">[" + courseId + "]</span> could not be deleted " + "as there is only one instructor left to be able to modify instructors.<br>";
    }
    /* Create redirection. It will redirect back to 'Courses' page if the instructor deletes himself */
    RedirectResult result = null;
    if (logic.isInstructorOfCourse(account.googleId, courseId)) {
        result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
        result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
    } else {
        result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE);
    }
    return result;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 100 with InstructorAttributes

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

the class Logic method createInstructorAccount.

/**
 * Creates an instructor and an new account if the instructor doesn't not have account yet.<br>
 * Used as a shorthand when the account entity is not important and is
 * only needed for completeness<br>
 * <b>Note: Now used for the purpose of testing only.</b><br>
 * Preconditions: <br>
 * * All parameters are non-null.
 */
@Deprecated
public void createInstructorAccount(String googleId, String courseId, String name, String email, Boolean isArchived, String roleParam, boolean isDisplayedToStudents, String displayedNameParam, String privileges, String institute) throws EntityAlreadyExistsException, InvalidParametersException {
    Assumption.assertNotNull(googleId);
    Assumption.assertNotNull(courseId);
    Assumption.assertNotNull(name);
    Assumption.assertNotNull(email);
    Assumption.assertNotNull(institute);
    if (accountsLogic.getAccount(googleId) == null) {
        AccountAttributes account = AccountAttributes.builder().withGoogleId(googleId).withName(name).withEmail(email).withInstitute(institute).withIsInstructor(true).withDefaultStudentProfileAttributes(googleId).build();
        accountsLogic.createAccount(account);
    }
    // In case when roleParam is null, default values used both for role and for privileges.
    // If privileges is null and roleParam is not null, for privileges will be created value based on roleParam
    InstructorAttributes instructor = InstructorAttributes.builder(googleId, courseId, name, email).withRole(roleParam).withDisplayedName(displayedNameParam).withPrivileges(privileges).withIsDisplayedToStudents(isDisplayedToStudents).withIsArchived(isArchived).build();
    instructorsLogic.createInstructor(instructor);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

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