This is an automated email from the ASF dual-hosted git repository.

matthieu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit aa543390973de8c9e0e975a5be49b7758da5011e
Author: Rémi KOWALSKI <rkowal...@linagora.com>
AuthorDate: Thu Dec 5 17:54:14 2019 +0100

    JAMES-3009 convert to scala cassandra event store
---
 event-sourcing/event-store-cassandra/pom.xml       |  21 ++++
 .../eventstore/cassandra/CassandraEventStore.java  |  64 ------------
 .../eventstore/cassandra/EventStoreDao.java        | 113 ---------------------
 .../cassandra/CassandraEventStore.scala}           |  48 ++++-----
 .../cassandra/CassandraEventStoreModule.scala}     |  35 +++----
 .../cassandra/CassandraEventStoreTable.scala}      |  17 ++--
 .../eventstore/cassandra/EventStoreDao.scala       |  81 +++++++++++++++
 .../eventstore/cassandra/dto/EventDTO.scala}       |   8 +-
 .../eventstore/cassandra/dto/EventDTOModule.scala} |  31 +++---
 .../CassandraEventSourcingSystemTest.java          |   2 +-
 .../cassandra/CassandraEventStoreExtension.java    |   2 +-
 .../cassandra/CassandraEventStoreTest.java         |   2 +-
 .../cassandra/JsonEventSerializerTest.java         |  12 +--
 .../cassandra/dto/OtherTestEventDTO.java           |  70 -------------
 .../eventstore/cassandra/dto/TestEventDTO.java     |  71 -------------
 .../cassandra/dto/TestEventDTOModules.java         |  51 ----------
 .../eventstore/cassandra/dto/OtherEvent.scala}     |  15 +--
 .../cassandra/dto/OtherTestEventDTO.scala          |  37 +++++++
 .../eventstore/cassandra/dto/TestEventDTO.scala}   |  35 ++++---
 .../cassandra/dto/TestEventDTOModules.scala}       |  30 +++++-
 .../apache/james/json/JsonGenericSerializer.java   |   2 +-
 .../eventsourcing/distributed/TaskEventDTO.scala   |   1 -
 22 files changed, 262 insertions(+), 486 deletions(-)

diff --git a/event-sourcing/event-store-cassandra/pom.xml 
b/event-sourcing/event-store-cassandra/pom.xml
index 97fb315..f091c06 100644
--- a/event-sourcing/event-store-cassandra/pom.xml
+++ b/event-sourcing/event-store-cassandra/pom.xml
@@ -79,6 +79,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>io.projectreactor</groupId>
+            <artifactId>reactor-scala-extensions_2.13</artifactId>
+            <version>0.5.0</version>
+        </dependency>
+        <dependency>
             <groupId>net.javacrumbs.json-unit</groupId>
             <artifactId>json-unit-assertj</artifactId>
             <scope>test</scope>
@@ -93,7 +98,23 @@
             <artifactId>testcontainers</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.scala-lang</groupId>
+            <artifactId>scala-library</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.scala-lang.modules</groupId>
+            <artifactId>scala-java8-compat_${scala.base}</artifactId>
+        </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>net.alchim31.maven</groupId>
+                <artifactId>scala-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
 
 
 </project>
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStore.java
 
b/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStore.java
deleted file mode 100644
index 79f6646..0000000
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStore.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.eventsourcing.eventstore.cassandra;
-
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.james.eventsourcing.AggregateId;
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.eventstore.EventStore;
-import org.apache.james.eventsourcing.eventstore.EventStoreFailedException;
-import org.apache.james.eventsourcing.eventstore.History;
-
-import com.google.common.base.Preconditions;
-
-public class CassandraEventStore implements EventStore {
-
-    private final EventStoreDao eventStoreDao;
-
-    @Inject
-    public CassandraEventStore(EventStoreDao eventStoreDao) {
-        this.eventStoreDao = eventStoreDao;
-    }
-
-    @Override
-    public void appendAll(List<Event> events) {
-        if (events.isEmpty()) {
-            return;
-        }
-        doAppendAll(events);
-    }
-
-    public void doAppendAll(List<Event> events) {
-        Preconditions.checkArgument(Event.belongsToSameAggregate(events));
-
-        boolean success = eventStoreDao.appendAll(events).block();
-        if (!success) {
-            throw new EventStoreFailedException("Concurrent update to the 
EventStore detected");
-        }
-    }
-
-    @Override
-    public History getEventsOfAggregate(AggregateId aggregateId) {
-        return eventStoreDao.getEventsOfAggregate(aggregateId);
-    }
-}
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/EventStoreDao.java
 
b/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/EventStoreDao.java
deleted file mode 100644
index b022ca7..0000000
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/EventStoreDao.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.eventsourcing.eventstore.cassandra;
-
-import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;
-import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
-import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto;
-import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
-import static 
org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreTable.AGGREGATE_ID;
-import static 
org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreTable.EVENT;
-import static 
org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreTable.EVENTS_TABLE;
-import static 
org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreTable.EVENT_ID;
-
-import java.io.IOException;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
-import org.apache.james.eventsourcing.AggregateId;
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.eventstore.History;
-
-import com.datastax.driver.core.BatchStatement;
-import com.datastax.driver.core.BoundStatement;
-import com.datastax.driver.core.PreparedStatement;
-import com.datastax.driver.core.Row;
-import com.datastax.driver.core.Session;
-import com.fasterxml.jackson.core.JsonProcessingException;
-
-import reactor.core.publisher.Mono;
-
-public class EventStoreDao {
-    private final CassandraAsyncExecutor cassandraAsyncExecutor;
-    private final PreparedStatement insert;
-    private final PreparedStatement select;
-    private final JsonEventSerializer jsonEventSerializer;
-
-    @Inject
-    public EventStoreDao(Session session, JsonEventSerializer 
jsonEventSerializer) {
-        this.cassandraAsyncExecutor = new CassandraAsyncExecutor(session);
-        this.jsonEventSerializer = jsonEventSerializer;
-        this.insert = prepareInsert(session);
-        this.select = prepareSelect(session);
-    }
-
-    private PreparedStatement prepareInsert(Session session) {
-        return session.prepare(insertInto(EVENTS_TABLE)
-            .value(AGGREGATE_ID, bindMarker(AGGREGATE_ID))
-            .value(EVENT_ID, bindMarker(EVENT_ID))
-            .value(EVENT, bindMarker(EVENT))
-            .ifNotExists());
-    }
-
-    private PreparedStatement prepareSelect(Session session) {
-        return session.prepare(select()
-            .from(EVENTS_TABLE)
-            .where(eq(AGGREGATE_ID, bindMarker(AGGREGATE_ID))));
-    }
-
-    public Mono<Boolean> appendAll(List<Event> events) {
-        BatchStatement batch = new BatchStatement();
-        events.forEach(event -> batch.add(insertEvent(event)));
-        return cassandraAsyncExecutor.executeReturnApplied(batch);
-    }
-
-    private BoundStatement insertEvent(Event event) {
-        try {
-            return insert
-                .bind()
-                .setString(AGGREGATE_ID, 
event.getAggregateId().asAggregateKey())
-                .setInt(EVENT_ID, event.eventId().serialize())
-                .setString(EVENT, jsonEventSerializer.serialize(event));
-        } catch (JsonProcessingException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    public History getEventsOfAggregate(AggregateId aggregateId) {
-        return cassandraAsyncExecutor.executeRows(
-                select.bind()
-                    .setString(AGGREGATE_ID, aggregateId.asAggregateKey()))
-            .map(this::toEvent)
-            .collectList()
-            .map(History::of)
-            .block();
-    }
-
-    private Event toEvent(Row row) {
-        try {
-            return jsonEventSerializer.deserialize(row.getString(EVENT));
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
-}
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherEvent.java
 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStore.scala
similarity index 53%
rename from 
event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherEvent.java
rename to 
event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStore.scala
index 1b21a36..6c41973 100644
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherEvent.java
+++ 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStore.scala
@@ -7,7 +7,7 @@
  * "License"); you may not use this file except in compliance   *
  * with the License.  You may obtain a copy of the License at   *
  *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *  http://www.apache.org/licenses/LICENSE-2.0                  *
  *                                                              *
  * Unless required by applicable law or agreed to in writing,   *
  * software distributed under the License is distributed on an  *
@@ -16,35 +16,29 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra
 
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
+import com.google.common.base.Preconditions
+import javax.inject.Inject
+import org.apache.james.eventsourcing.eventstore.{EventStore, 
EventStoreFailedException, History}
+import org.apache.james.eventsourcing.{AggregateId, Event}
 
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.EventId;
-import org.apache.james.eventsourcing.TestAggregateId;
-
-public class OtherEvent implements Event {
-    private final EventId eventId;
-    private final TestAggregateId aggregateId;
-    private final long payload;
-
-    public OtherEvent(EventId eventId, TestAggregateId aggregateId, long 
payload) {
-        this.eventId = eventId;
-        this.aggregateId = aggregateId;
-        this.payload = payload;
+class CassandraEventStore @Inject() (eventStoreDao: EventStoreDao) extends 
EventStore {
+  override def appendAll(events: List[Event]): Unit = {
+    if (events.nonEmpty) {
+      doAppendAll(events)
     }
+  }
 
-    @Override
-    public EventId eventId() {
-        return eventId;
+  private def doAppendAll(events: List[Event]): Unit = {
+    Preconditions.checkArgument(Event.belongsToSameAggregate(events))
+    val success: Boolean = eventStoreDao.appendAll(events).block()
+    if (!success) {
+      throw EventStoreFailedException("Concurrent update to the EventStore 
detected")
     }
+  }
 
-    @Override
-    public TestAggregateId getAggregateId() {
-        return aggregateId;
-    }
-
-    public long getPayload() {
-        return payload;
-    }
-}
+  override def getEventsOfAggregate(aggregateId: AggregateId): History = {
+    eventStoreDao.getEventsOfAggregate(aggregateId).block()
+  }
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreModule.java
 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreModule.scala
similarity index 60%
rename from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreModule.java
rename to 
event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreModule.scala
index 17c147a..189be31 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreModule.java
+++ 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreModule.scala
@@ -16,24 +16,21 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra
 
-package org.apache.james.eventsourcing.eventstore.cassandra;
+import org.apache.james.backends.cassandra.components.CassandraModule
+import org.apache.james.backends.cassandra.utils.CassandraConstants
+import com.datastax.driver.core.DataType
+import com.datastax.driver.core.schemabuilder.{Create, SchemaBuilder}
 
-import org.apache.james.backends.cassandra.components.CassandraModule;
-import org.apache.james.backends.cassandra.utils.CassandraConstants;
-
-import com.datastax.driver.core.DataType;
-import com.datastax.driver.core.schemabuilder.SchemaBuilder;
-
-public interface CassandraEventStoreModule {
-    CassandraModule MODULE = 
CassandraModule.table(CassandraEventStoreTable.EVENTS_TABLE)
-        .comment("Store events of a EventSourcing aggregate")
-        .options(options -> options
-            .caching(SchemaBuilder.KeyCaching.ALL,
-                
SchemaBuilder.rows(CassandraConstants.DEFAULT_CACHED_ROW_PER_PARTITION)))
-        .statement(statement -> statement
-            .addPartitionKey(CassandraEventStoreTable.AGGREGATE_ID, 
DataType.varchar())
-            .addClusteringColumn(CassandraEventStoreTable.EVENT_ID, 
DataType.cint())
-            .addColumn(CassandraEventStoreTable.EVENT, DataType.text()))
-        .build();
-}
+object CassandraEventStoreModule {
+  val MODULE = CassandraModule.table(CassandraEventStoreTable.EVENTS_TABLE)
+    .comment("Store events of a EventSourcing aggregate")
+    .options((options: Create.Options) => options.caching(
+      SchemaBuilder.KeyCaching.ALL,
+      SchemaBuilder.rows(CassandraConstants.DEFAULT_CACHED_ROW_PER_PARTITION)))
+    .statement(_.addPartitionKey(CassandraEventStoreTable.AGGREGATE_ID, 
DataType.varchar)
+      .addClusteringColumn(CassandraEventStoreTable.EVENT_ID, DataType.cint)
+      .addColumn(CassandraEventStoreTable.EVENT, DataType.text))
+    .build
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTable.java
 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTable.scala
similarity index 78%
rename from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTable.java
rename to 
event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTable.scala
index fb4575b..1b901e2 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTable.java
+++ 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTable.scala
@@ -1,4 +1,4 @@
-/****************************************************************
+ /***************************************************************
  * Licensed to the Apache Software Foundation (ASF) under one   *
  * or more contributor license agreements.  See the NOTICE file *
  * distributed with this work for additional information        *
@@ -16,12 +16,11 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra
 
-package org.apache.james.eventsourcing.eventstore.cassandra;
-
-public interface CassandraEventStoreTable {
-    String EVENTS_TABLE = "eventStore";
-    String AGGREGATE_ID = "aggregateId";
-    String EVENT = "event";
-    String EVENT_ID = "eventId";
-}
+object CassandraEventStoreTable {
+  val EVENTS_TABLE = "eventStore"
+  val AGGREGATE_ID = "aggregateId"
+  val EVENT = "event"
+  val EVENT_ID = "eventId"
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/EventStoreDao.scala
 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/EventStoreDao.scala
new file mode 100644
index 0000000..acac08b
--- /dev/null
+++ 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/EventStoreDao.scala
@@ -0,0 +1,81 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra
+
+import com.datastax.driver.core._
+import com.datastax.driver.core.querybuilder.QueryBuilder
+import com.datastax.driver.core.querybuilder.QueryBuilder.{bindMarker, 
insertInto}
+import javax.inject.Inject
+import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor
+import org.apache.james.eventsourcing.eventstore.History
+import 
org.apache.james.eventsourcing.eventstore.cassandra.CassandraEventStoreTable.{AGGREGATE_ID,
 EVENT, EVENTS_TABLE, EVENT_ID}
+import org.apache.james.eventsourcing.{AggregateId, Event}
+import reactor.core.scala.publisher.{SFlux, SMono}
+
+class EventStoreDao @Inject() (val session: Session, val jsonEventSerializer: 
JsonEventSerializer) {
+  private val cassandraAsyncExecutor = new CassandraAsyncExecutor(session)
+  private val insert = prepareInsert(session)
+  private val select = prepareSelect(session)
+
+  private def prepareInsert(session: Session): PreparedStatement = {
+    session.prepare(
+      insertInto(EVENTS_TABLE)
+        .value(AGGREGATE_ID, bindMarker(AGGREGATE_ID))
+        .value(EVENT_ID, bindMarker(EVENT_ID))
+        .value(EVENT, bindMarker(EVENT))
+        .ifNotExists)
+  }
+
+  private def prepareSelect(session: Session): PreparedStatement = {
+    session.prepare(QueryBuilder
+      .select()
+      .from(EVENTS_TABLE)
+      .where(QueryBuilder.eq(AGGREGATE_ID, bindMarker(AGGREGATE_ID))))
+  }
+
+  private[cassandra] def appendAll(events: List[Event]): SMono[Boolean] = {
+    val batch: BatchStatement = new BatchStatement
+    events.foreach((event: Event) => batch.add(insertEvent(event)))
+    SMono(cassandraAsyncExecutor.executeReturnApplied(batch))
+      .map(_.booleanValue())
+  }
+
+  private def insertEvent(event: Event): BoundStatement = {
+    insert
+      .bind
+      .setString(AGGREGATE_ID, event.getAggregateId.asAggregateKey)
+      .setInt(EVENT_ID, event.eventId.serialize)
+      .setString(EVENT, jsonEventSerializer.serialize(event))
+  }
+
+  private[cassandra] def getEventsOfAggregate(aggregateId: AggregateId): 
SMono[History] = {
+    val preparedStatement = select.bind.setString(AGGREGATE_ID, 
aggregateId.asAggregateKey)
+    val rows: SFlux[Row] = 
SFlux[Row](cassandraAsyncExecutor.executeRows(preparedStatement))
+
+    val events: SFlux[Event] = rows.map(toEvent)
+    val listEvents: SMono[List[Event]] = events.collectSeq()
+      .map(_.toList)
+
+    listEvents.map(History.of)
+  }
+
+  private def toEvent(row: Row): Event = {
+    jsonEventSerializer.deserialize(row.getString(EVENT))
+  }
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.scala
similarity index 89%
copy from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
copy to 
event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.scala
index 8e849c1..39ef2ac 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
+++ 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.scala
@@ -16,10 +16,8 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra.dto
 
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
+import org.apache.james.json.DTO
 
-import org.apache.james.json.DTO;
-
-public interface EventDTO extends DTO {
-}
+trait EventDTO extends DTO
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.scala
similarity index 57%
copy from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
copy to 
event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.scala
index fc0d675..86234a4 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
+++ 
b/event-sourcing/event-store-cassandra/src/main/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.scala
@@ -16,24 +16,19 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra.dto
 
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
+import org.apache.james.eventsourcing.Event
+import org.apache.james.json.DTOModule
 
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.json.DTOModule;
-
-public class EventDTOModule<T extends Event, U extends EventDTO> extends 
DTOModule<T, U> {
-
-    public static <EventTypeT extends Event> DTOModule.Builder<EventTypeT> 
forEvent(Class<EventTypeT> eventType) {
-        return new DTOModule.Builder<>(eventType);
-    }
-
-    public EventDTOModule(DTOConverter<T, U> converter, 
DomainObjectConverter<T, U> toDomainObjectConverter, Class<T> domainObjectType, 
Class<U> dtoType, String typeName) {
-        super(converter, toDomainObjectConverter, domainObjectType, dtoType, 
typeName);
-    }
-
-    @Override
-    public U toDTO(T domainObject) {
-        return super.toDTO(domainObject);
-    }
+object EventDTOModule {
+  def forEvent[EventTypeT <: Event](eventType: Class[EventTypeT]) = new 
DTOModule.Builder[EventTypeT](eventType)
 }
+
+case class EventDTOModule[T <: Event, U <: EventDTO](converter: 
DTOModule.DTOConverter[T, U],
+                                                     toDomainObjectConverter: 
DTOModule.DomainObjectConverter[T, U],
+                                                     domainObjectType: 
Class[T],
+                                                     dtoType: Class[U],
+                                                     typeName: String) extends 
DTOModule[T, U](converter, toDomainObjectConverter, domainObjectType, dtoType, 
typeName) {
+  override def toDTO(domainObject: T) : U = super.toDTO(domainObject)
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventSourcingSystemTest.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventSourcingSystemTest.java
index 6858b2d..4a20058 100644
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventSourcingSystemTest.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventSourcingSystemTest.java
@@ -25,5 +25,5 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 public class CassandraEventSourcingSystemTest implements 
EventSourcingSystemTest {
     @RegisterExtension
-    static CassandraEventStoreExtension eventStoreExtension = new 
CassandraEventStoreExtension(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE).withoutNestedType());
+    static CassandraEventStoreExtension eventStoreExtension = new 
CassandraEventStoreExtension(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE()).withoutNestedType());
 }
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.java
index d338495..d319d8f 100644
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.java
@@ -37,7 +37,7 @@ public class CassandraEventStoreExtension implements 
BeforeAllCallback, AfterAll
     private EventStoreDao eventStoreDao;
 
     public CassandraEventStoreExtension(JsonEventSerializer eventSerializer) {
-        this(new CassandraClusterExtension(CassandraEventStoreModule.MODULE), 
eventSerializer);
+        this(new 
CassandraClusterExtension(CassandraEventStoreModule.MODULE()), eventSerializer);
     }
 
     public CassandraEventStoreExtension(CassandraClusterExtension cassandra, 
JsonEventSerializer eventSerializer) {
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTest.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTest.java
index 562bd9b..316195c 100644
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTest.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreTest.java
@@ -25,5 +25,5 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 
 class CassandraEventStoreTest implements EventStoreTest {
     @RegisterExtension
-    static CassandraEventStoreExtension eventStoreExtension = new 
CassandraEventStoreExtension(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE).withoutNestedType());
+    static CassandraEventStoreExtension eventStoreExtension = new 
CassandraEventStoreExtension(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE()).withoutNestedType());
 }
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.java
index d0d6c65..45b7b61 100644
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.java
@@ -44,7 +44,7 @@ class JsonEventSerializerTest {
 
     @Test
     void shouldDeserializeKnownEvent() throws Exception {
-        
assertThat(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE).withoutNestedType()
+        
assertThat(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE()).withoutNestedType()
             .deserialize(TEST_EVENT_JSON))
             .isEqualTo(TEST_EVENT);
     }
@@ -59,7 +59,7 @@ class JsonEventSerializerTest {
     @Test
     void serializeShouldHandleAllKnownEvents() throws Exception {
         JsonEventSerializer jsonEventSerializer = JsonEventSerializer
-            .forModules(TestEventDTOModules.TEST_TYPE, 
TestEventDTOModules.OTHER_TEST_TYPE)
+            .forModules(TestEventDTOModules.TEST_TYPE(), 
TestEventDTOModules.OTHER_TEST_TYPE())
             .withoutNestedType();
 
         assertThatJson(
@@ -74,7 +74,7 @@ class JsonEventSerializerTest {
     @Test
     void deserializeShouldHandleAllKnownEvents() throws Exception {
         JsonEventSerializer jsonEventSerializer = JsonEventSerializer
-            .forModules(TestEventDTOModules.TEST_TYPE, 
TestEventDTOModules.OTHER_TEST_TYPE)
+            .forModules(TestEventDTOModules.TEST_TYPE(), 
TestEventDTOModules.OTHER_TEST_TYPE())
             .withoutNestedType();
 
         assertThatJson(
@@ -90,7 +90,7 @@ class JsonEventSerializerTest {
     @Test
     void deserializeShouldThrowWhenEventWithDuplicatedTypes() {
         assertThatThrownBy(() -> JsonEventSerializer
-            .forModules(TestEventDTOModules.TEST_TYPE, 
TestEventDTOModules.OTHER_TEST_TYPE)
+            .forModules(TestEventDTOModules.TEST_TYPE(), 
TestEventDTOModules.OTHER_TEST_TYPE())
             .withoutNestedType()
             .deserialize(DUPLICATE_TYPE_EVENT_JSON))
             .isInstanceOf(JsonEventSerializer.InvalidEventException.class);
@@ -99,7 +99,7 @@ class JsonEventSerializerTest {
     @Test
     void deserializeShouldThrowWhenEventWithMissingType() {
         assertThatThrownBy(() -> JsonEventSerializer
-            .forModules(TestEventDTOModules.TEST_TYPE, 
TestEventDTOModules.OTHER_TEST_TYPE)
+            .forModules(TestEventDTOModules.TEST_TYPE(), 
TestEventDTOModules.OTHER_TEST_TYPE())
             .withoutNestedType()
             .deserialize(MISSING_TYPE_EVENT_JSON))
             .isInstanceOf(JsonEventSerializer.InvalidEventException.class);
@@ -107,7 +107,7 @@ class JsonEventSerializerTest {
 
     @Test
     void shouldSerializeKnownEvent() throws Exception {
-        
assertThatJson(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE).withoutNestedType()
+        
assertThatJson(JsonEventSerializer.forModules(TestEventDTOModules.TEST_TYPE()).withoutNestedType()
             .serialize(TEST_EVENT))
             .isEqualTo(TEST_EVENT_JSON);
     }
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTO.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTO.java
deleted file mode 100644
index cb68fd6..0000000
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTO.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
-
-import org.apache.james.eventsourcing.EventId;
-import org.apache.james.eventsourcing.TestAggregateId;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class OtherTestEventDTO implements EventDTO {
-    private final String type;
-    private final long data;
-    private final int eventId;
-    private final int aggregate;
-
-    @JsonCreator
-    public OtherTestEventDTO(
-            @JsonProperty("type") String type,
-            @JsonProperty("data") long data,
-            @JsonProperty("eventId") int eventId,
-            @JsonProperty("aggregate") int aggregate) {
-        this.type = type;
-        this.data = data;
-        this.eventId = eventId;
-        this.aggregate = aggregate;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public long getData() {
-        return data;
-    }
-
-    public long getEventId() {
-        return eventId;
-    }
-
-    public int getAggregate() {
-        return aggregate;
-    }
-
-    @JsonIgnore
-    public OtherEvent toEvent() {
-        return new OtherEvent(
-            EventId.fromSerialized(eventId),
-            TestAggregateId.testId(aggregate),
-            data);
-    }
-}
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTO.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTO.java
deleted file mode 100644
index 6274387..0000000
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTO.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
-
-import org.apache.james.eventsourcing.EventId;
-import org.apache.james.eventsourcing.TestAggregateId;
-import org.apache.james.eventsourcing.TestEvent;
-
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class TestEventDTO implements EventDTO {
-    private final String type;
-    private final String data;
-    private final int eventId;
-    private final int aggregate;
-
-    @JsonCreator
-    public TestEventDTO(
-            @JsonProperty("type") String type,
-            @JsonProperty("data") String data,
-            @JsonProperty("eventId") int eventId,
-            @JsonProperty("aggregate") int aggregate) {
-        this.type = type;
-        this.data = data;
-        this.eventId = eventId;
-        this.aggregate = aggregate;
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public String getData() {
-        return data;
-    }
-
-    public long getEventId() {
-        return eventId;
-    }
-
-    public int getAggregate() {
-        return aggregate;
-    }
-
-    @JsonIgnore
-    public TestEvent toEvent() {
-        return new TestEvent(
-            EventId.fromSerialized(eventId),
-            TestAggregateId.testId(aggregate),
-            data);
-    }
-}
diff --git 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.java
 
b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.java
deleted file mode 100644
index dc51583..0000000
--- 
a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
-
-import org.apache.james.eventsourcing.TestEvent;
-
-public interface TestEventDTOModules {
-
-
-    EventDTOModule<?, ?> TEST_TYPE = EventDTOModule
-            .forEvent(TestEvent.class)
-            .convertToDTO(TestEventDTO.class)
-            .toDomainObjectConverter(TestEventDTO::toEvent)
-            .toDTOConverter((event, typeName) -> new TestEventDTO(
-                typeName,
-                event.getData(),
-                event.eventId().serialize(),
-                event.getAggregateId().getId()))
-            .typeName("TestType")
-            .withFactory(EventDTOModule::new);
-
-    EventDTOModule<?, ?> OTHER_TEST_TYPE =
-        EventDTOModule
-            .forEvent(OtherEvent.class)
-            .convertToDTO(OtherTestEventDTO.class)
-            .toDomainObjectConverter(OtherTestEventDTO::toEvent)
-            .toDTOConverter((event, typeName) -> new OtherTestEventDTO(
-                typeName,
-                event.getPayload(),
-                event.eventId().serialize(),
-                event.getAggregateId().getId()))
-            .typeName("other-type")
-            .withFactory(EventDTOModule::new);
-}
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherEvent.scala
similarity index 69%
copy from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
copy to 
event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherEvent.scala
index 8e849c1..7940c1c 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherEvent.scala
@@ -7,7 +7,7 @@
  * "License"); you may not use this file except in compliance   *
  * with the License.  You may obtain a copy of the License at   *
  *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
  *                                                              *
  * Unless required by applicable law or agreed to in writing,   *
  * software distributed under the License is distributed on an  *
@@ -15,11 +15,14 @@
  * KIND, either express or implied.  See the License for the    *
  * specific language governing permissions and limitations      *
  * under the License.                                           *
- ****************************************************************/
+ * ***************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra.dto
 
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
+import org.apache.james.eventsourcing.{Event, EventId, TestAggregateId}
 
-import org.apache.james.json.DTO;
+final case class OtherEvent(override val eventId: EventId, aggregateId: 
TestAggregateId, payload: Long) extends Event {
 
-public interface EventDTO extends DTO {
-}
+  override def getAggregateId = aggregateId
+
+  def getPayload = payload
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTO.scala
 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTO.scala
new file mode 100644
index 0000000..9515670
--- /dev/null
+++ 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTO.scala
@@ -0,0 +1,37 @@
+/** **************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ * ***************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra.dto
+
+import com.fasterxml.jackson.annotation.{JsonCreator, JsonIgnore, JsonProperty}
+import org.apache.james.eventsourcing.{EventId, TestAggregateId}
+
+case class OtherTestEventDTO @JsonCreator()(
+                                             @JsonProperty("type") `type`: 
String,
+                                             @JsonProperty("data") data: Long,
+                                             @JsonProperty("eventId") eventId: 
Int,
+                                             @JsonProperty("aggregate") 
aggregate: Int) extends EventDTO {
+  override def getType: String = `type`
+  def getData: Long = data
+  def getEventId: Long = eventId
+
+  def getAggregate: Int = aggregate
+
+  @JsonIgnore def toEvent: OtherEvent = 
OtherEvent(EventId.fromSerialized(eventId), TestAggregateId.testId(aggregate), 
data)
+
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTO.scala
similarity index 52%
rename from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
rename to 
event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTO.scala
index fc0d675..761f68a 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTO.scala
@@ -7,7 +7,7 @@
  * "License"); you may not use this file except in compliance   *
  * with the License.  You may obtain a copy of the License at   *
  *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ * http://www.apache.org/licenses/LICENSE-2.0                   *
  *                                                              *
  * Unless required by applicable law or agreed to in writing,   *
  * software distributed under the License is distributed on an  *
@@ -15,25 +15,24 @@
  * KIND, either express or implied.  See the License for the    *
  * specific language governing permissions and limitations      *
  * under the License.                                           *
- ****************************************************************/
+ * ***************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra.dto
 
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
+import com.fasterxml.jackson.annotation.{JsonCreator, JsonIgnore, JsonProperty}
+import org.apache.james.eventsourcing.{EventId, TestAggregateId, TestEvent}
 
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.json.DTOModule;
-
-public class EventDTOModule<T extends Event, U extends EventDTO> extends 
DTOModule<T, U> {
+final case class TestEventDTO @JsonCreator() ( @JsonProperty("type") `type`: 
String,
+                                    @JsonProperty("data") data: String,
+                                    @JsonProperty("eventId") eventId: Int,
+                                    @JsonProperty("aggregate") aggregate: Int) 
extends EventDTO {
+  override def getType: String = {
+  `type`
+}
+  def getData: String = data
 
-    public static <EventTypeT extends Event> DTOModule.Builder<EventTypeT> 
forEvent(Class<EventTypeT> eventType) {
-        return new DTOModule.Builder<>(eventType);
-    }
+  def getEventId: Long = eventId
 
-    public EventDTOModule(DTOConverter<T, U> converter, 
DomainObjectConverter<T, U> toDomainObjectConverter, Class<T> domainObjectType, 
Class<U> dtoType, String typeName) {
-        super(converter, toDomainObjectConverter, domainObjectType, dtoType, 
typeName);
-    }
+  def getAggregate: Int = aggregate
 
-    @Override
-    public U toDTO(T domainObject) {
-        return super.toDTO(domainObject);
-    }
-}
+  @JsonIgnore def toEvent: TestEvent = new TestEvent(EventId.fromSerialized 
(eventId), TestAggregateId.testId (aggregate), data)
+}
\ No newline at end of file
diff --git 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.scala
similarity index 52%
rename from 
event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
rename to 
event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.scala
index 8e849c1..93d3d47 100644
--- 
a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTO.java
+++ 
b/event-sourcing/event-store-cassandra/src/test/scala/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.scala
@@ -16,10 +16,32 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
+package org.apache.james.eventsourcing.eventstore.cassandra.dto
 
-package org.apache.james.eventsourcing.eventstore.cassandra.dto;
+import org.apache.james.eventsourcing.TestEvent
+import org.apache.james.json.DTOModule
 
-import org.apache.james.json.DTO;
+object TestEventDTOModules {
+  val TEST_TYPE: EventDTOModule[TestEvent, TestEventDTO] = 
EventDTOModule.forEvent(classOf[TestEvent])
+    .convertToDTO(classOf[TestEventDTO]).toDomainObjectConverter(_.toEvent)
+    .toDTOConverter((event: TestEvent, typeName: String) => TestEventDTO(
+      typeName,
+      event.getData,
+      event.eventId.serialize,
+      event.getAggregateId.getId))
+    .typeName("TestType")
+    .withFactory(EventDTOModule.apply)
 
-public interface EventDTO extends DTO {
-}
+
+  val OTHER_TEST_TYPE: EventDTOModule[OtherEvent, OtherTestEventDTO] = 
EventDTOModule
+    .forEvent(classOf[OtherEvent])
+    .convertToDTO(classOf[OtherTestEventDTO])
+    .toDomainObjectConverter(_.toEvent)
+    .toDTOConverter((event: OtherEvent, typeName: String) => OtherTestEventDTO(
+      typeName,
+      event.getPayload,
+      event.eventId.serialize,
+      event.getAggregateId.getId))
+    .typeName("other-type")
+    .withFactory(EventDTOModule.apply)
+}
\ No newline at end of file
diff --git 
a/json/src/main/java/org/apache/james/json/JsonGenericSerializer.java 
b/json/src/main/java/org/apache/james/json/JsonGenericSerializer.java
index 6ebb443..371e887 100644
--- a/json/src/main/java/org/apache/james/json/JsonGenericSerializer.java
+++ b/json/src/main/java/org/apache/james/json/JsonGenericSerializer.java
@@ -44,7 +44,7 @@ import com.google.common.collect.Sets;
 
 public class JsonGenericSerializer<T, U extends DTO> {
 
-    public static <T, U extends DTO> RequireNestedConfiguration<T, U> 
forModules(Set<? extends DTOModule<? extends T, ? extends U>> modules) {
+    public static <T, U extends DTO> RequireNestedConfiguration<T, U> 
forModules(java.util.Set<? extends DTOModule<? extends T, ? extends U>> 
modules) {
         return nestedTypesModules -> {
             ImmutableSet<DTOModule<? extends T, ? extends U>> dtoModules = 
ImmutableSet.copyOf(modules);
             return new JsonGenericSerializer<>(dtoModules, 
ImmutableSet.copyOf(nestedTypesModules), new DTOConverter<>(dtoModules));
diff --git 
a/server/task/task-distributed/src/main/scala/org/apache/james/task/eventsourcing/distributed/TaskEventDTO.scala
 
b/server/task/task-distributed/src/main/scala/org/apache/james/task/eventsourcing/distributed/TaskEventDTO.scala
index fa058c1..ed7b9e6 100644
--- 
a/server/task/task-distributed/src/main/scala/org/apache/james/task/eventsourcing/distributed/TaskEventDTO.scala
+++ 
b/server/task/task-distributed/src/main/scala/org/apache/james/task/eventsourcing/distributed/TaskEventDTO.scala
@@ -24,7 +24,6 @@ import java.util.function.Function
 
 import com.fasterxml.jackson.annotation.JsonProperty
 import org.apache.james.eventsourcing.EventId
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO
 import org.apache.james.json.DTOConverter
 import org.apache.james.server.task.json.JsonTaskSerializer
 import org.apache.james.server.task.json.dto.{AdditionalInformationDTO, 
TaskDTO}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to