Search in sources :

Example 6 with FieldValidator

use of teammates.common.util.FieldValidator in project teammates by TEAMMATES.

the class FeedbackResponseCommentAttributes method getInvalidityInfo.

@Override
public List<String> getInvalidityInfo() {
    FieldValidator validator = new FieldValidator();
    List<String> errors = new ArrayList<>();
    addNonEmptyError(validator.getInvalidityInfoForCourseId(courseId), errors);
    addNonEmptyError(validator.getInvalidityInfoForFeedbackSessionName(feedbackSessionName), errors);
    addNonEmptyError(validator.getInvalidityInfoForEmail(giverEmail), errors);
    return errors;
}
Also used : FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList)

Example 7 with FieldValidator

use of teammates.common.util.FieldValidator in project teammates by TEAMMATES.

the class InstructorAttributes method getInvalidityInfo.

@Override
public List<String> getInvalidityInfo() {
    FieldValidator validator = new FieldValidator();
    List<String> errors = new ArrayList<>();
    if (googleId != null) {
        addNonEmptyError(validator.getInvalidityInfoForGoogleId(googleId), errors);
    }
    addNonEmptyError(validator.getInvalidityInfoForCourseId(courseId), errors);
    addNonEmptyError(validator.getInvalidityInfoForPersonName(name), errors);
    addNonEmptyError(validator.getInvalidityInfoForEmail(email), errors);
    addNonEmptyError(validator.getInvalidityInfoForPersonName(displayedName), errors);
    addNonEmptyError(validator.getInvalidityInfoForRole(role), errors);
    return errors;
}
Also used : FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList)

Example 8 with FieldValidator

use of teammates.common.util.FieldValidator in project teammates by TEAMMATES.

the class InstructorsLogic method getInvalidityInfoForNewInstructorData.

public List<String> getInvalidityInfoForNewInstructorData(String name, String institute, String email) {
    FieldValidator validator = new FieldValidator();
    List<String> errors = new ArrayList<>();
    String error;
    error = validator.getInvalidityInfoForPersonName(name);
    if (!error.isEmpty()) {
        errors.add(error);
    }
    error = validator.getInvalidityInfoForEmail(email);
    if (!error.isEmpty()) {
        errors.add(error);
    }
    error = validator.getInvalidityInfoForInstituteName(institute);
    if (!error.isEmpty()) {
        errors.add(error);
    }
    // No validation for isInstructor and createdAt fields.
    return errors;
}
Also used : FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList)

Example 9 with FieldValidator

use of teammates.common.util.FieldValidator in project teammates by TEAMMATES.

the class StudentsLogic method updateStudentCascade.

public void updateStudentCascade(String originalEmail, StudentAttributes student, boolean hasDocument) throws InvalidParametersException, EntityDoesNotExistException {
    StudentAttributes originalStudent = getStudentForEmail(student.course, originalEmail);
    updateStudentCascadeWithSubmissionAdjustmentScheduled(originalEmail, student, hasDocument);
    /* finalEmail is the string to be used to represent a student's email.
         * This is because:
         *  - originalEmail cannot be used when student's email is being updated with a new valid email
         *  - student.email cannot be used always because it is null when non-email attributes
         *    of a student are being updated or when the new email to be updated is invalid
         */
    FieldValidator validator = new FieldValidator();
    // Untested case: The deletion is not persisted immediately (i.e. persistence delay)
    // Reason: Difficult to reproduce a persistence delay during testing
    String finalEmail = student.email == null || !validator.getInvalidityInfoForEmail(student.email).isEmpty() ? originalEmail : student.email;
    // adjust submissions if moving to a different team
    if (isTeamChanged(originalStudent.team, student.team)) {
        frLogic.updateFeedbackResponsesForChangingTeam(student.course, finalEmail, originalStudent.team, student.team);
    }
    if (isSectionChanged(originalStudent.section, student.section)) {
        frLogic.updateFeedbackResponsesForChangingSection(student.course, finalEmail, originalStudent.section, student.section);
    }
// TODO: check to delete comments for this section/team if the section/team is no longer existent in the course
}
Also used : FieldValidator(teammates.common.util.FieldValidator) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 10 with FieldValidator

use of teammates.common.util.FieldValidator in project teammates by TEAMMATES.

the class InstructorCourseEditPageUiTest method testAddInstructorAction.

private void testAddInstructorAction() throws Exception {
    ______TS("success: add an instructor with privileges");
    courseEditPage.clickShowNewInstructorFormButton();
    courseEditPage.fillNewInstructorName("Teammates Instructor");
    courseEditPage.fillNewInstructorEmail("InsCrsEdit.instructor@gmail.tmt");
    int newInstructorIndex = 8;
    courseEditPage.selectRoleForInstructor(newInstructorIndex, "Custom");
    courseEditPage.clickCourseLevelPrivilegesLink(newInstructorIndex, InstructorCourseEditPage.COURSE_MODIFY_COURSE);
    courseEditPage.clickCourseLevelPrivilegesLink(newInstructorIndex, InstructorCourseEditPage.COURSE_MODIFY_STUDENTS);
    courseEditPage.clickAddSectionLevelPrivilegesLink(newInstructorIndex);
    courseEditPage.clickSectionSelectionCheckBox(newInstructorIndex, 0, 1);
    courseEditPage.clickSectionLevelPrivilegeLink(newInstructorIndex, 0, InstructorCourseEditPage.SECTION_VIEW_STUDENTS);
    courseEditPage.clickSectionLevelPrivilegeLink(newInstructorIndex, 0, InstructorCourseEditPage.SECTION_VIEW_RESPONSES_IN_SESSION);
    courseEditPage.clickAddInstructorButton();
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_ADDED, "Teammates Instructor", "InsCrsEdit.instructor@gmail.tmt"));
    AppUrl courseDetailsLink = createUrl(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE).withCourseId(courseId).withUserId(testData.instructors.get("InsCrsEdit.test").googleId);
    InstructorCourseDetailsPage courseDetailsPage = AppPage.getNewPageInstance(browser, courseDetailsLink, InstructorCourseDetailsPage.class);
    courseDetailsPage.verifyHtmlPart(By.id("instructors"), "/instructorCourseDetailsAddInstructor.html");
    courseEditPage = getCourseEditPage();
    courseEditPage.clickEditInstructorLink(3);
    courseEditPage.verifyHtmlMainContent("/instructorCourseEditAddInstructor.html");
    ______TS("failure: add an existing instructor");
    courseEditPage.addNewInstructor("Teammates Instructor", "InsCrsEdit.instructor@gmail.tmt");
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.COURSE_INSTRUCTOR_EXISTS);
    ______TS("failure: add an instructor with an invalid parameter");
    String invalidEmail = "InsCrsEdit.email.tmt";
    courseEditPage.addNewInstructor("Teammates Instructor", invalidEmail);
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(new FieldValidator().getInvalidityInfoForEmail(invalidEmail));
    String invalidName = "";
    courseEditPage.addNewInstructor(invalidName, "teammates@email.tmt");
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(new FieldValidator().getInvalidityInfoForPersonName(invalidName));
}
Also used : AppUrl(teammates.common.util.AppUrl) InstructorCourseDetailsPage(teammates.test.pageobjects.InstructorCourseDetailsPage) FieldValidator(teammates.common.util.FieldValidator)

Aggregations

FieldValidator (teammates.common.util.FieldValidator)17 ArrayList (java.util.ArrayList)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 Test (org.testng.annotations.Test)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 NullPostParameterException (teammates.common.exception.NullPostParameterException)1 AppUrl (teammates.common.util.AppUrl)1 StatusMessage (teammates.common.util.StatusMessage)1 InstructorCourseDetailsPage (teammates.test.pageobjects.InstructorCourseDetailsPage)1 InstructorCourseInstructorEditSaveAction (teammates.ui.controller.InstructorCourseInstructorEditSaveAction)1 RedirectResult (teammates.ui.controller.RedirectResult)1