<commit_before><?xml version="1.0" encoding="UTF-8"?>
<mule version="EE-3.7.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:context="http://www.springframework.org/schema/context" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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-current.xsd  http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd  http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd  http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd  http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd  http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd  http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
 	
    <sfdc:config doc:name="Salesforce" name="Salesforce" password="<PASSWORD>!" securityToken="<PASSWORD>" username="<EMAIL>">
        <sfdc:connection-pooling-profile exhaustedAction="WHEN_EXHAUSTED_GROW" initialisationPolicy="INITIALISE_ONE"/>
    </sfdc:config>
    <db:mysql-config database="company" doc:name="MySQL Configuration" host="${mysql.host}" name="MySQL_Configuration" password="${<PASSWORD>}" port="3306" user="${mysql.user}"/>
    <batch:job name="salesforce-to-database-Batch">
        <batch:threading-profile poolExhaustedAction="WAIT"/>
        
        <batch:process-records>
            <batch:step name="queryExistingContactInDbStep">
                <dw:transform-message doc:name="Transform Message">
                    <dw:set-payload><![CDATA[%dw 1.0
%input payload application/java
%output application/java
---
{
	"email" : payload.Email,
	"first_name" : payload.FirstName,
	"last_name" : payload.LastName,
	"last_modified" : payload.LastModifiedDate
}]]></dw:set-payload>
                </dw:transform-message>

                <enricher doc:name="Message Enricher">
                    <db:select config-ref="MySQL_Configuration" doc:name="Check existence in Database">
                        <db:parameterized-query><![CDATA[SELECT first_name,last_name,email FROM contact WHERE email=#[payload.email]]]></db:parameterized-query>


                    </db:select>
                    <enrich source="#[payload.size() > 0]" target="#[recordVars['exists']]"/>
                    <enrich source="#[payload]" target="#[recordVars['dbRecord']]"/>
                </enricher>
            </batch:step>
            <batch:step name="upsertContactInDbStep">
            	<choice doc:name="Choice">
                    <when expression="#[recordVars['exists']==false]">
                        <db:insert config-ref="MySQL_Configuration" doc:name="Create contact">
                            <db:parameterized-query><![CDATA[INSERT INTO contact (first_name, last_name, email) VALUES (#[payload.first_name],#[payload.last_name],#[payload.email])]]></db:parameterized-query>

                        </db:insert>
                    </when>
                    <when expression="#[recordVars['exists']==true and recordVars['dbRecord'] != null]">
                        <db:update config-ref="MySQL_Configuration" doc:name="Update Contact">
                            <db:parameterized-query><![CDATA[UPDATE contact SET first_name=#[payload.first_name],last_name=#[payload.last_name] WHERE email = #[payload.email]]]></db:parameterized-query>

                        </db:update>
                    </when>
                    <otherwise>
                        <logger doc:name="Logger" level="INFO" message="Error with #[payload.email] contact"/>
                    </otherwise>
                </choice>
            </batch:step>                        
        </batch:process-records>
        <batch:on-complete>
            <logger doc:name="Log completion" level="INFO" message="Batch sf->db has finished"/>
        </batch:on-complete>
    </batch:job>
    <flow name="triggerFlow" processingStrategy="synchronous">
        <poll doc:name="Poll">
                <fixed-frequency-scheduler frequency="60" timeUnit="SECONDS"/>
                <watermark default-expression="#[groovy: new Date(System.currentTimeMillis() - 10000).format(&amp;quot;yyyy-MM-dd'T'HH:mm:ss.SSS'Z'&amp;quot;, TimeZone.getTimeZone('UTC'))]" selector="MAX" selector-expression="#[payload.LastModifiedDate]" variable="timestamp"/>                
                <sfdc:query config-ref="Salesforce" doc:name="Query Salesforce every 10 seconds" query="dsql:SELECT Email,FirstName,LastModifiedDate,LastName FROM Contact WHERE LastModifiedDate > #[timestamp]"/>
        </poll>
        <logger doc:name="Logger" level="INFO" message="#[flowVars.timestamp]"/>
        <batch:execute doc:name="salesforce-to-database-Batch" name="salesforce-to-database-Batch"/>
    </flow>

    
</mule><commit_msg>SIT-1151 - corrected default poll expresstion for salesforce-to-MySQL-DB-using-Batch-Processing<commit_after><?xml version="1.0" encoding="UTF-8"?>
<mule version="EE-3.7.0" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:context="http://www.springframework.org/schema/context" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
 	
    <sfdc:config doc:name="Salesforce" name="Salesforce" password="<PASSWORD>!" securityToken="iz<PASSWORD>" username="<EMAIL>">
        <sfdc:connection-pooling-profile exhaustedAction="WHEN_EXHAUSTED_GROW" initialisationPolicy="INITIALISE_ONE"/>
    </sfdc:config>
    <db:mysql-config database="company" doc:name="MySQL Configuration" host="${mysql.host}" name="MySQL_Configuration" password="${<PASSWORD>}" port="3306" user="${mysql.user}"/>
    <batch:job name="salesforce-to-database-Batch">
        <batch:threading-profile poolExhaustedAction="WAIT"/>
        
        <batch:process-records>
            <batch:step name="queryExistingContactInDbStep">
                <dw:transform-message doc:name="Transform Message">
                    <dw:set-payload><![CDATA[%dw 1.0
%input payload application/java
%output application/java
---
{
	"email" : payload.Email,
	"first_name" : payload.FirstName,
	"last_name" : payload.LastName,
	"last_modified" : payload.LastModifiedDate
}]]></dw:set-payload>
                </dw:transform-message>

                <enricher doc:name="Message Enricher">
                    <db:select config-ref="MySQL_Configuration" doc:name="Check existence in Database">
                        <db:parameterized-query><![CDATA[SELECT first_name,last_name,email FROM contact WHERE email=#[payload.email]]]></db:parameterized-query>


                    </db:select>
                    <enrich source="#[payload.size() > 0]" target="#[recordVars['exists']]"/>
                    <enrich source="#[payload]" target="#[recordVars['dbRecord']]"/>
                </enricher>
            </batch:step>
            <batch:step name="upsertContactInDbStep">
            	<choice doc:name="Choice">
                    <when expression="#[recordVars['exists']==false]">
                        <db:insert config-ref="MySQL_Configuration" doc:name="Create contact">
                            <db:parameterized-query><![CDATA[INSERT INTO contact (first_name, last_name, email) VALUES (#[payload.first_name],#[payload.last_name],#[payload.email])]]></db:parameterized-query>

                        </db:insert>
                    </when>
                    <when expression="#[recordVars['exists']==true and recordVars['dbRecord'] != null]">
                        <db:update config-ref="MySQL_Configuration" doc:name="Update Contact">
                            <db:parameterized-query><![CDATA[UPDATE contact SET first_name=#[payload.first_name],last_name=#[payload.last_name] WHERE email = #[payload.email]]]></db:parameterized-query>

                        </db:update>
                    </when>
                    <otherwise>
                        <logger doc:name="Logger" level="INFO" message="Error with #[payload.email] contact"/>
                    </otherwise>
                </choice>
            </batch:step>                        
        </batch:process-records>
        <batch:on-complete>
            <logger doc:name="Log completion" level="INFO" message="Batch sf->db has finished"/>
        </batch:on-complete>
    </batch:job>
    <flow name="triggerFlow" processingStrategy="synchronous">
        <poll doc:name="Poll">
                <fixed-frequency-scheduler frequency="60" timeUnit="SECONDS"/>
                <watermark default-expression="#[groovy: new Date(System.currentTimeMillis() - 10000).format(&quot;yyyy-MM-dd'T'HH:mm:ss.SSS'Z'&quot;, TimeZone.getTimeZone('UTC'))]" selector="MAX" selector-expression="#[payload.LastModifiedDate]" variable="timestamp"/>                
                <sfdc:query config-ref="Salesforce" doc:name="Query Salesforce every 10 seconds" query="dsql:SELECT Email,FirstName,LastModifiedDate,LastName FROM Contact WHERE LastModifiedDate > #[timestamp]"/>
        </poll>
        <logger doc:name="Logger" level="INFO" message="#[flowVars.timestamp]"/>
        <batch:execute doc:name="salesforce-to-database-Batch" name="salesforce-to-database-Batch"/>
    </flow>

    
</mule>
{'fraction_non_alphanumeric': 0.16611414747782458, 'fraction_numerical': 0.005196666965325687, 'mean_word_length': 3.166480029861889, 'pattern_counts': {'":': 0, '<': 133, '<?xml version=': 2, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 52, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '537883', 'n_tokens_mistral': 3517, 'n_tokens_neox': 3334, 'n_words': 413}