
001package ca.uhn.fhir.jpa.subscription.channel.subscription; 002 003/*- 004 * #%L 005 * HAPI FHIR Subscription Server 006 * %% 007 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.jpa.subscription.match.deliver.email.IEmailSender; 024import ca.uhn.fhir.jpa.subscription.match.deliver.email.SubscriptionDeliveringEmailSubscriber; 025import ca.uhn.fhir.jpa.subscription.match.deliver.message.SubscriptionDeliveringMessageSubscriber; 026import ca.uhn.fhir.jpa.subscription.match.deliver.resthook.SubscriptionDeliveringRestHookSubscriber; 027import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; 028import org.springframework.beans.factory.annotation.Autowired; 029import org.springframework.context.ApplicationContext; 030import org.springframework.messaging.MessageHandler; 031 032import java.util.Optional; 033 034public class SubscriptionDeliveryHandlerFactory { 035 private IEmailSender myEmailSender; 036 037 @Autowired 038 private ApplicationContext myApplicationContext; 039 040 protected SubscriptionDeliveringEmailSubscriber newSubscriptionDeliveringEmailSubscriber(IEmailSender theEmailSender) { 041 return myApplicationContext.getBean(SubscriptionDeliveringEmailSubscriber.class, theEmailSender); 042 } 043 044 protected SubscriptionDeliveringRestHookSubscriber newSubscriptionDeliveringRestHookSubscriber() { 045 return myApplicationContext.getBean(SubscriptionDeliveringRestHookSubscriber.class); 046 } 047 048 protected SubscriptionDeliveringMessageSubscriber newSubscriptionDeliveringMessageSubscriber() { 049 return myApplicationContext.getBean(SubscriptionDeliveringMessageSubscriber.class); 050 } 051 052 public Optional<MessageHandler> createDeliveryHandler(CanonicalSubscriptionChannelType theChannelType) { 053 if (theChannelType == CanonicalSubscriptionChannelType.EMAIL) { 054 return Optional.of(newSubscriptionDeliveringEmailSubscriber(myEmailSender)); 055 } else if (theChannelType == CanonicalSubscriptionChannelType.RESTHOOK) { 056 return Optional.of(newSubscriptionDeliveringRestHookSubscriber()); 057 } else if (theChannelType == CanonicalSubscriptionChannelType.MESSAGE) { 058 return Optional.of(newSubscriptionDeliveringMessageSubscriber()); 059 } else { 060 return Optional.empty(); 061 } 062 } 063 064 public void setEmailSender(IEmailSender theEmailSender) { 065 myEmailSender = theEmailSender; 066 } 067}