Skip to content

Commit 414265b

Browse files
committed
refactor: make use an advantage of @repeatable annotations to make code shorter.
1 parent d556e2c commit 414265b

File tree

4 files changed

+89
-168
lines changed

4 files changed

+89
-168
lines changed

src/main/java/ru/mystamps/web/feature/account/ActivateAccountForm.java

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
import javax.validation.constraints.Size;
2929

3030
import static ru.mystamps.web.feature.account.AccountValidation.ACT_KEY_REGEXP;
31+
import static ru.mystamps.web.feature.account.AccountValidation.LOGIN_MAX_LENGTH;
32+
import static ru.mystamps.web.feature.account.AccountValidation.LOGIN_MIN_LENGTH;
33+
import static ru.mystamps.web.feature.account.AccountValidation.LOGIN_REGEXP;
3134
import static ru.mystamps.web.feature.account.AccountValidation.NAME_MAX_LENGTH;
35+
import static ru.mystamps.web.feature.account.AccountValidation.NAME_NO_HYPHEN_REGEXP;
36+
import static ru.mystamps.web.feature.account.AccountValidation.NAME_REGEXP;
37+
import static ru.mystamps.web.feature.account.AccountValidation.PASSWORD_MAX_LENGTH;
38+
import static ru.mystamps.web.feature.account.AccountValidation.PASSWORD_MIN_LENGTH;
3239

3340
@Getter
3441
@Setter
@@ -47,61 +54,25 @@
4754
public class ActivateAccountForm implements ActivateAccountDto {
4855

4956
@NotEmpty(groups = Login1Checks.class)
50-
@Size.List({
51-
@Size(
52-
min = AccountValidation.LOGIN_MIN_LENGTH,
53-
message = "{value.too-short}",
54-
groups = Login2Checks.class
55-
),
56-
@Size(
57-
max = AccountValidation.LOGIN_MAX_LENGTH,
58-
message = "{value.too-long}",
59-
groups = Login2Checks.class
60-
)
61-
})
62-
@Pattern.List({
63-
@Pattern(
64-
regexp = AccountValidation.LOGIN_REGEXP,
65-
message = "{login.invalid}",
66-
groups = Login3Checks.class
67-
),
68-
@Pattern(
69-
regexp = AccountValidation.LOGIN_NO_REPEATING_CHARS_REGEXP,
70-
message = "{login.repetition_chars}",
71-
groups = Login4Checks.class
72-
)
73-
})
57+
@Size(min = LOGIN_MIN_LENGTH, message = "{value.too-short}", groups = Login2Checks.class)
58+
@Size(max = LOGIN_MAX_LENGTH, message = "{value.too-long}", groups = Login2Checks.class)
59+
@Pattern(regexp = LOGIN_REGEXP, message = "{login.invalid}", groups = Login3Checks.class)
60+
@Pattern(
61+
regexp = AccountValidation.LOGIN_NO_REPEATING_CHARS_REGEXP,
62+
message = "{login.repetition_chars}",
63+
groups = Login4Checks.class
64+
)
7465
@UniqueLogin(groups = Login5Checks.class)
7566
private String login;
7667

7768
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}", groups = Name1Checks.class)
78-
@Pattern.List({
79-
@Pattern(
80-
regexp = AccountValidation.NAME_REGEXP,
81-
message = "{name.invalid}",
82-
groups = Name2Checks.class
83-
),
84-
@Pattern(
85-
regexp = AccountValidation.NAME_NO_HYPHEN_REGEXP,
86-
message = "{value.hyphen}",
87-
groups = Name3Checks.class
88-
)
89-
})
69+
@Pattern(regexp = NAME_REGEXP, message = "{name.invalid}", groups = Name2Checks.class)
70+
@Pattern(regexp = NAME_NO_HYPHEN_REGEXP, message = "{value.hyphen}", groups = Name3Checks.class)
9071
private String name;
9172

9273
@NotEmpty(groups = Password1Checks.class)
93-
@Size.List({
94-
@Size(
95-
min = AccountValidation.PASSWORD_MIN_LENGTH,
96-
message = "{value.too-short}",
97-
groups = Password2Checks.class
98-
),
99-
@Size(
100-
max = AccountValidation.PASSWORD_MAX_LENGTH,
101-
message = "{value.too-long}",
102-
groups = Password2Checks.class
103-
)
104-
})
74+
@Size(min = PASSWORD_MIN_LENGTH, message = "{value.too-short}", groups = Password2Checks.class)
75+
@Size(max = PASSWORD_MAX_LENGTH, message = "{value.too-long}", groups = Password2Checks.class)
10576
private String password;
10677

10778
@NotEmpty(groups = PasswordConfirmation1Checks.class)

src/main/java/ru/mystamps/web/feature/category/AddCategoryForm.java

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -51,69 +51,45 @@
5151
public class AddCategoryForm implements AddCategoryDto {
5252

5353
@NotEmpty(groups = Group.Level1.class)
54-
@Size.List({
55-
@Size(
56-
min = NAME_MIN_LENGTH,
57-
message = "{value.too-short}",
58-
groups = Group.Level2.class
59-
),
60-
@Size(
61-
max = NAME_MAX_LENGTH,
62-
message = "{value.too-long}",
63-
groups = Group.Level2.class
64-
)
65-
})
66-
@Pattern.List({
67-
@Pattern(
68-
regexp = NAME_EN_REGEXP,
69-
message = "{value.invalid-en-chars}",
70-
groups = Group.Level3.class
71-
),
72-
@Pattern(
73-
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
74-
message = "{value.repeating-hyphen}",
75-
groups = Group.Level4.class
76-
),
77-
@Pattern(
78-
regexp = NAME_NO_HYPHEN_REGEXP,
79-
message = "{value.hyphen}",
80-
groups = Group.Level5.class
81-
)
82-
})
54+
@Size(min = NAME_MIN_LENGTH, message = "{value.too-short}", groups = Group.Level2.class)
55+
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}", groups = Group.Level2.class)
56+
@Pattern(
57+
regexp = NAME_EN_REGEXP,
58+
message = "{value.invalid-en-chars}",
59+
groups = Group.Level3.class
60+
)
61+
@Pattern(
62+
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
63+
message = "{value.repeating-hyphen}",
64+
groups = Group.Level4.class
65+
)
66+
@Pattern(
67+
regexp = NAME_NO_HYPHEN_REGEXP,
68+
message = "{value.hyphen}",
69+
groups = Group.Level5.class
70+
)
8371
@DenyValues(value = {"add", "list"}, groups = Group.Level6.class)
8472
@UniqueCategoryName(lang = Lang.EN, groups = Group.Level7.class)
8573
@UniqueCategorySlug(groups = Group.Level8.class)
8674
private String name;
8775

88-
@Size.List({
89-
@Size(
90-
min = NAME_MIN_LENGTH,
91-
message = "{value.too-short}",
92-
groups = Group.Level2.class
93-
),
94-
@Size(
95-
max = NAME_MAX_LENGTH,
96-
message = "{value.too-long}",
97-
groups = Group.Level2.class
98-
)
99-
})
100-
@Pattern.List({
101-
@Pattern(
102-
regexp = NAME_RU_REGEXP,
103-
message = "{value.invalid-ru-chars}",
104-
groups = Group.Level3.class
105-
),
106-
@Pattern(
107-
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
108-
message = "{value.repeating-hyphen}",
109-
groups = Group.Level4.class
110-
),
111-
@Pattern(
112-
regexp = NAME_NO_HYPHEN_REGEXP,
113-
message = "{value.hyphen}",
114-
groups = Group.Level5.class
115-
)
116-
})
76+
@Size(min = NAME_MIN_LENGTH, message = "{value.too-short}", groups = Group.Level2.class)
77+
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}", groups = Group.Level2.class)
78+
@Pattern(
79+
regexp = NAME_RU_REGEXP,
80+
message = "{value.invalid-ru-chars}",
81+
groups = Group.Level3.class
82+
)
83+
@Pattern(
84+
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
85+
message = "{value.repeating-hyphen}",
86+
groups = Group.Level4.class
87+
)
88+
@Pattern(
89+
regexp = NAME_NO_HYPHEN_REGEXP,
90+
message = "{value.hyphen}",
91+
groups = Group.Level5.class
92+
)
11793
@UniqueCategoryName(lang = Lang.RU, groups = Group.Level7.class)
11894
private String nameRu;
11995

src/main/java/ru/mystamps/web/feature/country/AddCountryForm.java

Lines changed: 34 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -51,69 +51,45 @@
5151
public class AddCountryForm implements AddCountryDto {
5252

5353
@NotEmpty(groups = Group.Level1.class)
54-
@Size.List({
55-
@Size(
56-
min = NAME_MIN_LENGTH,
57-
message = "{value.too-short}",
58-
groups = Group.Level2.class
59-
),
60-
@Size(
61-
max = NAME_MAX_LENGTH,
62-
message = "{value.too-long}",
63-
groups = Group.Level2.class
64-
)
65-
})
66-
@Pattern.List({
67-
@Pattern(
68-
regexp = NAME_EN_REGEXP,
69-
message = "{value.invalid-en-chars}",
70-
groups = Group.Level3.class
71-
),
72-
@Pattern(
73-
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
74-
message = "{value.repeating-hyphen}",
75-
groups = Group.Level4.class
76-
),
77-
@Pattern(
78-
regexp = NAME_NO_HYPHEN_REGEXP,
79-
message = "{value.hyphen}",
80-
groups = Group.Level5.class
81-
)
82-
})
54+
@Size(min = NAME_MIN_LENGTH, message = "{value.too-short}", groups = Group.Level2.class)
55+
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}", groups = Group.Level2.class)
56+
@Pattern(
57+
regexp = NAME_EN_REGEXP,
58+
message = "{value.invalid-en-chars}",
59+
groups = Group.Level3.class
60+
)
61+
@Pattern(
62+
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
63+
message = "{value.repeating-hyphen}",
64+
groups = Group.Level4.class
65+
)
66+
@Pattern(
67+
regexp = NAME_NO_HYPHEN_REGEXP,
68+
message = "{value.hyphen}",
69+
groups = Group.Level5.class
70+
)
8371
@DenyValues(value = {"add", "list"}, groups = Group.Level6.class)
8472
@UniqueCountryName(lang = Lang.EN, groups = Group.Level7.class)
8573
@UniqueCountrySlug(groups = Group.Level8.class)
8674
private String name;
8775

88-
@Size.List({
89-
@Size(
90-
min = NAME_MIN_LENGTH,
91-
message = "{value.too-short}",
92-
groups = Group.Level2.class
93-
),
94-
@Size(
95-
max = NAME_MAX_LENGTH,
96-
message = "{value.too-long}",
97-
groups = Group.Level2.class
98-
)
99-
})
100-
@Pattern.List({
101-
@Pattern(
102-
regexp = NAME_RU_REGEXP,
103-
message = "{value.invalid-ru-chars}",
104-
groups = Group.Level3.class
105-
),
106-
@Pattern(
107-
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
108-
message = "{value.repeating-hyphen}",
109-
groups = Group.Level4.class
110-
),
111-
@Pattern(
112-
regexp = NAME_NO_HYPHEN_REGEXP,
113-
message = "{value.hyphen}",
114-
groups = Group.Level5.class
115-
)
116-
})
76+
@Size(min = NAME_MIN_LENGTH, message = "{value.too-short}", groups = Group.Level2.class)
77+
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}", groups = Group.Level2.class)
78+
@Pattern(
79+
regexp = NAME_RU_REGEXP,
80+
message = "{value.invalid-ru-chars}",
81+
groups = Group.Level3.class
82+
)
83+
@Pattern(
84+
regexp = NAME_NO_REPEATING_HYPHENS_REGEXP,
85+
message = "{value.repeating-hyphen}",
86+
groups = Group.Level4.class
87+
)
88+
@Pattern(
89+
regexp = NAME_NO_HYPHEN_REGEXP,
90+
message = "{value.hyphen}",
91+
groups = Group.Level5.class
92+
)
11793
@UniqueCountryName(lang = Lang.RU, groups = Group.Level7.class)
11894
private String nameRu;
11995

src/main/java/ru/mystamps/web/feature/participant/AddParticipantForm.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434
public class AddParticipantForm implements AddParticipantDto {
3535

3636
@NotEmpty
37-
@Size.List({
38-
@Size(min = NAME_MIN_LENGTH, message = "{value.too-short}"),
39-
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}")
40-
})
37+
@Size(min = NAME_MIN_LENGTH, message = "{value.too-short}")
38+
@Size(max = NAME_MAX_LENGTH, message = "{value.too-long}")
4139
private String name;
4240

4341
@URL

0 commit comments

Comments
 (0)