Skip to content

Instantly share code, notes, and snippets.

View adrianhsieh's full-sized avatar

Adrian Hsieh adrianhsieh

  • Adaptive Connections
View GitHub Profile
@adrianhsieh
adrianhsieh / paycheck.xml
Created November 20, 2012 00:28
show me the paycheck
<choice doc:name="Choice">
<when expression="payload.get('paycheckstyle') == 'Walmart Fozzy'">
<processor-chain>
<http:response-builder status="302" doc:name="HTTP Response Builder">
<http:location value="http://happyhour.atotis.com"/>
</http:response-builder>
</processor-chain>
</when>
<otherwise>
<processor-chain>
@adrianhsieh
adrianhsieh / handshake-to-quickbooks.js
Last active January 3, 2016 12:49
Sample mapping showing how to map from Handshake to QuickBooks
//#CTL2
// Transforms input record into output record.
function integer transform() {
if ($in.0.unitPrice != 0.0 && $in.0.qty != 0.0) {
$out.0.itemType = lookup(QBRefLookup).get($in.0.sku,dictionary.realmid,'ITEM').type;
$out.0.discountRatePercent = isnull($in.0.percentageDiscount) ? null : str2decimal($in.0.percentageDiscount);
$out.0.itemName = $in.0.sku;
$out.0.discountAmount = isnull($in.0.discount) ? null : str2decimal($in.0.discount);
$out.0.desc = $in.0.description + (isnull($in.0.notes) ? null : ' ' + $in.0.notes);
@adrianhsieh
adrianhsieh / recursive-flow.xml
Created January 17, 2014 00:36
Recursive call to find the right number to increment against QuickBooks Online
<flow name="qb-findname-flow" doc:name="qb-findname-flow" processingStrategy="synchronous">
<vm:inbound-endpoint exchange-pattern="request-response" path="qb.findname" doc:name="qb.findname"/>
<enricher source="#[payload.size()]" target="#[variable:matched]" doc:name="Message Enricher">
<quickbooks:find-objects config-ref="quickbooks" queryFilter="name :EQUALS: #[payload.workingname]" accessTokenId="#[map-payload:realmid]" type="#[map-payload:synctype]" doc:name="Quickbooks Online"/>
</enricher>
<choice doc:name="Choice">
<when expression="#[matched > 0]">
<processor-chain>
<scripting:transformer doc:name="append-to-name">
<scripting:script engine="Groovy">
@adrianhsieh
adrianhsieh / error-handling-subflow.xml
Created January 17, 2014 08:09
Sub-flow example for handling excpetion
<catch-exception-strategy doc:name="Catch Exception Strategy">
<flow-ref name="set-errorresponse-subflow" doc:name="set-errorresponse-subflow"/>
</catch-exception-strategy>
<sub-flow name="set-errorresponse-subflow" doc:name="set-errorresponse-subflow">
<set-variable variableName="jsonpmsg" value="#[exception.cause.message]" doc:name="jsonpmsgError"/>
<scripting:transformer doc:name="json-map">
<scripting:script engine="Groovy"><![CDATA[def jsonpmsg = message.getInvocationProperty('jsonpmsg');
def estatus = 500;
@adrianhsieh
adrianhsieh / express_example.xml
Last active August 29, 2015 13:56
Expression Example
<choice doc:name="Choice">
<!-- <when expression="#[payload['goodguy']=true]"> -->
<when expression="#[payload['goodguy']==true]">
<set-payload value="#['All Good']" doc:name="set-valid-payload-response"/>
<http:response-builder status="200" contentType="text/plain" doc:name="HTTP Response 200"/>
</when>
<otherwise>
<set-payload value="#['Invalid Payload']" doc:name="invalid-payload-goes-here"/>
<http:response-builder status="400" contentType="text/plain" doc:name="HTTP Response 400"/>
</otherwise>
@adrianhsieh
adrianhsieh / munit-example.xml
Last active August 29, 2015 13:56
Munit example
<!--Beginning of First Test, Generally the Happy Path where payload values are expected / valid-->
<munit:test name="ValidateHappyPath" description="Test when input is as expected">
<!--Mock inbound endpoint since it is a unit test-->
<mock:when messageProcessor="http:inbound-endpoint"/>
<!--Now set the payload to have the valid value-->
<munit:set payload-ref="#['']">
<munit:inbound-properties>
<munit:inbound-property key="flag" value-ref="#['true']"/>
</munit:inbound-properties>
</munit:set>
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:context="http://www.springframework.org/schema/context" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.1"
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mul
<flow name="jms-demo-senderFlow1" doc:name="jms-demo-senderFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="start-demo" doc:name="HTTP"/>
<set-session-variable variableName="demo-session" value="#['this is session']" doc:name="Session Variable"/>
<set-property propertyName="demo-outbound" value="#['this is outbound']" doc:name="Property"/>
<set-variable variableName="demo-flowvar" value="#['this is flow variable']" doc:name="Variable"/>
<set-payload value="#['demo-message']" doc:name="Set Payload"/>
<logger level="INFO" doc:name="Logger"/>
<jms:outbound-endpoint queue="blog-demo" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>
<flow name="jms-demo-receiverFlow1" doc:name="jms-demo-receiverFlow1">
<jms:inbound-endpoint queue="blog-demo" connector-ref="Active_MQ" doc:name="JMS"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
@adrianhsieh
adrianhsieh / sfdc-iterate-demo.xml
Created September 23, 2014 16:30
sfdc-connector iterating using standard message processors
<sub-flow name="generic-iterate-to-list" doc:name="generic-iterate-to-list">
<collection-splitter doc:name="Collection Splitter"/>
<logger message="#[payload]" level="DEBUG" doc:name="debug-logger"/>
<collection-aggregator failOnTimeout="true" doc:name="Collection Aggregator"/>
</sub-flow>
<flow name="sfdc-mt-blog-demoFlow2" doc:name="sfdc-mt-blog-demoFlow2">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="test2"/>
<sfdc:query config-ref="Salesforce" query="Select Id, Account.Name, Name, Type, CloseDate From Opportunity" username="${sfdc.user1}" password="${sfdc.pass1}" securityToken="${sfdc.token1}" doc:name="query-opportunity"/>
<flow-ref name="generic-iterate-to-list" doc:name="generic-iterate-to-list"/>
<logger message="Post process payload #[payload]" level="INFO" doc:name="post-process"/>