WIP
authorKai Moritz <kai@juplo.de>
Mon, 9 Jan 2023 22:25:22 +0000 (23:25 +0100)
committerKai Moritz <kai@juplo.de>
Mon, 9 Jan 2023 22:25:22 +0000 (23:25 +0100)
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MessageTo.java
src/main/java/de/juplo/kafka/chat/backend/persistence/storage/mongodb/MongoDbStorageStrategy.java

index 1eef273..c61a1cc 100644 (file)
@@ -17,7 +17,7 @@ import java.util.regex.Pattern;
 @ToString(of = { "user", "id" })
 class MessageTo
 {
-  final static Pattern SPLIT_ID = Pattern.compile("^([a-z-]+)--([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$");
+  final static Pattern SPLIT_ID = Pattern.compile("^([a-z-]+)--([0-9]+)$");
   private String id;
   private Long serial;
   private LocalDateTime time;
@@ -28,19 +28,18 @@ class MessageTo
     Matcher matcher = SPLIT_ID.matcher(id);
     if (!matcher.matches())
       throw new RuntimeException("MessageTo with invalid ID: " + id);
-    UUID uuid = UUID.fromString(matcher.group(2));
+    Long messageId = Long.parseLong(matcher.group(2));
     String user = matcher.group(1);
-    return new Message(Message.MessageKey.of(user, uuid), serial, time, text);
+    return new Message(Message.MessageKey.of(user, messageId), serial, time, text);
   }
 
   static MessageTo from(Message message)
   {
     return
         new MessageTo(
-            message.getId(),
+            message.getId() + "--" + message.getUsername(),
             message.getSerialNumber(),
             message.getTimestamp(),
-            message.getUsername(),
             message.getMessageText());
   }
 }
index 200e323..ac249fc 100644 (file)
@@ -1,6 +1,5 @@
 package de.juplo.kafka.chat.backend.persistence.storage.mongodb;
 
-import de.juplo.kafka.chat.backend.api.ChatRoomTo;
 import de.juplo.kafka.chat.backend.domain.ChatRoom;
 import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
 import reactor.core.publisher.Flux;
@@ -15,42 +14,9 @@ public class MongoDbStorageStrategy implements StorageStrategy
   {
     chatroomFlux
         .log()
-        .doFirst(() ->
-        {
-          try
-          {
-            generator.useDefaultPrettyPrinter();
-            generator.writeStartArray();
-          }
-          catch (IOException e)
-          {
-            throw new RuntimeException(e);
-          }
-        })
-        .doOnTerminate(() ->
-        {
-          try
-          {
-            generator.writeEndArray();
-            generator.close();
-          }
-          catch (IOException e)
-          {
-            throw new RuntimeException(e);
-          }
-        })
+        .map(ChatRoomTo::from)
         .subscribe(chatroom ->
         {
-          try
-          {
-            ChatRoomTo chatroomTo = ChatRoomTo.from(chatroom);
-            generator.writeObject(chatroomTo);
-            writeMessages(chatroomTo, chatroom.getMessages());
-          }
-          catch (IOException e)
-          {
-            throw new RuntimeException(e);
-          }
         });
   }
     catch (IOException e)