org.hibernate.validator.constraints.Length Java Examples

The following examples show how to use org.hibernate.validator.constraints.Length. 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: DataAwareComponentsTools.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #2
Source File: JsonSchemaFromFieldDescriptorsGeneratorTest.java    From restdocs-raml with MIT License 6 votes vote down vote up
private void givenFieldDescriptorsWithConstraints() {
    Attribute constraintAttributeWithNotNull = Attributes.key("notImportant").value(singletonList(new Constraint(NotNull.class.getName(), emptyMap())));

    HashMap<String, Object> lengthAttributes = new HashMap<>();
    lengthAttributes.put("min", 2);
    lengthAttributes.put("max", 255);
    Attribute constraintAttributeWithLength = Attributes.key("notImportant").value(singletonList(new Constraint(Length.class.getName(), lengthAttributes)));

    fieldDescriptors =  Arrays.asList(
            fieldWithPath("id").description("some").type(STRING).attributes(constraintAttributeWithNotNull),
            fieldWithPath("lineItems[*].name").description("some").type(STRING).type(STRING).attributes(constraintAttributeWithLength),
            fieldWithPath("lineItems[*]._id").description("some").type(STRING).attributes(constraintAttributeWithNotNull),
            fieldWithPath("lineItems[*].quantity.value").description("some").type(NUMBER).attributes(constraintAttributeWithNotNull),
            fieldWithPath("lineItems[*].quantity.unit").description("some").type(STRING),
            fieldWithPath("shippingAddress").description("some").type(OBJECT),
            fieldWithPath("billingAddress").description("some").type(OBJECT).attributes(constraintAttributeWithNotNull),
            fieldWithPath("billingAddress.firstName").description("some").type(STRING).attributes(Attributes
                    .key("notImportant")
                    .value(singletonList(new Constraint(NotEmpty.class.getName(), emptyMap())))),
            fieldWithPath("billingAddress.valid").description("some").type(BOOLEAN),
            fieldWithPath("paymentLineItem.lineItemTaxes").description("some").type(ARRAY)
    );
}
 
Example #3
Source File: FdName.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
/**
 * 读-名称
 *
 * @return
 */
@Length(max = 200)
@NotBlank
@MetaProperty(messageKey = "property.fdName")
default String getFdName() {
    return (String) getExtendProps().get("fdName");
}
 
Example #4
Source File: HibernateValidateController.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * ok
 * 方法上的@Validated注解,一般用来指定 验证组
 *
 * @param code
 * @return
 */
@GetMapping("/requestParam/get")
@Validated
public String paramGet(@Length(max = 3)
                       @NotEmpty(message = "不能为空")
                       @RequestParam(value = "code", required = false) String code) {
    return "方法上的@Validated注解,一般用来指定 验证组";
}
 
Example #5
Source File: ZwitscherRepository.java    From cloud-native-zwitscher with MIT License 5 votes vote down vote up
/**
 * Find the matching Zwitscher messages for the given query.
 *
 * @param q the query, max 500 chars long
 * @return the tweets, never NULL
 */
@HystrixCommand(fallbackMethod = "none")
public Collection<Zwitscher> findByQ(final @Length(max = 500) String q) {
    log.info("Get Zwitscher message from /tweets using q={}.", q);

    Zwitscher[] tweets = restTemplate.getForObject(tweetsRibbonUrl, Zwitscher[].class, q);
    return Arrays.asList(tweets);
}
 
Example #6
Source File: ZwitscherBoardController.java    From cloud-native-zwitscher with MIT License 5 votes vote down vote up
/**
 * Called when posting the search form on the Zwitscher board.
 *
 * @param q         the query string
 * @param viewModel the view model used to render the template
 * @return the template to use
 */
@RequestMapping(value = "/search", method = RequestMethod.GET)
public String search(@RequestParam("q") @Length(max = 500) String q,
                     Model viewModel) {
    populateDefault(viewModel);
    populateTweets(q, viewModel);
    return "index";
}
 
Example #7
Source File: RuleDatabaseBase.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
public RuleDatabaseBase(Integer userId, Integer brokerId,
                        @NotBlank String databaseUrl, @NotBlank String username,
                        @NotBlank String password, @NotBlank String datasourceName,
                        @Length(max = 256) String optionalParameter,
                        Boolean systemTag, Integer databaseType) {
    this.userId = userId;
    this.brokerId = brokerId;
    this.databaseUrl = databaseUrl;
    this.username = username;
    this.password = password;
    this.datasourceName = datasourceName;
    this.optionalParameter = optionalParameter;
    this.systemTag = systemTag;
    this.databaseType = databaseType;
}
 
Example #8
Source File: TreeEntity.java    From mPass with Apache License 2.0 5 votes vote down vote up
/**
 * 读-层级ID
 *
 * @return
 */
@MetaProperty(showType = ShowType.NONE, messageKey = "property.fdHierarchyId")
@Length(max = 900)
@Column(columnDefinition = "varchar(900)")
default String getFdHierarchyId() {
    return (String) getExtendProps().get("fdHierarchyId");
}
 
Example #9
Source File: Office.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=0, max=100)
public String getZipCode() {
	return zipCode;
}
 
Example #10
Source File: Site.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=0, max=255)
public String getKeywords() {
	return keywords;
}
 
Example #11
Source File: ValidateController.java    From springboot-learning-experience with Apache License 2.0 4 votes vote down vote up
@GetMapping("/test2")
public String test2(@NotBlank(message = "name 不能为空") @Length(min = 2, max = 10, message = "name 长度必须在 {min} - {max} 之间") String name) {
    return "success";
}
 
Example #12
Source File: Menu.java    From mysiteforme with Apache License 2.0 4 votes vote down vote up
@Length(min = 0, max = 1000, message = "icon长度必须介于 1 和 1000 之间")
public String getIcon() {
	return icon;
}
 
Example #13
Source File: TreeEntity.java    From mysiteforme with Apache License 2.0 4 votes vote down vote up
@Length( max = 1000, message = "路径长度必须介于 1 和 1000 之间")
public String getParentIds() {
    return parentIds;
}
 
Example #14
Source File: Office.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=0, max=255)
public String getAddress() {
	return address;
}
 
Example #15
Source File: Category.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=1, max=1)
public String getInMenu() {
	return inMenu;
}
 
Example #16
Source File: LengthStrategy.java    From hsweb-framework with Apache License 2.0 4 votes vote down vote up
@Override
protected Class<Length> getAnnotationType() {
    return Length.class;
}
 
Example #17
Source File: TreeEntity.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=1, max=2000)
public String getParentIds() {
	return parentIds;
}
 
Example #18
Source File: OaNotify.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=0, max=1, message="类型长度必须介于 0 和 1 之间")
public String getType() {
	return type;
}
 
Example #19
Source File: OaNotifyRecord.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=0, max=1, message="阅读标记(0:未读;1:已读)长度必须介于 0 和 1 之间")
public String getReadFlag() {
	return readFlag;
}
 
Example #20
Source File: Category.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=0, max=255)
public String getKeywords() {
	return keywords;
}
 
Example #21
Source File: CustomCommentGenerator.java    From BlogManagePlatform with Apache License 2.0 4 votes vote down vote up
private void resolveImports(TopLevelClass klass, IntrospectedTable table) {
	addImport(klass, Data.class);
	addImport(klass, Id.class);
	addImport(klass, Table.class);
	addImport(klass, Column.class);
	addImport(klass, Entity.class);
	addImport(klass, ApiModel.class);
	addImport(klass, ApiModelProperty.class);
	boolean hasNullable = false;
	boolean hasNotNull = false;
	boolean hasNotBlank = false;
	boolean hasLength = false;
	for (IntrospectedColumn iter : table.getAllColumns()) {
		if (iter.isNullable()) {
			hasNullable = true;
		} else {
			if (iter.isStringColumn()) {
				hasNotBlank = true;
			} else {
				hasNotNull = true;
			}
		}
		if (iter.isStringColumn()) {
			if (iter.getLength() != 0) {
				hasLength = true;
			}
		}
	}
	if (hasNullable) {
		addImport(klass, Nullable.class);
	}
	if (hasNotNull) {
		addImport(klass, NotNull.class);
	}
	if (hasNotBlank) {
		addImport(klass, NotBlank.class);
	}
	if (hasLength) {
		addImport(klass, Length.class);
	}
}
 
Example #22
Source File: Validator.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Path("/sayhi/{name}")
@PUT
public String sayHi(@Length(min = 3) @PathParam("name") String name) {
  ContextUtils.getInvocationContext().setStatus(202);
  return name + " sayhi";
}
 
Example #23
Source File: Office.java    From frpMgr with MIT License 4 votes vote down vote up
@Length(min=0, max=200, message="邮箱长度不能超过 200 个字符")
public String getEmail() {
	return email;
}
 
Example #24
Source File: GenTemplate.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=1, max=200)
public String getName() {
	return name;
}
 
Example #25
Source File: Office.java    From frpMgr with MIT License 4 votes vote down vote up
@Length(min=0, max=255, message="联系地址长度不能超过 255 个字符")
public String getAddress() {
	return address;
}
 
Example #26
Source File: Office.java    From frpMgr with MIT License 4 votes vote down vote up
@Length(min=0, max=100, message="电话长度不能超过 100 个字符")
public String getPhone() {
	return phone;
}
 
Example #27
Source File: Office.java    From frpMgr with MIT License 4 votes vote down vote up
@Length(min=0, max=100, message="负责人长度不能超过 100 个字符")
public String getLeader() {
	return leader;
}
 
Example #28
Source File: GenTable.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Length(min=1, max=200)
public String getName() {
	return StringUtils.lowerCase(name);
}
 
Example #29
Source File: User.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
@Email(message="邮箱格式不正确")
@Length(min=0, max=200, message="邮箱长度必须介于 1 和 200 之间")
@ExcelField(title="邮箱", align=1, sort=50)
public String getEmail() {
	return email;
}
 
Example #30
Source File: Office.java    From frpMgr with MIT License 4 votes vote down vote up
@NotBlank(message="机构名称不能为空")
@Length(min=0, max=100, message="机构名称长度不能超过 100 个字符")
public String getOfficeName() {
	return officeName;
}