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

<beans>
    <bean id="mailer" class="com.wisemapping.mail.Mailer" singleton="true">
        <constructor-arg index="0" value="${mail.serverSendEmail}"/>
        <constructor-arg index="1" value="${mail.supportEmail}"/>
        <constructor-arg index="2" value="${mail.errorReporterEmail}"/>

        <property name="mailSender" ref="mailSender"/>
        <property name="velocityEngine" ref="velocityEngine"/>
    </bean>

    <bean id="userServiceTarget" class="com.wisemapping.service.UserServiceImpl">
        <property name="userManager" ref="userManager"/>
        <property name="mindmapService" ref="mindMapServiceTarget"/>
        <property name="notificationService" ref="notificationService"/>
        <property name="messageSource" ref="messageSource"/>
        <property name="velocityEngine" ref="velocityEngine"/>
    </bean>

    <bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="target">
            <ref local="userServiceTarget"/>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>

    <bean id="mindMapServiceTarget" class="com.wisemapping.service.MindmapServiceImpl">
        <property name="mindmapManager" ref="mindmapManager"/>
        <property name="userService" ref="userService"/>
        <property name="notificationService" ref="notificationService"/>
        <property name="adminUser" value="${admin.user}"/>
    </bean>

    <bean id="mindmapService" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces" value="com.wisemapping.service.MindmapService"/>
        <property name="interceptorNames">
            <list>
                <value>txInterceptor</value>
                <value>viewSecurityAdvisor</value>
                <value>updateSecurityAdvisor</value>
            </list>
        </property>
        <property name="target" ref="mindMapServiceTarget"/>
    </bean>

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${mail.smtp.host}"/>
        <property name="port" value="${mail.smtp.port}"/>
        <property name="protocol" value="smtp"/>
        <property name="username" value="${mail.username}"/>
        <property name="password" value="${mail.password}"/>
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
                <prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop>
                <prop key="mail.smtp.quitwait">${mail.smtp.quitwait}</prop>
            </props>
        </property>
    </bean>

    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
        <property name="velocityProperties">
            <value>
                resource.loader=class
                class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
            </value>
        </property>
    </bean>

    <bean id="notificationService" class="com.wisemapping.mail.NotificationService" singleton="true">
        <property name="baseUrl" value="${site.baseurl}"/>
        <property name="mailer" ref="mailer"/>
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>messages</value>
            </list>
        </property>
    </bean>

</beans>
