From a11e4b98cc1b506e3bfac4de7d90c94bfe0600b0 Mon Sep 17 00:00:00 2001 From: Vladik Date: Sun, 8 Sep 2024 13:58:00 +0300 Subject: [PATCH] refactor: Create BaseRuntimeException.java and updated files --- .../rest/ChangePasswordController.java | 3 +-- ...tactAlreadySubscribedToTopicException.java | 5 ++-- .../exception/ContactEmailNotExist.java | 4 +++- .../exception/ContactNotFoundException.java | 4 +++- .../exception/EmailSendingException.java | 4 +++- .../EmailTokenNotFoundException.java | 4 +++- .../InvalidCredentialsException.java | 4 +++- .../exception/InvalidTokenException.java | 4 +++- .../MessageHasAlreadyReportedException.java | 4 +++- .../exception/MessageNotFoundException.java | 4 +++- .../MessagePermissionDeniedException.java | 4 +++- .../NotSubscribedTopicException.java | 4 +++- .../OwnerCantUnsubscribedException.java | 4 +++- .../PasswordsAreNotEqualException.java | 4 +++- .../exception/TokenNotFoundException.java | 4 +++- .../exception/TopicAccessException.java | 4 +++- .../exception/TopicNotFoundException.java | 4 +++- .../TopicSubscriberNotFoundException.java | 4 +++- .../exception/ValueNotUniqException.java | 6 +++-- .../handler/BaseRuntimeException.java | 23 +++++++++++++++++++ .../listener/StompSubscriptionListener.java | 1 - 21 files changed, 79 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/chat/yourway/exception/handler/BaseRuntimeException.java diff --git a/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java b/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java index dbf1121a..14f5e663 100644 --- a/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java +++ b/src/main/java/com/chat/yourway/controller/rest/ChangePasswordController.java @@ -28,8 +28,7 @@ public class ChangePasswordController { private static final String PASSWORD_EMAIL = "/password/email"; private static final String PASSWORD_RESTORE = "/password/restore"; - @Operation(summary = "Change to new password", - responses = { + @Operation(summary = "Change to new password", responses = { @ApiResponse(responseCode = "200", description = SUCCESSFULLY_CHANGING_PASSWORD, content = @Content), @ApiResponse(responseCode = "400", description = INVALID_OLD_PASSWORD, diff --git a/src/main/java/com/chat/yourway/exception/ContactAlreadySubscribedToTopicException.java b/src/main/java/com/chat/yourway/exception/ContactAlreadySubscribedToTopicException.java index 0c8356f7..7ee91014 100644 --- a/src/main/java/com/chat/yourway/exception/ContactAlreadySubscribedToTopicException.java +++ b/src/main/java/com/chat/yourway/exception/ContactAlreadySubscribedToTopicException.java @@ -1,8 +1,9 @@ package com.chat.yourway.exception; -public class ContactAlreadySubscribedToTopicException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; +public class ContactAlreadySubscribedToTopicException extends BaseRuntimeException { public ContactAlreadySubscribedToTopicException(String message) { super(message); } -} +} \ No newline at end of file diff --git a/src/main/java/com/chat/yourway/exception/ContactEmailNotExist.java b/src/main/java/com/chat/yourway/exception/ContactEmailNotExist.java index 108468b6..8c58abe7 100644 --- a/src/main/java/com/chat/yourway/exception/ContactEmailNotExist.java +++ b/src/main/java/com/chat/yourway/exception/ContactEmailNotExist.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class ContactEmailNotExist extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class ContactEmailNotExist extends BaseRuntimeException { public ContactEmailNotExist(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/ContactNotFoundException.java b/src/main/java/com/chat/yourway/exception/ContactNotFoundException.java index 1d5000bc..afc99dc3 100644 --- a/src/main/java/com/chat/yourway/exception/ContactNotFoundException.java +++ b/src/main/java/com/chat/yourway/exception/ContactNotFoundException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class ContactNotFoundException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class ContactNotFoundException extends BaseRuntimeException { public ContactNotFoundException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/EmailSendingException.java b/src/main/java/com/chat/yourway/exception/EmailSendingException.java index bfea9015..b6ad0918 100644 --- a/src/main/java/com/chat/yourway/exception/EmailSendingException.java +++ b/src/main/java/com/chat/yourway/exception/EmailSendingException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class EmailSendingException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class EmailSendingException extends BaseRuntimeException { public EmailSendingException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/EmailTokenNotFoundException.java b/src/main/java/com/chat/yourway/exception/EmailTokenNotFoundException.java index 3e08f2c6..9ce0bf32 100644 --- a/src/main/java/com/chat/yourway/exception/EmailTokenNotFoundException.java +++ b/src/main/java/com/chat/yourway/exception/EmailTokenNotFoundException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class EmailTokenNotFoundException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class EmailTokenNotFoundException extends BaseRuntimeException { public EmailTokenNotFoundException() { super("Current token does not exist"); } diff --git a/src/main/java/com/chat/yourway/exception/InvalidCredentialsException.java b/src/main/java/com/chat/yourway/exception/InvalidCredentialsException.java index ac480bdb..4a97f101 100644 --- a/src/main/java/com/chat/yourway/exception/InvalidCredentialsException.java +++ b/src/main/java/com/chat/yourway/exception/InvalidCredentialsException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class InvalidCredentialsException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class InvalidCredentialsException extends BaseRuntimeException { public InvalidCredentialsException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/InvalidTokenException.java b/src/main/java/com/chat/yourway/exception/InvalidTokenException.java index 7d3036c7..d2168338 100644 --- a/src/main/java/com/chat/yourway/exception/InvalidTokenException.java +++ b/src/main/java/com/chat/yourway/exception/InvalidTokenException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class InvalidTokenException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class InvalidTokenException extends BaseRuntimeException { public InvalidTokenException(String message) { super(message); diff --git a/src/main/java/com/chat/yourway/exception/MessageHasAlreadyReportedException.java b/src/main/java/com/chat/yourway/exception/MessageHasAlreadyReportedException.java index 447a132b..a7332f2b 100644 --- a/src/main/java/com/chat/yourway/exception/MessageHasAlreadyReportedException.java +++ b/src/main/java/com/chat/yourway/exception/MessageHasAlreadyReportedException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class MessageHasAlreadyReportedException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class MessageHasAlreadyReportedException extends BaseRuntimeException { public MessageHasAlreadyReportedException() { super("Message has already reported."); } diff --git a/src/main/java/com/chat/yourway/exception/MessageNotFoundException.java b/src/main/java/com/chat/yourway/exception/MessageNotFoundException.java index 5eae0cc5..220c6f32 100644 --- a/src/main/java/com/chat/yourway/exception/MessageNotFoundException.java +++ b/src/main/java/com/chat/yourway/exception/MessageNotFoundException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class MessageNotFoundException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class MessageNotFoundException extends BaseRuntimeException { public MessageNotFoundException() { super("Message is not found."); } diff --git a/src/main/java/com/chat/yourway/exception/MessagePermissionDeniedException.java b/src/main/java/com/chat/yourway/exception/MessagePermissionDeniedException.java index de3b5b0c..2e8651d5 100644 --- a/src/main/java/com/chat/yourway/exception/MessagePermissionDeniedException.java +++ b/src/main/java/com/chat/yourway/exception/MessagePermissionDeniedException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class MessagePermissionDeniedException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class MessagePermissionDeniedException extends BaseRuntimeException { public MessagePermissionDeniedException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/NotSubscribedTopicException.java b/src/main/java/com/chat/yourway/exception/NotSubscribedTopicException.java index 8eb70b7f..9e534fb3 100644 --- a/src/main/java/com/chat/yourway/exception/NotSubscribedTopicException.java +++ b/src/main/java/com/chat/yourway/exception/NotSubscribedTopicException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class NotSubscribedTopicException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class NotSubscribedTopicException extends BaseRuntimeException { public NotSubscribedTopicException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/OwnerCantUnsubscribedException.java b/src/main/java/com/chat/yourway/exception/OwnerCantUnsubscribedException.java index 4151390d..9647229c 100644 --- a/src/main/java/com/chat/yourway/exception/OwnerCantUnsubscribedException.java +++ b/src/main/java/com/chat/yourway/exception/OwnerCantUnsubscribedException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class OwnerCantUnsubscribedException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class OwnerCantUnsubscribedException extends BaseRuntimeException { public OwnerCantUnsubscribedException(String message) { super(message); diff --git a/src/main/java/com/chat/yourway/exception/PasswordsAreNotEqualException.java b/src/main/java/com/chat/yourway/exception/PasswordsAreNotEqualException.java index 508b5e71..63509008 100644 --- a/src/main/java/com/chat/yourway/exception/PasswordsAreNotEqualException.java +++ b/src/main/java/com/chat/yourway/exception/PasswordsAreNotEqualException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class PasswordsAreNotEqualException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class PasswordsAreNotEqualException extends BaseRuntimeException { public PasswordsAreNotEqualException() { super("Passwords are not equal."); } diff --git a/src/main/java/com/chat/yourway/exception/TokenNotFoundException.java b/src/main/java/com/chat/yourway/exception/TokenNotFoundException.java index 399e9cd0..d5f8be06 100644 --- a/src/main/java/com/chat/yourway/exception/TokenNotFoundException.java +++ b/src/main/java/com/chat/yourway/exception/TokenNotFoundException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class TokenNotFoundException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class TokenNotFoundException extends BaseRuntimeException { public TokenNotFoundException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/TopicAccessException.java b/src/main/java/com/chat/yourway/exception/TopicAccessException.java index ce2df05f..eef075e5 100644 --- a/src/main/java/com/chat/yourway/exception/TopicAccessException.java +++ b/src/main/java/com/chat/yourway/exception/TopicAccessException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class TopicAccessException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class TopicAccessException extends BaseRuntimeException { public TopicAccessException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/TopicNotFoundException.java b/src/main/java/com/chat/yourway/exception/TopicNotFoundException.java index f9a82acb..ff86058d 100644 --- a/src/main/java/com/chat/yourway/exception/TopicNotFoundException.java +++ b/src/main/java/com/chat/yourway/exception/TopicNotFoundException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class TopicNotFoundException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class TopicNotFoundException extends BaseRuntimeException { public TopicNotFoundException(String message) { super(message); } diff --git a/src/main/java/com/chat/yourway/exception/TopicSubscriberNotFoundException.java b/src/main/java/com/chat/yourway/exception/TopicSubscriberNotFoundException.java index f519a86a..de4028d5 100644 --- a/src/main/java/com/chat/yourway/exception/TopicSubscriberNotFoundException.java +++ b/src/main/java/com/chat/yourway/exception/TopicSubscriberNotFoundException.java @@ -1,6 +1,8 @@ package com.chat.yourway.exception; -public class TopicSubscriberNotFoundException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class TopicSubscriberNotFoundException extends BaseRuntimeException { public TopicSubscriberNotFoundException(String message) { super(message); diff --git a/src/main/java/com/chat/yourway/exception/ValueNotUniqException.java b/src/main/java/com/chat/yourway/exception/ValueNotUniqException.java index b61c20e8..9a370072 100644 --- a/src/main/java/com/chat/yourway/exception/ValueNotUniqException.java +++ b/src/main/java/com/chat/yourway/exception/ValueNotUniqException.java @@ -1,7 +1,9 @@ package com.chat.yourway.exception; -public class ValueNotUniqException extends RuntimeException { +import com.chat.yourway.exception.handler.BaseRuntimeException; + +public class ValueNotUniqException extends BaseRuntimeException { public ValueNotUniqException(String message) { super(message); } -} +} \ No newline at end of file diff --git a/src/main/java/com/chat/yourway/exception/handler/BaseRuntimeException.java b/src/main/java/com/chat/yourway/exception/handler/BaseRuntimeException.java new file mode 100644 index 00000000..2d2f89ac --- /dev/null +++ b/src/main/java/com/chat/yourway/exception/handler/BaseRuntimeException.java @@ -0,0 +1,23 @@ +package com.chat.yourway.exception.handler; + +public class BaseRuntimeException extends RuntimeException { + public BaseRuntimeException() { + super(); + } + + public BaseRuntimeException(Throwable cause) { + super(cause); + } + + public BaseRuntimeException(String message) { + super(message); + } + + public BaseRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + protected BaseRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java b/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java index 5267e49a..bb491925 100644 --- a/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java +++ b/src/main/java/com/chat/yourway/listener/StompSubscriptionListener.java @@ -45,7 +45,6 @@ public void handleWebSocketUnsubscribeListener(SessionUnsubscribeEvent event) { String email = getEmail(event); if (isTopicDestination(destination)) { - UUID topicId = getTopicId(event); contactOnlineService.setUserOnline(email); log.info("Contact [{}] unsubscribe from [{}]", email, destination); }