You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2024/06/14 07:26:40 UTC
(james-project) branch master updated: JAMES-3946 Add a DropLists JPA backend (#2289)
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new ba7dc618ab JAMES-3946 Add a DropLists JPA backend (#2289)
ba7dc618ab is described below
commit ba7dc618ab2f9727a18220ffe988978629bf062a
Author: Maksim <85...@users.noreply.github.com>
AuthorDate: Fri Jun 14 10:26:35 2024 +0300
JAMES-3946 Add a DropLists JPA backend (#2289)
---
.../sample-configuration/droplists.properties | 3 +
.../org/apache/james/JPAJamesConfiguration.java | 28 +++-
.../java/org/apache/james/JPAJamesServerMain.java | 14 +-
.../src/main/resources/META-INF/persistence.xml | 1 +
.../james/modules/data/JPADropListsModule.java | 33 ++++
server/data/data-jpa/pom.xml | 6 +-
.../apache/james/droplists/jpa/JPADropList.java | 124 ++++++++++++++
.../droplists/jpa/model/JPADropListEntry.java | 182 +++++++++++++++++++++
.../james/droplists/jpa/JPADropListTest.java | 49 ++++++
.../data-jpa/src/test/resources/persistence.xml | 1 +
10 files changed, 434 insertions(+), 7 deletions(-)
diff --git a/server/apps/jpa-app/sample-configuration/droplists.properties b/server/apps/jpa-app/sample-configuration/droplists.properties
new file mode 100644
index 0000000000..bbc27568cb
--- /dev/null
+++ b/server/apps/jpa-app/sample-configuration/droplists.properties
@@ -0,0 +1,3 @@
+# Configuration file for DropLists
+
+enabled=false
\ No newline at end of file
diff --git a/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesConfiguration.java b/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesConfiguration.java
index de353049ac..882222c993 100644
--- a/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesConfiguration.java
+++ b/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesConfiguration.java
@@ -22,6 +22,7 @@ package org.apache.james;
import java.io.File;
import java.util.Optional;
+import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.james.data.UsersRepositoryModuleChooser;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.filesystem.api.JamesDirectoriesProvider;
@@ -36,11 +37,13 @@ public class JPAJamesConfiguration implements Configuration {
private Optional<String> rootDirectory;
private Optional<ConfigurationPath> configurationPath;
private Optional<UsersRepositoryModuleChooser.Implementation> usersRepositoryImplementation;
+ private Optional<Boolean> dropListsEnabled;
private Builder() {
rootDirectory = Optional.empty();
configurationPath = Optional.empty();
usersRepositoryImplementation = Optional.empty();
+ dropListsEnabled = Optional.empty();
}
public Builder workingDirectory(String path) {
@@ -76,6 +79,11 @@ public class JPAJamesConfiguration implements Configuration {
return this;
}
+ public Builder enableDropLists() {
+ this.dropListsEnabled = Optional.of(true);
+ return this;
+ }
+
public JPAJamesConfiguration build() {
ConfigurationPath configurationPath = this.configurationPath.orElse(new ConfigurationPath(FileSystem.FILE_PROTOCOL_AND_CONF));
JamesServerResourceLoader directories = new JamesServerResourceLoader(rootDirectory
@@ -90,10 +98,19 @@ public class JPAJamesConfiguration implements Configuration {
UsersRepositoryModuleChooser.Implementation usersRepositoryChoice = usersRepositoryImplementation.orElseGet(
() -> UsersRepositoryModuleChooser.Implementation.parse(configurationProvider));
+ boolean dropListsEnabled = this.dropListsEnabled.orElseGet(() -> {
+ try {
+ return configurationProvider.getConfiguration("droplists").getBoolean("enabled", false);
+ } catch (ConfigurationException e) {
+ return false;
+ }
+ });
+
return new JPAJamesConfiguration(
configurationPath,
directories,
- usersRepositoryChoice);
+ usersRepositoryChoice,
+ dropListsEnabled);
}
}
@@ -104,11 +121,14 @@ public class JPAJamesConfiguration implements Configuration {
private final ConfigurationPath configurationPath;
private final JamesDirectoriesProvider directories;
private final UsersRepositoryModuleChooser.Implementation usersRepositoryImplementation;
+ private final boolean dropListsEnabled;
- public JPAJamesConfiguration(ConfigurationPath configurationPath, JamesDirectoriesProvider directories, UsersRepositoryModuleChooser.Implementation usersRepositoryImplementation) {
+ public JPAJamesConfiguration(ConfigurationPath configurationPath, JamesDirectoriesProvider directories,
+ UsersRepositoryModuleChooser.Implementation usersRepositoryImplementation, boolean dropListsEnabled) {
this.configurationPath = configurationPath;
this.directories = directories;
this.usersRepositoryImplementation = usersRepositoryImplementation;
+ this.dropListsEnabled = dropListsEnabled;
}
@Override
@@ -124,4 +144,8 @@ public class JPAJamesConfiguration implements Configuration {
public UsersRepositoryModuleChooser.Implementation getUsersRepositoryImplementation() {
return usersRepositoryImplementation;
}
+
+ public boolean isDropListsEnabled() {
+ return dropListsEnabled;
+ }
}
diff --git a/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesServerMain.java
index 54d764c5d8..ff4a03b09b 100644
--- a/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesServerMain.java
+++ b/server/apps/jpa-app/src/main/java/org/apache/james/JPAJamesServerMain.java
@@ -24,6 +24,7 @@ import org.apache.james.modules.MailboxModule;
import org.apache.james.modules.MailetProcessingModule;
import org.apache.james.modules.RunArgumentsModule;
import org.apache.james.modules.data.JPADataModule;
+import org.apache.james.modules.data.JPADropListsModule;
import org.apache.james.modules.data.JPAUsersRepositoryModule;
import org.apache.james.modules.data.SieveJPARepositoryModules;
import org.apache.james.modules.mailbox.DefaultEventModule;
@@ -39,6 +40,7 @@ import org.apache.james.modules.protocols.SMTPServerModule;
import org.apache.james.modules.queue.activemq.ActiveMQQueueModule;
import org.apache.james.modules.server.DataRoutesModules;
import org.apache.james.modules.server.DefaultProcessorsConfigurationProviderModule;
+import org.apache.james.modules.server.DropListsRoutesModule;
import org.apache.james.modules.server.InconsistencyQuotasSolvingRoutesModule;
import org.apache.james.modules.server.JMXServerModule;
import org.apache.james.modules.server.MailQueueRoutesModule;
@@ -107,7 +109,8 @@ public class JPAJamesServerMain implements JamesServerMain {
LOGGER.info("Loading configuration {}", configuration.toString());
GuiceJamesServer server = createServer(configuration)
.combineWith(new JMXServerModule())
- .overrideWith(new RunArgumentsModule(args));
+ .overrideWith(new RunArgumentsModule(args))
+ .overrideWith(chooseDropListsModule(configuration));
JamesServerMain.main(server);
}
@@ -118,4 +121,13 @@ public class JPAJamesServerMain implements JamesServerMain {
.combineWith(new UsersRepositoryModuleChooser(new JPAUsersRepositoryModule())
.chooseModules(configuration.getUsersRepositoryImplementation()));
}
+
+ private static Module chooseDropListsModule(JPAJamesConfiguration configuration) {
+ if (configuration.isDropListsEnabled()) {
+ return Modules.combine(new JPADropListsModule(), new DropListsRoutesModule());
+ }
+ return binder -> {
+
+ };
+ }
}
diff --git a/server/apps/jpa-app/src/main/resources/META-INF/persistence.xml b/server/apps/jpa-app/src/main/resources/META-INF/persistence.xml
index 3c26a90ca2..e585342d0f 100644
--- a/server/apps/jpa-app/src/main/resources/META-INF/persistence.xml
+++ b/server/apps/jpa-app/src/main/resources/META-INF/persistence.xml
@@ -32,6 +32,7 @@
<class>org.apache.james.mailbox.jpa.user.model.JPASubscription</class>
<class>org.apache.james.domainlist.jpa.model.JPADomain</class>
+ <class>org.apache.james.droplists.jpa.model.JPADropListEntry</class>
<class>org.apache.james.mailrepository.jpa.model.JPAUrl</class>
<class>org.apache.james.mailrepository.jpa.model.JPAMail</class>
<class>org.apache.james.user.jpa.model.JPAUser</class>
diff --git a/server/container/guice/jpa-common/src/main/java/org/apache/james/modules/data/JPADropListsModule.java b/server/container/guice/jpa-common/src/main/java/org/apache/james/modules/data/JPADropListsModule.java
new file mode 100644
index 0000000000..1f41241f24
--- /dev/null
+++ b/server/container/guice/jpa-common/src/main/java/org/apache/james/modules/data/JPADropListsModule.java
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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.data;
+
+import org.apache.james.droplists.api.DropList;
+import org.apache.james.droplists.jpa.JPADropList;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+
+public class JPADropListsModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ bind(DropList.class).to(JPADropList.class).in(Scopes.SINGLETON);
+ }
+}
\ No newline at end of file
diff --git a/server/data/data-jpa/pom.xml b/server/data/data-jpa/pom.xml
index bef4926339..2bc8cb1194 100644
--- a/server/data/data-jpa/pom.xml
+++ b/server/data/data-jpa/pom.xml
@@ -32,10 +32,6 @@
<name>Apache James :: Server :: Data :: JPA Persistence</name>
- <properties>
- <target.jdk>11</target.jdk>
- </properties>
-
<dependencies>
<dependency>
<groupId>${james.groupId}</groupId>
@@ -174,6 +170,7 @@
org/apache/james/user/jpa/model/JPAUser.class,
org/apache/james/rrt/jpa/model/JPARecipientRewrite.class,
org/apache/james/domainlist/jpa/model/JPADomain.class,
+ org/apache/james/droplists/jpa/model/JPADropListEntry.class,
org/apache/james/mailrepository/jpa/model/JPAUrl.class,
org/apache/james/mailrepository/jpa/model/JPAMail.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
@@ -190,6 +187,7 @@
org.apache.james.user.jpa.model.JPAUser;
org.apache.james.rrt.jpa.model.JPARecipientRewrite;
org.apache.james.domainlist.jpa.model.JPADomain;
+ org.apache.james.droplists.jpa.model.JPADropListEntry
org.apache.james.mailrepository.jpa.model.JPAUrl;
org.apache.james.mailrepository.jpa.model.JPAMail)</value>
</property>
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/droplists/jpa/JPADropList.java b/server/data/data-jpa/src/main/java/org/apache/james/droplists/jpa/JPADropList.java
new file mode 100644
index 0000000000..88d87cf03c
--- /dev/null
+++ b/server/data/data-jpa/src/main/java/org/apache/james/droplists/jpa/JPADropList.java
@@ -0,0 +1,124 @@
+/****************************************************************
+ * 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.droplists.jpa;
+
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+import jakarta.inject.Inject;
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
+import jakarta.persistence.PersistenceException;
+
+import org.apache.james.backends.jpa.EntityManagerUtils;
+import org.apache.james.backends.jpa.TransactionRunner;
+import org.apache.james.core.MailAddress;
+import org.apache.james.droplists.api.DropList;
+import org.apache.james.droplists.api.DropListEntry;
+import org.apache.james.droplists.api.OwnerScope;
+import org.apache.james.droplists.jpa.model.JPADropListEntry;
+import org.apache.james.sieverepository.api.exception.StorageException;
+
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class JPADropList implements DropList {
+
+ private static final String OWNER_SCOPE = "ownerScope";
+ private static final String OWNER = "owner";
+ private static final String DENIED_ENTITY = "deniedEntity";
+
+ private final TransactionRunner transactionRunner;
+ private final EntityManagerFactory entityManagerFactory;
+
+ @Inject
+ public JPADropList(EntityManagerFactory entityManagerFactory) {
+ this.entityManagerFactory = entityManagerFactory;
+ this.transactionRunner = new TransactionRunner(entityManagerFactory);
+ }
+
+ @Override
+ public Mono<Void> add(DropListEntry entry) {
+ Preconditions.checkArgument(entry != null);
+ return Mono.fromRunnable(() ->
+ transactionRunner.run(entityManager ->
+ entityManager.persist(JPADropListEntry.fromDropListEntry(entry))));
+ }
+
+ @Override
+ public Mono<Void> remove(DropListEntry entry) {
+ Preconditions.checkArgument(entry != null);
+ return Mono.fromRunnable(() -> transactionRunner.runAndHandleException(Throwing.consumer(entityManager ->
+ entityManager.createNamedQuery("removeDropListEntry")
+ .setParameter(OWNER_SCOPE, entry.getOwnerScope().name())
+ .setParameter(OWNER, entry.getOwner())
+ .setParameter(DENIED_ENTITY, entry.getDeniedEntity())
+ .executeUpdate()
+ ), throwStorageExceptionConsumer("Unable to remove denied entity " + entry.getDeniedEntity())));
+ }
+
+ @Override
+ public Flux<DropListEntry> list(OwnerScope ownerScope, String owner) {
+ Preconditions.checkArgument(ownerScope != null);
+ Preconditions.checkArgument(owner != null);
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ return Flux.fromStream(() -> getDropListEntries(entityManager, ownerScope, owner)
+ .map(JPADropListEntry::toDropListEntry))
+ .doFinally(any -> EntityManagerUtils.safelyClose(entityManager));
+ }
+
+ @Override
+ public Mono<Status> query(OwnerScope ownerScope, String owner, MailAddress sender) {
+ Preconditions.checkArgument(ownerScope != null);
+ Preconditions.checkArgument(owner != null);
+ Preconditions.checkArgument(sender != null);
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ return Mono.fromCallable(() -> queryDropList(entityManager, ownerScope, owner, sender))
+ .doFinally(any -> EntityManagerUtils.safelyClose(entityManager));
+ }
+
+ @SuppressWarnings("unchecked")
+ private Stream<JPADropListEntry> getDropListEntries(EntityManager entityManager, OwnerScope ownerScope, String owner) {
+ return entityManager
+ .createNamedQuery("listDropListEntries")
+ .setParameter(OWNER_SCOPE, ownerScope.name())
+ .setParameter(OWNER, owner)
+ .getResultStream();
+ }
+
+ private DropList.Status queryDropList(EntityManager entityManager, OwnerScope ownerScope, String owner, MailAddress sender) {
+ String specifiedOwner = ownerScope.equals(OwnerScope.GLOBAL) ? "" : owner;
+ return entityManager.createNamedQuery("queryDropListEntry")
+ .setParameter(OWNER_SCOPE, ownerScope.name())
+ .setParameter(OWNER, specifiedOwner)
+ .setParameter(DENIED_ENTITY, List.of(sender.asString(), sender.getDomain().asString()))
+ .getResultList().isEmpty() ? DropList.Status.ALLOWED : DropList.Status.BLOCKED;
+ }
+
+ private Consumer<PersistenceException> throwStorageExceptionConsumer(String message) {
+ return Throwing.<PersistenceException>consumer(e -> {
+ throw new StorageException(message, e);
+ }).sneakyThrow();
+ }
+}
diff --git a/server/data/data-jpa/src/main/java/org/apache/james/droplists/jpa/model/JPADropListEntry.java b/server/data/data-jpa/src/main/java/org/apache/james/droplists/jpa/model/JPADropListEntry.java
new file mode 100644
index 0000000000..dded720f49
--- /dev/null
+++ b/server/data/data-jpa/src/main/java/org/apache/james/droplists/jpa/model/JPADropListEntry.java
@@ -0,0 +1,182 @@
+/****************************************************************
+ * 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.droplists.jpa.model;
+
+import static org.apache.james.droplists.api.OwnerScope.DOMAIN;
+
+import java.util.Objects;
+
+import jakarta.mail.internet.AddressException;
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.Id;
+import jakarta.persistence.NamedQuery;
+import jakarta.persistence.Table;
+
+import org.apache.james.core.Domain;
+import org.apache.james.core.MailAddress;
+import org.apache.james.droplists.api.DropListEntry;
+import org.apache.james.droplists.api.OwnerScope;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * A JPA entity representing a drop list entry.
+ */
+@Entity(name = "JamesDropList")
+@Table(name = "JAMES_DROP_LIST")
+@NamedQuery(name = "listDropListEntries",
+ query = "SELECT j FROM JamesDropList j WHERE j.ownerScope = :ownerScope AND j.owner = :owner")
+@NamedQuery(name = "queryDropListEntry",
+ query = "SELECT j FROM JamesDropList j WHERE j.ownerScope = :ownerScope AND j.owner = :owner AND j.deniedEntity IN :deniedEntity")
+@NamedQuery(name = "removeDropListEntry",
+ query = "DELETE FROM JamesDropList j WHERE j.ownerScope = :ownerScope AND j.owner = :owner AND j.deniedEntity = :deniedEntity")
+public class JPADropListEntry {
+
+ @Id
+ @GeneratedValue
+ @Column(name = "DROPLIST_ID")
+ private long id;
+
+ @Column(name = "OWNER_SCOPE", nullable = false)
+ private String ownerScope;
+
+ @Column(name = "OWNER")
+ private String owner;
+
+ @Column(name = "DENIED_ENTITY_TYPE", nullable = false)
+ private String deniedEntityType;
+
+ @Column(name = "DENIED_ENTITY", nullable = false)
+ private String deniedEntity;
+
+ public JPADropListEntry() {
+ // Default no-args constructor for JPA class enhancement.
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getOwnerScope() {
+ return ownerScope;
+ }
+
+ public void setOwnerScope(String ownerScope) {
+ this.ownerScope = ownerScope;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+ public String getDeniedEntityType() {
+ return deniedEntityType;
+ }
+
+ public void setDeniedEntityType(String deniedEntityType) {
+ this.deniedEntityType = deniedEntityType;
+ }
+
+ public String getDeniedEntity() {
+ return deniedEntity;
+ }
+
+ public void setDeniedEntity(String deniedEntity) {
+ this.deniedEntity = deniedEntity;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o instanceof JPADropListEntry jpaDropListEntry) {
+ return Objects.equals(id, jpaDropListEntry.id) &&
+ Objects.equals(ownerScope, jpaDropListEntry.ownerScope) &&
+ Objects.equals(owner, jpaDropListEntry.owner) &&
+ Objects.equals(deniedEntityType, jpaDropListEntry.deniedEntityType) &&
+ Objects.equals(deniedEntity, jpaDropListEntry.deniedEntity);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, ownerScope, owner, deniedEntityType, deniedEntity);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("id", id)
+ .add("ownerScope", ownerScope)
+ .add("owner", owner)
+ .add("deniedEntityType", deniedEntityType)
+ .add("deniedEntity", deniedEntity)
+ .toString();
+ }
+
+ /**
+ * Converts this JPADropListEntry instance to a DropListEntry instance.
+ *
+ * @return the converted DropListEntry instance
+ * @throws IllegalArgumentException if the denied entity cannot be parsed as a MailAddress
+ */
+ public DropListEntry toDropListEntry() {
+ try {
+ DropListEntry.Builder builder = DropListEntry.builder();
+ switch (OwnerScope.valueOf(this.ownerScope)) {
+ case USER -> builder.userOwner(new MailAddress(this.owner));
+ case DOMAIN -> builder.domainOwner(Domain.of(this.owner));
+ case GLOBAL -> builder.forAll();
+ }
+ if (DOMAIN.name().equals(this.deniedEntityType)) {
+ builder.denyDomain(Domain.of(this.deniedEntity));
+ } else {
+ builder.denyAddress(new MailAddress(this.deniedEntity));
+ }
+ return builder.build();
+ } catch (AddressException e) {
+ throw new IllegalArgumentException("Entity could not be parsed as a MailAddress", e);
+ }
+ }
+
+ /**
+ * Creates a new JPADropListEntry instance from the specified DropListEntry instance.
+ *
+ * @param dropListEntry the DropListEntry instance to create a JPADropListEntry from
+ * @return the created JPADropListEntry instance
+ */
+ public static JPADropListEntry fromDropListEntry(DropListEntry dropListEntry) {
+ JPADropListEntry jpaDropListEntry = new JPADropListEntry();
+ jpaDropListEntry.setOwnerScope(dropListEntry.getOwnerScope().name());
+ jpaDropListEntry.setOwner(dropListEntry.getOwner());
+ jpaDropListEntry.setDeniedEntityType(dropListEntry.getDeniedEntityType().name());
+ jpaDropListEntry.setDeniedEntity(dropListEntry.getDeniedEntity());
+ return jpaDropListEntry;
+ }
+}
diff --git a/server/data/data-jpa/src/test/java/org/apache/james/droplists/jpa/JPADropListTest.java b/server/data/data-jpa/src/test/java/org/apache/james/droplists/jpa/JPADropListTest.java
new file mode 100644
index 0000000000..b75f4fb79f
--- /dev/null
+++ b/server/data/data-jpa/src/test/java/org/apache/james/droplists/jpa/JPADropListTest.java
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.droplists.jpa;
+
+import org.apache.james.backends.jpa.JpaTestCluster;
+import org.apache.james.droplists.api.DropList;
+import org.apache.james.droplists.api.DropListContract;
+import org.apache.james.droplists.jpa.model.JPADropListEntry;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+
+class JPADropListTest implements DropListContract {
+
+ static final JpaTestCluster jpaTestCluster = JpaTestCluster.create(JPADropListEntry.class);
+
+ JPADropList jpaDropList;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ jpaDropList = new JPADropList(jpaTestCluster.getEntityManagerFactory());
+ }
+
+ @AfterEach
+ void tearDown() {
+ jpaTestCluster.clear("JAMES_DROP_LIST");
+ }
+
+ @Override
+ public DropList dropList() {
+ return jpaDropList;
+ }
+}
\ No newline at end of file
diff --git a/server/data/data-jpa/src/test/resources/persistence.xml b/server/data/data-jpa/src/test/resources/persistence.xml
index 6224adb74f..9b440351c7 100644
--- a/server/data/data-jpa/src/test/resources/persistence.xml
+++ b/server/data/data-jpa/src/test/resources/persistence.xml
@@ -27,6 +27,7 @@
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/james)</jta-data-source>
<class>org.apache.james.domainlist.jpa.model.JPADomain</class>
+ <class>org.apache.james.droplists.jpa.model.JPADropListEntry</class>
<class>org.apache.james.user.jpa.model.JPAUser</class>
<class>org.apache.james.rrt.jpa.model.JPARecipientRewrite</class>
<class>org.apache.james.mailrepository.jpa.model.JPAUrl</class>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org