<?xml version="1.0" encoding="UTF-8"?>
<!--
    Generate and sign per-entity metadata using a local private key resource.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
    default-lazy-init="true"
    xmlns:c="http://www.springframework.org/schema/c"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:util="http://www.springframework.org/schema/util"
    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/util http://www.springframework.org/schema/util/spring-util.xsd">

    <!--
        Import commonly used beans.
    -->
    <import resource="classpath:common-beans.xml"/>

    <!--
        Import channel-specific beans.
    -->
    <import resource="classpath:incommon/beans.xml"/>

    <!--
        Generate per-entity metadata.
    -->
    <bean id="mdq-multisign-localkey" parent="mda.SimplePipeline">
        <property name="stages">
            <list>
                <!--
                    Start with the unsigned production aggregate.
                -->
                <bean id="production_aggregate" parent="mda.DOMResourceSourceStage">
                    <property name="parserPool" ref="parserPool"/>
                    <property name="DOMResource">
                        <bean parent="FileSystemResource" c:_0="${mdq.input}"/>
                    </property>
                </bean>

                <!-- Break down into individual entities. -->
                <ref bean="disassemble"/>

                <!-- Populate ItemId with the entityID. -->
                <ref bean="populateItemIds"/>

                <!-- Discard entities in the InCommon entity blacklist. -->
                <ref bean="remove_blacklisted_incommon_entities"/>

                <!-- Set ID, cacheDuration and validUntil attributes. -->
                <bean parent="mda.GenerateIdStage"/>
                <bean parent="mda.SetValidUntilStage" p:validityDuration="P14D"/>

                <!-- Identity transform fixes signing issues. -->
                <bean parent="mda.XSLTransformationStage"
                    p:XSLResource="classpath:identity.xsl"/>

                <!-- Sign each item. -->
                <bean id="perform.signature" parent="mda.XMLSignatureSigningStage">
                    <property name="privateKey">
                        <bean parent="mda.PrivateKeyFactoryBean"
                            p:resource="${sign.keyResource}"
                            p:privateKeyPassword="${sign.keyPassword}"
                        />
                    </property>
                </bean>

                <!-- Write individual entity documents to files. -->
                <bean id="write.perentity" parent="mda.MultiOutputSerializationStage">
                    <property name="serializer" ref="serializer"/>
                    <property name="outputStrategy">
                        <bean parent="mda.FilesInDirectoryMultiOutputStrategy" p:nameSuffix=".xml">
                            <property name="directory">
                                <bean parent="File" c:_="${mdq.output}"/>
                            </property>
                            <property name="nameTransformer">
                                <bean parent="mda.PathSegmentStringTransformer"/>
                            </property>
                        </bean>
                    </property>
                </bean>

            </list>
        </property>
    </bean>

</beans>