<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

	<!-- import resource="classpath:gov/va/med/cds/tools/cleanup/errorq/errorQCleanUpContext.xml" /-->

	<bean
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
	</bean>


	<bean id="errorQCleanUp" class="gov.va.med.cds.tools.cleanup.errorq.ErrorQueueCleanUpWithErrors">
		<property name="listenerContainer" ref="listenerContainer" />
	</bean>

	<bean id="listenerContainer"
		class="org.springframework.jms.listener.DefaultMessageListenerContainer"
		lazy-init="true">
		<property name="concurrentConsumers" value="${cds.consumer.count}" />
		<property name="connectionFactory" ref="jmsConnectionFactory" />
		<property name="destination" ref="destination" />
		<property name="messageListener" ref="errorQListener" />
		<property name="autoStartup" value="false" />
		<property name="messageSelector" value="CDSProcessedMsg IS NULL AND CDSFailureReason IS NULL" />
		<!-- property name="sessionTransacted" value="true" /-->
	</bean>

	<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiTemplate" ref="jndiTemplate" />
		<property name="jndiName" value="jms/cds/CDSClinicalJMSConnectionFactory" />
	</bean>

	<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiTemplate" ref="jndiTemplate" />
		<property name="jndiName" value="jms/cds/ErrorQueue" />
	</bean>

	<bean id="errorQListener"
		class="gov.va.med.cds.tools.cleanup.errorq.ErrorQListenerWithErrors"
		lazy-init="true">
		<property name="jmsTemplate" ref="jmsTemplate" />
		<property name="exceptionsMap" ref="exceptionsMap" />
	</bean>
	
	<bean id="errorQueueCleanUpLogger" 
		class="gov.va.med.cds.tools.cleanup.errorq.ErrorQueueCleanUpLogger" scope="prototype" >
		<property name="hdrJdbcTemplate" ref="hdrJdbcTemplate" />
	</bean>

	<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate102">
		<property name="connectionFactory" ref="jmsConnectionFactory" />
		<property name="defaultDestination" ref="destination" />
	</bean>

	<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
		<property name="environment">
			<props>
				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
				<prop key="java.naming.provider.url">${cds.jndi.provider.url}</prop>
				<prop key="java.naming.security.principal">${cds.appserver.admin.username}</prop>
				<prop key="java.naming.security.credentials">${cds.appserver.admin.password}</prop>
			</props>
		</property>
	</bean>

	<util:map id="exceptionsMap" map-class="java.util.HashMap">
		<entry key="HL7_SUPPORT_HAPI_ENCODE_EXCEPTIONca.uhn.hl7v2.HL7Exception: Can't encode group" value="Failed in Message Mediator. HL7 message with incorrect format" />
		<entry key="MSH 4.1 and MSH 4.2 in the message are empty" value="Failed in ErrorQ cleanup. HL7 message with empty MSH 4.1 and MSH 4.2" />
		<entry key="MSH 4.1 is empty and not in facilityId map and thus cannot populate the empty PID 3.6.2" value="Failed in ErrorQ cleanup. HL7 message with empty MSH 4.1 and PID 3.6.2" />
		<entry key="DoD Patient with LID and ICN does not have Correlated ID between LID and ICN" value="Failed in ErrorQ cleanup. PSIM Graph Message has DoD Patient with LID and ICN does not have Correlated ID between LID and ICN" />
		<entry key="VA Patient with LID and ICN does not have Correlated ID between LID and ICN" value="Failed in ErrorQ cleanup. PSIM Graph Message has VA Patient with LID and ICN does not have Correlated ID between LID and ICN" />
		<entry key="DoD Patient with only LID, and does not have Correlated ID for LID" value="Failed in ErrorQ cleanup. PSIM Graph Message has DoD Patient with only LID, and does not have Correlated ID for LID" />
		<entry key="Patient has only ICN" value="Failed in ErrorQ cleanup. PSIM Graph Message has Patient with only ICN" />
		<entry key="EncodingNotSupportedException" value="Failed in ErrorQ cleanup. HL7 message encoding failed" />
		<entry key="HL7Exception" value="Failed in ErrorQ cleanup. HL7 message Parsing failed" />
	</util:map>

	<bean id="errorQueueSender" class="gov.va.med.cds.tools.cleanup.errorq.QueueSender">
		<property name="jmsTemplate" ref="jmsTemplate" />
	</bean>

</beans>
