From 9add4f460091bb3bede8a8f6877f52f4f3dbde2e Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Sat, 3 Feb 2018 18:07:19 +0900 Subject: [PATCH] Support repeatable on constraint annotation of BV See gh-5 --- src/main/java/com/kazuki43zoo/app/account/PasswordForm.java | 6 ++---- .../java/com/kazuki43zoo/core/validation/AccountId.java | 2 ++ .../kazuki43zoo/core/validation/EqualsPropertyValues.java | 2 ++ .../java/com/kazuki43zoo/core/validation/FirstName.java | 1 + src/main/java/com/kazuki43zoo/core/validation/LastName.java | 1 + .../core/validation/NotEqualsPropertyValues.java | 2 ++ src/main/java/com/kazuki43zoo/core/validation/Password.java | 1 + 7 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/kazuki43zoo/app/account/PasswordForm.java b/src/main/java/com/kazuki43zoo/app/account/PasswordForm.java index d870532..c14c868 100644 --- a/src/main/java/com/kazuki43zoo/app/account/PasswordForm.java +++ b/src/main/java/com/kazuki43zoo/app/account/PasswordForm.java @@ -7,10 +7,8 @@ import javax.validation.constraints.NotNull; import java.io.Serializable; -@NotEqualsPropertyValues.List({ - @NotEqualsPropertyValues(property = "password", comparingProperty = "username", message = "{NotEqualsWithAccountId.message}") - , @NotEqualsPropertyValues(property = "password", comparingProperty = "currentPassword", message = "{NotEqualsWithCurrentPassword.message}") -}) +@NotEqualsPropertyValues(property = "password", comparingProperty = "username", message = "{NotEqualsWithAccountId.message}") +@NotEqualsPropertyValues(property = "password", comparingProperty = "currentPassword", message = "{NotEqualsWithCurrentPassword.message}") @EqualsPropertyValues(property = "confirmPassword", comparingProperty = "password", message = "{EqualsWithPassword.message}") @lombok.Data @lombok.ToString(exclude = {"currentPassword", "password", "confirmPassword"}) diff --git a/src/main/java/com/kazuki43zoo/core/validation/AccountId.java b/src/main/java/com/kazuki43zoo/core/validation/AccountId.java index fa10258..a46b976 100644 --- a/src/main/java/com/kazuki43zoo/core/validation/AccountId.java +++ b/src/main/java/com/kazuki43zoo/core/validation/AccountId.java @@ -5,6 +5,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.lang.annotation.Documented; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -18,6 +19,7 @@ @Retention(RUNTIME) @NotNull @Size(max = 128) +@Repeatable(AccountId.List.class) public @interface AccountId { String message() default "{com.github.kazuki43zoo.core.validation.AccountId.message}"; diff --git a/src/main/java/com/kazuki43zoo/core/validation/EqualsPropertyValues.java b/src/main/java/com/kazuki43zoo/core/validation/EqualsPropertyValues.java index f9955fa..bd17908 100644 --- a/src/main/java/com/kazuki43zoo/core/validation/EqualsPropertyValues.java +++ b/src/main/java/com/kazuki43zoo/core/validation/EqualsPropertyValues.java @@ -6,6 +6,7 @@ import javax.validation.OverridesAttribute; import javax.validation.Payload; import java.lang.annotation.Documented; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -18,6 +19,7 @@ @Target({TYPE, ANNOTATION_TYPE}) @Retention(RUNTIME) @Compare(left = "", right = "", operator = Compare.Operator.EQUAL, message = "{com.github.kazuki43zoo.core.validation.EqualsPropertyValues.message}") +@Repeatable(EqualsPropertyValues.List.class) public @interface EqualsPropertyValues { @OverridesAttribute(constraint = Compare.class, name = "message") String message() default ""; diff --git a/src/main/java/com/kazuki43zoo/core/validation/FirstName.java b/src/main/java/com/kazuki43zoo/core/validation/FirstName.java index 56ba9c0..466e4f4 100644 --- a/src/main/java/com/kazuki43zoo/core/validation/FirstName.java +++ b/src/main/java/com/kazuki43zoo/core/validation/FirstName.java @@ -15,6 +15,7 @@ @Retention(RUNTIME) @NotNull @Size(max = 128) +@Repeatable(FirstName.List.class) public @interface FirstName { String message() default "{com.github.kazuki43zoo.core.validation.FirstName.message}"; diff --git a/src/main/java/com/kazuki43zoo/core/validation/LastName.java b/src/main/java/com/kazuki43zoo/core/validation/LastName.java index 6f944d1..9119695 100644 --- a/src/main/java/com/kazuki43zoo/core/validation/LastName.java +++ b/src/main/java/com/kazuki43zoo/core/validation/LastName.java @@ -13,6 +13,7 @@ @Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @Retention(RUNTIME) @Size(max = 128) +@Repeatable(LastName.List.class) public @interface LastName { String message() default "{com.github.kazuki43zoo.core.validation.LastName.message}"; diff --git a/src/main/java/com/kazuki43zoo/core/validation/NotEqualsPropertyValues.java b/src/main/java/com/kazuki43zoo/core/validation/NotEqualsPropertyValues.java index f645db4..7423f3c 100644 --- a/src/main/java/com/kazuki43zoo/core/validation/NotEqualsPropertyValues.java +++ b/src/main/java/com/kazuki43zoo/core/validation/NotEqualsPropertyValues.java @@ -6,6 +6,7 @@ import javax.validation.OverridesAttribute; import javax.validation.Payload; import java.lang.annotation.Documented; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -18,6 +19,7 @@ @Target({TYPE, ANNOTATION_TYPE}) @Retention(RUNTIME) @Compare(left = "", right = "", operator = Compare.Operator.NOT_EQUAL, message = "{com.github.kazuki43zoo.core.validation.NotEqualsPropertyValues.message}") +@Repeatable(NotEqualsPropertyValues.List.class) public @interface NotEqualsPropertyValues { @OverridesAttribute(constraint = Compare.class, name = "message") String message() default ""; diff --git a/src/main/java/com/kazuki43zoo/core/validation/Password.java b/src/main/java/com/kazuki43zoo/core/validation/Password.java index 148422e..9cd0af1 100644 --- a/src/main/java/com/kazuki43zoo/core/validation/Password.java +++ b/src/main/java/com/kazuki43zoo/core/validation/Password.java @@ -15,6 +15,7 @@ @Retention(RUNTIME) @ReportAsSingleViolation @Size(min = 8) +@Repeatable(Password.List.class) public @interface Password { String message() default "{com.github.kazuki43zoo.core.validation.Password.message}";