JAMES-2393 Injections for Quota mailing listener
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dcdd5847 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dcdd5847 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dcdd5847 Branch: refs/heads/master Commit: dcdd58472c0616fb11b001af01d07d70c360c805 Parents: 8683586 Author: Matthieu Baechler <[email protected]> Authored: Wed May 16 15:38:55 2018 +0200 Committer: Matthieu Baechler <[email protected]> Committed: Fri May 18 19:43:49 2018 +0200 ---------------------------------------------------------------------- .../DetectThresholdCrossingHandler.java | 3 -- .../QuotaThresholdCrossingListener.java | 21 ++++++++- .../subscribers/QuotaThresholdMailer.java | 1 + .../QuotaThresholdListenersTestSystem.java | 12 +----- pom.xml | 5 +++ server/container/guice/cassandra-guice/pom.xml | 8 ++++ .../apache/james/CassandraJamesServerMain.java | 6 ++- .../mailbox/CassandraQuotaMailingModule.java | 37 ++++++++++++++++ .../guice/mailbox-plugin-quota-mailing/pom.xml | 45 ++++++++++++++++++++ .../modules/mailbox/QuotaMailingModule.java | 41 ++++++++++++++++++ server/container/guice/memory-guice/pom.xml | 4 ++ .../org/apache/james/MemoryJamesServerMain.java | 7 ++- server/container/guice/pom.xml | 6 +++ 13 files changed, 178 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingHandler.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingHandler.java b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingHandler.java index bbf480e..b44ab3e 100644 --- a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingHandler.java +++ b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/commands/DetectThresholdCrossingHandler.java @@ -21,8 +21,6 @@ package org.apache.james.mailbox.quota.mailing.commands; import java.util.List; -import javax.inject.Inject; - import org.apache.james.eventsourcing.CommandHandler; import org.apache.james.eventsourcing.Event; import org.apache.james.eventsourcing.eventstore.EventStore; @@ -35,7 +33,6 @@ public class DetectThresholdCrossingHandler implements CommandHandler<DetectThre private final EventStore eventStore; private final QuotaMailingListenerConfiguration quotaMailingListenerConfiguration; - @Inject public DetectThresholdCrossingHandler(EventStore eventStore, QuotaMailingListenerConfiguration quotaMailingListenerConfiguration) { this.eventStore = eventStore; this.quotaMailingListenerConfiguration = quotaMailingListenerConfiguration; http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java index a4b1094..bf917f7 100644 --- a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java +++ b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdCrossingListener.java @@ -19,21 +19,38 @@ package org.apache.james.mailbox.quota.mailing.listeners; +import javax.inject.Inject; + import org.apache.james.core.User; import org.apache.james.eventsourcing.EventSourcingSystem; +import org.apache.james.eventsourcing.eventstore.EventStore; +import org.apache.james.filesystem.api.FileSystem; import org.apache.james.mailbox.Event; import org.apache.james.mailbox.MailboxListener; +import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration; import org.apache.james.mailbox.quota.mailing.commands.DetectThresholdCrossing; +import org.apache.james.mailbox.quota.mailing.commands.DetectThresholdCrossingHandler; +import org.apache.james.mailbox.quota.mailing.subscribers.QuotaThresholdMailer; +import org.apache.james.user.api.UsersRepository; +import org.apache.mailet.MailetContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.ImmutableSet; + public class QuotaThresholdCrossingListener implements MailboxListener { private static final Logger LOGGER = LoggerFactory.getLogger(QuotaThresholdCrossingListener.class); private final EventSourcingSystem eventSourcingSystem; - public QuotaThresholdCrossingListener(EventSourcingSystem eventSourcingSystem) { - this.eventSourcingSystem = eventSourcingSystem; + @Inject + public QuotaThresholdCrossingListener(MailetContext mailetContext, UsersRepository usersRepository, + FileSystem fileSystem, EventStore eventStore, QuotaMailingListenerConfiguration configuration) { + this.eventSourcingSystem = new EventSourcingSystem( + ImmutableSet.of(new DetectThresholdCrossingHandler(eventStore, configuration)), + ImmutableSet.of(new QuotaThresholdMailer(mailetContext, usersRepository, fileSystem, configuration)), + eventStore + ); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdMailer.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdMailer.java b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdMailer.java index 54cb1b9..fcf17e2 100644 --- a/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdMailer.java +++ b/mailbox/plugin/quota-mailing/src/main/java/org/apache/james/mailbox/quota/mailing/subscribers/QuotaThresholdMailer.java @@ -22,6 +22,7 @@ package org.apache.james.mailbox.quota.mailing.subscribers; import java.io.IOException; import java.util.Optional; +import javax.inject.Inject; import javax.mail.MessagingException; import org.apache.james.core.MailAddress; http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdListenersTestSystem.java ---------------------------------------------------------------------- diff --git a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdListenersTestSystem.java b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdListenersTestSystem.java index 0b279dd..32f19e3 100644 --- a/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdListenersTestSystem.java +++ b/mailbox/plugin/quota-mailing/src/test/java/org/apache/james/mailbox/quota/mailing/listeners/QuotaThresholdListenersTestSystem.java @@ -19,23 +19,18 @@ package org.apache.james.mailbox.quota.mailing.listeners; -import org.apache.james.eventsourcing.EventSourcingSystem; import org.apache.james.eventsourcing.eventstore.EventStore; import org.apache.james.filesystem.api.FileSystem; import org.apache.james.mailbox.Event; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.mock.MockMailboxSession; import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration; -import org.apache.james.mailbox.quota.mailing.commands.DetectThresholdCrossingHandler; -import org.apache.james.mailbox.quota.mailing.subscribers.QuotaThresholdMailer; import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener; import org.apache.james.server.core.JamesServerResourceLoader; import org.apache.james.server.core.filesystem.FileSystemImpl; import org.apache.james.user.memory.MemoryUsersRepository; import org.apache.mailet.MailetContext; -import com.google.common.collect.ImmutableSet; - public class QuotaThresholdListenersTestSystem { private final DefaultDelegatingMailboxListener delegatingListener; @@ -45,13 +40,8 @@ public class QuotaThresholdListenersTestSystem { FileSystem fileSystem = new FileSystemImpl(new JamesServerResourceLoader(".")); - EventSourcingSystem eventSourcingSystem = new EventSourcingSystem( - ImmutableSet.of(new DetectThresholdCrossingHandler(eventStore, configuration)), - ImmutableSet.of(new QuotaThresholdMailer(mailetContext, MemoryUsersRepository.withVirtualHosting(), fileSystem, configuration)), - eventStore); - QuotaThresholdCrossingListener thresholdCrossingListener = - new QuotaThresholdCrossingListener(eventSourcingSystem); + new QuotaThresholdCrossingListener(mailetContext, MemoryUsersRepository.withVirtualHosting(), fileSystem, eventStore, configuration); MockMailboxSession mailboxSession = new MockMailboxSession("system"); delegatingListener.addGlobalListener(thresholdCrossingListener, mailboxSession); http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 16beb29..468c331 100644 --- a/pom.xml +++ b/pom.xml @@ -1558,6 +1558,11 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>quota-mailing-cassandra</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version> http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/cassandra-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml index 3c8d691..11725ec 100644 --- a/server/container/guice/cassandra-guice/pom.xml +++ b/server/container/guice/cassandra-guice/pom.xml @@ -146,6 +146,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-mailbox-plugin-quota-mailing</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-mailbox-plugin-spamassassin</artifactId> </dependency> <dependency> @@ -221,6 +225,10 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>quota-mailing-cassandra</artifactId> + </dependency> + <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index fe75ebc..cc023c1 100644 --- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -28,6 +28,7 @@ import org.apache.james.modules.data.CassandraSieveRepositoryModule; import org.apache.james.modules.data.CassandraUsersRepositoryModule; import org.apache.james.modules.eventstore.CassandraEventStoreModule; import org.apache.james.modules.mailbox.CassandraMailboxModule; +import org.apache.james.modules.mailbox.CassandraQuotaMailingModule; import org.apache.james.modules.mailbox.CassandraSessionModule; import org.apache.james.modules.mailbox.ElasticSearchMailboxModule; import org.apache.james.modules.mailbox.TikaMailboxModule; @@ -76,6 +77,9 @@ public class CassandraJamesServerMain { new JMAPServerModule(), WEBADMIN); + public static final Module PLUGINS = Modules.combine( + new CassandraQuotaMailingModule()); + public static final Module CASSANDRA_SERVER_MODULE = Modules.combine( new ActiveMQQueueModule(), new CassandraDomainListModule(), @@ -97,7 +101,7 @@ public class CassandraJamesServerMain { public static void main(String[] args) throws Exception { Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build(); GuiceJamesServer server = new GuiceJamesServer(configuration) - .combineWith(CASSANDRA_SERVER_MODULE, PROTOCOLS, new JMXServerModule()); + .combineWith(CASSANDRA_SERVER_MODULE, PROTOCOLS, PLUGINS, new JMXServerModule()); server.start(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/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 new file mode 100644 index 0000000..c8994d4 --- /dev/null +++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraQuotaMailingModule.java @@ -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.modules.mailbox; + +import org.apache.james.eventsourcing.eventstore.cassandra.dto.EventDTOModule; +import org.apache.james.mailbox.quota.cassandra.dto.QuotaThresholdChangedEventDTOModule; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +public class CassandraQuotaMailingModule extends AbstractModule { + @Override + protected void configure() { + install(new QuotaMailingModule()); + + Multibinder.newSetBinder(binder(), EventDTOModule.class) + .addBinding() + .to(QuotaThresholdChangedEventDTOModule.class); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/mailbox-plugin-quota-mailing/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox-plugin-quota-mailing/pom.xml b/server/container/guice/mailbox-plugin-quota-mailing/pom.xml new file mode 100644 index 0000000..1a96872 --- /dev/null +++ b/server/container/guice/mailbox-plugin-quota-mailing/pom.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.james</groupId> + <artifactId>james-server-guice</artifactId> + <version>3.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>james-server-guice-mailbox-plugin-quota-mailing</artifactId> + + <name>Apache James :: Server :: Guice :: Mailbox :: Plugin :: Quota Mailing</name> + <description>Mailbox modules for Guice implementation of Quota mailing</description> + + <dependencies> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-quota-mailing</artifactId> + </dependency> + <dependency> + <groupId>com.google.inject</groupId> + <artifactId>guice</artifactId> + </dependency> + </dependencies> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/mailbox-plugin-quota-mailing/src/main/java/org/apache/james/modules/mailbox/QuotaMailingModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/mailbox-plugin-quota-mailing/src/main/java/org/apache/james/modules/mailbox/QuotaMailingModule.java b/server/container/guice/mailbox-plugin-quota-mailing/src/main/java/org/apache/james/modules/mailbox/QuotaMailingModule.java new file mode 100644 index 0000000..7d13cc6 --- /dev/null +++ b/server/container/guice/mailbox-plugin-quota-mailing/src/main/java/org/apache/james/modules/mailbox/QuotaMailingModule.java @@ -0,0 +1,41 @@ +/**************************************************************** + * 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.modules.mailbox; + +import java.time.Duration; + +import org.apache.james.mailbox.quota.mailing.QuotaMailingListenerConfiguration; +import org.apache.james.mailbox.quota.model.QuotaThreshold; + +import com.google.inject.AbstractModule; + +public class QuotaMailingModule extends AbstractModule { + @Override + protected void configure() { + bind(QuotaMailingListenerConfiguration.class) + .toInstance( + QuotaMailingListenerConfiguration.builder() + .addThresholds( + new QuotaThreshold(0.80), + new QuotaThreshold(0.99)) + .gracePeriod(Duration.ofDays(1)) + .build()); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/memory-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/pom.xml b/server/container/guice/memory-guice/pom.xml index 26a0322..a62830e 100644 --- a/server/container/guice/memory-guice/pom.xml +++ b/server/container/guice/memory-guice/pom.xml @@ -92,6 +92,10 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-mailbox-plugin-quota-mailing</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-mailbox-plugin-spamassassin</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java index 99783fd..30df53c 100644 --- a/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java +++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/MemoryJamesServerMain.java @@ -25,6 +25,7 @@ import org.apache.james.modules.data.MemoryDataJmapModule; import org.apache.james.modules.data.MemoryDataModule; import org.apache.james.modules.eventstore.MemoryEventStoreModule; import org.apache.james.modules.mailbox.MemoryMailboxModule; +import org.apache.james.modules.mailbox.QuotaMailingModule; import org.apache.james.modules.protocols.IMAPServerModule; import org.apache.james.modules.protocols.JMAPServerModule; import org.apache.james.modules.protocols.LMTPServerModule; @@ -67,6 +68,9 @@ public class MemoryJamesServerMain { new SMTPServerModule(), new SpamAssassinListenerModule()); + public static final Module PLUGINS = Modules.combine( + new QuotaMailingModule()); + public static final Module JMAP = Modules.combine( new MemoryDataJmapModule(), new JMAPServerModule()); @@ -95,7 +99,8 @@ public class MemoryJamesServerMain { IN_MEMORY_SERVER_MODULE, PROTOCOLS, JMAP, - WEBADMIN); + WEBADMIN, + PLUGINS); public static void main(String[] args) throws Exception { Configuration configuration = Configuration.builder().useWorkingDirectoryEnvProperty().build(); http://git-wip-us.apache.org/repos/asf/james-project/blob/dcdd5847/server/container/guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/pom.xml b/server/container/guice/pom.xml index ab62bb7..2bdaf1f 100644 --- a/server/container/guice/pom.xml +++ b/server/container/guice/pom.xml @@ -45,6 +45,7 @@ <module>jpa-guice</module> <module>jpa-smtp</module> <module>mailbox</module> + <module>mailbox-plugin-quota-mailing</module> <module>mailbox-plugin-spamassassin</module> <module>mailet</module> <module>memory-guice</module> @@ -110,6 +111,11 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-mailbox-plugin-quota-mailing</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-guice-mailbox-plugin-spamassassin</artifactId> <version>${project.version}</version> </dependency> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
