use of org.hibernate.validator.constraints.Length in project swagger-core by swagger-api.
the class BeanValidator method resolveProperty.
@Override
public Property resolveProperty(Type type, ModelConverterContext context, Annotation[] annotations, Iterator<ModelConverter> chain) {
Map<String, Annotation> annos = new HashMap<String, Annotation>();
if (annotations != null) {
for (Annotation anno : annotations) {
annos.put(anno.annotationType().getName(), anno);
}
}
Property property = null;
if (chain.hasNext()) {
property = chain.next().resolveProperty(type, context, annotations, chain);
}
if (property != null) {
if (annos.containsKey("org.hibernate.validator.constraints.NotEmpty")) {
property.setRequired(true);
if (property instanceof StringProperty) {
((StringProperty) property).minLength(1);
} else if (property instanceof ArrayProperty) {
((ArrayProperty) property).setMinItems(1);
}
}
if (annos.containsKey("org.hibernate.validator.constraints.NotBlank")) {
property.setRequired(true);
if (property instanceof StringProperty) {
((StringProperty) property).minLength(1);
}
}
if (annos.containsKey("org.hibernate.validator.constraints.Range")) {
if (property instanceof AbstractNumericProperty) {
Range range = (Range) annos.get("org.hibernate.validator.constraints.Range");
AbstractNumericProperty ap = (AbstractNumericProperty) property;
ap.setMinimum(new BigDecimal(range.min()));
ap.setMaximum(new BigDecimal(range.max()));
}
}
if (annos.containsKey("org.hibernate.validator.constraints.Length")) {
if (property instanceof StringProperty) {
Length length = (Length) annos.get("org.hibernate.validator.constraints.Length");
StringProperty sp = (StringProperty) property;
sp.minLength(new Integer(length.min()));
sp.maxLength(new Integer(length.max()));
}
}
if (annos.containsKey("org.hibernate.validator.constraints.Email")) {
if (property instanceof StringProperty) {
EmailProperty sp = new EmailProperty((StringProperty) property);
property = sp;
}
}
return property;
}
return super.resolveProperty(type, context, annotations, chain);
}
use of org.hibernate.validator.constraints.Length in project cuba by cuba-platform.
the class WebAbstractTextField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
super.setDatasource(datasource, property);
if (metaProperty != null) {
Map<String, Object> annotations = metaProperty.getAnnotations();
if (this instanceof CaseConversionSupported && ((CaseConversionSupported) this).getCaseConversion() == CaseConversion.NONE) {
String caseConversionAnnotation = com.haulmont.cuba.core.entity.annotation.CaseConversion.class.getName();
// noinspection unchecked
Map<String, Object> caseConversion = (Map<String, Object>) annotations.get(caseConversionAnnotation);
if (MapUtils.isNotEmpty(caseConversion)) {
ConversionType conversionType = (ConversionType) caseConversion.get("type");
CaseConversion conversion = CaseConversion.valueOf(conversionType.name());
((CaseConversionSupported) this).setCaseConversion(conversion);
}
}
if (this instanceof TextInputField.MaxLengthLimited) {
MaxLengthLimited maxLengthLimited = (MaxLengthLimited) this;
Integer maxLength = (Integer) annotations.get("length");
if (maxLength != null) {
maxLengthLimited.setMaxLength(maxLength);
}
Integer sizeMax = (Integer) annotations.get(Size.class.getName() + "_max");
if (sizeMax != null) {
maxLengthLimited.setMaxLength(sizeMax);
}
Integer lengthMax = (Integer) annotations.get(Length.class.getName() + "_max");
if (lengthMax != null) {
maxLengthLimited.setMaxLength(lengthMax);
}
}
}
}
use of org.hibernate.validator.constraints.Length in project cuba by cuba-platform.
the class MetaModelLoader method loadBeanValidationAnnotations.
protected void loadBeanValidationAnnotations(MetaProperty metaProperty, AnnotatedElement annotatedElement) {
NotNull notNull = annotatedElement.getAnnotation(NotNull.class);
if (notNull != null) {
if (isDefinedForDefaultValidationGroup(notNull)) {
metaProperty.getAnnotations().put(NotNull.class.getName() + VALIDATION_NOTNULL_MESSAGE, notNull.message());
}
if (isDefinedForValidationGroup(notNull, UiComponentChecks.class, true)) {
metaProperty.getAnnotations().put(NotNull.class.getName() + VALIDATION_NOTNULL_MESSAGE, notNull.message());
metaProperty.getAnnotations().put(NotNull.class.getName() + VALIDATION_NOTNULL_UI_COMPONENT, true);
}
}
Size size = annotatedElement.getAnnotation(Size.class);
if (size != null && isDefinedForDefaultValidationGroup(size)) {
metaProperty.getAnnotations().put(Size.class.getName() + VALIDATION_MIN, size.min());
metaProperty.getAnnotations().put(Size.class.getName() + VALIDATION_MAX, size.max());
}
Length length = annotatedElement.getAnnotation(Length.class);
if (length != null && isDefinedForDefaultValidationGroup(length)) {
metaProperty.getAnnotations().put(Length.class.getName() + VALIDATION_MIN, length.min());
metaProperty.getAnnotations().put(Length.class.getName() + VALIDATION_MAX, length.max());
}
Min min = annotatedElement.getAnnotation(Min.class);
if (min != null && isDefinedForDefaultValidationGroup(min)) {
metaProperty.getAnnotations().put(Min.class.getName(), min.value());
}
Max max = annotatedElement.getAnnotation(Max.class);
if (max != null && isDefinedForDefaultValidationGroup(max)) {
metaProperty.getAnnotations().put(Max.class.getName(), max.value());
}
DecimalMin decimalMin = annotatedElement.getAnnotation(DecimalMin.class);
if (decimalMin != null && isDefinedForDefaultValidationGroup(decimalMin)) {
metaProperty.getAnnotations().put(DecimalMin.class.getName(), decimalMin.value());
}
DecimalMax decimalMax = annotatedElement.getAnnotation(DecimalMax.class);
if (decimalMax != null && isDefinedForDefaultValidationGroup(decimalMax)) {
metaProperty.getAnnotations().put(DecimalMax.class.getName(), decimalMax.value());
}
Past past = annotatedElement.getAnnotation(Past.class);
if (past != null && isDefinedForDefaultValidationGroup(past)) {
metaProperty.getAnnotations().put(Past.class.getName(), true);
}
Future future = annotatedElement.getAnnotation(Future.class);
if (future != null && isDefinedForDefaultValidationGroup(future)) {
metaProperty.getAnnotations().put(Future.class.getName(), true);
}
PastOrPresent pastOrPresent = annotatedElement.getAnnotation(PastOrPresent.class);
if (pastOrPresent != null && isDefinedForDefaultValidationGroup(pastOrPresent)) {
metaProperty.getAnnotations().put(PastOrPresent.class.getName(), true);
}
FutureOrPresent futureOrPresent = annotatedElement.getAnnotation(FutureOrPresent.class);
if (futureOrPresent != null && isDefinedForDefaultValidationGroup(futureOrPresent)) {
metaProperty.getAnnotations().put(FutureOrPresent.class.getName(), true);
}
}
use of org.hibernate.validator.constraints.Length in project cuba by cuba-platform.
the class DataAwareComponentsTools method setupMaxLength.
/**
* Sets max length for textual UI component using Entity metadata.
*
* @param component UI component
* @param valueSource value source
*/
public void setupMaxLength(TextInputField.MaxLengthLimited component, EntityValueSource valueSource) {
MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty();
Map<String, Object> annotations = metaProperty.getAnnotations();
Integer maxLength = (Integer) annotations.get("length");
if (maxLength != null) {
component.setMaxLength(maxLength);
}
Integer sizeMax = (Integer) annotations.get(Size.class.getName() + "_max");
if (sizeMax != null) {
component.setMaxLength(sizeMax);
}
Integer lengthMax = (Integer) annotations.get(Length.class.getName() + "_max");
if (lengthMax != null) {
component.setMaxLength(lengthMax);
}
}
Aggregations