use of javax.validation.constraints.Size in project hibernate-orm by hibernate.
the class TypeSafeActivator method applySize.
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if (Size.class.equals(descriptor.getAnnotation().annotationType()) && String.class.equals(propertyDescriptor.getElementClass())) {
@SuppressWarnings("unchecked") ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
int max = sizeConstraint.getAnnotation().max();
@SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator();
if (itor.hasNext()) {
final Selectable selectable = itor.next();
Column col = (Column) selectable;
if (max < Integer.MAX_VALUE) {
col.setLength(max);
}
}
}
}
use of javax.validation.constraints.Size in project candlepin by candlepin.
the class CandlepinSwaggerModelConverter method applyBeanValidatorAnnotations.
protected void applyBeanValidatorAnnotations(Property property, Annotation[] annotations) {
Map<String, Annotation> annos = new HashMap<>();
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 Double(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 Double(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 Double(size.min()));
ap.setMaximum(new Double(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 Double(min.value()));
}
}
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 Double(max.value()));
}
}
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());
}
}
}
use of javax.validation.constraints.Size in project irida by phac-nml.
the class SequenceFilePair method getForwardSequenceFile.
/**
* Gets the forward {@link SequenceFile} from the pair.
*
* @return The forward {@link SequenceFile} from the pair.
*/
public SequenceFile getForwardSequenceFile() {
IridaSequenceFile[] pair = getFiles().toArray(new IridaSequenceFile[getFiles().size()]);
String[] filenames = { pair[0].getFile().getFileName().toString(), pair[1].getFile().getFileName().toString() };
int index = StringUtils.indexOfDifference(filenames[0], filenames[1]);
if (Stream.of(forwardMatches).anyMatch(x -> String.valueOf(filenames[0].charAt(index)).equals(x))) {
return (SequenceFile) pair[0];
} else if (Stream.of(forwardMatches).anyMatch(x -> String.valueOf(filenames[1].charAt(index)).equals(x))) {
return (SequenceFile) pair[1];
} else {
throw new NoSuchElementException();
}
}
use of javax.validation.constraints.Size in project irida by phac-nml.
the class SequenceFilePair method getReverseSequenceFile.
/**
* Gets the reverse {@link SequenceFile} from the pair.
*
* @return The reverse {@link SequenceFile} from the pair.
*/
public SequenceFile getReverseSequenceFile() {
IridaSequenceFile[] pair = getFiles().toArray(new IridaSequenceFile[getFiles().size()]);
String[] filenames = { pair[0].getFile().getFileName().toString(), pair[1].getFile().getFileName().toString() };
int index = StringUtils.indexOfDifference(filenames[0], filenames[1]);
if (Stream.of(reverseMatches).anyMatch(x -> String.valueOf(filenames[0].charAt(index)).equals(x))) {
return (SequenceFile) pair[0];
} else if (Stream.of(reverseMatches).anyMatch(x -> String.valueOf(filenames[1].charAt(index)).equals(x))) {
return (SequenceFile) pair[1];
} else {
throw new NoSuchElementException();
}
}
use of javax.validation.constraints.Size 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}");
}
Aggregations