<RESOURCE_PROFILE>
	<HEADER>
		<RESOURCE_IDENTIFIER value="bb36d5af-442c-488b-ad42-d9b068f6f1c0_V29ya2Zsb3dUZW1wbGF0ZURTUmVzb3VyY2VzL1dvcmtmbG93VGVtcGxhdGVEU1Jlc291cmNlVHlwZQ=="/>
		<RESOURCE_TYPE value="WorkflowTemplateDSResourceType"/>
		<RESOURCE_KIND value="WorkflowTemplateDSResources"/>
		<RESOURCE_URI value=""/>
		<DATE_OF_CREATION value="2017-03-07T10:00:00.0Z"/>
	</HEADER>
	<BODY>
		<CONFIGURATION>
			<PARAMETERS>
				<PARAM name="transformationMode" description="Incremental or refresh mode" required="true" type="string" />
				<PARAM name="dsId" description="Datasource Id" 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="cleanMdstoreId" description="Store for transformed records" required="true" type="string"/>
				<PARAM name="mappingPolicyProfile" description="Mapping policy to apply by X3M" required="false" type="string" />
				<PARAM name="mappingProfiles" description="X3M mapping rules" required="true" type="list" />
				<PARAM name="passFullRecord" description="True to pass the full record to x3m" required="true" type="boolean" />
				<PARAM name="verboseTransformationLogging" description="Enable verbose logging of X3M" required="false" type="boolean"/>
				<PARAM name="cleaningRuleId" description="Cleaning rule" required="true" type="string" />
			</PARAMETERS>
			<WORKFLOW>
				<NODE name="SELECT_MODE" type="Selection" isStart="true">
					<DESCRIPTION>Refresh or incremental?</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="selection" ref="transformationMode" />
					</PARAMETERS>
					<ARCS>
						<ARC to="FETCH_RECORDS" name="REFRESH" />
						<ARC to="PREPARE_INCREMENTAL" name="INCREMENTAL" />
					</ARCS>
				</NODE>
				<NODE name="PREPARE_INCREMENTAL" type="FindWfLatestSuccessDate">
					<DESCRIPTION>Find Date Range For Incremental Harvesting</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="dateParam" value="FROM_DATE"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="FETCH_RECORDS"/>
					</ARCS>
				</NODE>
				<NODE name="FETCH_RECORDS" type="FetchMDStoreRecords">
					<DESCRIPTION>Fetch records from MDStore</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="mdId" ref="collMdstoreId"/>
						<PARAM name="eprParam" value="orig_epr"/>
						<PARAM name="noCursorTimeout" value="true"/>
						<PARAM name="fromDate" env="FROM_DATE"/>
						<PARAM name="untilDate" value=""/>
					</PARAMETERS>
					<ARCS>
						<!--<ARC to="validateAgainstSchema"/> -->
						<ARC to="x3mTransform"/>
					</ARCS>
				</NODE>
				<!--<NODE name="validateAgainstSchema" type="XMLSchemaValidator">-->
					<!--<DESCRIPTION>Filters out non-valid XML records</DESCRIPTION>-->
					<!--<PARAMETERS>-->
						<!--<PARAM name="enableValidation" ref="enableSchemaValidation" />-->
						<!--<PARAM name="useDeclaredSchemaUrl" ref="useDeclaredSchema"/>-->
						<!--<PARAM name="xmlSchemaURL" ref="schemaURL"/>-->
						<!--<PARAM name="eprParam" value="orig_epr"/>-->
						<!--<PARAM name="validEprParam" value="valid_epr"/>-->
					<!--</PARAMETERS>-->
					<!--<ARCS>-->
						<!--<ARC to="x3mTransform"/>-->
					<!--</ARCS>-->
				<!--</NODE>-->
				<NODE name="x3mTransform" type="X3MTransform">
					<DESCRIPTION>Transform valid records</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="inputEprParam" value="orig_epr"/>
						<PARAM name="outputEprParam" value="trans_epr"/>
						<PARAM name="mappingPolicyProfileId" ref="mappingPolicyProfile"/>
						<PARAM name="mappingProfileIds" ref="mappingProfiles"/>
						<PARAM name="verboseLogging" ref="verboseTransformationLogging"/>
						<PARAM name="passFullRecord" ref="passFullRecord"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="clean"/>
					</ARCS>
				</NODE>
				<NODE name="clean" type="Clean">
					<DESCRIPTION>Clean records</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="inputEprParam" value="trans_epr"/>
						<PARAM name="outputEprParam" value="clean_epr"/>
						<PARAM name="ruleId" ref="cleaningRuleId"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="storeRecords"/>
					</ARCS>
				</NODE>
				<NODE name="storeRecords" type="StoreMDStoreRecords">
					<DESCRIPTION>Store mdtore records</DESCRIPTION>
					<PARAMETERS>
						<PARAM name="mdId" ref="cleanMdstoreId"/>
						<PARAM name="storingType" ref="transformationMode"/>
						<PARAM name="eprParam" value="clean_epr"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="UPDATE_INFO"/>
						<!-- <ARC to="LOG_REPORT"/> -->
					</ARCS>
				</NODE>
				<!--<NODE name="LOG_REPORT" type="ReportReader">-->
					<!--<DESCRIPTION>Store the validation report in the env</DESCRIPTION>-->
					<!--<PARAMETERS>-->
					<!--</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="cleanMdstoreId"/>
						<PARAM name="datasourceId" ref="dsId"/>
						<PARAM name="datasourceInterface" ref="interface"/>
						<PARAM name="extraFieldForTotal" value="last_aggregation_total"/>
						<PARAM name="extraFieldForDate" value="last_aggregation_date"/>
						<PARAM name="extraFieldForMdId" value="last_aggregation_mdId"/>
					</PARAMETERS>
					<ARCS>
						<ARC to="success"/>
					</ARCS>
				</NODE>
			</WORKFLOW>
		</CONFIGURATION>
	</BODY>
</RESOURCE_PROFILE>
