<workflow-app name="Extract Orcid XML Works From Activities" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>workingPath</name>
            <description>the working dir base path</description>
        </property>
    </parameters>

    <global>
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <configuration>
            <property>
                <name>oozie.action.sharelib.for.java</name>
                <value>${oozieActionShareLibForSpark2}</value>
            </property>
            <property>
                <name>oozie.launcher.mapreduce.user.classpath.first</name>
                <value>true</value>
            </property>
            <property>
                <name>oozie.launcher.mapreduce.map.java.opts</name>
                <value>-Xmx2g</value>
            </property>
            <property>
                <name>oozie.use.system.libpath</name>
                <value>true</value>
            </property>
        </configuration>
    </global>

    <start to="ResetWorkingPath"/>


    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>

    <action name="ResetWorkingPath">
        <fs>
            <delete path='${workingPath}/xml/works'/>
            <mkdir path='${workingPath}/xml/works'/>
        </fs>
        <ok to="fork_node"/>
        <error to="Kill"/>
    </action>

    <fork name = "fork_node">
        <path start = "ExtractXMLWorkActivities_0"/>
        <path start = "ExtractXMLWorkActivities_1"/>
        <path start = "ExtractXMLWorkActivities_2"/>
        <path start = "ExtractXMLWorkActivities_3"/>
        <path start = "ExtractXMLWorkActivities_4"/>
        <path start = "ExtractXMLWorkActivities_5"/>
        <path start = "ExtractXMLWorkActivities_6"/>
        <path start = "ExtractXMLWorkActivities_7"/>
        <path start = "ExtractXMLWorkActivities_8"/>
        <path start = "ExtractXMLWorkActivities_9"/>
        <path start = "ExtractXMLWorkActivities_X"/>
    </fork>
    
    <action name="ExtractXMLWorkActivities_0">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_0.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_0.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_1">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_1.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_1.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_2">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_2.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_2.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_3">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_3.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_3.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_4">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_4.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_4.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_5">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_5.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_5.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>


    <action name="ExtractXMLWorkActivities_6">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_6.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_6.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_7">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_7.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_7.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>


    <action name="ExtractXMLWorkActivities_8">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_8.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_8.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_9">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_9.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_9.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractXMLWorkActivities_X">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.orcid.ExtractXMLActivitiesData</main-class>
            <arg>-w</arg><arg>${workingPath}/</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-f</arg><arg>ORCID_2020_10_activites_X.tar.gz</arg>
            <arg>-ow</arg><arg>xml/works/xml_works_X.seq</arg>
            <arg>-oew</arg><arg>---</arg>
        </java>
        <ok to="join_node"/>
        <error to="Kill"/>
    </action>

    <join name = "join_node" to = "End"/>

    <end name="End"/>
</workflow-app>