use of javax.validation.constraints.DecimalMin in project AngularBeans by bessemHmidi.
the class BeanValidationProcessor method processBeanValidationParsing.
public void processBeanValidationParsing(Method method) {
String modelName = CommonUtils.obtainFieldNameFromAccessor(method.getName());
Annotation[] scannedAnnotations = method.getAnnotations();
buffer.append("\nif (modelName === '").append(modelName).append("') {");
for (Annotation a : scannedAnnotations) {
if (!validationAnnotations.contains(a.annotationType())) {
continue;
}
String name = (a.annotationType().getName());
switch(name) {
case "javax.validation.constraints.NotNull":
buffer.append("\nentries[e].setAttribute('required', 'true');");
break;
case "org.hibernate.validator.constraints.Email":
buffer.append("\nentries[e].setAttribute('type', 'email');");
break;
case "javax.validation.constraints.Pattern":
String regex = ((Pattern) a).regexp();
buffer.append("\nentries[e].setAttribute('ng-pattern', '").append(regex).append("');");
break;
case "javax.validation.constraints.Size":
buffer.append("\nentries[e].setAttribute('required', 'true');");
Size sizeConstraint = (Size) a;
int maxLength = sizeConstraint.max();
int minLength = sizeConstraint.min();
if (minLength < 0) {
throw new IllegalArgumentException("The min parameter cannot be negative.");
}
if (maxLength < 0) {
throw new IllegalArgumentException("The max parameter cannot be negative.");
}
if (minLength > 0) {
buffer.append("\nentries[e].setAttribute('ng-minlength', '").append(minLength).append("');");
}
if (maxLength < Integer.MAX_VALUE) {
buffer.append("\nentries[e].setAttribute('ng-maxlength', '").append(maxLength).append("');");
}
break;
case "javax.validation.constraints.DecimalMin":
String dMin = ((DecimalMin) a).value();
buffer.append("\nentries[e].setAttribute('min', '").append(dMin).append("');");
break;
case "javax.validation.constraints.DecimalMax":
String dMax = ((DecimalMax) a).value();
buffer.append("\nentries[e].setAttribute('max', '").append(dMax).append("');");
break;
case "javax.validation.constraints.Min":
long min = ((Min) a).value();
buffer.append("\nentries[e].setAttribute('min', '").append(min).append("');");
break;
case "javax.validation.constraints.Max":
long max = ((Max) a).value();
buffer.append("\nentries[e].setAttribute('max', '").append(max).append("');");
break;
default:
break;
}
}
buffer.append("\n}");
}
use of javax.validation.constraints.DecimalMin in project swagger-core by swagger-api.
the class ModelResolver method applyBeanValidatorAnnotations.
protected void applyBeanValidatorAnnotations(Property property, Annotation[] annotations) {
Map<String, Annotation> annos = new HashMap<String, Annotation>();
if (annotations != null) {
for (Annotation anno : annotations) {
annos.put(anno.annotationType().getName(), anno);
}
}
if (annos.containsKey("javax.validation.constraints.NotNull")) {
property.setRequired(true);
}
if (annos.containsKey("javax.validation.constraints.Min")) {
if (property instanceof AbstractNumericProperty) {
Min min = (Min) annos.get("javax.validation.constraints.Min");
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(min.value()));
}
}
if (annos.containsKey("javax.validation.constraints.Max")) {
if (property instanceof AbstractNumericProperty) {
Max max = (Max) annos.get("javax.validation.constraints.Max");
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMaximum(new BigDecimal(max.value()));
}
}
if (annos.containsKey("javax.validation.constraints.Size")) {
Size size = (Size) annos.get("javax.validation.constraints.Size");
if (property instanceof AbstractNumericProperty) {
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(size.min()));
ap.setMaximum(new BigDecimal(size.max()));
} else if (property instanceof StringProperty) {
StringProperty sp = (StringProperty) property;
sp.minLength(new Integer(size.min()));
sp.maxLength(new Integer(size.max()));
} else if (property instanceof ArrayProperty) {
ArrayProperty sp = (ArrayProperty) property;
sp.setMinItems(size.min());
sp.setMaxItems(size.max());
}
}
if (annos.containsKey("javax.validation.constraints.DecimalMin")) {
DecimalMin min = (DecimalMin) annos.get("javax.validation.constraints.DecimalMin");
if (property instanceof AbstractNumericProperty) {
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(min.value()));
ap.setExclusiveMinimum(!min.inclusive());
}
}
if (annos.containsKey("javax.validation.constraints.DecimalMax")) {
DecimalMax max = (DecimalMax) annos.get("javax.validation.constraints.DecimalMax");
if (property instanceof AbstractNumericProperty) {
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMaximum(new BigDecimal(max.value()));
ap.setExclusiveMaximum(!max.inclusive());
}
}
if (annos.containsKey("javax.validation.constraints.Pattern")) {
Pattern pattern = (Pattern) annos.get("javax.validation.constraints.Pattern");
if (property instanceof StringProperty) {
StringProperty ap = (StringProperty) property;
ap.setPattern(pattern.regexp());
}
}
}
Aggregations