<workflow-app name="create RAW Graph (all steps)" xmlns="uri:oozie:workflow:0.5">

    <parameters>
        <property>
            <name>graphOutputPath</name>
            <description>the target path to store raw graph</description>
        </property>
        <property>
            <name>reuseDBClaims</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseODFClaims</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseOAFClaims</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseDB</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseDBOpenorgs</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseODF</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseOAF</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseODF_hdfs</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>reuseOAF_hdfs</name>
            <value>false</value>
            <description>should import content from the aggregator or reuse a previous version</description>
        </property>
        <property>
            <name>contentPath</name>
            <description>path location to store (or reuse) content from the aggregator</description>
        </property>
        <property>
            <name>postgresURL</name>
            <description>the postgres URL to access to the database</description>
        </property>
        <property>
            <name>postgresUser</name>
            <description>the user postgres</description>
        </property>
        <property>
            <name>postgresPassword</name>
            <description>the password postgres</description>
        </property>
        <property>
            <name>postgresOpenOrgsURL</name>
            <description>the postgres URL to access to the OpenOrgs database</description>
        </property>
        <property>
            <name>postgresOpenOrgsUser</name>
            <description>the user of OpenOrgs database</description>
        </property>
        <property>
            <name>postgresOpenOrgsPassword</name>
            <description>the password of OpenOrgs database</description>
        </property>
		<property>
            <name>dbSchema</name>
            <value>beta</value>
            <description>the database schema according to the D-Net infrastructure (beta or production)</description>
        </property>
        <property>
            <name>mongoURL</name>
            <description>mongoDB url, example: mongodb://[username:password@]host[:port]</description>
        </property>
        <property>
            <name>mongoDb</name>
            <description>mongo database</description>
        </property>
        <property>
            <name>isLookupUrl</name>
            <description>the address of the lookUp service</description>
        </property>
        <property>
            <name>nsPrefixBlacklist</name>
            <value></value>
            <description>a blacklist of nsprefixes (comma separeted)</description>
        </property>
        <property>
            <name>shouldPatchRelations</name>
            <value>false</value>
            <description>activates the relation patching phase, driven by the content in ${idMappingPath}</description>
        </property>
        <property>
            <name>idMappingPath</name>
            <value></value>
            <description>path pointing to the relations identifiers mapping dataset</description>
        </property>
        <property>
            <name>sparkDriverMemory</name>
            <description>memory for driver process</description>
        </property>
        <property>
            <name>sparkExecutorMemory</name>
            <description>memory for individual executor</description>
        </property>
        <property>
            <name>sparkExecutorCores</name>
            <description>number of cores used by single executor</description>
        </property>
        <property>
            <name>oozieActionShareLibForSpark2</name>
            <description>oozie action sharelib for spark 2.*</description>
        </property>
        <property>
            <name>spark2ExtraListeners</name>
            <value>com.cloudera.spark.lineage.NavigatorAppListener</value>
            <description>spark 2.* extra listeners classname</description>
        </property>
        <property>
            <name>spark2SqlQueryExecutionListeners</name>
            <value>com.cloudera.spark.lineage.NavigatorQueryListener</value>
            <description>spark 2.* sql query execution listeners classname</description>
        </property>
        <property>
            <name>spark2YarnHistoryServerAddress</name>
            <description>spark 2.* yarn history server address</description>
        </property>
        <property>
            <name>spark2EventLogDir</name>
            <description>spark 2.* event log dir location</description>
        </property>
    </parameters>

    <global>
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <configuration>
            <property>
                <name>mapreduce.job.queuename</name>
                <value>${queueName}</value>
            </property>
            <property>
                <name>oozie.launcher.mapred.job.queue.name</name>
                <value>${oozieLauncherQueueName}</value>
            </property>
            <property>
                <name>oozie.action.sharelib.for.spark</name>
                <value>${oozieActionShareLibForSpark2}</value>
            </property>
        </configuration>
    </global>

    <start to="start_import"/>

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

    <fork name="start_import">
        <path start="reuse_db"/>
        <path start="reuse_db_claims"/>
        <path start="reuse_db_openorgs"/>
    </fork>

    <decision name="reuse_db_claims">
        <switch>
            <case to="ImportDB_claims">${wf:conf('reuseDBClaims') eq false}</case>
            <case to="reuse_odf_claims">${wf:conf('reuseDBClaims') eq true}</case>
            <default to="ImportDB_claims"/>
        </switch>
    </decision>

    <action name="ImportDB_claims">
        <java>
            <prepare>
                <delete path="${contentPath}/db_claims"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateDbEntitiesApplication</main-class>
            <arg>--hdfsPath</arg><arg>${contentPath}/db_claims</arg>
            <arg>--postgresUrl</arg><arg>${postgresURL}</arg>
            <arg>--postgresUser</arg><arg>${postgresUser}</arg>
            <arg>--postgresPassword</arg><arg>${postgresPassword}</arg>
            <arg>--isLookupUrl</arg><arg>${isLookupUrl}</arg>
            <arg>--action</arg><arg>claims</arg>
            <arg>--dbschema</arg><arg>${dbSchema}</arg>
            <arg>--nsPrefixBlacklist</arg><arg>${nsPrefixBlacklist}</arg>
        </java>
        <ok to="reuse_odf_claims"/>
        <error to="Kill"/>
    </action>

    <decision name="reuse_odf_claims">
        <switch>
            <case to="ImportODF_claims">${wf:conf('reuseODFClaims') eq false}</case>
            <case to="reuse_oaf_claims">${wf:conf('reuseODFClaims') eq true}</case>
            <default to="ImportODF_claims"/>
        </switch>
    </decision>

    <action name="ImportODF_claims">
        <java>
            <prepare>
                <delete path="${contentPath}/odf_claims"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateMongoMdstoresApplication</main-class>
            <arg>-p</arg><arg>${contentPath}/odf_claims</arg>
            <arg>-mongourl</arg><arg>${mongoURL}</arg>
            <arg>-mongodb</arg><arg>${mongoDb}</arg>
            <arg>-f</arg><arg>ODF</arg>
            <arg>-l</arg><arg>store</arg>
            <arg>-i</arg><arg>claim</arg>
        </java>
        <ok to="reuse_oaf_claims"/>
        <error to="Kill"/>
    </action>

    <decision name="reuse_oaf_claims">
        <switch>
            <case to="ImportOAF_claims">${wf:conf('reuseOAFClaims') eq false}</case>
            <case to="wait_import">${wf:conf('reuseOAFClaims') eq true}</case>
            <default to="ImportOAF_claims"/>
        </switch>
    </decision>

    <action name="ImportOAF_claims">
        <java>
            <prepare>
                <delete path="${contentPath}/oaf_claims"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateMongoMdstoresApplication</main-class>
            <arg>-p</arg><arg>${contentPath}/oaf_claims</arg>
            <arg>-mongourl</arg><arg>${mongoURL}</arg>
            <arg>-mongodb</arg><arg>${mongoDb}</arg>
            <arg>-f</arg><arg>OAF</arg>
            <arg>-l</arg><arg>store</arg>
            <arg>-i</arg><arg>claim</arg>
        </java>
        <ok to="wait_import"/>
        <error to="Kill"/>
    </action>

    <decision name="reuse_db">
        <switch>
            <case to="ImportDB">${wf:conf('reuseDB') eq false}</case>
            <case to="reuse_odf">${wf:conf('reuseDB') eq true}</case>
            <default to="ImportDB"/>
        </switch>
    </decision>

    <action name="ImportDB">
        <java>
            <prepare>
                <delete path="${contentPath}/db_openaire"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateDbEntitiesApplication</main-class>
            <arg>--hdfsPath</arg><arg>${contentPath}/db_openaire</arg>
            <arg>--postgresUrl</arg><arg>${postgresURL}</arg>
            <arg>--postgresUser</arg><arg>${postgresUser}</arg>
            <arg>--postgresPassword</arg><arg>${postgresPassword}</arg>
            <arg>--isLookupUrl</arg><arg>${isLookupUrl}</arg>
            <arg>--action</arg><arg>openaire</arg>
            <arg>--dbschema</arg><arg>${dbSchema}</arg>
            <arg>--nsPrefixBlacklist</arg><arg>${nsPrefixBlacklist}</arg>
        </java>
        <ok to="reuse_odf"/>
        <error to="Kill"/>
    </action>

    <decision name="reuse_odf">
        <switch>
            <case to="ImportODF">${wf:conf('reuseODF') eq false}</case>
            <case to="reuse_oaf">${wf:conf('reuseODF') eq true}</case>
            <default to="ImportODF"/>
        </switch>
    </decision>

    <action name="ImportODF">
        <java>
            <prepare>
                <delete path="${contentPath}/odf_records"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateMongoMdstoresApplication</main-class>
            <arg>--hdfsPath</arg><arg>${contentPath}/odf_records</arg>
            <arg>--mongoBaseUrl</arg><arg>${mongoURL}</arg>
            <arg>--mongoDb</arg><arg>${mongoDb}</arg>
            <arg>--mdFormat</arg><arg>ODF</arg>
            <arg>--mdLayout</arg><arg>store</arg>
            <arg>--mdInterpretation</arg><arg>cleaned</arg>
        </java>
        <ok to="reuse_oaf"/>
        <error to="Kill"/>
    </action>

    <decision name="reuse_oaf">
        <switch>
            <case to="ImportOAF">${wf:conf('reuseOAF') eq false}</case>
            <case to="reuse_odf_hdfs">${wf:conf('reuseOAF') eq true}</case>
            <default to="ImportOAF"/>
        </switch>
    </decision>

    <action name="ImportOAF">
        <java>
            <prepare>
                <delete path="${contentPath}/oaf_records"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateMongoMdstoresApplication</main-class>
            <arg>--hdfsPath</arg><arg>${contentPath}/oaf_records</arg>
            <arg>--mongoBaseUrl</arg><arg>${mongoURL}</arg>
            <arg>--mongoDb</arg><arg>${mongoDb}</arg>
            <arg>--mdFormat</arg><arg>OAF</arg>
            <arg>--mdLayout</arg><arg>store</arg>
            <arg>--mdInterpretation</arg><arg>cleaned</arg>
        </java>
        <ok to="ImportOAF_invisible"/>
        <error to="Kill"/>
    </action>
    
    <action name="ImportOAF_invisible">
        <java>
            <prepare>
                <delete path="${contentPath}/oaf_records_invisible"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateMongoMdstoresApplication</main-class>
            <arg>--hdfsPath</arg><arg>${contentPath}/oaf_records_invisible</arg>
            <arg>--mongoBaseUrl</arg><arg>${mongoURL}</arg>
            <arg>--mongoDb</arg><arg>${mongoDb}</arg>
            <arg>--mdFormat</arg><arg>OAF</arg>
            <arg>--mdLayout</arg><arg>store</arg>
            <arg>--mdInterpretation</arg><arg>intersection</arg>
        </java>
        <ok to="ImportODF_hdfs"/>
        <error to="Kill"/>
    </action>
    
    <decision name="reuse_odf_hdfs">
        <switch>
            <case to="ImportODF_hdfs">${wf:conf('reuseODF_hdfs') eq false}</case>
            <case to="reuse_oaf_hdfs">${wf:conf('reuseODF_hdfs') eq true}</case>
            <default to="ImportODF_hdfs"/>
        </switch>
    </decision>

    <action name="ImportODF_hdfs">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>ImportODF_hdfs</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MigrateHdfsMdstoresApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--hdfsPath</arg><arg>${contentPath}/odf_records_hdfs</arg>
            <arg>--mdstoreManagerUrl</arg><arg>${mdstoreManagerUrl}</arg>
            <arg>--mdFormat</arg><arg>ODF</arg>
            <arg>--mdLayout</arg><arg>store</arg>
            <arg>--mdInterpretation</arg><arg>cleaned</arg>
        </spark>
        <ok to="reuse_oaf_hdfs"/>
        <error to="Kill"/>
    </action>
    
    <decision name="reuse_oaf_hdfs">
        <switch>
            <case to="ImportOAF_hdfs">${wf:conf('reuseOAF_hdfs') eq false}</case>
            <case to="wait_import">${wf:conf('reuseOAF_hdfs') eq true}</case>
            <default to="ImportOAF_hdfs"/>
        </switch>
    </decision>

    <action name="ImportOAF_hdfs">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>ImportOAF_hdfs</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MigrateHdfsMdstoresApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--hdfsPath</arg><arg>${contentPath}/oaf_records_hdfs</arg>
            <arg>--mdstoreManagerUrl</arg><arg>${mdstoreManagerUrl}</arg>
            <arg>--mdFormat</arg><arg>OAF</arg>
            <arg>--mdLayout</arg><arg>store</arg>
            <arg>--mdInterpretation</arg><arg>cleaned</arg>
        </spark>
        <ok to="wait_import"/>
        <error to="Kill"/>
    </action>    
    
    <decision name="reuse_db_openorgs">
        <switch>
            <case to="ImportDB_openorgs">${wf:conf('reuseDBOpenorgs') eq false}</case>
            <case to="wait_import">${wf:conf('reuseDBOpenorgs') eq true}</case>
            <default to="ImportDB_openorgs"/>
        </switch>
    </decision>

    <action name="ImportDB_openorgs">
        <java>
            <prepare>
                <delete path="${contentPath}/db_openorgs"/>
            </prepare>
            <main-class>eu.dnetlib.dhp.oa.graph.raw.MigrateDbEntitiesApplication</main-class>
            <arg>--hdfsPath</arg><arg>${contentPath}/db_openorgs</arg>
            <arg>--postgresUrl</arg><arg>${postgresOpenOrgsURL}</arg>
            <arg>--postgresUser</arg><arg>${postgresOpenOrgsUser}</arg>
            <arg>--postgresPassword</arg><arg>${postgresOpenOrgsPassword}</arg>
            <arg>--isLookupUrl</arg><arg>${isLookupUrl}</arg>
            <arg>--action</arg><arg>openorgs</arg>
            <arg>--dbschema</arg><arg>${dbSchema}</arg>
            <arg>--nsPrefixBlacklist</arg><arg>${nsPrefixBlacklist}</arg>
        </java>
        <ok to="wait_import"/>
        <error to="Kill"/>
    </action>

    <join name="wait_import" to="fork_generate_entities"/>

    <fork name="fork_generate_entities">
        <path start="GenerateEntities_claim"/>
        <path start="GenerateEntities"/>
    </fork>

    <action name="GenerateEntities_claim">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>GenerateEntities_claim</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.GenerateEntitiesApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--sourcePaths</arg><arg>${contentPath}/db_claims,${contentPath}/oaf_claims,${contentPath}/odf_claims</arg>
            <arg>--targetPath</arg><arg>${workingDir}/entities_claim</arg>
            <arg>--isLookupUrl</arg><arg>${isLookupUrl}</arg>
            <arg>--shouldHashId</arg><arg>${shouldHashId}</arg>
            <arg>--mode</arg><arg>claim</arg>
        </spark>
        <ok to="GenerateGraph_claims"/>
        <error to="Kill"/>
    </action>

    <action name="GenerateGraph_claims">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>GenerateGraph_claims</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.DispatchEntitiesApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--sourcePath</arg><arg>${workingDir}/entities_claim</arg>
            <arg>--graphRawPath</arg><arg>${workingDir}/graph_claims</arg>
        </spark>
        <ok to="wait_graphs"/>
        <error to="Kill"/>
    </action>

    <action name="GenerateEntities">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>GenerateEntities</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.GenerateEntitiesApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--sourcePaths</arg><arg>${contentPath}/db_openaire,${contentPath}/db_openorgs,${contentPath}/oaf_records,${contentPath}/odf_records,${contentPath}/oaf_records_hdfs,${contentPath}/odf_records_hdfs,${contentPath}/oaf_records_invisible</arg>
            <arg>--targetPath</arg><arg>${workingDir}/entities</arg>
            <arg>--isLookupUrl</arg><arg>${isLookupUrl}</arg>
            <arg>--shouldHashId</arg><arg>${shouldHashId}</arg>
        </spark>
        <ok to="GenerateGraph"/>
        <error to="Kill"/>
    </action>

    <action name="GenerateGraph">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>GenerateGraph</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.DispatchEntitiesApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=7680
            </spark-opts>
            <arg>--sourcePath</arg><arg>${workingDir}/entities</arg>
            <arg>--graphRawPath</arg><arg>${workingDir}/graph_raw</arg>
        </spark>
        <ok to="Import_oaf_store_graph"/>
        <error to="Kill"/>
    </action>

    <action name="Import_oaf_store_graph">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>ImportOAF_hdfs_graph</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.CopyHdfsOafSparkApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--hdfsPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--mdstoreManagerUrl</arg><arg>${mdstoreManagerUrl}</arg>
            <arg>--mdFormat</arg><arg>OAF</arg>
            <arg>--mdLayout</arg><arg>store</arg>
            <arg>--master</arg><arg>yarn</arg>
            <arg>--mdInterpretation</arg><arg>graph</arg>
        </spark>
        <ok to="wait_graphs"/>
        <error to="Kill"/>
    </action>

    <join name="wait_graphs" to="fork_merge_claims"/>

    <fork name="fork_merge_claims">
        <path start="merge_claims_publication"/>
        <path start="merge_claims_dataset"/>
        <path start="merge_claims_software"/>
        <path start="merge_claims_otherresearchproduct"/>
        <path start="merge_claims_datasource"/>
        <path start="merge_claims_organization"/>
        <path start="merge_claims_project"/>
        <path start="merge_claims_relation"/>
    </fork>

    <action name="merge_claims_publication">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_publication</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=7680
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Publication</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_dataset">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_dataset</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=7680
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Dataset</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_relation">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_relation</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=3840
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Relation</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_software">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_software</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=1920
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Software</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_otherresearchproduct">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_otherresearchproduct</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=1920
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.OtherResearchProduct</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_datasource">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_datasource</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=200
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Datasource</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_organization">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_organization</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=200
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Organization</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <action name="merge_claims_project">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>MergeClaims_project</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.MergeClaimsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=200
            </spark-opts>
            <arg>--rawGraphPath</arg><arg>${workingDir}/graph_raw</arg>
            <arg>--claimsGraphPath</arg><arg>${workingDir}/graph_claims</arg>
            <arg>--outputRawGaphPath</arg><arg>${graphOutputPath}</arg>
            <arg>--graphTableClassName</arg><arg>eu.dnetlib.dhp.schema.oaf.Project</arg>
        </spark>
        <ok to="wait_merge"/>
        <error to="Kill"/>
    </action>

    <join name="wait_merge" to="decisionPatchRelations"/>

    <decision name="decisionPatchRelations">
        <switch>
            <case to="patchRelations">
                ${(shouldPatchRelations eq "true") and
                (fs:exists(concat(concat(wf:conf('nameNode'),'/'),wf:conf('idMappingPath'))) eq "true")}
            </case>
            <default to="End"/>
        </switch>
    </decision>

    <action name="patchRelations">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>PatchRelations</name>
            <class>eu.dnetlib.dhp.oa.graph.raw.PatchRelationsApplication</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --executor-cores ${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
                --conf spark.sql.shuffle.partitions=7680
            </spark-opts>
            <arg>--graphBasePath</arg><arg>${graphOutputPath}</arg>
            <arg>--workingDir</arg><arg>${workingDir}/patch_relations</arg>
            <arg>--idMappingPath</arg><arg>${idMappingPath}</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>

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