javax.validation.constraints.Past Java Examples

The following examples show how to use javax.validation.constraints.Past. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultModelPlugin.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
private String resolveDate(Field field) {
	Future future = field.getAnnotation(Future.class);
	if (future != null) {
		return "必须为未来的时间";
	}
	FutureOrPresent futureOrPresent = field.getAnnotation(FutureOrPresent.class);
	if (futureOrPresent != null) {
		return "必须为未来或现在的时间";
	}
	Past past = field.getAnnotation(Past.class);
	if (past != null) {
		return "必须为过去的时间";
	}
	PastOrPresent pastOrPresent = field.getAnnotation(PastOrPresent.class);
	if (pastOrPresent != null) {
		return "必须为过去或现在的时间";
	}
	return null;
}
 
Example #2
Source File: BeanValidationImpl.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected HibernateValidatorConfiguration getValidatorFactoryConfiguration(Locale locale) {
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class)
            .configure()
            .clockProvider(new CubaValidationTimeProvider(timeSource))
            .traversableResolver(new CubaValidationTraversableResolver(metadata, entityStates))
            .messageInterpolator(new CubaValidationMessagesInterpolator(messages, locale));

    ConstraintMapping constraintMapping = configuration.createConstraintMapping();

    //Hibernate validators doesn't support java.sql.Date.
    //Replace standard validators for java.util.Date with support java.sql.Date
    registerPastValidators(constraintMapping.constraintDefinition(Past.class));
    registerPastOrPresentValidators(constraintMapping.constraintDefinition(PastOrPresent.class));
    registerFutureValidators(constraintMapping.constraintDefinition(Future.class));
    registerFutureOrPresentValidators(constraintMapping.constraintDefinition(FutureOrPresent.class));

    configuration.addMapping(constraintMapping);

    return configuration;
}
 
Example #3
Source File: BeanValidationImpl.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void registerPastValidators(ConstraintDefinitionContext<Past> context) {
    context.includeExistingValidators(false)
            .validatedBy(PastValidatorForCalendar.class)
            .validatedBy(CubaPastValidatorForDate.class)
            // Java 8 date/time API validators
            .validatedBy(PastValidatorForHijrahDate.class)
            .validatedBy(PastValidatorForInstant.class)
            .validatedBy(PastValidatorForJapaneseDate.class)
            .validatedBy(PastValidatorForLocalDate.class)
            .validatedBy(PastValidatorForLocalDateTime.class)
            .validatedBy(PastValidatorForLocalTime.class)
            .validatedBy(PastValidatorForMinguoDate.class)
            .validatedBy(PastValidatorForMonthDay.class)
            .validatedBy(PastValidatorForOffsetDateTime.class)
            .validatedBy(PastValidatorForOffsetTime.class)
            .validatedBy(PastValidatorForThaiBuddhistDate.class)
            .validatedBy(PastValidatorForYear.class)
            .validatedBy(PastValidatorForYearMonth.class)
            .validatedBy(PastValidatorForZonedDateTime.class);
}
 
Example #4
Source File: ValidationUtils.java    From para with Apache License 2.0 6 votes vote down vote up
private static boolean isValidSimpleConstraint(String cName, String field, Object actual, LinkedList<String> err) {
	if ("required".equals(cName) && !required().isValid(actual)) {
		err.add(Utils.formatMessage("{0} is required.", field));
		return false;
	} else if (matches(AssertFalse.class, cName) && !falsy().isValid(actual)) {
		err.add(Utils.formatMessage("{0} must be false.", field));
		return false;
	} else if (matches(AssertTrue.class, cName) && !truthy().isValid(actual)) {
		err.add(Utils.formatMessage("{0} must be true.", field));
		return false;
	} else if (matches(Future.class, cName) && !future().isValid(actual)) {
		err.add(Utils.formatMessage("{0} must be in the future.", field));
		return false;
	} else if (matches(Past.class, cName) && !past().isValid(actual)) {
		err.add(Utils.formatMessage("{0} must be in the past.", field));
		return false;
	} else if (matches(URL.class, cName) && !url().isValid(actual)) {
		err.add(Utils.formatMessage("{0} is not a valid URL.", field));
		return false;
	} else if (matches(Email.class, cName) && !email().isValid(actual)) {
		err.add(Utils.formatMessage("{0} is not a valid email.", field));
		return false;
	}
	return true;
}
 
Example #5
Source File: User.java    From crudui with Apache License 2.0 5 votes vote down vote up
public User(@NotNull String name, @Past LocalDate birthDate, @NotNull int phoneNumber, @NotNull @Email String email,@NotNull BigDecimal salary,
            @NotNull @Size(min = 6, max = 100) String password, Boolean active, Group mainGroup, Set<Group> groups, MaritalStatus maritalStatus) {
    this.name = name;
    this.birthDate = birthDate;
    this.phoneNumber = phoneNumber;
    this.email = email;
    this.salary = salary;
    this.password = password;
    this.active = active;
    this.mainGroup = mainGroup;
    this.groups = groups;
    this.maritalStatus = maritalStatus;
}
 
Example #6
Source File: User.java    From picocli with Apache License 2.0 4 votes vote down vote up
public Optional<@Past LocalDate> getDateOfBirth() {
    return Optional.ofNullable(dateOfBirth);
}
 
Example #7
Source File: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void appendPastValidator(SourceWriter w, JField field) {
	Past pastAnnotation = field.getAnnotation(Past.class);
	if (pastAnnotation != null) {
		w.println(", new PastValidator(\"%s\")", pastAnnotation.message());
	}
}
 
Example #8
Source File: PastYearQuarterValidator.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Past constraintAnnotation) {
}
 
Example #9
Source File: PastYearWeekValidator.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Past constraintAnnotation) {
}
 
Example #10
Source File: User.java    From tutorials with MIT License 4 votes vote down vote up
public Optional<@Past LocalDate> getDateOfBirth() {
    return Optional.ofNullable(dateOfBirth);
}