@AssertTrue(message="{specificDate.isDateTimeValid.AssertTrue}") private boolean isDateTimeValid() { try { SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); dateformat.setLenient(false); ParsePosition position = new ParsePosition(0); String firstDateTime = this.startDate + " " + this.startTime; String secondDateTime = this.endDate + " " + this.endTime; Date first = dateformat.parse(firstDateTime, position); if (( first == null) || (position.getIndex() != firstDateTime.length())) return false; position = new ParsePosition(0); Date second = dateformat.parse(secondDateTime, position); if (( second == null) || (position.getIndex() != secondDateTime.length())) return false; return first.before(second); } catch (Exception e) { BeanValidation.logger.info(e.getMessage()); return false; } }
@AssertTrue @JsonIgnore public boolean isValidAddress() { return StringUtils.hasText(streetAddress) && StringUtils.hasText(postalCode) && StringUtils.hasText(city); }
@AssertTrue(message="{recurringSchedule.isRepeatOnValid.AssertTrue}") private boolean isRepeatOnValid() { String[] s_values = this.repeatOn.replace("\"", "").replace("[", "").replace("]", "").split(","); String[] weekday = {"1", "2", "3", "4", "5", "6", "7"}; List<String> weekday_list = Arrays.asList(weekday); Set<String> validValues = new HashSet<String>(weekday_list); List<String> value_list = Arrays.asList(s_values); Set<String> value_set = new HashSet<String>(value_list); if ( s_values.length > value_set.size()) { return false; } for (String s: s_values){ if(!validValues.contains(s)) { return false; } } if ( s_values.length > validValues.size()) { return false; } return true; }
@AssertTrue(message="{recurringSchedule.isTimeValid.AssertTrue}") private boolean isTimeValid() { try { SimpleDateFormat parser = new SimpleDateFormat("HH:mm"); parser.setLenient(false); ParsePosition position = new ParsePosition(0); Date start_time = parser.parse(this.startTime, position); if (( start_time == null) || (position.getIndex() != this.startTime.length())) return false; position = new ParsePosition(0); Date end_time = parser.parse(this.endTime, position); if (( end_time == null) || (position.getIndex() != this.endTime.length())) return false; return start_time.before(end_time); } catch (Exception e) { return false; } }
private static MinijaxConstraintDescriptor<AssertTrue> buildAssertTrueValidator(final AssertTrue assertTrue, final Class<?> valueClass) { if (valueClass == boolean.class || valueClass == Boolean.class) { return new MinijaxConstraintDescriptor<>(assertTrue, AssertTrueValidator.INSTANCE); } throw new ValidationException("Unsupported type for @AssertTrue annotation: " + valueClass); }
@Override public Object process(AnnotationInfo ctx, Object value) throws Exception { if (!ctx.isAnnotationPresent(AssertTrue.class)) { return value; } return true; }
@AssertTrue public boolean isPresenceOfHarvestCountsConsistentWithModeratorOverride() { final Object[] harvestCounts = { numberOfAdultMales, numberOfAdultFemales, numberOfYoungMales, numberOfYoungFemales, numberOfNonEdibleAdults, numberOfNonEdibleYoungs }; // When moderator-override flag is true then all harvest count fields must be non-null // and vice versa. return moderatorOverride ? F.allNotNull(harvestCounts) : F.allNull(harvestCounts); }
@AssertTrue(message = "Custom Configuration Key cannot be left blank") public boolean isValidCustom() { if (keyType == ConfigurationKeyType.CUSTOM) { return !Strings.isNullOrEmpty(customConfKey); } else { return true; } }
@AssertTrue(message = "Configuration Key is required") public boolean isValidPredefined() { if (keyType == ConfigurationKeyType.PREDEFINED) { return getPredefinedKey() != null; } else { return true; } }
@AssertTrue(message = "PlugSurfing requires the number of connectors") public boolean isValidNumberOfConnections() { if (plugSurfing) { return numberOfConnectors != null && numberOfConnectors > 0; } else { return true; } }
@AssertTrue(message = "PlugSurfing requires latitude and longitude values") public boolean isLocationEmpty() { if (plugSurfing) { return getLocationLatitude() != null && getLocationLongitude() != null; } else { return true; } }
@AssertTrue(message = "PlugSurfing requires a city") public boolean isValidCity() { if (plugSurfing) { return !Strings.isNullOrEmpty(getAddress().getCity()); } else { return true; } }
@Test public void testRegisteredPostConstructProcessor() { genie.registerPostConstructProcessor(AssertTrue.class, new AssertTrueHandler()); yes(genie.get(FooToPass.class).val); try { genie.get(FooToFail.class); fail("Expect ValidationException here"); } catch (ValidationException e) { // test pass } }
@AssertTrue(message = "PlugSurfing requires a street name") public boolean isValidStreetName() { if (plugSurfing) { return !Strings.isNullOrEmpty(getAddress().getStreet()); } else { return true; } }
@AssertTrue(message = "PlugSurfing requires non-empty phone number") public boolean isValidPhone() { if (plugSurfing) { return !Strings.isNullOrEmpty(getContact().getPhone()); } else { return true; } }
@Override public void validate(AssertTrue assertTrueAnnotation, String name, ValidationContext validationCtx, Errors errors) { Object value = validationCtx.value(name); boolean isFalse = false; if (value != null && value instanceof Boolean) isFalse = Boolean.TRUE.equals(value); if (!isFalse) errors.add(name, assertTrueAnnotation.message(), value); }
@AssertTrue(message = "I am a constructor annotated with a constraint even though it doesn't really make sense") public DifferentValidationAnnotationOptions(String nonAnnotatedConstructorParam, @NotNull(message = "I am a constructor param annotated with a constraint 1") String annotatedConstructorParam1, @NotNull(message = "I am a constructor param annotated with a constraint 2") String annotatedConstructorParam2, String alsoNotAnnotatedConstructorParam) { }
@AssertTrue(message="{HistoryData.isTimeZoneValid.AssertTrue}") private boolean isTimeZoneValid() { Set<String> timezoneset = new HashSet<String>(Arrays.asList(Constants.timezones)); if(timezoneset.contains(this.timeZone)) return true; return false; }
@AssertTrue(message="{PolicyTrigger.ismetricTypeValid.AssertTrue}") private boolean isMetricTypeValid() { for (PolicyTrigger trigger : this.policyTriggers){ if ((trigger.metricType == null) || (!(Arrays.asList(Constants.metrictype).contains(trigger.metricType)))) return false; } return true; }
@AssertTrue(message="{Policy.isMetricTypeValid.AssertTrue}") private boolean isMetricTypeUnique() { Set<String> metric_types = new HashSet<String>(); for (PolicyTrigger trigger : this.policyTriggers){ metric_types.add(trigger.metricType); } if (metric_types.size() != this.policyTriggers.size()) return false; else return true; }
@AssertTrue(message="{PolicyTrigger.isInstanceStepCountUpValid.AssertTrue}") private boolean isInstanceStepCountUpValid() { //debug we support count instead of percent change only currently for (PolicyTrigger trigger : this.policyTriggers){ if (trigger.instanceStepCountUp > (instanceMaxCount -1)) return false; } return true; }
@AssertTrue(message="{PolicyTrigger.isInstanceStepCountDownValid.AssertTrue}") private boolean isInstanceStepCountDownValid() { //debug we support count instead of percent change only currently for (PolicyTrigger trigger : this.policyTriggers){ if (trigger.instanceStepCountDown > instanceMaxCount) return false; } return true; }
@AssertTrue(message="{Policy.isMetricTypeMatched.AssertTrue}") private boolean isMetricTypeSupported() { String [] supported_metrics = Constants.getMetricTypeByAppType(this.appType); BeanValidation.logger.info("supported metrics are: " + Arrays.toString(supported_metrics)); if (supported_metrics != null) { for (PolicyTrigger trigger : this.policyTriggers) { if (!(Arrays.asList(supported_metrics).contains(trigger.metricType))) return false; } } return true; }
@AssertTrue(message="{Policy.isRecurringScheduleTimeValid.AssertTrue}") private boolean isRecurringScheduleTimeValid() { if ((this.schedules != null) && (RecurringScheduleTimeValid(this.schedules.recurringSchedule) == false)) { return false; } return true; }
@AssertTrue(message="{Policy.isSpecificDateTimeValid.AssertTrue}") private boolean isSpecificDateTimeValid() { if ((this.schedules != null) && (SpecificDateTimeValid(this.schedules.specificDate) == false)) { return false; } return true; }
@AssertTrue(message="{specificDate.isInstCountValid.AssertTrue}") private boolean isInstCountValid() { if (this.maxInstCount > 0) { //maxInstCount is set if (this.minInstCount > this.maxInstCount) { return false; } } return true; }
@AssertTrue(message="{recurringSchedule.isInstCountValid.AssertTrue}") private boolean isInstCountValid() { if (this.maxInstCount > 0) { //maxInstCount is set if (this.minInstCount > this.maxInstCount) { return false; } } return true; }
@AssertTrue(message="{Schedule.isTimeZoneValid.AssertTrue}") //debug private boolean isTimeZoneValid() { if ((null != this.timezone) && (this.timezone.trim().length() != 0)) { BeanValidation.logger.debug("In schedules timezone is " + this.timezone);//debug Set<String> timezoneset = new HashSet<String>(Arrays.asList(Constants.timezones)); if(timezoneset.contains(this.timezone)) return true; else return false; } else { BeanValidation.logger.debug("timezone is empty in schedules");//debug return false; //timezone must be specified in Schedule } }
@AssertTrue(message="{Schedule.isScheduleValid.AssertTrue}") //debug private boolean isScheduleValid() { if (((null == this.recurringSchedule) || (this.recurringSchedule.size() == 0) ) && ((null == this.specificDate) || (this.specificDate.size() == 0)) ){ return false; //at least one setting should be exist } return true; }
@AssertTrue(message = "Las claves no coinciden") public boolean isClavesCoinciden() { if (claveNueva != null && confirmacionClave != null) { return claveNueva.equals(confirmacionClave); } return false; }
@AssertTrue(message = "{error.to.sign.file.mandatory}") public boolean isDocumentToSign() { return (documentToSign != null) && (!documentToSign.isEmpty()); }
@AssertTrue(message = "{error.signed.file.mandatory}") public boolean isSignedFile() { return (signedFile != null) && (!signedFile.isEmpty()); }
@AssertTrue(message = "{error.to.sign.files.mandatory}") public boolean isDocumentsToSign() { return Utils.isCollectionNotEmpty(documentsToSign); }
@AssertTrue(message = "{error.certificate.mandatory}") public boolean isCertificateFile() { return (certificateFile != null) && (!certificateFile.isEmpty()); }
@AssertTrue public boolean isDataCorrect() { return type.equals("current") || !date.isEmpty(); }
@AssertTrue(message="Confirm password should match") public boolean isValid() { return this.password.equals(this.cpassword); }
@SuppressWarnings("unchecked") public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) { final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class); if (constraint == null) { return null; } final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType); final Class<?> annotationClass = annotation.annotationType(); if (constraint.validatedBy().length > 0) { return buildDeclaredValidator(annotation, constraint.validatedBy()[0]); } else if (annotationClass == AssertFalse.class) { return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass); } else if (annotationClass == AssertTrue.class) { return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass); } else if (annotationClass == Max.class) { return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass); } else if (annotationClass == Min.class) { return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass); } else if (annotationClass == NotBlank.class) { return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass); } else if (annotationClass == NotEmpty.class) { return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass); } else if (annotationClass == NotNull.class) { return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation); } else if (annotationClass == Pattern.class) { return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass); } else if (annotationClass == Size.class) { return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass); } else { throw new ValidationException("Unrecognized constraint annotation: " + annotation); } }
@AssertTrue public boolean isRegistered() { return isRegistered; }