From: Kai Moritz Date: Wed, 6 Sep 2023 21:38:15 +0000 (+0200) Subject: refactor: Moved exceptions into package `exceptions` - Moved classes X-Git-Tag: rebase--2023-09-13--21-01~27 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=900c22032c3f83b13fd8526f5e7574a4a87a5be7;p=demos%2Fkafka%2Fchat refactor: Moved exceptions into package `exceptions` - Moved classes --- diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/InvalidUsernameException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/InvalidUsernameException.java deleted file mode 100644 index f9a9b122..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/InvalidUsernameException.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.juplo.kafka.chat.backend.domain; - -import lombok.Getter; - - -public class InvalidUsernameException extends RuntimeException -{ - @Getter - private final String username; - - public InvalidUsernameException(String username) - { - super("Invalid username: " + username); - this.username = username; - } -} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/LoadInProgressException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/LoadInProgressException.java deleted file mode 100644 index d87e76d3..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/LoadInProgressException.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.juplo.kafka.chat.backend.domain; - - -public class LoadInProgressException extends IllegalStateException -{ - public LoadInProgressException() - { - super("Load in progress..."); - } -} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/MessageMutationException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/MessageMutationException.java deleted file mode 100644 index 3f027923..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/MessageMutationException.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.juplo.kafka.chat.backend.domain; - -import lombok.Getter; - - -public class MessageMutationException extends RuntimeException -{ - @Getter - private final Message existing; - @Getter - private final String mutatedText; - - public MessageMutationException(Message existing, String mutatedText) - { - super("Messages are imutable!"); - this.existing = existing; - this.mutatedText = mutatedText; - } -} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/ShardNotOwnedException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/ShardNotOwnedException.java deleted file mode 100644 index 3b638331..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/ShardNotOwnedException.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.juplo.kafka.chat.backend.domain; - -import lombok.Getter; - - -public class ShardNotOwnedException extends IllegalStateException -{ - @Getter - private final int shard; - - - public ShardNotOwnedException(int shard) - { - super("This instance does not own the shard " + shard); - this.shard = shard; - } -} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/UnknownChatroomException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/UnknownChatroomException.java deleted file mode 100644 index 714c2207..00000000 --- a/src/main/java/de/juplo/kafka/chat/backend/domain/UnknownChatroomException.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.juplo.kafka.chat.backend.domain; - -import lombok.Getter; - -import java.util.Arrays; -import java.util.Optional; -import java.util.UUID; -import java.util.stream.Collectors; - - -public class UnknownChatroomException extends IllegalStateException -{ - @Getter - private final UUID chatroomId; - @Getter - private final Optional shard; - @Getter - private final Optional ownedShards; - - public UnknownChatroomException(UUID chatroomId) - { - super("Chatroom does not exist: " + chatroomId); - this.chatroomId = chatroomId; - this.shard = Optional.empty(); - this.ownedShards = Optional.empty(); - } - - public UnknownChatroomException(UUID chatroomId, int shard, int[] ownedShards) - { - super( - "Chatroom does not exist (here): " + - chatroomId + - " shard=" + - shard + - ", owned=" + - Arrays - .stream(ownedShards) - .mapToObj(ownedShard -> Integer.toString(ownedShard)) - .collect(Collectors.joining(","))); - this.chatroomId = chatroomId; - this.shard = Optional.of(shard); - this.ownedShards = Optional.of(ownedShards); - } -} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/InvalidUsernameException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/InvalidUsernameException.java new file mode 100644 index 00000000..f9a9b122 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/InvalidUsernameException.java @@ -0,0 +1,16 @@ +package de.juplo.kafka.chat.backend.domain; + +import lombok.Getter; + + +public class InvalidUsernameException extends RuntimeException +{ + @Getter + private final String username; + + public InvalidUsernameException(String username) + { + super("Invalid username: " + username); + this.username = username; + } +} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/LoadInProgressException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/LoadInProgressException.java new file mode 100644 index 00000000..d87e76d3 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/LoadInProgressException.java @@ -0,0 +1,10 @@ +package de.juplo.kafka.chat.backend.domain; + + +public class LoadInProgressException extends IllegalStateException +{ + public LoadInProgressException() + { + super("Load in progress..."); + } +} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/MessageMutationException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/MessageMutationException.java new file mode 100644 index 00000000..3f027923 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/MessageMutationException.java @@ -0,0 +1,19 @@ +package de.juplo.kafka.chat.backend.domain; + +import lombok.Getter; + + +public class MessageMutationException extends RuntimeException +{ + @Getter + private final Message existing; + @Getter + private final String mutatedText; + + public MessageMutationException(Message existing, String mutatedText) + { + super("Messages are imutable!"); + this.existing = existing; + this.mutatedText = mutatedText; + } +} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/ShardNotOwnedException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/ShardNotOwnedException.java new file mode 100644 index 00000000..3b638331 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/ShardNotOwnedException.java @@ -0,0 +1,17 @@ +package de.juplo.kafka.chat.backend.domain; + +import lombok.Getter; + + +public class ShardNotOwnedException extends IllegalStateException +{ + @Getter + private final int shard; + + + public ShardNotOwnedException(int shard) + { + super("This instance does not own the shard " + shard); + this.shard = shard; + } +} diff --git a/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/UnknownChatroomException.java b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/UnknownChatroomException.java new file mode 100644 index 00000000..714c2207 --- /dev/null +++ b/src/main/java/de/juplo/kafka/chat/backend/domain/exceptions/UnknownChatroomException.java @@ -0,0 +1,44 @@ +package de.juplo.kafka.chat.backend.domain; + +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + + +public class UnknownChatroomException extends IllegalStateException +{ + @Getter + private final UUID chatroomId; + @Getter + private final Optional shard; + @Getter + private final Optional ownedShards; + + public UnknownChatroomException(UUID chatroomId) + { + super("Chatroom does not exist: " + chatroomId); + this.chatroomId = chatroomId; + this.shard = Optional.empty(); + this.ownedShards = Optional.empty(); + } + + public UnknownChatroomException(UUID chatroomId, int shard, int[] ownedShards) + { + super( + "Chatroom does not exist (here): " + + chatroomId + + " shard=" + + shard + + ", owned=" + + Arrays + .stream(ownedShards) + .mapToObj(ownedShard -> Integer.toString(ownedShard)) + .collect(Collectors.joining(","))); + this.chatroomId = chatroomId; + this.shard = Optional.of(shard); + this.ownedShards = Optional.of(ownedShards); + } +}