Skip to content

Commit ea2905d

Browse files
aNNiMONrubenlagus
andcommitted
Consistency in the common validation messages (#1459)
Co-authored-by: Ruben Bermudez <[email protected]>
1 parent 1f35807 commit ea2905d

File tree

89 files changed

+239
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+239
-296
lines changed

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessage.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard;
1919
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
2020
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
21+
import org.telegram.telegrambots.meta.util.Validations;
2122

2223
import java.util.List;
2324

@@ -170,10 +171,7 @@ public MessageId deserializeResponse(String answer) throws TelegramApiRequestExc
170171

171172
@Override
172173
public void validate() throws TelegramApiValidationException {
173-
if (chatId.isEmpty()) {
174-
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
175-
}
176-
174+
Validations.requiredChatId(chatId, this);
177175
if (parseMode != null && (captionEntities != null && !captionEntities.isEmpty()) ) {
178176
throw new TelegramApiValidationException("Parse mode can't be enabled if Entities are provided", this);
179177
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/CopyMessages.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.telegram.telegrambots.meta.api.objects.MessageId;
1717
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
1818
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
19+
import org.telegram.telegrambots.meta.util.Validations;
1920

2021
import java.util.ArrayList;
2122
import java.util.List;
@@ -129,9 +130,7 @@ public ArrayList<MessageId> deserializeResponse(String answer) throws TelegramAp
129130

130131
@Override
131132
public void validate() throws TelegramApiValidationException {
132-
if (chatId.isEmpty()) {
133-
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
134-
}
133+
Validations.requiredChatId(chatId, this);
135134
if (messageIds.isEmpty() || messageIds.size() > 100) {
136135
throw new TelegramApiValidationException("MessageIds parameter items count must be between 1 and 100", this);
137136
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import lombok.extern.jackson.Jacksonized;
1414
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
1515
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
16+
import org.telegram.telegrambots.meta.util.Validations;
1617

1718
/**
1819
* @author Ruben Bermudez
@@ -78,9 +79,7 @@ public void setFromChatId(@NonNull Long fromChatId) {
7879

7980
@Override
8081
public void validate() throws TelegramApiValidationException {
81-
if (chatId.isEmpty()) {
82-
throw new TelegramApiValidationException("ChatId can't be empty", this);
83-
}
82+
Validations.requiredChatId(chatId, this);
8483
if (fromChatId.isEmpty()) {
8584
throw new TelegramApiValidationException("FromChatId can't be empty", this);
8685
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessages.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.telegram.telegrambots.meta.api.objects.MessageId;
1717
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
1818
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
19+
import org.telegram.telegrambots.meta.util.Validations;
1920

2021
import java.util.ArrayList;
2122
import java.util.List;
@@ -100,9 +101,7 @@ public void setFromChatId(@NonNull Long fromChatId) {
100101

101102
@Override
102103
public void validate() throws TelegramApiValidationException {
103-
if (chatId.isEmpty()) {
104-
throw new TelegramApiValidationException("ChatId can't be empty", this);
105-
}
104+
Validations.requiredChatId(chatId, this);
106105
if (fromChatId.isEmpty()) {
107106
throw new TelegramApiValidationException("FromChatId can't be empty", this);
108107
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/SetUserEmojiStatus.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -43,7 +44,7 @@ public class SetUserEmojiStatus extends BotApiMethodBoolean {
4344
*/
4445
@JsonProperty(USER_ID_FIELD)
4546
@NonNull
46-
private Integer userId;
47+
private Long userId;
4748
/**
4849
* Optional
4950
* Custom emoji identifier of the emoji status to set.
@@ -65,8 +66,6 @@ public String getMethod() {
6566

6667
@Override
6768
public void validate() throws TelegramApiValidationException {
68-
if (userId == 0) {
69-
throw new TelegramApiValidationException("UserId parameter can't be empty", this);
70-
}
69+
Validations.requiredUserId(userId, this);
7170
}
7271
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/boosts/GetUserChatBoosts.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.telegram.telegrambots.meta.api.objects.boost.UserChatBoosts;
1515
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
1616
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
17+
import org.telegram.telegrambots.meta.util.Validations;
1718

1819
/**
1920
* @author Ruben Bermudez
@@ -59,12 +60,8 @@ public UserChatBoosts deserializeResponse(String answer) throws TelegramApiReque
5960

6061
@Override
6162
public void validate() throws TelegramApiValidationException {
62-
if (chatId.isEmpty()) {
63-
throw new TelegramApiValidationException("ChatId parameter can't be empty string", this);
64-
}
65-
if (userId <= 0) {
66-
throw new TelegramApiValidationException("userId can't be empty", this);
67-
}
63+
Validations.requiredChatId(chatId, this);
64+
Validations.requiredUserId(userId, this);
6865
}
6966

7067
public static class GetUserChatBoostsBuilder {

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/CloseForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -56,9 +57,7 @@ public void setChatId(@NonNull Long chatId) {
5657

5758
@Override
5859
public void validate() throws TelegramApiValidationException {
59-
if (chatId.isEmpty()) {
60-
throw new TelegramApiValidationException("ChatId can't be empty", this);
61-
}
60+
Validations.requiredChatId(chatId, this);
6261
if (messageThreadId <= 0) {
6362
throw new TelegramApiValidationException("Message Thread Id can't be empty", this);
6463
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/CloseGeneralForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -48,9 +49,7 @@ public void setChatId(@NonNull Long chatId) {
4849

4950
@Override
5051
public void validate() throws TelegramApiValidationException {
51-
if (chatId.isEmpty()) {
52-
throw new TelegramApiValidationException("ChatId can't be empty", this);
53-
}
52+
Validations.requiredChatId(chatId, this);
5453
}
5554

5655
@Override

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/CreateForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.telegram.telegrambots.meta.api.objects.forum.ForumTopic;
1616
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
1717
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
18+
import org.telegram.telegrambots.meta.util.Validations;
1819

1920
/**
2021
* @author Ruben Bermudez
@@ -74,9 +75,7 @@ public void setChatId(@NonNull Long chatId) {
7475

7576
@Override
7677
public void validate() throws TelegramApiValidationException {
77-
if (chatId.isEmpty()) {
78-
throw new TelegramApiValidationException("ChatId can't be empty", this);
79-
}
78+
Validations.requiredChatId(chatId, this);
8079
if (name.isEmpty() || name.length() > 128) {
8180
throw new TelegramApiValidationException("Name must be between 1 and 128 characters", this);
8281
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/DeleteForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -56,9 +57,7 @@ public void setChatId(@NonNull Long chatId) {
5657

5758
@Override
5859
public void validate() throws TelegramApiValidationException {
59-
if (chatId.isEmpty()) {
60-
throw new TelegramApiValidationException("ChatId can't be empty", this);
61-
}
60+
Validations.requiredChatId(chatId, this);
6261
if (messageThreadId <= 0) {
6362
throw new TelegramApiValidationException("Message Thread Id can't be empty", this);
6463
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/EditForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -74,9 +75,7 @@ public void setChatId(@NonNull Long chatId) {
7475

7576
@Override
7677
public void validate() throws TelegramApiValidationException {
77-
if (chatId.isEmpty()) {
78-
throw new TelegramApiValidationException("ChatId can't be empty", this);
79-
}
78+
Validations.requiredChatId(chatId, this);
8079
if (name != null && !name.isEmpty()) {
8180
if (name.length() > 128) {
8281
throw new TelegramApiValidationException("Name must be less than 128 characters", this);

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/EditGeneralForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -56,9 +57,7 @@ public void setChatId(@NonNull Long chatId) {
5657

5758
@Override
5859
public void validate() throws TelegramApiValidationException {
59-
if (chatId.isEmpty()) {
60-
throw new TelegramApiValidationException("ChatId can't be empty", this);
61-
}
60+
Validations.requiredChatId(chatId, this);
6261
if (name.isEmpty() || name.length() > 128) {
6362
throw new TelegramApiValidationException("Name must be between 1 and 128 characters", this);
6463
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/HideGeneralForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -49,9 +50,7 @@ public void setChatId(@NonNull Long chatId) {
4950

5051
@Override
5152
public void validate() throws TelegramApiValidationException {
52-
if (chatId.isEmpty()) {
53-
throw new TelegramApiValidationException("ChatId can't be empty", this);
54-
}
53+
Validations.requiredChatId(chatId, this);
5554
}
5655

5756
@Override

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/ReopenForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -57,9 +58,7 @@ public void setChatId(@NonNull Long chatId) {
5758

5859
@Override
5960
public void validate() throws TelegramApiValidationException {
60-
if (chatId.isEmpty()) {
61-
throw new TelegramApiValidationException("ChatId can't be empty", this);
62-
}
61+
Validations.requiredChatId(chatId, this);
6362
if (messageThreadId <= 0) {
6463
throw new TelegramApiValidationException("Message Thread Id can't be empty", this);
6564
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/ReopenGeneralForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -49,9 +50,7 @@ public void setChatId(@NonNull Long chatId) {
4950

5051
@Override
5152
public void validate() throws TelegramApiValidationException {
52-
if (chatId.isEmpty()) {
53-
throw new TelegramApiValidationException("ChatId can't be empty", this);
54-
}
53+
Validations.requiredChatId(chatId, this);
5554
}
5655

5756
@Override

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/UnhideGeneralForumTopic.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -48,9 +49,7 @@ public void setChatId(@NonNull Long chatId) {
4849

4950
@Override
5051
public void validate() throws TelegramApiValidationException {
51-
if (chatId.isEmpty()) {
52-
throw new TelegramApiValidationException("ChatId can't be empty", this);
53-
}
52+
Validations.requiredChatId(chatId, this);
5453
}
5554

5655
@Override

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/UnpinAllForumTopicMessages.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -56,9 +57,7 @@ public void setChatId(@NonNull Long chatId) {
5657

5758
@Override
5859
public void validate() throws TelegramApiValidationException {
59-
if (chatId.isEmpty()) {
60-
throw new TelegramApiValidationException("ChatId can't be empty", this);
61-
}
60+
Validations.requiredChatId(chatId, this);
6261
if (messageThreadId <= 0) {
6362
throw new TelegramApiValidationException("Message Thread Id can't be empty", this);
6463
}

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/forum/UnpinAllGeneralForumTopicMessages.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import lombok.extern.jackson.Jacksonized;
1313
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1414
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
15+
import org.telegram.telegrambots.meta.util.Validations;
1516

1617
/**
1718
* @author Ruben Bermudez
@@ -49,9 +50,7 @@ public void setChatId(@NonNull Long chatId) {
4950

5051
@Override
5152
public void validate() throws TelegramApiValidationException {
52-
if (chatId.isEmpty()) {
53-
throw new TelegramApiValidationException("ChatId can't be empty", this);
54-
}
53+
Validations.requiredChatId(chatId, this);
5554
}
5655

5756
@Override

telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/gifts/SendGift.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
1515
import org.telegram.telegrambots.meta.api.objects.MessageEntity;
1616
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
17+
import org.telegram.telegrambots.meta.util.Validations;
1718

1819
import java.util.List;
1920

@@ -47,7 +48,7 @@ public class SendGift extends BotApiMethodBoolean {
4748
*/
4849
@JsonProperty(USER_ID_FIELD)
4950
@NonNull
50-
private Integer userId;
51+
private Long userId;
5152
/**
5253
* Identifier of the gift
5354
*/
@@ -81,9 +82,7 @@ public class SendGift extends BotApiMethodBoolean {
8182

8283
@Override
8384
public void validate() throws TelegramApiValidationException {
84-
if (userId == 0) {
85-
throw new TelegramApiValidationException("UserId can't be empty", this);
86-
}
85+
Validations.requiredUserId(userId, this);
8786
if (giftId.isEmpty()) {
8887
throw new TelegramApiValidationException("GiftId can't be empty", this);
8988
}

0 commit comments

Comments
 (0)