<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans.xsd
						http://www.springframework.org/schema/context  
    					http://www.springframework.org/schema/context/spring-context-3.0.xsd">
	
	<bean id="isotc.abstract" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="abstract" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:abstract/gco:CharacterString/text()" />
	</bean>
	
	<bean id="isotc.author" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="author" />
		<constructor-arg name="xpath" 
			value="(//gmd:CI_ResponsibleParty/gmd:individualName/gco:CharacterString/text() | //gmd:CI_ResponsibleParty/gmd:individualName/gmx:Anchor/text())[1]" />
	</bean>

	<bean id="isotc.authorSurName" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="authorSurName" />
		<constructor-arg name="xpath"
			value="(//gmd:CI_ResponsibleParty/gmd:individualName/gco:CharacterString/text() | //gmd:CI_ResponsibleParty/gmd:individualName/gmx:Anchor/text())[1]" />
		<property name="multivalue" value="false" />
	</bean>

	<bean id="isotc.authorSurNameSort" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="authorSurNameSort" />
		<constructor-arg name="xpath"
			value="(//gmd:CI_ResponsibleParty/gmd:individualName/gco:CharacterString/text() | //gmd:CI_ResponsibleParty/gmd:individualName/gmx:Anchor/text())[1]" />
		<property name="multivalue" value="false" />
	</bean>
	
	<bean id="isotc.investigator" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="investigator" />
		<constructor-arg name="xpath" 
			value="//gmd:CI_ResponsibleParty/gmd:individualName/gco:CharacterString/text() | //gmd:CI_ResponsibleParty/gmd:individualName/gmx:Anchor/text()" />
		<property name="multivalue" value="true" />
		<property name="dedupe" value="true" />
	</bean>
	
	<bean id="isotc.contactOrganization" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="contactOrganization" />
		<constructor-arg name="xpath" 
			value="(//gmd:CI_ResponsibleParty/gmd:organisationName/gco:CharacterString/text())[1]" />
	</bean>
	
	<!-- index only the individualName (not organisationName) if there is a valid role -->
	<!-- valid roles: "owner", "originator", "principalInvestigator", "author" -->
	<!-- or -->
	<!-- index the organisationName the role is valid but no individualName is specified -->
	<bean id="isotc.origin" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="origin" />
		<constructor-arg name="xpath" 
			value='//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty[gmd:role/gmd:CI_RoleCode/text() = "owner" or gmd:role/gmd:CI_RoleCode/text() = "originator" or gmd:role/gmd:CI_RoleCode/text() = "principalInvestigator" or gmd:role/gmd:CI_RoleCode/text() = "author"]/gmd:individualName/*/text() | //gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:citedResponsibleParty/gmd:CI_ResponsibleParty[(gmd:role/gmd:CI_RoleCode/text() = "owner" or gmd:role/gmd:CI_RoleCode/text() = "originator" or gmd:role/gmd:CI_RoleCode/text() ="principalInvestigator" or gmd:role/gmd:CI_RoleCode/text() = "author") and (not(gmd:individualName) or gmd:individualName[@gco:nilReason = "missing"])]/gmd:organisationName/*/text()' />
		<property name="multivalue" value="true" />
		<property name="dedupe" value="true" />
	</bean>
	
	<bean id="isotc.pubDate" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="pubDate" />
		<constructor-arg name="xpath" 
			value="if (//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date[following-sibling::gmd:dateType/gmd:CI_DateTypeCode/text() = 'publication']/gco:Date/text()) 
			            then //gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date[following-sibling::gmd:dateType/gmd:CI_DateTypeCode/text() = 'publication']/gco:Date/text()
			       else if (//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date[following-sibling::gmd:dateType/gmd:CI_DateTypeCode/text() = 'publication']/gco:DateTime/text())
			             then //gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date[following-sibling::gmd:dateType/gmd:CI_DateTypeCode/text() = 'publication']/gco:DateTime/text() 
			       else if (//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:Date[1]/text())
			             then //gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:Date[1]/text()
			       else if (//gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:DateTime[1]/text())
			             then //gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:DateTime[1]/text()
			       else ()" />
		<property name="converter" ref="dateConverter" />
	</bean>
	
	<bean id="isotc.beginDate" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="beginDate" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/*[local-name() = 'TimePeriod']/*[local-name() = 'beginPosition']/text()" />
		<property name="converter" ref="dateConverter" />
	</bean>
	
	<bean id="isotc.endDate" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="endDate" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/*[local-name() = 'TimePeriod']/*[local-name() = 'endPosition']/text()" />
		<property name="converter" ref="dateConverter" />
	</bean>	

	<bean id="isotc.title" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="title" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString/text() | //gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gmx:Anchor/text()" />
	</bean>		
	
	<bean id="isotc.keywords" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="keywords" />
		<constructor-arg name="xpath"
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gmx:Anchor/text() | //gmd:identificationInfo/gmd:MD_DataIdentification/gmd:descriptiveKeywords/gmd:MD_Keywords/gmd:keyword/gco:CharacterString/text()" />
		<property name="multivalue" value="true" />
	</bean>
	
	<bean id="isotc.eastBoundCoord" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="eastBoundCoord" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:eastBoundLongitude/gco:Decimal/text()" />
	</bean>	
	
	<bean id="isotc.westBoundCoord" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="westBoundCoord" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:westBoundLongitude/gco:Decimal/text()" />
	</bean>
	
	<bean id="isotc.southBoundCoord" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="southBoundCoord" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:southBoundLatitude/gco:Decimal/text()" />
	</bean>
	
	<bean id="isotc.northBoundCoord" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="northBoundCoord" />
		<constructor-arg name="xpath" 
			value="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox/gmd:northBoundLatitude/gco:Decimal/text()" />
	</bean>

	<!-- define the root and leafs for accessing multiple bounding coordinates for geohash -->
	<bean id="isotc.geohashRoot" class="org.dataone.cn.indexer.parser.utility.RootElement"
		p:name="geohashRoot"
		p:xPath="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:extent/gmd:EX_Extent/gmd:geographicElement/gmd:EX_GeographicBoundingBox"
		p:template="[northBoundingCoordinate] [southBoundingCoordinate] [eastBoundingCoordinate] [westBoundingCoordinate]">
		<property name="leafs">
			<list>
				<ref bean="isotc.northBoundingCoordinateLeaf"/>
				<ref bean="isotc.southBoundingCoordinateLeaf"/>
				<ref bean="isotc.eastBoundingCoordinateLeaf"/>
				<ref bean="isotc.westBoundingCoordinateLeaf"/>
			</list>
		</property>
	</bean>
	
	<bean id="isotc.northBoundingCoordinateLeaf" class="org.dataone.cn.indexer.parser.utility.LeafElement"
		p:name="northBoundingCoordinate"
		p:xPath="gmd:northBoundLatitude/gco:Decimal/text()" />
		
	<bean id="isotc.westBoundingCoordinateLeaf" class="org.dataone.cn.indexer.parser.utility.LeafElement"
		p:name="westBoundingCoordinate"
		p:xPath="gmd:westBoundLongitude/gco:Decimal/text()" />
	
	<bean id="isotc.southBoundingCoordinateLeaf" class="org.dataone.cn.indexer.parser.utility.LeafElement"
		p:name="southBoundingCoordinate"
		p:xPath="gmd:southBoundLatitude/gco:Decimal/text()" />		
		
	<bean id="isotc.eastBoundingCoordinateLeaf" class="org.dataone.cn.indexer.parser.utility.LeafElement"
		p:name="eastBoundingCoordinate"
		p:xPath="gmd:eastBoundLongitude/gco:Decimal/text()" />
	
		
	<!-- use the root to calculate different geohash lengths -->
	<bean id="isotc.geohash1" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_1" />
		<property name="converter" ref="geohashConverter_1"/>
	</bean>

	<bean id="isotc.geohash2" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_2" />
		<property name="converter" ref="geohashConverter_2"/>
	</bean>
	
	<bean id="isotc.geohash3" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_3" />
		<property name="converter" ref="geohashConverter_3"/>
	</bean>
	
	<bean id="isotc.geohash4" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_4" />
		<property name="converter" ref="geohashConverter_4"/>
	</bean>

	<bean id="isotc.geohash5" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_5" />
		<property name="converter" ref="geohashConverter_5"/>
	</bean>
	
	<bean id="isotc.geohash6" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_6" />
		<property name="converter" ref="geohashConverter_6"/>
	</bean>
	
	<bean id="isotc.geohash7" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_7" />
		<property name="converter" ref="geohashConverter_7"/>
	</bean>	

	<bean id="isotc.geohash8" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_8" />
		<property name="converter" ref="geohashConverter_8"/>
	</bean>

	<bean id="isotc.geohash9" class="org.dataone.cn.indexer.parser.CommonRootSolrField"
		p:multivalue="true"
		p:root-ref="isotc.geohashRoot">
		<constructor-arg name="name" value="geohash_9" />
		<property name="converter" ref="geohashConverter_9"/>
	</bean>
		
	<bean id="isotc.fileID" class="org.dataone.cn.indexer.parser.ResolveSolrField">
		<constructor-arg name="name" value="fileID" />
	</bean>

	<bean id="isotc.fullText" class="org.dataone.cn.indexer.parser.FullTextSolrField">
		<constructor-arg name="name" value="text" />
		<constructor-arg name="xpath" value="//*/text()" />
		<property name="combineNodes" value="true"/>
	</bean>
	
	<!-- service fields -->
	
	<!-- checks for existence of either srv service description or distribution "service" info -->
	<bean id="isotc.isService" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="isService" />
		<constructor-arg name="xpath" value="boolean(//srv:SV_ServiceIdentification or //gmd:distributionInfo/gmd:MD_Distribution)"/>
	</bean>
	
	<!-- combines the srv service title with the distribution "service" info's titles -->
	<bean id="isotc.serviceTitle" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceTitle" />
		<constructor-arg name="xpath" 
			value="(//srv:SV_ServiceIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString | //gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor/gmd:MD_Distributor/gmd:distributorTransferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:name/gco:CharacterString)/text()" />
		<property name="combineNodes" value="true"/>
		<property name="combineDelimiter" value=":" />
	</bean>
	
	<!-- combines the srv service description with the distribution "service" info's descriptions -->
	<bean id="isotc.serviceDescription" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceDescription" />
		<constructor-arg name="xpath" 
			value="(//srv:SV_ServiceIdentification/gmd:abstract/gco:CharacterString | //gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor/gmd:MD_Distributor/gmd:distributorTransferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:description/gco:CharacterString)/text()" />
		<property name="combineNodes" value="true"/>
		<property name="combineDelimiter" value=":" />
	</bean>	
	
	<bean id="isotc.serviceType" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceType" />
		<constructor-arg name="xpath" 
			value="//srv:SV_ServiceIdentification/srv:serviceType/gco:LocalName/text()"/>
		<property name="multivalue" value="true" />
		<property name="converter" ref="serviceTypesConverter" />
	</bean>
	
	<bean id="isotc.serviceEndpoint" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceEndpoint" />
		<constructor-arg name="xpath" 
			value="//srv:SV_ServiceIdentification/srv:containsOperations/srv:SV_OperationMetadata/srv:connectPoint/gmd:CI_OnlineResource/gmd:linkage/gmd:URL/text()"/>
		<property name="multivalue" value="true" />
	</bean>	

	<bean id="isotc.serviceInput" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceInput" />
		<constructor-arg name="xpath" 
			value="//srv:SV_ServiceIdentification/srv:operatesOn/@xlink:href"/>
		<property name="multivalue" value="true" />
	</bean>	

	<bean id="isotc.serviceOutput" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceOutput" />
		<constructor-arg name="xpath" 
			value="//srv:SV_ServiceIdentification/gmd:resourceFormat/@xlink:href"/>
		<property name="multivalue" value="true" />
	</bean>	
	
	<!-- loose coupling if srv:SV_CouplingType is loose -->
	<!-- tight coupling if srv:SV_CouplingType is tight -->
	<!-- tight coupling if distribution service info exists and srv:SV_CouplingType doesn't / is unspecified -->
	<!-- empty if neither exists -->
	<bean id="isotc.serviceCoupling" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceCoupling" />
		<constructor-arg name="xpath" 
			value="concat(	substring('loose',	1 div number(boolean(	//srv:SV_ServiceIdentification/srv:couplingType/srv:SV_CouplingType/@codeListValue = 'loose'))),
							substring('tight',	1 div number(boolean(	//srv:SV_ServiceIdentification/srv:couplingType/srv:SV_CouplingType/@codeListValue = 'tight'))),
							substring('tight',	1 div number(boolean(	//gmd:distributionInfo/gmd:MD_Distribution and not(//srv:SV_ServiceIdentification/srv:couplingType/srv:SV_CouplingType/@codeListValue)))),
							substring('',		1 div number(boolean(	not(   //srv:SV_ServiceIdentification/srv:couplingType/srv:SV_CouplingType/@codeListValue) 
																and not(   //gmd:distributionInfo/gmd:MD_Distribution)))))"/>
	</bean>
	
	<!-- below fields are multivalue, so will just be added to existing service fields extracted above -->
	
	<bean id="isotc.distribServiceType" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceType" />
		<constructor-arg name="xpath" 
			value="//gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor/gmd:MD_Distributor/gmd:distributorTransferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:protocol/gco:CharacterString/text()"/>
		<property name="multivalue" value="true" />
		<property name="converter" ref="serviceTypesConverter" />
	</bean>
	
	<bean id="isotc.distribServiceEndpoint" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceEndpoint" />
		<constructor-arg name="xpath" 
			value="//gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor/gmd:MD_Distributor/gmd:distributorTransferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:linkage/gmd:URL/text() | //gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions/gmd:MD_DigitalTransferOptions/gmd:onLine/gmd:CI_OnlineResource/gmd:linkage/gmd:URL/text()"/>
		<property name="multivalue" value="true" />
	</bean>	

	<bean id="isotc.distribServiceInput" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceInput" />
		<constructor-arg name="xpath" 
			value="//gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor/gmd:MD_Distributor/gmd:distributorTransferOptions/@xlink:href"/>
		<property name="multivalue" value="true" />
	</bean>

	<bean id="isotc.distribServiceOutput" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="serviceOutput" />
		<constructor-arg name="xpath" 
			value="//gmd:distributionInfo/gmd:MD_Distribution/gmd:distributor/gmd:MD_Distributor/gmd:distributorFormat/gmd:MD_Format/gmd:version/gco:CharacterString/text()"/>
		<property name="multivalue" value="true" />
	</bean>	

	<bean id="isotc.licenseName" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="licenseName" />
		<constructor-arg name="xpath"
			value="//gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:accessConstraints/gmd:MD_RestrictionCode/text()[normalize-space()] |
        //gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:useConstraints/gmd:MD_RestrictionCode/text()[normalize-space()] |
        //gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:otherConstraints/gmd:MD_RestrictionCode/text()[normalize-space()]"/>
		<property name="multivalue" value="true" />
		<property name="dedupe" value="true" />
	</bean>

	<bean id="isotc.licenseDescription" class="org.dataone.cn.indexer.parser.SolrField">
		<constructor-arg name="name" value="licenseDescription" />
		<constructor-arg name="xpath"
			value="//gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:accessConstraints/gco:CharacterString/text()[normalize-space()] |
        //gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:useConstraints/gco:CharacterString/text()[normalize-space()] |
        //gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:otherConstraints/gco:CharacterString/text()[normalize-space()] |
        //gmd:resourceConstraints/gmd:MD_LegalConstraints/gmd:useLimitation/gco:CharacterString/text()[normalize-space()] |
        //gmd:resourceConstraints/gmd:MD_Constraints/gmd:useLimitation/gco:CharacterString/text()[normalize-space()]"/>
		<property name="multivalue" value="true" />
	</bean>
	
</beans>
