Search in sources :

Example 1 with FieldValidator

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

the class InstructorFeedbackAbstractAction method validateTimeData.

protected void validateTimeData(FeedbackSessionAttributes attributes) throws InvalidParametersException {
    FieldValidator validator = new FieldValidator();
    // Stop if invalid or fixed offset time zone is detected
    String paramTimeZone = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_TIMEZONE);
    String timeZoneErrorMessage = validator.getInvalidityInfoForTimeZone(paramTimeZone);
    if (!timeZoneErrorMessage.isEmpty()) {
        // Collect other errors before throwing an exception
        List<String> errors = new ArrayList<>(attributes.getInvalidityInfo());
        errors.add(timeZoneErrorMessage);
        throw new InvalidParametersException(errors);
    }
    // The time zone is valid at this point and can be used for future calculations
    ZoneId timeZone = attributes.getTimeZone();
    // Warn if ambiguity of time fields (brought about by DST) is detected
    validateLocalDateTimeUnambiguity(inputStartTimeLocal, attributes.getStartTime(), timeZone, FieldValidator.SESSION_START_TIME_FIELD_NAME);
    validateLocalDateTimeUnambiguity(inputEndTimeLocal, attributes.getEndTime(), timeZone, FieldValidator.SESSION_END_TIME_FIELD_NAME);
    validateLocalDateTimeUnambiguity(inputVisibleTimeLocal, attributes.getSessionVisibleFromTime(), timeZone, FieldValidator.SESSION_VISIBLE_TIME_FIELD_NAME);
    validateLocalDateTimeUnambiguity(inputPublishTimeLocal, attributes.getResultsVisibleFromTime(), timeZone, FieldValidator.RESULTS_VISIBLE_TIME_FIELD_NAME);
}
Also used : ZoneId(java.time.ZoneId) FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList) InvalidParametersException(teammates.common.exception.InvalidParametersException)

Example 2 with FieldValidator

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

the class AdminEmailComposeSendAction method checkAddressReceiverString.

private void checkAddressReceiverString(String addressReceiverString) throws InvalidParametersException {
    FieldValidator validator = new FieldValidator();
    String[] emails = addressReceiverString.split(",");
    for (String email : emails) {
        String error = validator.getInvalidityInfoForEmail(email);
        if (!error.isEmpty()) {
            isError = true;
            statusToUser.add(new StatusMessage(error, StatusMessageColor.DANGER));
            throw new InvalidParametersException("<strong>Email Format Error</strong>");
        }
    }
}
Also used : FieldValidator(teammates.common.util.FieldValidator) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage)

Example 3 with FieldValidator

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

the class StudentAttributes method getInvalidityInfo.

@Override
public List<String> getInvalidityInfo() {
    // id is allowed to be null when the student is not registered
    Assumption.assertNotNull(team);
    Assumption.assertNotNull(comments);
    FieldValidator validator = new FieldValidator();
    List<String> errors = new ArrayList<>();
    if (isRegistered()) {
        addNonEmptyError(validator.getInvalidityInfoForGoogleId(googleId), errors);
    }
    addNonEmptyError(validator.getInvalidityInfoForCourseId(course), errors);
    addNonEmptyError(validator.getInvalidityInfoForEmail(email), errors);
    addNonEmptyError(validator.getInvalidityInfoForTeamName(team), errors);
    addNonEmptyError(validator.getInvalidityInfoForSectionName(section), errors);
    addNonEmptyError(validator.getInvalidityInfoForStudentRoleComments(comments), errors);
    addNonEmptyError(validator.getInvalidityInfoForPersonName(name), errors);
    return errors;
}
Also used : FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList)

Example 4 with FieldValidator

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

the class AdminEmailAttributes method getInvalidityInfo.

@Override
public List<String> getInvalidityInfo() {
    FieldValidator validator = new FieldValidator();
    List<String> errors = new ArrayList<>();
    addNonEmptyError(validator.getInvalidityInfoForEmailContent(content), errors);
    addNonEmptyError(validator.getInvalidityInfoForEmailSubject(subject), errors);
    return errors;
}
Also used : FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList)

Example 5 with FieldValidator

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

the class FeedbackQuestionAttributes method getInvalidityInfo.

@Override
public List<String> getInvalidityInfo() {
    FieldValidator validator = new FieldValidator();
    List<String> errors = new ArrayList<>();
    addNonEmptyError(validator.getInvalidityInfoForFeedbackSessionName(feedbackSessionName), errors);
    addNonEmptyError(validator.getInvalidityInfoForCourseId(courseId), errors);
    // special case when additional text should be added to error text
    String error = validator.getInvalidityInfoForEmail(creatorEmail);
    if (!error.isEmpty()) {
        error = new StringBuffer().append("Invalid creator's email: ").append(error).toString();
    }
    addNonEmptyError(error, errors);
    errors.addAll(validator.getValidityInfoForFeedbackParticipantType(giverType, recipientType));
    errors.addAll(validator.getValidityInfoForFeedbackResponseVisibility(showResponsesTo, showGiverNameTo, showRecipientNameTo));
    return errors;
}
Also used : FieldValidator(teammates.common.util.FieldValidator) ArrayList(java.util.ArrayList)

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