View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.example.loanbroker.lender;
8   
9   import org.mule.example.loanbroker.bank.Bank;
10  import org.mule.example.loanbroker.messages.CreditProfile;
11  import org.mule.example.loanbroker.messages.LoanBrokerQuoteRequest;
12  
13  /**
14   * <code>DefaultLenderService</code> is responsible for contacting the relivant
15   * banks depending on the amount of the loan
16   */
17  public class DefaultLender implements LenderService
18  {
19      /**
20       * Sets the list of lenders on the LoanBrokerQuoteRequest and returns it.
21       */
22      public void setLenderList(LoanBrokerQuoteRequest request)
23      {
24          Bank[] lenders = getLenders(request.getCreditProfile(), new Double(request.getCustomerRequest()
25              .getLoanAmount()));
26          request.setLenders(lenders);
27      }
28  
29      /**
30       * {@inheritDoc}
31       */
32      public Bank[] getLenders(CreditProfile creditProfile, Double loanAmount)
33      {
34          // TODO Add creditProfile info. to the logic below.
35          // TODO Look up the existing banks from the config/registry instead of
36          // creating them programatically here.
37          Bank[] lenders;
38          if ((loanAmount.doubleValue() >= 20000))
39          {
40              lenders = new Bank[2];
41              lenders[0] = new Bank("Bank1");
42              lenders[1] = new Bank("Bank2");
43          }
44          else if (((loanAmount.doubleValue() >= 10000) && (loanAmount.doubleValue() <= 19999)))
45          {
46              lenders = new Bank[2];
47              lenders[0] = new Bank("Bank3");
48              lenders[1] = new Bank("Bank4");
49          }
50          else
51          {
52              lenders = new Bank[1];
53              lenders[0] = new Bank("Bank5");
54          }
55  
56          return lenders;
57      }
58  }