<?xml version="1.0" encoding="UTF-8"?>
<bpel:process xmlns:ae4b4ptask="http://schemas.active-endpoints.com/b4p/wshumantask/2007/10/aeb4p-task-rt.xsd" xmlns:approvews="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApproval.wsdl" xmlns:b4p="http://www.example.org/BPEL4People" xmlns:bpel="http://docs.oasis-open.org/wsbpel/2.0/process/executable" xmlns:crmws="http://docs.active-endpoints.com/sample/wsdl/loanCRM/2008/02/loanCRM.wsdl" xmlns:htd="http://www.example.org/WS-HT" xmlns:loan="http://schemas.active-endpoints.com/sample/LoanRequest/2008/02/loanRequest.xsd" xmlns:loanhws="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApprovalHuman.wsdl" 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:loanws="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="loanProcessHumanCompleted" suppressJoinFailure="yes" targetNamespace="http://docs.active-endpoints.com/sample/bpel/loanprocess/2008/02/loanProcessHumanCompleted.bpel">
   <ns:humanInteractions xmlns:ext="http://www.example.org/WS-HT" xmlns:ns="http://www.example.org/BPEL4People">
      <ext:logicalPeopleGroups>
         <ext:logicalPeopleGroup name="loanmgrs"/>
         <ext:logicalPeopleGroup name="loanreps"/>
      </ext:logicalPeopleGroups>
      <ext:tasks/>
      <ext:notifications/>
   </ns:humanInteractions>
   <bpel:extensions>
      <bpel:extension mustUnderstand="yes" namespace="http://www.example.org/BPEL4People"/>
      <bpel:extension mustUnderstand="yes" namespace="http://www.example.org/WS-HT"/>
   </bpel:extensions>
   <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: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/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/loanApprovalHuman.wsdl" namespace="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApprovalHuman.wsdl"/>
   <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/loanCRM.wsdl" namespace="http://docs.active-endpoints.com/sample/wsdl/loanCRM/2008/02/loanCRM.wsdl"/>
   <bpel:import importType="http://www.w3.org/1999/XSL/Transform" location="../xsl-renderings/loan_param2commands.xsl"/>
   <bpel:import importType="http://www.w3.org/1999/XSL/Transform" location="../xsl-renderings/loan_taskdetail.xsl"/>
   <bpel:partnerLinks>
      <bpel:partnerLink myRole="loanProcessor" name="LoanProcess" partnerLinkType="loanprocess:LoanProcessLT"/>
      <bpel:partnerLink name="RiskAssessment" partnerLinkType="riskws:RiskAssessmentLT" partnerRole="assessor"/>
      <bpel:partnerLink name="LoanCRM" partnerLinkType="crmws:LoanCRMLT" partnerRole="customerRelationsManagement"/>
   </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:variable element="loan:loanApprovalResponse" name="approval-task"/>
   </bpel:variables>
   <bpel:faultHandlers>
      <bpel:catch faultElement="loan:errorMessage" faultName="riskws:loanProcessFault" faultVariable="errorfault">
         <bpel:reply faultName="loanprocess:unableToHandleRequest" name="ReplyWithErrorFault" operation="request" partnerLink="LoanProcess" variable="errorfault"/>
      </bpel:catch>
      <bpel:catch faultName="b4p:taskExpired">
         <bpel:flow>
            <bpel:links>
               <bpel:link name="L7"/>
            </bpel:links>
            <bpel:assign name="CreateExpirationResponse">
               <bpel:sources>
                  <bpel:source linkName="L7"/>
               </bpel:sources>
               <bpel:copy>
                  <bpel:from>
                     <bpel:literal>
                        <loan:loanApprovalResponse>
   <loan:responseToLoanRequest>declined</loan:responseToLoanRequest>
   <loan:responseDescription>We regret that your application could not be processed under our 15-minute guidelines. Please reapply in person at one of our offices.</loan:responseDescription>
   <loan:rejectionReason>
      <loan:reason>infoRequired</loan:reason>
      <loan:description>Loan underwriting could not be completed in 15-minute window.</loan:description>
   </loan:rejectionReason>
</loan:loanApprovalResponse>
                     </bpel:literal>
                  </bpel:from>
                  <bpel:to variable="approval-task"/>
               </bpel:copy>
            </bpel:assign>
            <bpel:invoke inputVariable="approval-task" name="NotifyCRMOfExpiration" operation="notify" partnerLink="LoanCRM">
               <bpel:targets>
                  <bpel:target linkName="L7"/>
               </bpel:targets>
            </bpel:invoke>
         </bpel:flow>
      </bpel:catch>
      <bpel:catch faultElement="loan:errorMessage" faultName="approvews:loanProcessFault" faultVariable="errorfault">
         <bpel:flow>
            <bpel:links>
               <bpel:link name="L8"/>
            </bpel:links>
            <bpel:assign name="CreateApprovalErrorResponse">
               <bpel:sources>
                  <bpel:source linkName="L8"/>
               </bpel:sources>
               <bpel:copy>
                  <bpel:from>
                     <bpel:literal>
                        <loan:loanApprovalResponse>
   <loan:responseToLoanRequest>declined</loan:responseToLoanRequest>
   <loan:responseDescription>An error occurred during loan underwriting.. Please reapply in person at one of our offices.</loan:responseDescription>
   <loan:rejectionReason>
      <loan:reason>infoRequired</loan:reason>
      <loan:description>Human approval fault.</loan:description>
   </loan:rejectionReason>
</loan:loanApprovalResponse>
                     </bpel:literal>
                  </bpel:from>
                  <bpel:to variable="approval-task"/>
               </bpel:copy>
               <bpel:copy>
                  <bpel:from variable="errorfault">
                     <bpel:query>concat( loan:errorCode , ' ', loan:reason )</bpel:query>
                  </bpel:from>
                  <bpel:to variable="approval-task">
                     <bpel:query>loan:rejectionReason/loan:description</bpel:query>
                  </bpel:to>
               </bpel:copy>
            </bpel:assign>
            <bpel:invoke inputVariable="approval-task" name="NotifyCRMOfApprovalError" operation="notify" partnerLink="LoanCRM">
               <bpel:targets>
                  <bpel:target linkName="L8"/>
               </bpel:targets>
            </bpel:invoke>
         </bpel:flow>
      </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="L6"/>
         <bpel:link name="L2"/>
         <bpel:link name="assess-to-deny"/>
         <bpel:link name="L1"/>
         <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:sequence name="ReviewActivities">
         <bpel:targets>
            <bpel:target linkName="receive-to-approve"/>
            <bpel:target linkName="L1"/>
         </bpel:targets>
         <bpel:assign name="Acknowledge" suppressJoinFailure="yes">
            <bpel:sources>
               <bpel:source linkName="L4"/>
            </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>underReview</ns2:responseToLoanRequest>
   <ns2:responseDescription/>
</ns2:loanApprovalResponse>
                  </bpel:literal>
               </bpel:from>
               <bpel:to variable="approval"/>
            </bpel:copy>
         </bpel:assign>
         <bpel:reply name="ReturnUnderReviewResponse" operation="request" partnerLink="LoanProcess" suppressJoinFailure="yes" variable="approval">
            <bpel:targets>
               <bpel:target linkName="L4"/>
            </bpel:targets>
         </bpel:reply>
         <bpel:extensionActivity>
            <b4p:peopleActivity inputVariable="creditInformation" name="ReviewLoan" outputVariable="approval-task">
               <bpel:sources>
                  <bpel:source linkName="L6"/>
               </bpel:sources>
               <wsht:task xmlns:wsht="http://www.example.org/WS-HT" name="reviewTask">
                  <wsht:interface xmlns:ns="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApproval.wsdl" xmlns:ns1="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApprovalHuman.wsdl" operation="approve" portType="ns:LoanApproval"/>
                  <wsht:priority>3</wsht:priority>
                  <wsht:peopleAssignments>
                     <wsht:potentialOwners>
                        <wsht:from logicalPeopleGroup="loanreps"/>
                     </wsht:potentialOwners>
                     <wsht:businessAdministrators>
                        <wsht:from logicalPeopleGroup="loanmgrs"/>
                     </wsht:businessAdministrators>
                  </wsht:peopleAssignments>
                  <wsht:presentationElements>
                     <wsht:name>Loan for review</wsht:name>
                     <wsht:presentationParameters>
                        <wsht:presentationParameter xmlns:ns="http://www.w3.org/2001/XMLSchema" name="loansummary" type="ns:string">concat( htd:getInput('Document')/loan:lastName , ", ", htd:getInput('Document')/loan:firstName , "; $" ,htd:getInput('Document')/loan:amountRequested )</wsht:presentationParameter>
                     </wsht:presentationParameters>
                     <wsht:subject>Please look at this loan and approve or decline it. (for {$loansummary})</wsht:subject>
                  </wsht:presentationElements>
                  <wsht:renderings>
                     <wsht:rendering xmlns:ns="http://schemas.active-endpoints.com/b4p/wshumantask/2007/10/aeb4p-task-rt.xsd" type="ns:xsl">
                        <aeb4p:xsl xmlns:aeb4p="http://schemas.active-endpoints.com/b4p/wshumantask/2007/10/aeb4p-task-rt.xsd" xmlns:xsl="http://schemas.active-endpoints.com/b4p/wshumantask/2007/10/aeb4p-task-rt.xsd" xmlns:ns="http://schemas.active-endpoints.com/b4p/wshumantask/2007/10/aeb4p-task-rt.xsd" xmlns:wsht="http://www.example.org/WS-HT">
                                 <aeb4p:presentation-xsl>project:/B4P_Sample/xsl-renderings/loan_taskdetail.xsl</aeb4p:presentation-xsl>
                                 <aeb4p:command-xsl>project:/B4P_Sample/xsl-renderings/loan_param2commands.xsl</aeb4p:command-xsl>
                              </aeb4p:xsl>
                     </wsht:rendering>
                  </wsht:renderings>
                  <wsht:deadlines>
                     <wsht:startDeadline>
                        <wsht:for>'PT5M'</wsht:for>
                        <wsht:escalation name="FiveMinuteReminder">
                           <wsht:notification name="ReminderToReps">
                              <wsht:interface xmlns:ns="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApproval.wsdl" xmlns:ns1="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApprovalHuman.wsdl" xmlns:ns2="http://docs.active-endpoints.com/sample/wsdl/loanCustomerService/2008/02/loanCustomerService.wsdl" operation="remind" portType="ns1:LoanApprovalPeople"/>
                              <wsht:priority>2</wsht:priority>
                              <wsht:peopleAssignments>
                                 <wsht:businessAdministrators>
                                    <wsht:from logicalPeopleGroup="loanmgrs"/>
                                 </wsht:businessAdministrators>
                                 <wsht:recipients>
                                    <wsht:from logicalPeopleGroup="loanreps"/>
                                 </wsht:recipients>
                              </wsht:peopleAssignments>
                              <wsht:presentationElements>
                                 <wsht:name>Unclaimed Task Reminder</wsht:name>
                                 <wsht:presentationParameters>
                                    <wsht:presentationParameter xmlns:ns="http://www.w3.org/2001/XMLSchema" name="firstname" type="ns:string">htd:getInput('Document')/loan:firstName</wsht:presentationParameter>
                                    <wsht:presentationParameter xmlns:ns="http://www.w3.org/2001/XMLSchema" name="lastname" type="ns:string">htd:getInput('Document')/loan:lastName</wsht:presentationParameter>
                                    <wsht:presentationParameter xmlns:ns="http://www.w3.org/2001/XMLSchema" name="amount" type="ns:string">htd:getInput('Document')/loan:amountRequested</wsht:presentationParameter>
                                    <wsht:presentationParameter xmlns:ns="http://www.w3.org/2001/XMLSchema" name="priority" type="ns:string">htd:getTaskPriority()</wsht:presentationParameter>
                                 </wsht:presentationParameters>
                                 <wsht:subject>There is a loan task waiting to be claimed. ({$lastname}, {$firstname}; ${$amount} priority {$priority})</wsht:subject>
                                 <wsht:description>A loan review has been unclaimed for 5 minutes. Please go to your inbox and claim if appropriate.</wsht:description>
                              </wsht:presentationElements>
                           </wsht:notification>
                        </wsht:escalation>
                     </wsht:startDeadline>
                     <wsht:completionDeadline>
                        <wsht:for>'PT10M'</wsht:for>
                        <wsht:escalation name="EscalateIfNotActedUpon">
                           <wsht:notification name="NotifyReassignToManager">
                              <wsht:interface xmlns:ns="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApproval.wsdl" xmlns:ns1="http://docs.active-endpoints.com/sample/wsdl/loanApproval/2008/02/loanApprovalHuman.wsdl" operation="remind" portType="ns1:LoanApprovalPeople"/>
                              <wsht:priority>1</wsht:priority>
                              <wsht:peopleAssignments>
                                 <wsht:businessAdministrators>
                                    <wsht:from logicalPeopleGroup="loanmgrs"/>
                                 </wsht:businessAdministrators>
                                 <wsht:recipients>
                                    <wsht:from logicalPeopleGroup="loanreps"/>
                                 </wsht:recipients>
                              </wsht:peopleAssignments>
                              <wsht:presentationElements>
                                 <wsht:name>Escalated To Manager</wsht:name>
                                 <wsht:subject>This loan is being reassigned to loanmgr1 for review</wsht:subject>
                                 <wsht:description>Needs to be completed within 5 minutes!</wsht:description>
                              </wsht:presentationElements>
                           </wsht:notification>
                        </wsht:escalation>
                        <wsht:escalation name="ReassignToMgr1">
                           <wsht:reassignment>
                              <wsht:potentialOwners>
                                 <wsht:from>
                                    <wsht:literal>
                                       <ht:organizationalEntity xmlns:ht="http://www.example.org/WS-HT">
	<ht:users>
		<ht:user>loanmgr1</ht:user>
	</ht:users>
</ht:organizationalEntity>
                                    </wsht:literal>
                                 </wsht:from>
                              </wsht:potentialOwners>
                           </wsht:reassignment>
                        </wsht:escalation>
                     </wsht:completionDeadline>
                  </wsht:deadlines>
               </wsht:task>
               <ns:scheduledActions xmlns:ns="http://www.example.org/BPEL4People">
                  <ns:expiration>
                     <ns:for>'PT15M'</ns:for>
                  </ns:expiration>
               </ns:scheduledActions>
               <ns:attachmentPropagation xmlns:ns="http://www.example.org/BPEL4People"/>
            </b4p:peopleActivity>
         </bpel:extensionActivity>
         <bpel:invoke inputVariable="approval-task" name="NotifyCustomerServiceOfDecision" operation="notify" partnerLink="LoanCRM">
            <bpel:targets>
               <bpel:target linkName="L6"/>
            </bpel:targets>
         </bpel:invoke>
      </bpel:sequence>
      <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="L2">
               <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:source linkName="L1">
               <bpel:transitionCondition>$riskAssessment/loan:riskAssessment = 'review'</bpel:transitionCondition>
            </bpel:source>
         </bpel:sources>
      </bpel:invoke>
      <bpel:assign name="Approve" suppressJoinFailure="yes">
         <bpel:targets>
            <bpel:target linkName="L2"/>
         </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="Deny">
         <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 that this application falls outside of our credit risk guidelines.</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:reply name="ReturnApprovalResponse" operation="request" partnerLink="LoanProcess" suppressJoinFailure="yes" variable="approval">
         <bpel:targets>
            <bpel:target linkName="L3"/>
            <bpel:target linkName="L5"/>
         </bpel:targets>
      </bpel:reply>
   </bpel:flow>
</bpel:process>
