<?xml version="1.0" encoding="UTF-8"?>
<bpel:process xmlns:approvews="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApproval.wsdl" xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable" xmlns:loan="http://schemas.active-endpoints.com/sample/LoanRequest/2008/02/loanRequest.xsd" xmlns:loanmsg="http://docs.active-endpoints.com/sample/wsdl/loanMessages/2008/02/loanMessages.wsdl" xmlns:loanprocess="http://docs.active-endpoints.com/sample/wsdl/loanprocess/2008/02/loanProcess.wsdl" xmlns:riskws="http://docs.active-endpoints.com/sample/wsdl/riskAssessment/2008/02/riskAssessment.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="loanProcessCompleted" suppressJoinFailure="yes" targetNamespace="http://docs.active-endpoints.com/sample/bpel/loanprocess/2008/02/loanProcessCompleted.bpel">
   <bpel:import importType="http://www.w3.org/2001/XMLSchema" location="../schema/loanRequest.xsd" namespace="http://schemas.active-endpoints.com/sample/LoanRequest/2008/02/loanRequest.xsd"/>
   <bpel:import importType="http://schemas.xmlsoap.org/wsdl/" location="../wsdl/loanProcess.wsdl" namespace="http://docs.active-endpoints.com/sample/wsdl/loanprocess/2008/02/loanProcess.wsdl"/>
   <bpel:import importType="http://schemas.xmlsoap.org/wsdl/" location="../wsdl/loanApproval.wsdl" namespace="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApproval.wsdl"/>
   <bpel:import importType="http://schemas.xmlsoap.org/wsdl/" location="../wsdl/riskAssessment.wsdl" namespace="http://docs.active-endpoints.com/sample/wsdl/riskAssessment/2008/02/riskAssessment.wsdl"/>
   <bpel:import importType="http://schemas.xmlsoap.org/wsdl/" location="../wsdl/loanMessages.wsdl" namespace="http://docs.active-endpoints.com/sample/wsdl/loanMessages/2008/02/loanMessages.wsdl"/>
   <bpel:partnerLinks>
      <bpel:partnerLink myRole="loanProcessor" name="LoanProcess" partnerLinkType="loanprocess:LoanProcessLT"/>
      <bpel:partnerLink name="LoanApproval" partnerLinkType="approvews:LoanApprovalLT" partnerRole="approver"/>
      <bpel:partnerLink name="RiskAssessment" partnerLinkType="riskws:RiskAssessmentLT" partnerRole="assessor"/>
   </bpel:partnerLinks>
   <bpel:variables>
      <bpel:variable element="loan:loanProcessRequest" name="creditInformation"/>
      <bpel:variable element="loan:loanApprovalResponse" name="approval"/>
      <bpel:variable element="loan:riskAssessmentResponse" name="riskAssessment"/>
   </bpel:variables>
   <bpel:faultHandlers>
      <bpel:catch faultElement="loan:errorMessage" faultName="approvews:loanProcessFault" faultVariable="error">
         <bpel:reply faultName="loanprocess:unableToHandleRequest" name="ReplyWithApprovalFault" operation="request" partnerLink="LoanProcess" variable="error"/>
      </bpel:catch>
      <bpel:catch faultElement="loan:errorMessage" faultName="riskws:loanProcessFault" faultVariable="error">
         <bpel:reply faultName="loanprocess:unableToHandleRequest" name="ReplyWithAssessmentFault" operation="request" partnerLink="LoanProcess" variable="error"/>
      </bpel:catch>
   </bpel:faultHandlers>
   <bpel:flow>
      <bpel:links>
         <bpel:link name="receive-to-assess"/>
         <bpel:link name="receive-to-approve"/>
         <bpel:link name="L4"/>
         <bpel:link name="assess-to-approver"/>
         <bpel:link name="assess-to-approve"/>
         <bpel:link name="assess-to-deny"/>
         <bpel:link name="L3"/>
         <bpel:link name="L5"/>
      </bpel:links>
      <bpel:receive createInstance="yes" name="ReceiveCustomerRequestForLoanAmount" operation="request" partnerLink="LoanProcess" variable="creditInformation">
         <bpel:sources>
            <bpel:source linkName="receive-to-assess">
               <bpel:transitionCondition>$creditInformation/loan:amountRequested &lt; 10000</bpel:transitionCondition>
            </bpel:source>
            <bpel:source linkName="receive-to-approve">
               <bpel:transitionCondition>$creditInformation/loan:amountRequested &gt;= 10000</bpel:transitionCondition>
            </bpel:source>
         </bpel:sources>
      </bpel:receive>
      <bpel:reply name="ReturnApprovalResponse" operation="request" partnerLink="LoanProcess" suppressJoinFailure="yes" variable="approval">
         <bpel:targets>
            <bpel:target linkName="L4"/>
            <bpel:target linkName="L3"/>
            <bpel:target linkName="L5"/>
         </bpel:targets>
      </bpel:reply>
      <bpel:invoke inputVariable="creditInformation" name="InvokeLoanApprover" operation="approve" outputVariable="approval" partnerLink="LoanApproval">
         <bpel:targets>
            <bpel:target linkName="receive-to-approve"/>
            <bpel:target linkName="assess-to-approver"/>
         </bpel:targets>
         <bpel:sources>
            <bpel:source linkName="L4"/>
         </bpel:sources>
      </bpel:invoke>
      <bpel:invoke inputVariable="creditInformation" name="InvokeRiskAssessor" operation="check" outputVariable="riskAssessment" partnerLink="RiskAssessment">
         <bpel:targets>
            <bpel:target linkName="receive-to-assess"/>
         </bpel:targets>
         <bpel:sources>
            <bpel:source linkName="assess-to-approver">
               <bpel:transitionCondition>$riskAssessment/loan:riskAssessment = 'review'</bpel:transitionCondition>
            </bpel:source>
            <bpel:source linkName="assess-to-approve">
               <bpel:transitionCondition>$riskAssessment/loan:riskAssessment = 'low'</bpel:transitionCondition>
            </bpel:source>
            <bpel:source linkName="assess-to-deny">
               <bpel:transitionCondition>$riskAssessment/loan:riskAssessment = 'high'</bpel:transitionCondition>
            </bpel:source>
         </bpel:sources>
      </bpel:invoke>
      <bpel:assign name="AssignApprove" suppressJoinFailure="yes">
         <bpel:targets>
            <bpel:target linkName="assess-to-approve"/>
         </bpel:targets>
         <bpel:sources>
            <bpel:source linkName="L3"/>
         </bpel:sources>
         <bpel:copy>
            <bpel:from>
               <bpel:literal>
                  <ns2:loanApprovalResponse xmlns:ns2="http://schemas.active-endpoints.com/sample/LoanRequest/2008/02/loanRequest.xsd">
   <ns2:responseToLoanRequest>approved</ns2:responseToLoanRequest>
   <ns2:responseDescription>Your excellent credit has earned you automatic approval for your loan!</ns2:responseDescription>
</ns2:loanApprovalResponse>
               </bpel:literal>
            </bpel:from>
            <bpel:to variable="approval"/>
         </bpel:copy>
      </bpel:assign>
      <bpel:assign name="AssignDeny">
         <bpel:targets>
            <bpel:target linkName="assess-to-deny"/>
         </bpel:targets>
         <bpel:sources>
            <bpel:source linkName="L5"/>
         </bpel:sources>
         <bpel:copy>
            <bpel:from>
               <bpel:literal>
                  <loan:loanApprovalResponse>
   <loan:responseToLoanRequest>declined</loan:responseToLoanRequest>
   <loan:responseDescription>We regret to inform you that this application falls outside of our credit risk guidelines, and has been declined.</loan:responseDescription>
   <loan:rejectionReason>
      <loan:reason>lowCredit</loan:reason>
      <loan:description>low credit score</loan:description>
   </loan:rejectionReason>
</loan:loanApprovalResponse>
               </bpel:literal>
            </bpel:from>
            <bpel:to variable="approval"/>
         </bpel:copy>
      </bpel:assign>
   </bpel:flow>
</bpel:process>
