<?xml version="1.0" encoding="UTF-8"?>
<!--
  This configuration file serves as a starting point for a fedora 3 to fedora 4
   migration when the fedora 3 content has been exported to "archive" FOXML 1.1
   files.

  There are several default values you will likely have to change below, each is
  marked with a comment starting with "CHANGE THIS":
-->
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       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">

    <context:property-placeholder/>

    <bean id="migrator" class="org.fcrepo.migration.Migrator">
        <property name="source" ref="${migration.layout:exported}" />
        <property name="handler" ref="objectAbstraction" />
        <property name="limit" value="${migration.limit:2}" /><!-- SET migration.limit OR CHANGE THIS IF YOU WANT TO MIGRATE MORE THAN 2 OBJECTS -->
        <!--PID List Managers help in selecting which source objects to migration, default is ALL-->
        <property name="pidListManagers">
            <list>
                <bean class="org.fcrepo.migration.pidlist.UserProvidedPidListManager">
                    <constructor-arg name="pidListFile" value="${migration.pid.list.file:#{null}}"/>
                </bean>
                <bean class="org.fcrepo.migration.pidlist.ResumePidListManager">
                    <constructor-arg name="pidDir" value="${migration.pid.resume.dir:target/test/pid}"/>
                    <constructor-arg name="acceptAll" value="${migration.pid.resume.all:true}"/>
                </bean>
            </list>
        </property>
    </bean>

    <bean id="exported" class="org.fcrepo.migration.foxml.ArchiveExportedFoxmlDirectoryObjectSource" lazy-init="true">
        <constructor-arg name="exportDir" ref="exportDir" />
        <constructor-arg name="localFedoraServer" ref="localFedoraServer" />
        <property name="fetcher" ref="httpClientURLFetcher"/>
    </bean>
    
    <bean id="legacy" class="org.fcrepo.migration.foxml.NativeFoxmlDirectoryObjectSource" lazy-init="true">
        <constructor-arg name="objectStore" ref="objectStore" />
        <constructor-arg name="resolver" ref="legacyIDResolver" />
        <constructor-arg name="localFedoraServer" ref="localFedoraServer" />
        <property name="fetcher" ref="httpClientURLFetcher"/>
    </bean>
    
    <bean id="akubra" class="org.fcrepo.migration.foxml.NativeFoxmlDirectoryObjectSource" lazy-init="true">
        <constructor-arg name="objectStore" ref="objectStore" />
        <constructor-arg name="resolver" ref="akubraIDResolver" />
        <constructor-arg name="localFedoraServer" ref="localFedoraServer" />
        <property name="fetcher" ref="httpClientURLFetcher"/>
    </bean>

    <bean id="legacyIDResolver" class="org.fcrepo.migration.foxml.LegacyFSIDResolver" lazy-init="true">
        <constructor-arg name="dsRoot" type="java.io.File" ref="datastreamStore"/>
        <!-- Add the following line back in if you wish to maintain a cache of the internal id mapping between
             runs of this application.  This will save substantial time at startup, but is not appropriate if
             the repository changes.  -->
        <!--  <constructor-arg name="indexDir" type="java.io.File" ref="indexRoot" /> -->
    </bean>
    
    <bean id="akubraIDResolver" class="org.fcrepo.migration.foxml.AkubraFSIDResolver" lazy-init="true">
        <constructor-arg name="dsRoot" type="java.io.File" ref="datastreamStore"/>
        <!-- Add the following line back in if you wish to maintain a cache of the internal id mapping between
             runs of this application.  This will save substantial time at startup, but is not appropriate if
             the repository changes.  -->
        <!--<constructor-arg name="indexDir" type="java.io.File" ref="indexRoot" />-->
    </bean>
    
    
    <!-- Set foxml.dir.objects or CHANGE THIS TO YOUR FEDORA 3 OBJECTS DIRECTORY -->
    <bean id="objectStore" class="java.io.File">
        <constructor-arg type="java.lang.String" value="${foxml.object.dir:src/test/resources/legacyFS/objects}" />
    </bean>

    <!-- Set foxml.store.datastreams or CHANGE THIS TO YOUR FEDORA 3 DATASTREAM DIRECTORY -->
    <bean id="datastreamStore" class="java.io.File">
        <constructor-arg type="java.lang.String" value="${foxml.datastream.dir:src/test/resources/legacyFS/datastreams}" />
    </bean>  
    
    <bean id="indexRoot" class="java.io.File">
        <constructor-arg type="java.lang.String" value="${migration.index.root:index}" />
    </bean>  

    <bean id="objectAbstraction" class="org.fcrepo.migration.handlers.ObjectAbstractionStreamingFedoraObjectHandler">
        <constructor-arg ref="ldpFull"/>
    </bean>

    <!-- Full LDP migration impl -->
    <bean id="ldpFull" class="org.fcrepo.migration.handlers.BasicObjectVersionHandler">
        <constructor-arg name="client" ref="${fedora.client:ocfl}" />
        <constructor-arg name="idMapper" ref="idMapper" />
        <constructor-arg name="localFedoraServer" ref="localFedoraServer" />
        <constructor-arg name="namespacePrefixMapper" ref="namespacePrefixMapper"/>
        <property name="customPropertyMapping" ref="propertiesFile" />
        <property name="importExternal" value="${migration.import.external:false}" /><!-- CHANGE THIS IF YOU WANT TO IMPORT E DATASTREAMS -->
        <property name="importRedirect" value="${migration.import.redirect:false}" /><!-- CHANGE THIS IF YOU WANT TO IMPORT R DATASTREAMS -->
    </bean>

    <!--
       Mints a new fedora 4 path for each PID encountered during the migration.
       The mappings are persisted in a lucene index configured in the "idIndex"
       bean.  Furthermore, a file id-minter.log will contain the mapping as well.
    -->
    <bean id="idMapper" class="org.fcrepo.migration.idmappers.OpaqueIDMapper">
        <constructor-arg name="cachedIDIndexDir" ref="idIndex" />
        <constructor-arg name="f4Client" ref="${fedora.client:ocfl}" />
    </bean>


    <bean id="namespacePrefixMapper" class="org.fcrepo.migration.foxml.NamespacePrefixMapper">
        <constructor-arg name="namespaceFile" type="java.io.File" ref="namespaceFile"/>
    </bean>
    
    <bean id="minimal" class="org.fcrepo.migration.handlers.ocfl.ArchiveGroupHandler">
        <constructor-arg name="sessionFactory" ref="ocflSessionFactory" />
        <constructor-arg name="migrationType" value="FEDORA_OCFL" />
        <constructor-arg name="addDatastreamExtensions" value="false" />
        <constructor-arg name="user" value="fedoraAdmin" />
    </bean>

    <bean id="ocflSessionFactory" class="org.fcrepo.migration.OcflSessionFactoryFactoryBean">
        <constructor-arg name="ocflRoot" value="${migration.ocfl.storage.dir:target/test/storage}" />
        <constructor-arg name="stagingDir" value="${migration.ocfl.staging.dir:target/test/staging}" />
        <constructor-arg name="migrationType" value="FEDORA_OCFL" />
        <constructor-arg name="user" value="fedoraAdmin" />
        <constructor-arg name="userUri" value="info:fedora/fedoraAdmin" />
    </bean>

    <bean id="fedora4" class="org.fcrepo.migration.f4clients.StatelessFedora4Client">
        <constructor-arg name="fcrepoBaseURL" ref="fedora4Url" />
        <!--If Fedora 4 requires authorized requests, uncomment the following and provide appropriate values.-->
        <!--<constructor-arg name="username" value="admin-username"/>-->
        <!--<constructor-arg name="password" value="admin-password"/>-->
    </bean>
    
    <bean id="httpClientURLFetcher" class="org.fcrepo.migration.foxml.HttpClientURLFetcher" />

    <!-- CHANGE THIS TO THE FEDORA 4 URL TO WHICH YOU WANT TO MIGRATE THE CONTENT -->
    <bean id="fedora4Url" class="java.lang.String">
        <constructor-arg value="${fedora.to.baseuri:http://localhost:${fcrepo.dynamic.test.port:8080}/rest/}" />
    </bean>

    <!-- The fedora 3 server migrated content is coming from -->
    <bean id="localFedoraServer" class="java.lang.String">
        <constructor-arg value="${fedora.from.server:localhost:8080}" />
    </bean>

    <bean id="namespaceFile" class="java.io.File">
        <constructor-arg type="java.lang.String" value="${migration.namespace.file:src/main/resources/namespaces.properties}"/>
    </bean>

    <bean id="propertiesFile" class="java.io.File">
        <constructor-arg type="java.lang.String" value="${migration.mapping.file:src/test/resources/custom-mapping.properties}"/>
    </bean>

    <!-- SER foxml.export.dir OR CHANGE THIS TO THE DIRECTORY TO WHICH YOU EXPORTED "ARCHIVE" FOXML -->
    <bean id="exportDir" class="java.io.File">
        <constructor-arg type="java.lang.String" value="${foxml.export.dir:src/test/resources/exported}" />
    </bean>

    <bean id="idIndex" class="java.io.File">
        <constructor-arg type="java.lang.String" value="exported-id-index" />
    </bean>
</beans>
