<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--
	=========================================
	Copyright © 2004 VHA. All rights reserved
	=========================================
	
	@description: Configuration file containing bean configuration definitions of all event-related
	components.  Common candidates for this context file are the following bean types:
	
	a. Trigger Event
	b. TriggerableService
	c. ServiceDescriptor 
	d. All other services that depend on trigger event architecture to process events asynchronously
	
	@project: Common
	@author: DNS   LEV
	@version: 1.3
	
-->
<beans default-lazy-init="true">
	
	<!--
		@type: gov.va.med.fw.report.AsynchronousReportService
		@description: This service implements a ReportService interface to generate reports
		synchronously.  Messaging and UI layer can extend from this bean deifinition to override
		a default "reportServiceImpl" bean defined in commons.xml.  
		
		For instance, if messaging wants to inject an asynchronous report service implementation 
		into a report service defined in commons.xml, define the following bean in messaging
		application context file:
		
		<bean id="reportServiceImpl" parent="common.asynchronousReportService"/>
		
		The same guideline applies for UI, Workflow, and Comms
	-->
	<bean 
		id="common.asynchronousReportService" 
		class="gov.va.med.fw.report.AsynchronousReportService"
		abstract="true">

		<!-- Use the same queue as internal messaging events -->
		<property name="triggerService" ref="batchProcess.triggerEventPublisherService"/>
		<property name="triggerEventName"><idref bean="triggerEvent.generateReport"/></property>
	</bean>
	
	<!--
		@type: gov.va.med.fw.report.AsynchronousMailService
		@description: This service implements a ReportService interface to send e-mail messages
		synchronously.  Messaging and UI layer can extend from this bean deifinition to override
		a default "mailServiceImpl" bean defined in commons.xml.  
		
		For instance, if messaging wants to inject an asynchronous mail service implementation 
		into a mail service defined in commons.xml, define the following bean in messaging
		application context file:
		
		<bean id="mailServiceImpl" parent="common.asynchronousMailService"/>
		
		The same guideline applies for UI, Workflow, and Comms
	-->
	<bean 
		id="common.asynchronousMailService" 
		class="gov.va.med.fw.report.AsynchronousReportService"
		abstract="true">

		<!-- Use the same queue as internal messaging events -->
		<property name="triggerService" ref="batchProcess.triggerEventPublisherService"/>
		<property name="triggerEventName"><idref bean="triggerEvent.sendEmail"/></property>
	</bean>
	
	<bean id="log4jConfigService" class="gov.va.med.esr.service.Log4jConfigService" />
	
	
    <!-- =========================== Internal Routing of TriggerEvent's ============================ -->		

	<bean id="targetType.vba" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
		<property name="staticField" value="gov.va.med.esr.service.trigger.CommonTrigger$TargetType.VBA" />
	</bean>
	<bean id="targetType.vista" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
		<property name="staticField" value="gov.va.med.esr.service.trigger.CommonTrigger$TargetType.VISTA" />
	</bean>
	<bean id="targetType.mhv" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
		<property name="staticField" value="gov.va.med.esr.service.trigger.CommonTrigger$TargetType.MHV" />
	</bean>

    <bean id="destinationType.default" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="gov.va.med.fw.service.trigger.TriggerIdentity$DestinationType.DEFAULT" />
    </bean>		
    <bean id="destinationType.batchProcess" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="gov.va.med.fw.service.trigger.TriggerIdentity$DestinationType.BATCH_PROCESS" />
    </bean>	
    <bean id="destinationType.report" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="gov.va.med.fw.service.trigger.TriggerIdentity$DestinationType.REPORT" />
    </bean>	
    <bean id="destinationType.messagingBatchProcess" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="gov.va.med.esr.service.trigger.CommonTrigger$DestinationType.MESSAGING_BATCH_PROCESS" />
    </bean>		
    <bean id="destinationType.common" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="gov.va.med.esr.service.trigger.CommonTrigger$DestinationType.COMMON" />
    </bean>	
    <bean id="destinationType.messaging" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
        <property name="staticField" value="gov.va.med.esr.service.trigger.CommonTrigger$DestinationType.MESSAGING" />
    </bean>
	
    <bean id="common.triggerEventRouter" class="gov.va.med.fw.service.trigger.TriggerRouterImpl">
        <property name="triggerableServices">
			<map>
				<!-- note that these two use the same publisher and therefore go to the same queue -->
				<entry key-ref="destinationType.default" value-ref="common.triggerEventPublisherService"/>																				
				<entry key-ref="destinationType.common" value-ref="common.triggerEventPublisherService"/>				

				<!-- note that these two use the same publisher and therefore go to the same queue -->				
				<entry key-ref="destinationType.batchProcess" value-ref="batchProcess.triggerEventPublisherService"/>				
				<entry key-ref="destinationType.messagingBatchProcess" value-ref="batchProcess.triggerEventPublisherService"/>								
								
				<entry key-ref="destinationType.messaging" value-ref="messaging.triggerEventPublisherService"/>				
				
				<entry key-ref="destinationType.report" value-ref="reporting.triggerEventPublisherService"/>												
			</map>
        </property>
    </bean>

    <bean id="common.triggerEventPublisherService" class="gov.va.med.fw.service.trigger.QueuePublishTriggerableServiceImpl">
        <property name="messageProducer" ref="common.triggerEventProducerService" />
    </bean>
	<!-- provide an alias for default publishing into the CommonEventQueue -->
	<alias name="common.triggerEventPublisherService" alias="PublishTriggerableService"/>	
	
    <bean id="messaging.triggerEventPublisherService" class="gov.va.med.fw.service.trigger.QueuePublishTriggerableServiceImpl">
        <property name="messageProducer" ref="messaging.triggerEventProducerService" />
    </bean>
    <bean id="batchProcess.triggerEventPublisherService" class="gov.va.med.fw.service.trigger.QueuePublishTriggerableServiceImpl">
        <property name="messageProducer" ref="batchProcess.triggerEventProducerService" />
    </bean>
    <bean id="reporting.triggerEventPublisherService" class="gov.va.med.fw.service.trigger.QueuePublishTriggerableServiceImpl">
        <property name="messageProducer" ref="reporting.triggerEventProducerService" />
    </bean>
    
    <bean id="log4j.triggerEventPublisherService" class="gov.va.med.fw.service.trigger.TopicPublishTriggerableServiceImpl">
        <property name="messageProducer" ref="log4j.triggerEventProducerService" />
    </bean>
    
	
	<bean id="common.triggerEventProducerService"
		  class="gov.va.med.fw.service.jms.QueueMessageProducerService">		
		<property name="descriptor" ref="common.triggerEventQueue" />
	</bean>
	<bean id="messaging.triggerEventProducerService"
		  class="gov.va.med.fw.service.jms.QueueMessageProducerService">		
		<property name="descriptor" ref="messaging.triggerEventQueue" />
	</bean>
	<bean id="batchProcess.triggerEventProducerService"
		  class="gov.va.med.fw.service.jms.QueueMessageProducerService">		
		<property name="descriptor" ref="batchProcess.triggerEventQueue" />
	</bean>
	<bean id="reporting.triggerEventProducerService"
		  class="gov.va.med.fw.service.jms.QueueMessageProducerService">		
		<property name="descriptor" ref="reporting.triggerEventQueue" />
	</bean>
	<bean id="log4j.triggerEventProducerService"
		  class="gov.va.med.fw.service.jms.TopicMessageProducerService">		
		<property name="descriptor" ref="log4j.triggerEventTopic" />
	</bean>

		
    <bean id="common.triggerEventQueue" class="gov.va.med.fw.service.jms.QueueDescriptor">
        <property name="contextName" value="weblogic.jndi.WLInitialContextFactory" />    
        <property name="providerURLs">            
        	<list>
       	        <value>${bea.cluster.url.common}</value>   
       	        <value>${bea.cluster.url.inboundMessaging}</value>           	                	        
       	        <value>${bea.cluster.url.outboundMessaging}</value>           	         
        	</list>        	
        </property>
        <property name="factoryName" value="esr.jms.connectionFactory.EventConnFactory" />    
		<!-- assumes this queue is created in domain -->
        <property name="queueName" value="Edb.jms.queue.CommonEventQueue" />
    </bean>	
    <bean id="messaging.triggerEventQueue" class="gov.va.med.fw.service.jms.QueueDescriptor">
        <property name="contextName" value="weblogic.jndi.WLInitialContextFactory" />    
        <property name="providerURLs">            
        	<list>
       	        <value>${bea.cluster.url.outboundMessaging}</value>    
       	        <value>${bea.cluster.url.common}</value>         	        
       	        <value>${bea.cluster.url.inboundMessaging}</value>           	                	        
        	</list>        	
        </property>
        <property name="factoryName" value="esr.jms.connectionFactory.EventConnFactory" />    
		<!-- assumes this queue is created in domain -->
        <property name="queueName" value="Edb.jms.queue.MessagingEventQueue" />
    </bean>	
    <bean id="batchProcess.triggerEventQueue" class="gov.va.med.fw.service.jms.QueueDescriptor">
        <property name="contextName" value="weblogic.jndi.WLInitialContextFactory" />    
        <property name="providerURLs">            
        	<list>
       	        <value>${bea.cluster.url.batchProcess}</value> 
       	        <value>${bea.cluster.url.outboundMessaging}</value>           	           
       	        <value>${bea.cluster.url.inboundMessaging}</value>           	                	        
        	</list>        	
        </property>
        <property name="factoryName" value="esr.jms.connectionFactory.EventConnFactory" />    
		<!-- assumes this queue is created in domain -->
        <property name="queueName" value="Edb.jms.queue.BatchProcessEventQueue" />
    </bean>	
    <bean id="reporting.triggerEventQueue" class="gov.va.med.fw.service.jms.QueueDescriptor">
        <property name="contextName" value="weblogic.jndi.WLInitialContextFactory" />    
        <property name="providerURLs">            
        	<list>
       	        <value>${bea.cluster.url.reporting}</value>    
       	        <value>${bea.cluster.url.outboundMessaging}</value>           	        
       	        <value>${bea.cluster.url.inboundMessaging}</value>           	                	        
        	</list>        	
        </property>
        <property name="factoryName" value="esr.jms.connectionFactory.EventConnFactory" />    
		<!-- assumes this queue is created in domain -->
        <property name="queueName" value="Edb.jms.queue.BatchProcessEventQueue" />
    </bean>	

	<bean id="log4j.triggerEventTopic" class="gov.va.med.fw.service.jms.TopicDescriptor">
        <property name="contextName" value="weblogic.jndi.WLInitialContextFactory" />    
        <property name="providerURLs">            
        	<list>
       	        <value>${bea.cluster.url.log4j}</value>    
        	</list>        	
        </property>
        <property name="factoryName" value="esr.jms.connectionFactory.LoggingEventConnFactory" />    
		<!-- assumes this topic is created in domain -->
        <property name="topicName" value="Edb.jms.topic.LoggingEventTopic" />
    </bean>

    <bean
        id="triggerEventBuilder"
        class="gov.va.med.fw.service.trigger.TriggerEventBuilder"/>
			
    <bean
        id="secureTriggerEventBuilder"
        class="gov.va.med.fw.service.trigger.SecureTriggerEventBuilder"/>
        
    <bean
        id="secureTriggerMsdsEventBuilder"
        class="gov.va.med.fw.service.trigger.SecureTriggerMsdsEventBuilder"/>
        
    <bean
        id="secureTriggerEventBuilder.extractTriggerEventPayload" parent="secureTriggerEventBuilder">
        <property name="shouldExtractTriggerEventPayload" value="true" />
    </bean>
	
    <!--
        @type: gov.va.med.fw.service.ServiceDescriptor
        @description: Defines the service descriptor that will be invoked when a JMS message whose TriggerEvent
        contains a TriggerIdentity of type BulletinTriggerIdentity is received.
        This is invoked by MessageDrivenService whose actually processes the JMS message.
    -->
    <bean
        id="gov.va.med.esr.service.trigger.BulletinTriggerIdentity" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="comms.messageConsumer" /></property>
        <property name="methodName" value="trigger" />
        <property name="builder" ref="secureTriggerEventBuilder" />
    </bean>

    <!--
        @type: gov.va.med.fw.service.ServiceDescriptor
        @description: Defines the service descriptor that will be invoked when a JMS message whose TriggerEvent
        contains a TriggerIdentity of type LetterTriggerIdentity is received.
        This is invoked by MessageDrivenService whose actually processes the JMS message.
    -->
    <bean
        id="gov.va.med.esr.service.trigger.LetterTriggerIdentity" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="comms.messageConsumer" /></property>
        <property name="methodName" value="trigger" />
        <property name="builder" ref="secureTriggerEventBuilder" />
    </bean>

    <!--
        @type: gov.va.med.fw.service.ServiceDescriptor
        @description: Defines the service descriptor that will be invoked when a JMS message whose TriggerEvent
        contains a TriggerIdentity of type VOATriggerIdentity is received.
        This is invoked by MessageDrivenService whose actually processes the JMS message.
    -->
    <bean
        id="gov.va.med.esr.service.trigger.VOATriggerIdentity" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="comms.messageConsumer" /></property>
        <property name="methodName" value="trigger" />
        <property name="builder" ref="secureTriggerEventBuilder" />
    </bean>
    
    <!--
        @type: gov.va.med.fw.service.ServiceDescriptor
        @description: Defines the service descriptor that will be invoked when a JMS message whose TriggerEvent
        contains a TriggerIdentity of type BatchJobTriggerIdentity is received.
        This is invoked by MessageDrivenService whose actually processes the JMS message.
    -->
    <bean
        id="gov.va.med.esr.service.trigger.BatchJobTriggerIdentity" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="comms.messageConsumer" /></property>
        <property name="methodName" value="trigger" />
        <property name="builder" ref="secureTriggerEventBuilder" />
    </bean>

	<!-- Define simple TriggerEvents here -->
    <bean
        id="triggerEvent.executeJob" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="batchProcessService" /></property>		
        <property name="methodName" value="executeJob" />
		<property name="builder" ref="triggerEventBuilder" />
    </bean>	    		
    <bean
        id="triggerEvent.fireJobWithImmediateTrigger" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="common.schedulingService" /></property>		
        <property name="methodName" value="fireJobWithImmediateTrigger"/>
		<property name="builder" ref="triggerEventBuilder" />
    </bean>	    		

    <bean
        id="triggerEvent.migrateBulkEE" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="common.batchprocess.migrateBulkEE.worker" /></property>		
        <property name="methodName" value="process" />
		<property name="builder" ref="secureTriggerEventBuilder.extractTriggerEventPayload" />
    </bean>	    		

    <bean
        id="triggerEvent.cancelClock" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="scheduledTaskService" /></property>		
        <property name="methodName" value="cancelClock"/>
		<property name="builder" ref="triggerEventBuilder" />
    </bean>	    		
	
    <bean
        id="triggerEvent.startClock" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="scheduledTaskService" /></property>		
        <property name="methodName" value="startClock"/>
		<property name="builder" ref="triggerEventBuilder" />
    </bean>	    		
	
    <bean
        id="triggerEvent.generateReport" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="synchReportService" /></property>		
        <property name="methodName" value="generateReport"/>
		<property name="builder" ref="secureTriggerEventBuilder.extractTriggerEventPayload" />
    </bean>	    		

    <bean
        id="triggerEvent.sendMail" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="mailServiceImpl" /></property>		
        <property name="methodName" value="send"/>
		<property name="builder" ref="secureTriggerEventBuilder.extractTriggerEventPayload" />
    </bean>	    		
    
	<bean
        id="triggerEvent.updateLogLevel" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="log4jConfigService" /></property>		
        <property name="methodName" value="updateLogLevel"/>
		<property name="builder" ref="triggerEventBuilder" />
    </bean>
    
    <bean
        id="triggerEvent.createHecRecord" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="militaryInfoProcessor" /></property>	
        <property name="methodName" value="processHecRecordTrigger"/>
		<property name="builder" ref="secureTriggerEventBuilder" />
    </bean>
    
    <bean
        id="triggerEvent.updateMVIofDod" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="demographicService" /></property>	
        <property name="methodName" value="sendDodUpdate"/>
		<property name="builder" ref="secureTriggerEventBuilder" />
    </bean>	 
    
    	
	<!--
		THIS SECTION IS FOR CONSUMER-SIDE OF EVENTS
	-->
	
    <!-- use this for CAIP-JMS
    <alias name="triggerEventBuilder" alias="crossApplication.builder"/> -->
    <!-- use this for CAIP-EJB -->
    <alias name="secureTriggerEventBuilder.extractTriggerEventPayload" alias="crossApplication.builder"/>
    
    <bean
        id="crossApplication.notification.personLink" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="personService" /></property>		
        <property name="methodName" value="processExternalPersonLink" />
		<property name="builder" ref="crossApplication.builder" />
    </bean>		
    <bean
        id="crossApplication.notification.personMove" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="personService" /></property>		
        <property name="methodName" value="processExternalPersonMove" />
		<property name="builder" ref="crossApplication.builder" />      
    </bean>
    <bean
        id="crossApplication.notification.personPrimaryview" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="personService" /></property>		
        <property name="methodName" value="processExternalPersonPrimaryview" />
		<property name="builder" ref="crossApplication.builder" />      
    </bean>	
    <bean
        id="crossApplication.notification.demographicsChange" class="gov.va.med.fw.service.ServiceDescriptor">
        <property name="serviceName"><idref bean="demographicService" /></property>		
        <property name="methodName" value="processExternalDemographicsChange" />
		<property name="builder" ref="crossApplication.builder" />
    </bean>	    	
</beans>