javax.validation.constraints.Future Java Examples

The following examples show how to use javax.validation.constraints.Future. 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 registerFutureValidators(ConstraintDefinitionContext<Future> context) {
    context.includeExistingValidators(false)
            .validatedBy(FutureValidatorForCalendar.class)
            .validatedBy(CubaFutureValidatorForDate.class)
            // Java 8 date/time API validators
            .validatedBy(FutureValidatorForHijrahDate.class)
            .validatedBy(FutureValidatorForInstant.class)
            .validatedBy(FutureValidatorForJapaneseDate.class)
            .validatedBy(FutureValidatorForLocalDate.class)
            .validatedBy(FutureValidatorForLocalDateTime.class)
            .validatedBy(FutureValidatorForLocalTime.class)
            .validatedBy(FutureValidatorForMinguoDate.class)
            .validatedBy(FutureValidatorForMonthDay.class)
            .validatedBy(FutureValidatorForOffsetDateTime.class)
            .validatedBy(FutureValidatorForOffsetTime.class)
            .validatedBy(FutureValidatorForThaiBuddhistDate.class)
            .validatedBy(FutureValidatorForYear.class)
            .validatedBy(FutureValidatorForYearMonth.class)
            .validatedBy(FutureValidatorForZonedDateTime.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: ModelCreator.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void appendFutureValidator(SourceWriter w, JField field) {
	Future futureAnnotation = field.getAnnotation(Future.class);
	if (futureAnnotation != null) {
		w.println(", new FutureValidator(\"%s\")", futureAnnotation.message());
	}
}
 
Example #6
Source File: FutureYearQuarterValidator.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Future constraintAnnotation) {
}
 
Example #7
Source File: FutureYearWeekValidator.java    From hibernate-demos with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(Future constraintAnnotation) {
}
 
Example #8
Source File: RentalStation.java    From wisdom with Apache License 2.0 4 votes vote down vote up
public void rentCar(
        @NotNull String customer,
        @NotNull @Future Date startDate,
        @Min(1) int durationInDays) {
    //...
}
 
Example #9
Source File: ReservationManagement.java    From tutorials with MIT License 2 votes vote down vote up
public void createReservation(@NotNull @Future LocalDate begin, @Min(1) int duration, @NotNull Customer customer) {

        // ...
    }