<?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:jaxws="http://cxf.apache.org/jaxws"
	xmlns:sec="http://cxf.apache.org/configuration/security" xmlns:wsa="http://cxf.apache.org/ws/addressing"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:http="http://cxf.apache.org/transports/http/configuration"
	xmlns:t="http://dnetlib.eu/springbeans/t" xmlns:template="http://dnetlib.eu/springbeans/template"
	xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	 										http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
                      http://cxf.apache.org/ws/addressing http://cxf.apache.org/schemas/ws-addr-conf.xsd
                      http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
                      http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
                      http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                      http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd">
	<!-- beans -->

	<bean name="abstractExistDatabase" init-method="start"
		destroy-method="stop" p:triggerConf-ref="issnTriggers" abstract="true"
		p:backupDir="${services.is.store.data.path}/backups" />

	<bean name="temporaryExistDatabase" class="eu.dnetlib.xml.database.exist.TemporaryExistDatabase"
		parent="abstractExistDatabase" lazy-init="true" />

	<bean name="persistentExistDatabase" class="eu.dnetlib.xml.database.exist.PersistentExistDatabase"
		parent="abstractExistDatabase"
		p:dbRootPath="${services.is.store.data.path}/db" p:XQueryJavaEnabled="${services.is.store.enable.java}"
		lazy-init="true" />

	<alias name="${services.is.store.database.bean}" alias="existDatabase"/>

	<!-- Adding interceptors to log about the execution of methods on exist -->
	<bean name="persistentExistLogInterceptor"
	      class="eu.dnetlib.enabling.tools.LogInterceptor">
		<property name="enterMessage"
		          value="ENTER | $[targetClassShortName].$[methodName]($[arguments])"/>
		<property name="exitMessage"
		          value="EXIT | $[targetClassShortName].$[methodName]($[arguments]) | $[invocationTime]ms"/>
	</bean>

	<bean
			class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames" value="persistentExistDatabase"/>
		<property name="proxyTargetClass" value="true"/>
		<property name="interceptorNames">
			<list>
				<value>persistentExistLogInterceptor</value>
			</list>
		</property>
	</bean>

	<!-- end AOP interceptors -->

	<util:map id="issnTriggers">
		<entry key="/db" value-ref="issnIntegrationTrigger" />
	</util:map>

	<bean name="isStoreService" class="eu.dnetlib.enabling.is.store.ISStoreServiceImpl"
		scope="singleton" init-method="start" destroy-method="stop"
		p:xmlDatabase-ref="existDatabase" p:endpoint-ref="isStoreServiceEndpoint"
		p:contentInitializerJob-ref="embeddedContentLoaderJob" />

	<bean id="bulkResourceImporter" class="eu.dnetlib.enabling.is.store.BulkResourceImporter"
		p:serviceLocator-ref="uniqueServiceLocator" p:xqueryUtils-ref="xqueryUtils"
		p:resourceValidator-ref="resourceValidator" p:validating="${services.is.store.bulk.validation}" />

	<bean id="embeddedContentLoaderJob" class="eu.dnetlib.enabling.is.store.TestContentInitializerJob"
		scope="singleton" p:serviceLocator-ref="uniqueServiceLocator"
		p:resources="classpath*:/eu/dnetlib/test/profiles/**/*.xml" p:schemas="${services.schemas}"
		p:resourceLoader-ref="resourceLoaderHelper" p:bulkImporter-ref="bulkResourceImporter"
		p:snDisable-ref="issnInhibitionCondition" p:timeToSleep="${services.is.store.initializer.timetosleep}" />

	<!-- <bean id="testContentLoaderTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean" -->
	<!-- p:repeatCount="0" p:startDelay="3000"> -->
	<!-- <property name="jobDetail"> -->
	<!-- <bean id="testContentLoaderTriggerDetails" class="org.springframework.scheduling.quartz.JobDetailBean" -->
	<!-- p:jobClass="eu.dnetlib.enabling.is.store.TestContentInitializerJob" -->
	<!-- depends-on="snLocator"> -->
	<!-- <property name="jobDataAsMap"> -->
	<!-- <map> -->
	<!-- <entry key="registryLocator" value-ref="registryLocator" /> -->
	<!-- <entry key="resources" value="classpath*:/eu/dnetlib/test/profiles/**/*.xml" 
		/> -->
	<!-- <entry key="schemas" value="${services.schemas}" /> -->
	<!-- <entry key="resourceLoader" value-ref="resourceLoaderHelper" /> -->
	<!-- <entry key="bulkImporter" value-ref="bulkResourceImporter" /> -->
	<!-- <entry key="snDisable" value-ref="issnInhibitionCondition" /> -->
	<!-- </map> -->
	<!-- </property> -->
	<!-- </bean> -->
	<!-- </property> -->
	<!-- </bean> -->

	<bean id="resourceLoaderHelper" class="eu.dnetlib.enabling.tools.ResourceLoaderHelper" />

	<!-- <bean id="storeJobSchedulerAccessor" -->
	<!-- class="org.springframework.scheduling.quartz.SchedulerAccessorBean" -->
	<!-- p:scheduler-ref="jobScheduler"> -->
	<!-- <property name="triggers"> -->
	<!-- <list> -->
	<!-- <ref bean="testContentLoaderTrigger" /> -->
	<!-- </list> -->
	<!-- </property> -->
	<!-- </bean> -->

	<!-- endpoints -->
	<jaxws:endpoint id="isStoreServiceEndpoint" implementor="#isStoreService"
		implementorClass="eu.dnetlib.enabling.is.store.rmi.ISStoreService"
		address="/isStore" />

	<template:instance name="serviceRegistrationManager"
		t:serviceRegistrationManagerClass="eu.dnetlib.enabling.tools.registration.ValidatingServiceRegistrationManagerImpl"
		t:name="isStoreServiceRegistrationManager" t:service="isStoreService"
		t:endpoint="isStoreServiceEndpoint" t:jobScheduler="jobScheduler" />


</beans>
