You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2018/08/24 11:59:51 UTC
[1/2] james-project git commit: JAMES-2527 implements the
FilteringManagementContract with a Cassandra Event Store
Repository: james-project
Updated Branches:
refs/heads/master 8bfefda83 -> a999bd604
JAMES-2527 implements the FilteringManagementContract with a Cassandra Event Store
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8659a18e
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8659a18e
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8659a18e
Branch: refs/heads/master
Commit: 8659a18e06da878c1c90552c43d63e7536aa6699
Parents: 8bfefda
Author: Matthieu Baechler <ma...@apache.org>
Authored: Wed Aug 22 17:46:24 2018 +0200
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Fri Aug 24 11:19:23 2018 +0200
----------------------------------------------------------------------
event-sourcing/event-store-cassandra/pom.xml | 4 +
.../cassandra/JsonEventSerializer.java | 2 +
server/data/data-jmap-cassandra/pom.xml | 30 +++++-
.../FilteringRuleSetDefineDTOModule.java | 52 ++++++++++
.../filtering/FilteringRuleSetDefinedDTO.java | 102 +++++++++++++++++++
.../james/jmap/cassandra/filtering/RuleDTO.java | 87 ++++++++++++++++
...draEventSourcingFilteringManagementTest.java | 28 +++++
.../filtering/CassandraFilteringExtension.java | 31 ++++++
.../src/test/resources/logback-test.xml | 28 +++++
server/data/data-jmap/pom.xml | 6 ++
.../jmap/api/filtering/impl/RuleSetDefined.java | 2 +-
.../filtering/FilteringManagementContract.java | 42 ++++----
.../EventSourcingFilteringManagementTest.java | 32 ------
...oryEventSourcingFilteringManagementTest.java | 29 ++++++
14 files changed, 418 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/event-sourcing/event-store-cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/event-sourcing/event-store-cassandra/pom.xml b/event-sourcing/event-store-cassandra/pom.xml
index 64b6e12..dc2c100 100644
--- a/event-sourcing/event-store-cassandra/pom.xml
+++ b/event-sourcing/event-store-cassandra/pom.xml
@@ -85,6 +85,10 @@
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializer.java
----------------------------------------------------------------------
diff --git a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializer.java b/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializer.java
index dea4a5e..189eeec 100644
--- a/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializer.java
+++ b/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializer.java
@@ -35,6 +35,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.github.steveash.guavate.Guavate;
import com.google.common.collect.ImmutableSet;
@@ -54,6 +55,7 @@ public class JsonEventSerializer {
public JsonEventSerializer(Set<EventDTOModule> modules) {
objectMapper = new ObjectMapper();
objectMapper.registerModule(new Jdk8Module());
+ objectMapper.registerModule(new GuavaModule());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
typeToModule = modules.stream()
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/pom.xml b/server/data/data-jmap-cassandra/pom.xml
index 115ff7a..e9f4e85 100644
--- a/server/data/data-jmap-cassandra/pom.xml
+++ b/server/data/data-jmap-cassandra/pom.xml
@@ -46,6 +46,16 @@
</dependency>
<dependency>
<groupId>${james.groupId}</groupId>
+ <artifactId>event-sourcing-event-store-cassandra</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>event-sourcing-event-store-cassandra</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
<artifactId>james-server-data-jmap</artifactId>
</dependency>
<dependency>
@@ -55,6 +65,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
@@ -63,11 +78,6 @@
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
@@ -78,6 +88,16 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java
new file mode 100644
index 0000000..9a59fa6
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java
@@ -0,0 +1,52 @@
+/****************************************************************
+ * 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.jmap.cassandra.filtering;
+
+import org.apache.james.eventsourcing.Event;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
+import org.apache.james.jmap.api.filtering.impl.RuleSetDefined;
+
+import com.google.common.base.Preconditions;
+
+public class FilteringRuleSetDefineDTOModule implements EventDTOModule {
+ private static final String FILTERING_RULE_SET_DEFINED = "filtering-rule-set-defined";
+
+ @Override
+ public String getType() {
+ return FILTERING_RULE_SET_DEFINED;
+ }
+
+ @Override
+ public Class<? extends EventDTO> getDTOClass() {
+ return FilteringRuleSetDefinedDTO.class;
+ }
+
+ @Override
+ public Class<? extends Event> getEventClass() {
+ return RuleSetDefined.class;
+ }
+
+ @Override
+ public EventDTO toDTO(Event event) {
+ Preconditions.checkArgument(event instanceof RuleSetDefined);
+ return FilteringRuleSetDefinedDTO.from((RuleSetDefined) event, FILTERING_RULE_SET_DEFINED);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
new file mode 100644
index 0000000..c2357f9
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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.jmap.cassandra.filtering;
+
+import java.util.Objects;
+
+import org.apache.james.eventsourcing.Event;
+import org.apache.james.eventsourcing.EventId;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
+import org.apache.james.jmap.api.filtering.impl.FilteringAggregateId;
+import org.apache.james.jmap.api.filtering.impl.RuleSetDefined;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.collect.ImmutableList;
+
+public class FilteringRuleSetDefinedDTO implements EventDTO {
+
+ public static EventDTO from(RuleSetDefined event, String type) {
+ return new FilteringRuleSetDefinedDTO(
+ type, event.eventId().serialize(),
+ event.getAggregateId().asAggregateKey(),
+ RuleDTO.from(event.getRules()));
+ }
+
+ private final String type;
+ private final int eventId;
+ private final String aggregateId;
+ private final ImmutableList<RuleDTO> rules;
+
+ @JsonCreator
+ public FilteringRuleSetDefinedDTO(@JsonProperty("type") String type,
+ @JsonProperty("eventId") int eventId,
+ @JsonProperty("aggregateId") String aggregateId,
+ @JsonProperty("rules") ImmutableList<RuleDTO> rules) {
+ this.type = type;
+ this.eventId = eventId;
+ this.aggregateId = aggregateId;
+ this.rules = rules;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public int getEventId() {
+ return eventId;
+ }
+
+ public String getAggregateId() {
+ return aggregateId;
+ }
+
+ public ImmutableList<RuleDTO> getRules() {
+ return rules;
+ }
+
+ @JsonIgnore
+ @Override
+ public Event toEvent() {
+ return new RuleSetDefined(
+ FilteringAggregateId.parse(aggregateId),
+ EventId.fromSerialized(eventId),
+ RuleDTO.toRules(rules));
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof FilteringRuleSetDefinedDTO) {
+ FilteringRuleSetDefinedDTO that = (FilteringRuleSetDefinedDTO) o;
+
+ return Objects.equals(this.eventId, that.eventId)
+ && Objects.equals(this.type, that.type)
+ && Objects.equals(this.aggregateId, that.aggregateId)
+ && Objects.equals(this.rules, that.rules);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(type, eventId, aggregateId, rules);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/RuleDTO.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/RuleDTO.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/RuleDTO.java
new file mode 100644
index 0000000..a361465
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/RuleDTO.java
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.jmap.cassandra.filtering;
+
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.james.jmap.api.filtering.Rule;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+public class RuleDTO {
+
+ public static ImmutableList<Rule> toRules(List<RuleDTO> ruleDTOList) {
+ Preconditions.checkNotNull(ruleDTOList);
+ return ruleDTOList.stream()
+ .map(dto -> Rule.of(dto.getId()))
+ .collect(ImmutableList.toImmutableList());
+ }
+
+ public static ImmutableList<RuleDTO> from(List<Rule> rules) {
+ Preconditions.checkNotNull(rules);
+ return rules.stream()
+ .map(RuleDTO::from)
+ .collect(ImmutableList.toImmutableList());
+ }
+
+ public static RuleDTO from(Rule rule) {
+ return new RuleDTO(rule.getId());
+ }
+
+ private final String id;
+
+ @JsonCreator
+ public RuleDTO(@JsonProperty("id") String id) {
+ Preconditions.checkNotNull(id);
+
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof RuleDTO) {
+ RuleDTO ruleDTO = (RuleDTO) o;
+
+ return Objects.equals(this.id, ruleDTO.id);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(id);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraEventSourcingFilteringManagementTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraEventSourcingFilteringManagementTest.java b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraEventSourcingFilteringManagementTest.java
new file mode 100644
index 0000000..61cf8e8
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraEventSourcingFilteringManagementTest.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.jmap.cassandra.filtering;
+
+import org.apache.james.jmap.api.filtering.FilteringManagementContract;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(CassandraFilteringExtension.class)
+public class CassandraEventSourcingFilteringManagementTest implements FilteringManagementContract {
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
new file mode 100644
index 0000000..522b45f
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.jmap.cassandra.filtering;
+
+import org.apache.james.eventsourcing.eventstore.cassandra.CassandraGenericEventStoreExtension;
+
+import com.google.common.collect.ImmutableSet;
+
+public class CassandraFilteringExtension extends CassandraGenericEventStoreExtension {
+ public CassandraFilteringExtension() {
+ super(ImmutableSet.of(
+ new FilteringRuleSetDefineDTOModule()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap-cassandra/src/test/resources/logback-test.xml
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/test/resources/logback-test.xml b/server/data/data-jmap-cassandra/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..fe43bd9
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/test/resources/logback-test.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
+ <resetJUL>true</resetJUL>
+ </contextListener>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
+ <immediateFlush>false</immediateFlush>
+ </encoder>
+ </appender>
+
+ <root level="WARN">
+ <appender-ref ref="CONSOLE" />
+ </root>
+
+
+ <logger name="org.apache.james" level="WARN" >
+ <appender-ref ref="CONSOLE" />
+ </logger>
+
+ <logger name="org.apache.james.backends.cassandra.DockerCassandraRule" level="DEBUG" >
+ <appender-ref ref="CONSOLE" />
+ </logger>
+
+</configuration>
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap/pom.xml
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/pom.xml b/server/data/data-jmap/pom.xml
index 169120b..ab5742c 100644
--- a/server/data/data-jmap/pom.xml
+++ b/server/data/data-jmap/pom.xml
@@ -51,6 +51,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>event-sourcing-event-store-memory</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/RuleSetDefined.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/RuleSetDefined.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/RuleSetDefined.java
index dacba35..a607369 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/RuleSetDefined.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/RuleSetDefined.java
@@ -35,7 +35,7 @@ public class RuleSetDefined implements Event {
private final EventId eventId;
private final ImmutableList<Rule> rules;
- RuleSetDefined(FilteringAggregateId aggregateId, EventId eventId, ImmutableList<Rule> rules) {
+ public RuleSetDefined(FilteringAggregateId aggregateId, EventId eventId, ImmutableList<Rule> rules) {
this.aggregateId = aggregateId;
this.eventId = eventId;
this.rules = rules;
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/FilteringManagementContract.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/FilteringManagementContract.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/FilteringManagementContract.java
index 21718e8..dd2f773 100644
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/FilteringManagementContract.java
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/FilteringManagementContract.java
@@ -22,6 +22,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.apache.james.core.User;
+import org.apache.james.eventsourcing.eventstore.EventStore;
+import org.apache.james.jmap.api.filtering.impl.EventSourcingFilteringManagement;
import org.junit.jupiter.api.Test;
import com.google.common.collect.ImmutableList;
@@ -33,72 +35,74 @@ public interface FilteringManagementContract {
Rule RULE_2 = Rule.of("2");
Rule RULE_3 = Rule.of("3");
- FilteringManagement instanciateFilteringManagement();
+ default FilteringManagement instanciateFilteringManagement(EventStore eventStore) {
+ return new EventSourcingFilteringManagement(eventStore);
+ }
@Test
- default void listingRulesForUnknownUserShouldReturnEmptyList() {
+ default void listingRulesForUnknownUserShouldReturnEmptyList(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- assertThat(instanciateFilteringManagement().listRulesForUser(user)).isEmpty();
+ assertThat(instanciateFilteringManagement(eventStore).listRulesForUser(user)).isEmpty();
}
@Test
- default void listingRulesShouldThrowWhenNullUser() {
+ default void listingRulesShouldThrowWhenNullUser(EventStore eventStore) {
User user = null;
- assertThatThrownBy(() -> instanciateFilteringManagement().listRulesForUser(user)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> instanciateFilteringManagement(eventStore).listRulesForUser(user)).isInstanceOf(NullPointerException.class);
}
@Test
- default void listingRulesShouldReturnDefinedRules() {
+ default void listingRulesShouldReturnDefinedRules(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- FilteringManagement testee = instanciateFilteringManagement();
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
testee.defineRulesForUser(user, ImmutableList.of(RULE_1, RULE_2));
assertThat(testee.listRulesForUser(user)).containsExactly(RULE_1, RULE_2);
}
@Test
- default void listingRulesShouldReturnLastDefinedRules() {
+ default void listingRulesShouldReturnLastDefinedRules(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- FilteringManagement testee = instanciateFilteringManagement();
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
testee.defineRulesForUser(user, ImmutableList.of(RULE_1, RULE_2));
testee.defineRulesForUser(user, ImmutableList.of(RULE_2, RULE_1));
assertThat(testee.listRulesForUser(user)).containsExactly(RULE_2, RULE_1);
}
@Test
- default void definingRulesShouldThrowWhenDuplicateRules() {
+ default void definingRulesShouldThrowWhenDuplicateRules(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- FilteringManagement testee = instanciateFilteringManagement();
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
assertThatThrownBy(() -> testee.defineRulesForUser(user, ImmutableList.of(RULE_1, RULE_1)))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
- default void definingRulesShouldThrowWhenNullUser() {
- FilteringManagement testee = instanciateFilteringManagement();
+ default void definingRulesShouldThrowWhenNullUser(EventStore eventStore) {
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
assertThatThrownBy(() -> testee.defineRulesForUser(null, ImmutableList.of(RULE_1, RULE_1)))
.isInstanceOf(NullPointerException.class);
}
@Test
- default void definingRulesShouldThrowWhenNullRuleList() {
+ default void definingRulesShouldThrowWhenNullRuleList(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- FilteringManagement testee = instanciateFilteringManagement();
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
assertThatThrownBy(() -> testee.defineRulesForUser(user, null))
.isInstanceOf(NullPointerException.class);
}
@Test
- default void definingRulesShouldKeepOrdering() {
+ default void definingRulesShouldKeepOrdering(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- FilteringManagement testee = instanciateFilteringManagement();
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
testee.defineRulesForUser(user, ImmutableList.of(RULE_3, RULE_2, RULE_1));
assertThat(testee.listRulesForUser(user)).containsExactly(RULE_3, RULE_2, RULE_1);
}
@Test
- default void definingEmptyRuleListShouldRemoveExistingRules() {
+ default void definingEmptyRuleListShouldRemoveExistingRules(EventStore eventStore) {
User user = User.fromUsername(BART_SIMPSON_CARTOON);
- FilteringManagement testee = instanciateFilteringManagement();
+ FilteringManagement testee = instanciateFilteringManagement(eventStore);
testee.defineRulesForUser(user, ImmutableList.of(RULE_3, RULE_2, RULE_1));
testee.defineRulesForUser(user, ImmutableList.of());
assertThat(testee.listRulesForUser(user)).isEmpty();
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/EventSourcingFilteringManagementTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/EventSourcingFilteringManagementTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/EventSourcingFilteringManagementTest.java
deleted file mode 100644
index 45120c3..0000000
--- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/EventSourcingFilteringManagementTest.java
+++ /dev/null
@@ -1,32 +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.jmap.api.filtering.impl;
-
-import org.apache.james.eventsourcing.eventstore.memory.InMemoryEventStore;
-import org.apache.james.jmap.api.filtering.FilteringManagement;
-import org.apache.james.jmap.api.filtering.FilteringManagementContract;
-
-public class EventSourcingFilteringManagementTest implements FilteringManagementContract {
-
- @Override
- public FilteringManagement instanciateFilteringManagement() {
- return new EventSourcingFilteringManagement(new InMemoryEventStore());
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8659a18e/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/InMemoryEventSourcingFilteringManagementTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/InMemoryEventSourcingFilteringManagementTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/InMemoryEventSourcingFilteringManagementTest.java
new file mode 100644
index 0000000..39dffe7
--- /dev/null
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/filtering/impl/InMemoryEventSourcingFilteringManagementTest.java
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.jmap.api.filtering.impl;
+
+import org.apache.james.eventsourcing.eventstore.memory.InMemoryEventStoreExtension;
+import org.apache.james.jmap.api.filtering.FilteringManagementContract;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(InMemoryEventStoreExtension.class)
+public class InMemoryEventSourcingFilteringManagementTest implements FilteringManagementContract {
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/2] james-project git commit: JAMES-2527 don't require new classes
for creating DTO converters
Posted by ad...@apache.org.
JAMES-2527 don't require new classes for creating DTO converters
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a999bd60
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a999bd60
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a999bd60
Branch: refs/heads/master
Commit: a999bd6043745bd8fdd1c42b748fb5fe51a3e948
Parents: 8659a18
Author: Matthieu Baechler <ma...@apache.org>
Authored: Thu Aug 23 11:11:24 2018 +0200
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Fri Aug 24 11:19:26 2018 +0200
----------------------------------------------------------------------
.../cassandra/dto/EventDTOModule.java | 78 ++++++++++++++++++--
.../cassandra/CassandraEventStoreExtension.java | 4 +-
.../cassandra/JsonEventSerializerTest.java | 15 ++--
.../cassandra/dto/OtherTestEventDTOModule.java | 55 --------------
.../cassandra/dto/TestEventDTOModule.java | 56 --------------
.../cassandra/dto/TestEventDTOModules.java | 47 ++++++++++++
.../cassandra/dto/QuotaEventDTOModules.java | 34 +++++++++
.../QuotaThresholdChangedEventDTOModule.java | 54 --------------
.../mailbox/quota/cassandra/dto/DTOTest.java | 18 ++---
.../listeners/CassandraEventStoreExtension.java | 5 +-
.../CassandraDLPConfigurationStoreModule.java | 7 +-
.../mailbox/CassandraQuotaMailingModule.java | 4 +-
.../DLPConfigurationItemAddedDTOModule.java | 53 -------------
.../DLPConfigurationItemsRemovedDTOModule.java | 53 -------------
.../cassandra/DLPConfigurationModules.java | 43 +++++++++++
...tSourcingDLPConfigurationStoreExtension.java | 4 +-
.../FilteringRuleSetDefineDTOModule.java | 52 -------------
.../FilteringRuleSetDefineDTOModules.java | 34 +++++++++
.../filtering/FilteringRuleSetDefinedDTO.java | 2 +-
.../filtering/CassandraFilteringExtension.java | 3 +-
20 files changed, 261 insertions(+), 360 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/event-sourcing/event-store-cassandra/src/main/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
----------------------------------------------------------------------
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/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
index feaa5ef..ba29e91 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/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/EventDTOModule.java
@@ -21,12 +21,80 @@ package org.apache.james.eventsourcing.eventstore.cassandra.dto;
import org.apache.james.eventsourcing.Event;
-public interface EventDTOModule {
- String getType();
+public class EventDTOModule<T extends Event, U extends EventDTO> {
- Class<? extends EventDTO> getDTOClass();
+ public interface EventDTOConverter<T extends Event, U extends EventDTO> {
+ U convert(T event, String typeName);
+ }
- Class<? extends Event> getEventClass();
+ public static <U extends Event> Builder<U> forEvent(Class<U> eventType) {
+ return new Builder<>(eventType);
+ }
- EventDTO toDTO(Event event);
+ public static class Builder<T extends Event> {
+
+ private final Class<T> eventType;
+
+ private Builder(Class<T> eventType) {
+ this.eventType = eventType;
+ }
+
+ public <U extends EventDTO> RequireConversionFunctionBuilder<U> convertToDTO(Class<U> dtoType) {
+ return new RequireConversionFunctionBuilder<>(dtoType);
+ }
+
+ public class RequireConversionFunctionBuilder<U extends EventDTO> {
+
+ private final Class<U> dtoType;
+
+ private RequireConversionFunctionBuilder(Class<U> dtoType) {
+ this.dtoType = dtoType;
+ }
+
+ public RequireTypeNameBuilder convertWith(EventDTOConverter<T, U> converter) {
+ return new RequireTypeNameBuilder(converter);
+ }
+
+ public class RequireTypeNameBuilder {
+ private final EventDTOConverter<T, U> converter;
+
+ private RequireTypeNameBuilder(EventDTOConverter<T, U> converter) {
+ this.converter = converter;
+ }
+
+ public EventDTOModule<T, U> typeName(String typeName) {
+ return new EventDTOModule<>(converter, eventType, dtoType, typeName);
+ }
+ }
+ }
+
+ }
+
+ private final EventDTOConverter<T, U> converter;
+ private final Class<T> eventType;
+ private final Class<U> dtoType;
+ private final String typeName;
+
+ private EventDTOModule(EventDTOConverter<T, U> converter, Class<T> eventType, Class<U> dtoType, String typeName) {
+ this.converter = converter;
+ this.eventType = eventType;
+ this.dtoType = dtoType;
+ this.typeName = typeName;
+ }
+
+ public String getType() {
+ return typeName;
+ }
+
+ public Class<U> getDTOClass() {
+ return dtoType;
+ }
+
+ public Class<T> getEventClass() {
+ return eventType;
+ }
+
+ public EventDTO toDTO(T event) {
+ return converter.convert(event, typeName);
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/CassandraEventStoreExtension.java
----------------------------------------------------------------------
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 73754a9..b913ef8 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
@@ -19,12 +19,12 @@
package org.apache.james.eventsourcing.eventstore.cassandra;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.TestEventDTOModule;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.TestEventDTOModules;
import com.google.common.collect.ImmutableSet;
public class CassandraEventStoreExtension extends CassandraGenericEventStoreExtension {
public CassandraEventStoreExtension() {
- super(ImmutableSet.of(new TestEventDTOModule()));
+ super(ImmutableSet.of(TestEventDTOModules.TEST_TYPE));
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/JsonEventSerializerTest.java
----------------------------------------------------------------------
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 eadb69e..bfa669f 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
@@ -27,8 +27,7 @@ import org.apache.james.eventsourcing.EventId;
import org.apache.james.eventsourcing.TestAggregateId;
import org.apache.james.eventsourcing.TestEvent;
import org.apache.james.eventsourcing.eventstore.cassandra.dto.OtherEvent;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.OtherTestEventDTOModule;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.TestEventDTOModule;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.TestEventDTOModules;
import org.junit.jupiter.api.Test;
class JsonEventSerializerTest {
@@ -43,7 +42,7 @@ class JsonEventSerializerTest {
@Test
void shouldDeserializeKnownEvent() throws Exception {
- assertThat(new JsonEventSerializer(new TestEventDTOModule())
+ assertThat(new JsonEventSerializer(TestEventDTOModules.TEST_TYPE)
.deserialize(TEST_EVENT_JSON))
.isEqualTo(TEST_EVENT);
}
@@ -58,8 +57,8 @@ class JsonEventSerializerTest {
@Test
void serializeShouldHandleAllKnownEvents() throws Exception {
JsonEventSerializer jsonEventSerializer = new JsonEventSerializer(
- new TestEventDTOModule(),
- new OtherTestEventDTOModule());
+ TestEventDTOModules.TEST_TYPE,
+ TestEventDTOModules.OTHER_TEST_TYPE);
assertThatJson(
jsonEventSerializer.serialize(OTHER_EVENT))
@@ -73,8 +72,8 @@ class JsonEventSerializerTest {
@Test
void deserializeShouldHandleAllKnownEvents() throws Exception {
JsonEventSerializer jsonEventSerializer = new JsonEventSerializer(
- new TestEventDTOModule(),
- new OtherTestEventDTOModule());
+ TestEventDTOModules.TEST_TYPE,
+ TestEventDTOModules.OTHER_TEST_TYPE);
assertThatJson(
jsonEventSerializer.deserialize(OTHER_EVENT_JSON))
@@ -87,7 +86,7 @@ class JsonEventSerializerTest {
@Test
void shouldSerializeKnownEvent() throws Exception {
- assertThatJson(new JsonEventSerializer(new TestEventDTOModule())
+ assertThatJson(new JsonEventSerializer(TestEventDTOModules.TEST_TYPE)
.serialize(TEST_EVENT))
.isEqualTo(TEST_EVENT_JSON);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTOModule.java
----------------------------------------------------------------------
diff --git a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTOModule.java b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTOModule.java
deleted file mode 100644
index d025add..0000000
--- a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/OtherTestEventDTOModule.java
+++ /dev/null
@@ -1,55 +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.Event;
-import org.testcontainers.shaded.com.google.common.base.Preconditions;
-
-public class OtherTestEventDTOModule implements EventDTOModule {
-
- public static final String OTHER_TYPE = "other-type";
-
- @Override
- public String getType() {
- return OTHER_TYPE;
- }
-
- @Override
- public Class<? extends EventDTO> getDTOClass() {
- return OtherTestEventDTO.class;
- }
-
- @Override
- public Class<? extends Event> getEventClass() {
- return OtherEvent.class;
- }
-
- @Override
- public EventDTO toDTO(Event event) {
- Preconditions.checkArgument(event instanceof OtherEvent);
- OtherEvent otherEvent = (OtherEvent) event;
-
- return new OtherTestEventDTO(
- OTHER_TYPE,
- otherEvent.getPayload(),
- otherEvent.eventId().serialize(),
- otherEvent.getAggregateId().getId());
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModule.java
----------------------------------------------------------------------
diff --git a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModule.java b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModule.java
deleted file mode 100644
index f0613ee..0000000
--- a/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModule.java
+++ /dev/null
@@ -1,56 +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.Event;
-import org.apache.james.eventsourcing.TestEvent;
-import org.testcontainers.shaded.com.google.common.base.Preconditions;
-
-public class TestEventDTOModule implements EventDTOModule {
-
- public static final String TEST_TYPE = "TestType";
-
- @Override
- public String getType() {
- return TEST_TYPE;
- }
-
- @Override
- public Class<? extends EventDTO> getDTOClass() {
- return TestEventDTO.class;
- }
-
- @Override
- public Class<? extends Event> getEventClass() {
- return TestEvent.class;
- }
-
- @Override
- public EventDTO toDTO(Event event) {
- Preconditions.checkArgument(event instanceof TestEvent);
-
- TestEvent testEvent = (TestEvent) event;
- return new TestEventDTO(
- TEST_TYPE,
- testEvent.getData(),
- testEvent.eventId().serialize(),
- testEvent.getAggregateId().getId());
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..1040380
--- /dev/null
+++ b/event-sourcing/event-store-cassandra/src/test/java/org/apache/james/eventsourcing/eventstore/cassandra/dto/TestEventDTOModules.java
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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<TestEvent, TestEventDTO> TEST_TYPE =
+ EventDTOModule
+ .forEvent(TestEvent.class)
+ .convertToDTO(TestEventDTO.class)
+ .convertWith((event, typeName) -> new TestEventDTO(
+ typeName,
+ event.getData(),
+ event.eventId().serialize(),
+ event.getAggregateId().getId()))
+ .typeName("TestType");
+
+ EventDTOModule<OtherEvent, OtherTestEventDTO> OTHER_TEST_TYPE =
+ EventDTOModule
+ .forEvent(OtherEvent.class)
+ .convertToDTO(OtherTestEventDTO.class)
+ .convertWith(((event, typeName) -> new OtherTestEventDTO(
+ typeName,
+ event.getPayload(),
+ event.eventId().serialize(),
+ event.getAggregateId().getId())))
+ .typeName("other-type");
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaEventDTOModules.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaEventDTOModules.java b/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaEventDTOModules.java
new file mode 100644
index 0000000..1697d5e
--- /dev/null
+++ b/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaEventDTOModules.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.mailbox.quota.cassandra.dto;
+
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
+import org.apache.james.mailbox.quota.mailing.events.QuotaThresholdChangedEvent;
+
+public interface QuotaEventDTOModules {
+
+ EventDTOModule<QuotaThresholdChangedEvent, QuotaThresholdChangedEventDTO> QUOTA_THRESHOLD_CHANGE =
+ EventDTOModule
+ .forEvent(QuotaThresholdChangedEvent.class)
+ .convertToDTO(QuotaThresholdChangedEventDTO.class)
+ .convertWith(QuotaThresholdChangedEventDTO::from)
+ .typeName("quota-threshold-change");
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaThresholdChangedEventDTOModule.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaThresholdChangedEventDTOModule.java b/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaThresholdChangedEventDTOModule.java
deleted file mode 100644
index 7c37b7f..0000000
--- a/mailbox/plugin/quota-mailing-cassandra/src/main/java/org/apache/james/mailbox/quota/cassandra/dto/QuotaThresholdChangedEventDTOModule.java
+++ /dev/null
@@ -1,54 +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.mailbox.quota.cassandra.dto;
-
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
-import org.apache.james.mailbox.quota.mailing.events.QuotaThresholdChangedEvent;
-
-import com.google.common.base.Preconditions;
-
-public class QuotaThresholdChangedEventDTOModule implements EventDTOModule {
- private static final String QUOTA_THRESHOLD_CHANGE = "quota-threshold-change";
-
- @Override
- public String getType() {
- return QUOTA_THRESHOLD_CHANGE;
- }
-
- @Override
- public Class<? extends EventDTO> getDTOClass() {
- return QuotaThresholdChangedEventDTO.class;
- }
-
- @Override
- public Class<? extends Event> getEventClass() {
- return QuotaThresholdChangedEvent.class;
- }
-
- @Override
- public EventDTO toDTO(Event event) {
- Preconditions.checkArgument(event instanceof QuotaThresholdChangedEvent);
- return QuotaThresholdChangedEventDTO.from(
- (QuotaThresholdChangedEvent) event,
- QUOTA_THRESHOLD_CHANGE);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/dto/DTOTest.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/dto/DTOTest.java b/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/dto/DTOTest.java
index 7556e38..e644f97 100644
--- a/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/dto/DTOTest.java
+++ b/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/dto/DTOTest.java
@@ -133,7 +133,7 @@ class DTOTest {
@Test
void shouldSerializeQuotaThresholdChangedEventDTO() throws Exception {
assertThatJson(objectMapper.writeValueAsString(
- new QuotaThresholdChangedEventDTOModule().toDTO(EVENT)))
+ QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE.toDTO(EVENT)))
.isEqualTo(EVENT_JSON);
}
@@ -146,56 +146,56 @@ class DTOTest {
@Test
void shouldSerializeQuotaThresholdChangedEvent() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.serialize(EVENT))
.isEqualTo(EVENT_JSON);
}
@Test
void shouldDeserializeQuotaThresholdChangedEvent() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.deserialize(EVENT_JSON))
.isEqualTo(EVENT);
}
@Test
void shouldSerializeEvent2() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.serialize(EVENT_2))
.isEqualTo(EVENT_JSON_2);
}
@Test
void shouldDeserializeEvent2() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.deserialize(EVENT_JSON_2))
.isEqualTo(EVENT_2);
}
@Test
void shouldSerializeEvent3() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.serialize(EVENT_3))
.isEqualTo(EVENT_JSON_3);
}
@Test
void shouldDeserializeEvent3() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.deserialize(EVENT_JSON_3))
.isEqualTo(EVENT_3);
}
@Test
void shouldSerializeEvent4() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.serialize(EVENT_4))
.isEqualTo(EVENT_JSON_4);
}
@Test
void shouldDeserializeEvent4() throws Exception {
- assertThatJson(new JsonEventSerializer(new QuotaThresholdChangedEventDTOModule())
+ assertThatJson(new JsonEventSerializer(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE)
.deserialize(EVENT_JSON_4))
.isEqualTo(EVENT_4);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/listeners/CassandraEventStoreExtension.java
----------------------------------------------------------------------
diff --git a/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/listeners/CassandraEventStoreExtension.java b/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/listeners/CassandraEventStoreExtension.java
index f46a605..0218c78 100644
--- a/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/listeners/CassandraEventStoreExtension.java
+++ b/mailbox/plugin/quota-mailing-cassandra/src/test/java/org/apache/james/mailbox/quota/cassandra/listeners/CassandraEventStoreExtension.java
@@ -20,13 +20,12 @@
package org.apache.james.mailbox.quota.cassandra.listeners;
import org.apache.james.eventsourcing.eventstore.cassandra.CassandraGenericEventStoreExtension;
-import org.apache.james.mailbox.quota.cassandra.dto.QuotaThresholdChangedEventDTOModule;
+import org.apache.james.mailbox.quota.cassandra.dto.QuotaEventDTOModules;
import com.google.common.collect.ImmutableSet;
public class CassandraEventStoreExtension extends CassandraGenericEventStoreExtension {
public CassandraEventStoreExtension() {
- super(ImmutableSet.of(
- new QuotaThresholdChangedEventDTOModule()));
+ super(ImmutableSet.of(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE));
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDLPConfigurationStoreModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDLPConfigurationStoreModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDLPConfigurationStoreModule.java
index 5d3abc7..1ee1595 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDLPConfigurationStoreModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDLPConfigurationStoreModule.java
@@ -21,8 +21,7 @@ package org.apache.james.modules.data;
import org.apache.james.dlp.api.DLPConfigurationStore;
import org.apache.james.dlp.eventsourcing.EventSourcingDLPConfigurationStore;
-import org.apache.james.dlp.eventsourcing.cassandra.DLPConfigurationItemAddedDTOModule;
-import org.apache.james.dlp.eventsourcing.cassandra.DLPConfigurationItemsRemovedDTOModule;
+import org.apache.james.dlp.eventsourcing.cassandra.DLPConfigurationModules;
import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
import com.google.inject.AbstractModule;
@@ -38,7 +37,7 @@ public class CassandraDLPConfigurationStoreModule extends AbstractModule {
Multibinder<EventDTOModule> eventDTOModuleBinder = Multibinder.newSetBinder(binder(), EventDTOModule.class);
- eventDTOModuleBinder.addBinding().to(DLPConfigurationItemAddedDTOModule.class);
- eventDTOModuleBinder.addBinding().to(DLPConfigurationItemsRemovedDTOModule.class);
+ eventDTOModuleBinder.addBinding().toInstance(DLPConfigurationModules.DLP_CONFIGURATION_STORE);
+ eventDTOModuleBinder.addBinding().toInstance(DLPConfigurationModules.DLP_CONFIGURATION_CLEAR);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraQuotaMailingModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraQuotaMailingModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraQuotaMailingModule.java
index f81d572..c33137e 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraQuotaMailingModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraQuotaMailingModule.java
@@ -20,7 +20,7 @@
package org.apache.james.modules.mailbox;
import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
-import org.apache.james.mailbox.quota.cassandra.dto.QuotaThresholdChangedEventDTOModule;
+import org.apache.james.mailbox.quota.cassandra.dto.QuotaEventDTOModules;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
@@ -30,6 +30,6 @@ public class CassandraQuotaMailingModule extends AbstractModule {
protected void configure() {
Multibinder.newSetBinder(binder(), EventDTOModule.class)
.addBinding()
- .to(QuotaThresholdChangedEventDTOModule.class);
+ .toInstance(QuotaEventDTOModules.QUOTA_THRESHOLD_CHANGE);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemAddedDTOModule.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemAddedDTOModule.java b/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemAddedDTOModule.java
deleted file mode 100644
index d38808b..0000000
--- a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemAddedDTOModule.java
+++ /dev/null
@@ -1,53 +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.dlp.eventsourcing.cassandra;
-
-import org.apache.james.dlp.eventsourcing.events.ConfigurationItemsAdded;
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
-
-import com.google.common.base.Preconditions;
-
-public class DLPConfigurationItemAddedDTOModule implements EventDTOModule {
- private static final String DLP_CONFIGURATION_STORE = "dlp-configuration-store";
-
- @Override
- public String getType() {
- return DLP_CONFIGURATION_STORE;
- }
-
- @Override
- public Class<? extends EventDTO> getDTOClass() {
- return DLPConfigurationItemAddedDTO.class;
- }
-
- @Override
- public Class<? extends Event> getEventClass() {
- return ConfigurationItemsAdded.class;
- }
-
- @Override
- public EventDTO toDTO(Event event) {
- Preconditions.checkArgument(event instanceof ConfigurationItemsAdded);
- return DLPConfigurationItemAddedDTO
- .from((ConfigurationItemsAdded) event, DLP_CONFIGURATION_STORE);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemsRemovedDTOModule.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemsRemovedDTOModule.java b/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemsRemovedDTOModule.java
deleted file mode 100644
index 9e259cd..0000000
--- a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationItemsRemovedDTOModule.java
+++ /dev/null
@@ -1,53 +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.dlp.eventsourcing.cassandra;
-
-import org.apache.james.dlp.eventsourcing.events.ConfigurationItemsRemoved;
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
-
-import com.google.common.base.Preconditions;
-
-public class DLPConfigurationItemsRemovedDTOModule implements EventDTOModule {
- private static final String DLP_CONFIGURATION_CLEAR = "dlp-configuration-clear";
-
- @Override
- public String getType() {
- return DLP_CONFIGURATION_CLEAR;
- }
-
- @Override
- public Class<? extends EventDTO> getDTOClass() {
- return DLPConfigurationItemsRemovedDTO.class;
- }
-
- @Override
- public Class<? extends Event> getEventClass() {
- return ConfigurationItemsRemoved.class;
- }
-
- @Override
- public EventDTO toDTO(Event event) {
- Preconditions.checkArgument(event instanceof ConfigurationItemsRemoved);
- return DLPConfigurationItemsRemovedDTO
- .from((ConfigurationItemsRemoved) event, DLP_CONFIGURATION_CLEAR);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationModules.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationModules.java b/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationModules.java
new file mode 100644
index 0000000..c068900
--- /dev/null
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/dlp/eventsourcing/cassandra/DLPConfigurationModules.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.dlp.eventsourcing.cassandra;
+
+import org.apache.james.dlp.eventsourcing.events.ConfigurationItemsAdded;
+import org.apache.james.dlp.eventsourcing.events.ConfigurationItemsRemoved;
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
+
+public interface DLPConfigurationModules {
+
+ EventDTOModule<ConfigurationItemsAdded, DLPConfigurationItemAddedDTO> DLP_CONFIGURATION_STORE =
+ EventDTOModule
+ .forEvent(ConfigurationItemsAdded.class)
+ .convertToDTO(DLPConfigurationItemAddedDTO.class)
+ .convertWith(DLPConfigurationItemAddedDTO::from)
+ .typeName("dlp-configuration-store");
+
+ EventDTOModule<ConfigurationItemsRemoved, DLPConfigurationItemsRemovedDTO> DLP_CONFIGURATION_CLEAR =
+ EventDTOModule
+ .forEvent(ConfigurationItemsRemoved.class)
+ .convertToDTO(DLPConfigurationItemsRemovedDTO.class)
+ .convertWith(DLPConfigurationItemsRemovedDTO::from)
+ .typeName("dlp-configuration-clear");
+
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreExtension.java
----------------------------------------------------------------------
diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreExtension.java b/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreExtension.java
index e5d04fb..1f152d2 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreExtension.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/dlp/eventsourcing/cassandra/CassandraEventSourcingDLPConfigurationStoreExtension.java
@@ -73,7 +73,9 @@ public class CassandraEventSourcingDLPConfigurationStoreExtension implements Bef
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
JsonEventSerializer jsonEventSerializer = new JsonEventSerializer(
- ImmutableSet.of(new DLPConfigurationItemAddedDTOModule(), new DLPConfigurationItemsRemovedDTOModule()));
+ ImmutableSet.of(
+ DLPConfigurationModules.DLP_CONFIGURATION_STORE,
+ DLPConfigurationModules.DLP_CONFIGURATION_CLEAR));
EventStoreDao eventStoreDao = new EventStoreDao(
cassandra.getConf(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java
deleted file mode 100644
index 9a59fa6..0000000
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModule.java
+++ /dev/null
@@ -1,52 +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.jmap.cassandra.filtering;
-
-import org.apache.james.eventsourcing.Event;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTO;
-import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
-import org.apache.james.jmap.api.filtering.impl.RuleSetDefined;
-
-import com.google.common.base.Preconditions;
-
-public class FilteringRuleSetDefineDTOModule implements EventDTOModule {
- private static final String FILTERING_RULE_SET_DEFINED = "filtering-rule-set-defined";
-
- @Override
- public String getType() {
- return FILTERING_RULE_SET_DEFINED;
- }
-
- @Override
- public Class<? extends EventDTO> getDTOClass() {
- return FilteringRuleSetDefinedDTO.class;
- }
-
- @Override
- public Class<? extends Event> getEventClass() {
- return RuleSetDefined.class;
- }
-
- @Override
- public EventDTO toDTO(Event event) {
- Preconditions.checkArgument(event instanceof RuleSetDefined);
- return FilteringRuleSetDefinedDTO.from((RuleSetDefined) event, FILTERING_RULE_SET_DEFINED);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModules.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModules.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModules.java
new file mode 100644
index 0000000..0c56b1c
--- /dev/null
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefineDTOModules.java
@@ -0,0 +1,34 @@
+/****************************************************************
+ * 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.jmap.cassandra.filtering;
+
+import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule;
+import org.apache.james.jmap.api.filtering.impl.RuleSetDefined;
+
+public interface FilteringRuleSetDefineDTOModules {
+
+ EventDTOModule<RuleSetDefined, FilteringRuleSetDefinedDTO> FILTERING_RULE_SET_DEFINED =
+ EventDTOModule
+ .forEvent(RuleSetDefined.class)
+ .convertToDTO(FilteringRuleSetDefinedDTO.class)
+ .convertWith(FilteringRuleSetDefinedDTO::from)
+ .typeName("filtering-rule-set-defined");
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
index c2357f9..5a0de2c 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/filtering/FilteringRuleSetDefinedDTO.java
@@ -34,7 +34,7 @@ import com.google.common.collect.ImmutableList;
public class FilteringRuleSetDefinedDTO implements EventDTO {
- public static EventDTO from(RuleSetDefined event, String type) {
+ public static FilteringRuleSetDefinedDTO from(RuleSetDefined event, String type) {
return new FilteringRuleSetDefinedDTO(
type, event.eventId().serialize(),
event.getAggregateId().asAggregateKey(),
http://git-wip-us.apache.org/repos/asf/james-project/blob/a999bd60/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
----------------------------------------------------------------------
diff --git a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
index 522b45f..300bd5d 100644
--- a/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
+++ b/server/data/data-jmap-cassandra/src/test/java/org/apache/james/jmap/cassandra/filtering/CassandraFilteringExtension.java
@@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableSet;
public class CassandraFilteringExtension extends CassandraGenericEventStoreExtension {
public CassandraFilteringExtension() {
- super(ImmutableSet.of(
- new FilteringRuleSetDefineDTOModule()));
+ super(ImmutableSet.of(FilteringRuleSetDefineDTOModules.FILTERING_RULE_SET_DEFINED));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org