<RESOURCE_PROFILE>
	<HEADER>
		<RESOURCE_IDENTIFIER value="8536236a-7074-4155-9279-8cb2fcc8887a_V29ya2Zsb3dUZW1wbGF0ZURTUmVzb3VyY2VzL1dvcmtmbG93VGVtcGxhdGVEU1Jlc291cmNlVHlwZQ=="/>
		<RESOURCE_TYPE value="WorkflowTemplateDSResourceType"/>
		<RESOURCE_KIND value="WorkflowTemplateDSResources"/>
		<RESOURCE_URI value=""/>
		<DATE_OF_CREATION value="2017-01-17T17:00:00.0Z"/>
	</HEADER>
	<BODY>
		<CONFIGURATION>
			<PARAMETERS>
				<PARAM name="dsId" description="Datasource Id" required="true" type="string"/>
				<PARAM name="dsName" description="Datasource Name" required="true" type="string"/>
				<PARAM name="interface" description="Datasource Interface" required="true" type="string"/>
				<PARAM name="collMdstoreId" description="Store for collected records" required="true" type="string"/>
				<PARAM name="harvestingMode" description="Incremental or refresh mode" required="true" type="string" />
			</PARAMETERS>
			<WORKFLOW>
				<NODE name="SELECT_MODE" type="Selection" isStart="true">
					<DESCRIPTION>Refresh or incremental?</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="selection" ref="harvestingMode" />
					</PARAMETERS>
					<ARCS>
						<ARC to="COLLECT" name="REFRESH" />
						<ARC to="PREPARE_INCREMENTAL" name="INCREMENTAL" />
					</ARCS>
				</NODE>
				<NODE name="PREPARE_INCREMENTAL" type="FindDateRangeForIncrementalHarvesting">
					<DESCRIPTION>Find Date Range For Incremental Harvesting</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="dateParam" value="FROM_DATE"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="COLLECT"/>
					</ARCS>
				</NODE>
				<NODE name="COLLECT" type="CollectRecords">
					<DESCRIPTION>Start Harvesting</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="datasourceId" ref="dsId"/>
						<PARAM name="datasourceInterface" ref="interface"/>
						<PARAM name="eprParam" value="collected_epr"/>
						<PARAM name="fromDate" env="FROM_DATE"/>
						<PARAM name="untilDate" value=""/>
					</PARAMETERS>
					<ARCS>
						<ARC to="MD_BUILDER"/>
					</ARCS>
				</NODE>
				<NODE name="MD_BUILDER" type="MdBuilder">
					<DESCRIPTION>Prepare mdstore records</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="inputEprParam" value="collected_epr"/>
						<PARAM name="outputEprParam" value="store_epr"/>
						<PARAM name="datasourceId" ref="dsId"/>
						<PARAM name="datasourceName" ref="dsName"/>
						<PARAM name="datasourceInterface" ref="interface"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="STORE"/>
					</ARCS>
				</NODE>
				<NODE name="STORE" type="StoreMDStoreRecords">
					<DESCRIPTION>Store mdstore records</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="mdId" ref="collMdstoreId"/>
						<PARAM name="storingType" ref="harvestingMode"/>
						<PARAM name="eprParam" value="store_epr"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="UPDATE_INFO"/>
					</ARCS>
				</NODE>

				<NODE name="UPDATE_INFO" type="MDStoreToApiExtraField">
					<DESCRIPTION>Update datasouce API extra fields</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="mdId" ref="collMdstoreId"/>
						<PARAM name="datasourceId" ref="dsId"/>
						<PARAM name="datasourceInterface" ref="interface"/>
						<PARAM name="extraFieldForTotal" value="last_collection_total"/>
						<PARAM name="extraFieldForDate" value="last_collection_date"/>
						<PARAM name="extraFieldForMdId" value="last_collection_mdId"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="success"/>
					</ARCS>
				</NODE>
			</WORKFLOW>
		</CONFIGURATION>
	</BODY>
</RESOURCE_PROFILE>
