Improve mail service (#3230)

* move mail config to mail service constructor

* update subscription email sender

* added license text

* [2669] bump HAPI version to 5.7.0-PRE6-SNAPSHOT

* add changelog
This commit is contained in:
VK-SMILECDR 2021-12-09 17:05:42 -05:00 committed by GitHub
parent 9593b6b0b8
commit bd89cf022b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
67 changed files with 173 additions and 133 deletions

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -10,7 +10,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-cli</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../hapi-deployable-pom</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -0,0 +1,3 @@
---
type: change
title: "Add email configuration to MailSvc constructor"

View File

@ -11,7 +11,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -1,21 +1,18 @@
package ca.uhn.fhir.jpa.config;
import ca.uhn.fhir.jpa.dao.BaseJpaTest;
import ca.uhn.fhir.jpa.search.HapiLuceneAnalysisConfigurer;
import ca.uhn.fhir.jpa.subscription.match.deliver.email.EmailSenderImpl;
import ca.uhn.fhir.jpa.subscription.match.deliver.email.IEmailSender;
import ca.uhn.fhir.jpa.util.CircularQueueCaptureQueriesListener;
import ca.uhn.fhir.jpa.util.CurrentThreadCaptureQueriesListener;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.rest.server.mail.IMailSvc;
import ca.uhn.fhir.rest.server.mail.MailConfig;
import ca.uhn.fhir.rest.server.mail.MailSvc;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.search.backend.lucene.cfg.LuceneBackendSettings;
import org.hibernate.search.backend.lucene.cfg.LuceneIndexSettings;
import org.hibernate.search.engine.cfg.BackendSettings;
import org.hibernate.search.mapper.orm.cfg.HibernateOrmMapperSettings;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -32,8 +29,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import static ca.uhn.fhir.jpa.dao.BaseJpaTest.buildHeapLuceneHibernateSearchProperties;
import static ca.uhn.fhir.jpa.dao.BaseJpaTest.buildHibernateSearchProperties;
import static org.junit.jupiter.api.Assertions.fail;
@Configuration
@ -65,7 +60,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
ourLog.error("Exceeded maximum wait for connection", e);
logGetConnectionStackTrace();
// if ("true".equals(System.getStringProperty("ci"))) {
fail("Exceeded maximum wait for connection: " + e.toString());
fail("Exceeded maximum wait for connection: " + e);
// }
// System.exit(1);
retVal = null;
@ -138,7 +133,9 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
@Bean
public IEmailSender emailSender() {
return new EmailSenderImpl(new MailConfig().setSmtpHostname("localhost").setSmtpPort(3025));
final MailConfig mailConfig = new MailConfig().setSmtpHostname("localhost").setSmtpPort(3025);
final IMailSvc mailSvc = new MailSvc(mailConfig);
return new EmailSenderImpl(mailSvc);
}
@Override

View File

@ -2,7 +2,9 @@ package ca.uhn.fhir.jpa.subscription.email;
import ca.uhn.fhir.jpa.subscription.match.deliver.email.EmailDetails;
import ca.uhn.fhir.jpa.subscription.match.deliver.email.EmailSenderImpl;
import ca.uhn.fhir.rest.server.mail.IMailSvc;
import ca.uhn.fhir.rest.server.mail.MailConfig;
import ca.uhn.fhir.rest.server.mail.MailSvc;
import com.icegreen.greenmail.junit5.GreenMailExtension;
import com.icegreen.greenmail.util.GreenMailUtil;
import com.icegreen.greenmail.util.ServerSetupTest;
@ -31,7 +33,7 @@ public class EmailSenderImplTest {
@BeforeEach
public void setUp() {
fixture = new EmailSenderImpl(withMailConfig());
fixture = new EmailSenderImpl(withMailService());
}
@Test
@ -62,10 +64,11 @@ public class EmailSenderImplTest {
assertEquals("foo", foundBody);
}
private MailConfig withMailConfig() {
return new MailConfig()
private IMailSvc withMailService() {
final MailConfig mailConfig = new MailConfig()
.setSmtpHostname(ServerSetupTest.SMTP.getBindAddress())
.setSmtpPort(ServerSetupTest.SMTP.getPort());
.setSmtpPort(ourGreenMail.getSmtp().getPort());
return new MailSvc(mailConfig);
}
}

View File

@ -11,7 +11,9 @@ import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.mail.IMailSvc;
import ca.uhn.fhir.rest.server.mail.MailConfig;
import ca.uhn.fhir.rest.server.mail.MailSvc;
import com.icegreen.greenmail.junit5.GreenMailExtension;
import com.icegreen.greenmail.util.GreenMailUtil;
import com.icegreen.greenmail.util.ServerSetupTest;
@ -43,7 +45,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test {
@RegisterExtension
static GreenMailExtension ourGreenMail = new GreenMailExtension(ServerSetupTest.SMTP.withPort(0));
private List<IIdType> mySubscriptionIds = new ArrayList<>();
private final List<IIdType> mySubscriptionIds = new ArrayList<>();
@Autowired
private SubscriptionTestUtil mySubscriptionTestUtil;
@ -123,7 +125,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test {
Subscription subscription1 = createSubscription(criteria1, payload, "to1@example.com,to2@example.com");
mySubscriptionTestUtil.waitForQueueToDrain();
await().until(() -> mySubscriptionRegistry.get(subscription1.getIdElement().getIdPart()), Matchers.not(Matchers.nullValue()));
mySubscriptionTestUtil.setEmailSender(subscription1.getIdElement(), new EmailSenderImpl(withMailConfig()));
mySubscriptionTestUtil.setEmailSender(subscription1.getIdElement(), new EmailSenderImpl(withMailService()));
assertEquals(0, Arrays.asList(ourGreenMail.getReceivedMessages()).size());
Observation observation1 = sendObservation(code, "SNOMED-CT");
@ -145,10 +147,11 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test {
assertEquals("", foundBody);
}
private MailConfig withMailConfig() {
return new MailConfig()
private IMailSvc withMailService() {
final MailConfig mailConfig = new MailConfig()
.setSmtpHostname(ServerSetupTest.SMTP.getBindAddress())
.setSmtpPort(ourGreenMail.getSmtp().getPort());
return new MailSvc(mailConfig);
}
}

View File

@ -5,12 +5,13 @@ import ca.uhn.fhir.jpa.provider.dstu3.BaseResourceProviderDstu3Test;
import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil;
import ca.uhn.fhir.jpa.subscription.match.deliver.email.EmailSenderImpl;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.mail.IMailSvc;
import ca.uhn.fhir.rest.server.mail.MailConfig;
import ca.uhn.fhir.rest.server.mail.MailSvc;
import ca.uhn.fhir.util.HapiExtensions;
import com.icegreen.greenmail.junit5.GreenMailExtension;
import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.util.ServerSetupTest;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.CodeableConcept;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Observation;
@ -32,7 +33,6 @@ import java.util.function.Consumer;
import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@ -48,7 +48,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
@Autowired
private SubscriptionTestUtil mySubscriptionTestUtil;
private List<IIdType> mySubscriptionIds = new ArrayList<>();
private final List<IIdType> mySubscriptionIds = new ArrayList<>();
@AfterEach
public void afterUnregisterEmailListener() {
@ -140,7 +140,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
String criteria1 = "Observation?code=SNOMED-CT|" + code + "&_format=xml";
Subscription subscription = createSubscription(criteria1, payload);
waitForQueueToDrain();
mySubscriptionTestUtil.setEmailSender(subscription.getIdElement(), new EmailSenderImpl(withMailConfig()));
mySubscriptionTestUtil.setEmailSender(subscription.getIdElement(), new EmailSenderImpl(withMailService()));
sendObservation(code, "SNOMED-CT");
waitForQueueToDrain();
@ -185,7 +185,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
Subscription sub1 = createSubscription(criteria1, payload, modifier);
waitForQueueToDrain();
mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailConfig()));
mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailService()));
sendObservation(code, "SNOMED-CT");
waitForQueueToDrain();
@ -199,7 +199,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
assertEquals(1, received.get(0).getAllRecipients().length);
assertEquals("foo@example.com", ((InternetAddress) received.get(0).getAllRecipients()[0]).getAddress());
assertEquals("text/plain; charset=UTF-8", received.get(0).getContentType());
assertEquals("This is a subject", received.get(0).getSubject().toString().trim());
assertEquals("This is a subject", received.get(0).getSubject().trim());
assertEquals(mySubscriptionIds.get(0).toUnqualifiedVersionless().getValue(), received.get(0).getHeader("X-FHIR-Subscription")[0]);
// Expect the body of the email subscription to be an Observation formatted as JSON
@ -232,7 +232,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
Subscription sub1 = createSubscription(criteria1, payload, modifier);
waitForQueueToDrain();
mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailConfig()));
mySubscriptionTestUtil.setEmailSender(sub1.getIdElement(), new EmailSenderImpl(withMailService()));
sendObservation(code, "SNOMED-CT");
waitForQueueToDrain();
@ -247,7 +247,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
assertEquals(1, received.get(0).getAllRecipients().length);
assertEquals("foo@example.com", ((InternetAddress) received.get(0).getAllRecipients()[0]).getAddress());
assertEquals("text/plain; charset=UTF-8", received.get(0).getContentType());
assertEquals("This is a subject", received.get(0).getSubject().toString().trim());
assertEquals("This is a subject", received.get(0).getSubject().trim());
assertEquals("", received.get(0).getContent().toString().trim());
assertEquals(mySubscriptionIds.get(0).toUnqualifiedVersionless().getValue(), received.get(0).getHeader("X-FHIR-Subscription")[0]);
@ -260,11 +260,11 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
mySubscriptionTestUtil.waitForQueueToDrain();
}
private MailConfig withMailConfig() {
return new MailConfig()
private IMailSvc withMailService() {
final MailConfig mailConfig = new MailConfig()
.setSmtpHostname(ServerSetupTest.SMTP.getBindAddress())
.setSmtpPort(ourGreenMail.getSmtp().getPort());
return new MailSvc(mailConfig);
}
}

View File

@ -7,7 +7,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -20,8 +20,7 @@ package ca.uhn.fhir.jpa.subscription.match.deliver.email;
* #L%
*/
import ca.uhn.fhir.rest.server.mail.MailConfig;
import ca.uhn.fhir.rest.server.mail.MailSvc;
import ca.uhn.fhir.rest.server.mail.IMailSvc;
import ca.uhn.fhir.util.StopWatch;
import org.apache.commons.lang3.Validate;
import org.simplejavamail.api.email.Email;
@ -33,25 +32,23 @@ import javax.annotation.Nonnull;
public class EmailSenderImpl implements IEmailSender {
private static final Logger ourLog = LoggerFactory.getLogger(EmailSenderImpl.class);
private MailSvc myMailSvc = new MailSvc();
private MailConfig myMailConfig;
public EmailSenderImpl(@Nonnull MailConfig theMailConfig) {
Validate.notNull(theMailConfig);
myMailConfig = theMailConfig;
private final IMailSvc myMailSvc;
public EmailSenderImpl(@Nonnull IMailSvc theMailSvc) {
Validate.notNull(theMailSvc);
myMailSvc = theMailSvc;
}
@Override
public void send(EmailDetails theDetails) {
Validate.notNull(myMailConfig, "Mail configuration is not set!");
StopWatch stopWatch = new StopWatch();
ourLog.info("Sending email for subscription {} from [{}] to recipients: [{}]", theDetails.getSubscriptionId(), theDetails.getFrom(), theDetails.getTo());
Email email = theDetails.toEmail();
myMailSvc.sendMail(myMailConfig, email,
myMailSvc.sendMail(email,
() -> ourLog.info("Done sending email for subscription {} from [{}] to recipients: [{}] (took {}ms)",
theDetails.getSubscriptionId(), theDetails.getFrom(), theDetails.getTo(), stopWatch.getMillis()),
(e) -> {

View File

@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -0,0 +1,38 @@
package ca.uhn.fhir.rest.server.mail;
/*-
* #%L
* HAPI FHIR - Server Framework
* %%
* Copyright (C) 2014 - 2021 Smile CDR, Inc.
* %%
* Licensed 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.
* #L%
*/
import org.simplejavamail.api.email.Email;
import org.simplejavamail.api.mailer.AsyncResponse;
import javax.annotation.Nonnull;
import java.util.List;
public interface IMailSvc {
void sendMail(@Nonnull List<Email> theEmails);
void sendMail(@Nonnull Email theEmail);
void sendMail(@Nonnull Email theEmail,
@Nonnull Runnable theOnSuccess,
@Nonnull AsyncResponse.ExceptionConsumer theErrorHandler);
}

View File

@ -36,41 +36,44 @@ import javax.annotation.Nonnull;
import java.util.List;
import java.util.stream.Collectors;
public class MailSvc {
public class MailSvc implements IMailSvc {
private static final Logger ourLog = LoggerFactory.getLogger(MailSvc.class);
public void sendMail(@Nonnull MailConfig theMailConfig, @Nonnull List<Email> theEmails) {
private final MailConfig myMailConfig;
private final Mailer myMailer;
public MailSvc(@Nonnull MailConfig theMailConfig) {
Validate.notNull(theMailConfig);
myMailConfig = theMailConfig;
myMailer = makeMailer(myMailConfig);
}
@Override
public void sendMail(@Nonnull List<Email> theEmails) {
Validate.notNull(theEmails);
final Mailer mailer = makeMailer(theMailConfig);
theEmails.forEach(theEmail -> sendMail(mailer, theEmail, new OnSuccess(theEmail), new ErrorHandler(theEmail)));
theEmails.forEach(theEmail -> send(theEmail, new OnSuccess(theEmail), new ErrorHandler(theEmail)));
}
public void sendMail(@Nonnull MailConfig theMailConfig, @Nonnull Email theEmail) {
Validate.notNull(theMailConfig);
final Mailer mailer = makeMailer(theMailConfig);
sendMail(mailer, theEmail, new OnSuccess(theEmail), new ErrorHandler(theEmail));
@Override
public void sendMail(@Nonnull Email theEmail) {
send(theEmail, new OnSuccess(theEmail), new ErrorHandler(theEmail));
}
public void sendMail(@Nonnull MailConfig theMailConfig,
@Nonnull Email theEmail,
@Override
public void sendMail(@Nonnull Email theEmail,
@Nonnull Runnable theOnSuccess,
@Nonnull ExceptionConsumer theErrorHandler) {
Validate.notNull(theMailConfig);
final Mailer mailer = makeMailer(theMailConfig);
sendMail(mailer, theEmail, theOnSuccess, theErrorHandler);
send(theEmail, theOnSuccess, theErrorHandler);
}
private void sendMail(@Nonnull Mailer theMailer,
@Nonnull Email theEmail,
private void send(@Nonnull Email theEmail,
@Nonnull Runnable theOnSuccess,
@Nonnull ExceptionConsumer theErrorHandler) {
Validate.notNull(theMailer);
Validate.notNull(theEmail);
Validate.notNull(theOnSuccess);
Validate.notNull(theErrorHandler);
try {
final AsyncResponse asyncResponse = theMailer.sendMail(theEmail, true);
final AsyncResponse asyncResponse = myMailer.sendMail(theEmail, true);
if (asyncResponse != null) {
asyncResponse.onSuccess(theOnSuccess);
asyncResponse.onException(theErrorHandler);

View File

@ -28,20 +28,19 @@ public class MailSvcIT {
@RegisterExtension
static GreenMailExtension ourGreenMail = new GreenMailExtension(ServerSetupTest.SMTP);
private MailSvc fixture;
private IMailSvc fixture;
@BeforeEach
public void setUp() {
fixture = new MailSvc();
fixture = new MailSvc(withMailConfig());
}
@Test
public void testSendSingleMail() throws Exception {
// setup
final MailConfig mailConfig = withMailConfig();
final Email email = withEmail();
// execute
fixture.sendMail(mailConfig, email);
fixture.sendMail(email);
// validate
assertTrue(ourGreenMail.waitForIncomingEmail(1000, 1));
final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages();
@ -53,10 +52,9 @@ public class MailSvcIT {
@Test
public void testSendMultipleMail() throws Exception {
// setup
final MailConfig mailConfig = withMailConfig();
final List<Email> emails = Arrays.asList(withEmail(), withEmail(), withEmail());
// execute
fixture.sendMail(mailConfig, emails);
fixture.sendMail(emails);
// validate
assertTrue(ourGreenMail.waitForIncomingEmail(1000, emails.size()));
final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages();
@ -72,10 +70,9 @@ public class MailSvcIT {
@Test
public void testSendMailWithInvalidToAddress() {
// setup
final MailConfig mailConfig = withMailConfig();
final Email email = withEmail("xyz");
// execute
fixture.sendMail(mailConfig, email);
fixture.sendMail(email);
// validate
assertTrue(ourGreenMail.waitForIncomingEmail(1000, 0));
final MimeMessage[] receivedMessages = ourGreenMail.getReceivedMessages();
@ -85,10 +82,9 @@ public class MailSvcIT {
@Test
public void testSendMailWithInvalidToAddressExpectErrorHandler() {
// setup
final MailConfig mailConfig = withMailConfig();
final Email email = withEmail("xyz");
// execute
fixture.sendMail(mailConfig, email,
fixture.sendMail(email,
() -> fail("Should not execute on Success"),
(e) -> {
assertTrue(e instanceof MailException);

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-spring-boot-samples</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</parent>
<artifactId>hapi-fhir-spring-boot-sample-client-apache</artifactId>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-spring-boot-samples</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</parent>
<artifactId>hapi-fhir-spring-boot-sample-client-okhttp</artifactId>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-spring-boot-samples</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</parent>
<artifactId>hapi-fhir-spring-boot-sample-server-jersey</artifactId>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-spring-boot</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</parent>
<artifactId>hapi-fhir-spring-boot-samples</artifactId>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-deployable-pom</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../hapi-deployable-pom/pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
@ -58,37 +58,37 @@
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu3</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r4</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r5</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu2</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-dstu3</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-validation-resources-r4</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

View File

@ -6,7 +6,7 @@
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<packaging>pom</packaging>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<name>HAPI-FHIR</name>
<description>An open-source implementation of the FHIR specification in Java.</description>
<url>https://hapifhir.io</url>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -4,7 +4,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId>
<version>5.7.0-PRE5-SNAPSHOT</version>
<version>5.7.0-PRE6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>