<?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:jaxrs="http://cxf.apache.org/jaxrs"
	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://cxf.apache.org/jaxws
	http://cxf.apache.org/schemas/jaxws.xsd
	http://cxf.apache.org/jaxrs
	http://cxf.apache.org/schemas/jaxrs.xsd
	http://www.springframework.org/schema/util
	http://www.springframework.org/schema/util/spring-util-3.1.xsd">

	<description>Configuration for the TextGrid/DARIAH-DE OAI-PMH Interface
	</description>

	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

	<bean id="propertyPlaceholderConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>file:/etc/dhrep/oaipmh/oaipmh.properties</value>
			</list>
		</property>
		<property name="ignoreResourceNotFound" value="true" />
		<property name="ignoreUnresolvablePlaceholders" value="true" />
	</bean>

	<bean id="ElasticSearchClient"
		class="info.textgrid.middleware.OAI_ESClient">
		<constructor-arg index="0"
			value="${elasticSearch.url}" />
		<constructor-arg index="1"
			value="${elasticSearch.port}" />
		<constructor-arg index="2"
			value="${elasticSearch.clusterName}" />
		<property name="esIndex" value="${elasticSearch.index}" />
		<property name="esType" value="${elasticSearch.type}" />
	</bean>

	<!--bean id="drc" class="info.textgrid.middleware.oaipmh.${DeletedRecordInfo}" -->

	<bean id="RepIdentification"
		class="info.textgrid.middleware.RepIdentification">
		<constructor-arg index="0" value="${RepositoryName}" />
		<constructor-arg index="1" value="${BaseUrl}" />
		<constructor-arg index="2"
			value="${DeletedRecordInfo}" />
		<constructor-arg index="3"
			value="${EarliestDateStamp}" />
		<constructor-arg index="4" value="${Granularity}" />
		<constructor-arg index="5" value="${ProtocolVersion}" />
		<constructor-arg index="6" value="${AdminMail}" />
	</bean>

	<bean id="RecordListDC" class="info.textgrid.middleware.RecordListDelivererDC">
		<!--constructor-arg index="0" ref="ElasticSearchClient" / -->
		<!-- <constructor-arg index="0" value="${fields}" />-->
		<!-- <constructor-arg index="1" value="${workFields}" /> -->
		<constructor-arg index="0" value="${textgrid}" />
		<constructor-arg index="1" value="${dariah}" />
		<property name="fields" value="${fields}" />
		<property name="workFields" value="${workFields}" />
		<!-- <property name="oaiEsClient" value="${formatToFilter}" /> -->
		<property name="formatField" value="${formatField}" />
		<property name="formatToFilter" value="${formatToFilter}" />
		<property name="dateOfObjectCreation" value="${dateOfObjectCreation}" />
		<property name="relationToFurtherMetadataObject" value="${relationToFurtherMetadataObject}" />
		<property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" />
		<property name="FieldForRange" value="${rangeField}" />
		<property name="contributor" value="${contributorList}" />
		<property name="coverage" value="${coverageList}" />
		<property name="creators" value="${creatorList}" />
		<property name="dates" value="${dateList}" />
		<property name="descriptions" value="${descriptionList}" />
		<property name="formats" value="${formatList}" />
		<property name="identifiers" value="${identifierList}" />
		<property name="languages" value="${languageList}" />
		<property name="publishers" value="${publisherList}" />
		<property name="relations" value="${relationList}" />
		<property name="relationsForWork" value="${relationsForWorkList}" />
		<property name="rights" value="${rightsList}" />
		<property name="sources" value="${sourceList}" />
		<property name="subjects" value="${subjectList}" />
		<property name="titles" value="${titleList}" />
		<property name="types" value="${typeList}" />
		<property name="modifiedField" value="${modifiedField}" />
		<property name="identifierField" value="${identifierField}" />
		<property name="searchResponseSize" value="${searchResponseSize}" />
	</bean>

	<bean id="RecordListIDIOM" class="info.textgrid.middleware.RecordListDelivererIDIOM">
		<constructor-arg index="0" value="${textgrid}" />
		<constructor-arg index="1" value="${dariah}" />
		<!-- <property name="oaiEsClient" value="${formatToFilter}" /> -->
	</bean>

	<bean id="RecordDC" class="info.textgrid.middleware.RecordDelivererDC">
		<!-- <constructor-arg index="0" ref="ElasticSearchClient" /> -->
		<!-- <constructor-arg index="1" value="${workFields}" /> -->
		<constructor-arg index="0" value="${textgrid}" />
		<constructor-arg index="1" value="${dariah}" />
		<property name="formatField" value="${formatField}" />
		<property name="formatToFilter" value="${formatToFilter}" />
		<!-- <property name="oaiEsClient" value="${formatToFilter}" /> -->
		<property name="dateOfObjectCreation" value="${dateOfObjectCreation}" />
		<property name="relationToFurtherMetadataObject" value="${relationToFurtherMetadataObject}" />
		<property name="repositoryObjectURIPrefix" value="${repositoryObjectURIPrefix}" />
		<property name="identifierField" value="${identifierField}" />
		<property name="fields" value="${fields}" />
		<property name="workFields" value="${workFields}" />
		<property name="contributor" value="${contributorList}" />
		<property name="coverage" value="${coverageList}" />
		<property name="creator" value="${creatorList}" />
		<property name="dates" value="${dateList}" />
		<property name="descriptions" value="${descriptionList}" />
		<property name="formats" value="${formatList}" />
		<property name="identifiers" value="${identifierList}" />
		<property name="languages" value="${languageList}" />
		<property name="publishers" value="${publisherList}" />
		<property name="relations" value="${relationList}" />
		<property name="relationsForWork" value="${relationsForWorkList}" />
		<property name="rights" value="${rightsList}" />
		<property name="sources" value="${sourceList}" />
		<property name="subjects" value="${subjectList}" />
		<property name="titles" value="${titleList}" />
		<property name="types" value="${typeList}" />
	</bean>
	
	<bean id="RecordDC" class="info.textgrid.middleware.RecordDelivererIDIOM">
		<constructor-arg index="0" value="${textgrid}" />
		<constructor-arg index="1" value="${dariah}" />
		<!-- <property name="oaiEsClient" value="${formatToFilter}" /> -->
	</bean>

	<bean id="ListIdentifierDC"	class="info.textgrid.middleware.IdentifierListDelivererDC">
		<!-- <constructor-arg index="0" ref="ElasticSearchClient" /> -->
		<constructor-arg index="0" value="${textgrid}" />
		<constructor-arg index="1" value="${dariah}" />
		<property name="formatField" value="${formatField}" />
		<property name="formatToFilter" value="${formatToFilter}" />
		<property name="dateOfObjectCreation"
			value="${dateOfObjectCreation}" />
		<property name="repositoryObjectURIPrefix"
			value="${repositoryObjectURIPrefix}" />
		<property name="identifierListFields"
			value="${identifierListFields}"></property>
		<property name="FieldForRange" value="${rangeField}" />
		<property name="identifierField" value="${identifierField}" />
		<property name="searchResponseSize"
			value="${searchResponseSize}" />
	</bean>
	
	<bean id="ListIdentifierIDIOM" class="info.textgrid.middleware.IdentifierListDelivererIDIOM">
		<!-- <constructor-arg index="0" ref="ElasticSearchClient" /> -->
		<constructor-arg index="0" value="${textgrid}" />
		<constructor-arg index="1" value="${dariah}" />
	</bean>

	<bean id="SetDeliverer"
		class="info.textgrid.middleware.SetDeliverer">
		<constructor-arg ref="ElasticSearchClient" />
		<constructor-arg index="1" value="${textgrid}" />
		<constructor-arg index="2" value="${dariah}" />
		<property name="formatField" value="${formatField}" />
		<property name="formatToFilter" value="${formatToFilter}" />
		<property name="identifierField" value="${identifierField}" />
		<property name="repositoryObjectURIPrefix"
			value="${repositoryObjectURIPrefix}" />
		<property name="specField" value="${specField}" />
		<property name="specFieldPrefix" value="${specFieldPrefix}" />
	</bean>

	<bean id="MetadataFormatList"
		class="info.textgrid.middleware.MetadataFormatListDeliverer">
		<constructor-arg ref="ElasticSearchClient" />
	</bean>

	<!-- REST Interface -->
	<bean id="rest" class="info.textgrid.middleware.Rest" />

	<bean id="cors-filter"
		class="org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter">
		<property name="allowOrigins">
			<util:list />
		</property>
	</bean>

	<bean id="oai" class="info.textgrid.middleware.OAIPMHImpl">
		<constructor-arg ref="RepIdentification" />
		<constructor-arg ref="RecordAbstract" />
		<constructor-arg ref="RecordDC" />
		<constructor-arg ref="RecordIDIOM" />
		<constructor-arg ref="RecordListDC" />
		<constructor-arg ref="RecordListIDIOM" />
		<constructor-arg ref="MetadataFormatList" />
		<constructor-arg ref="SetDeliverer" />
		<constructor-arg ref="ListIdentifierDC" />
		<constructor-arg ref="ListIdentifierIDIOM" />
		<property name="textGrid" value="${textgrid}" />
		<property name="dariah" value="${dariah}" />
	</bean>

	<jaxrs:server id="root" address="/root"
		publishedEndpointUrl="${RS_ENDPOINT}">
		<jaxrs:serviceBeans>
			<ref bean="rest" />
		</jaxrs:serviceBeans>
		<jaxrs:providers>
			<ref bean="cors-filter" />
		</jaxrs:providers>
	</jaxrs:server>

	<jaxrs:server id="queryEndpoint" address="/oai"
		publishedEndpointUrl="${RS_ENDPOINT}">
		<jaxrs:serviceBeans>
			<ref bean="oai" />
		</jaxrs:serviceBeans>
		<jaxrs:providers>
			<ref bean="cors-filter" />
		</jaxrs:providers>
	</jaxrs:server>
</beans>