1 17 package org.apache.servicemix.sca.bigbank.account; 18 19 import java.util.ArrayList ; 20 21 import org.apache.servicemix.sca.bigbank.accountdata.AccountDataService; 22 import org.apache.servicemix.sca.bigbank.accountdata.CheckingAccount; 23 import org.apache.servicemix.sca.bigbank.accountdata.SavingsAccount; 24 import org.apache.servicemix.sca.bigbank.accountdata.StockAccount; 25 import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteRequest; 26 import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteResponse; 27 import org.apache.servicemix.sca.bigbank.stockquote.StockQuoteService; 28 import org.osoa.sca.annotations.Property; 29 import org.osoa.sca.annotations.Reference; 30 import org.osoa.sca.annotations.Service; 31 32 @Service(interfaces=AccountService.class) 33 public class AccountServiceImpl implements AccountService { 34 35 @Property 36 public String currency = "USD"; 37 38 @Reference 39 public AccountDataService accountDataService; 40 @Reference 41 public StockQuoteService stockQuoteService; 42 43 public AccountServiceImpl() { 44 } 45 46 public AccountReportResponse getAccountReport(AccountReportRequest request) { 47 AccountReportResponse report = new AccountReportResponse(); 48 String customerID = request.getCustomerID(); 49 report.setAccountSummaries(new ArrayList <AccountSummary>()); 50 report.getAccountSummaries().add(getCheckAccountSummary(customerID)); 51 report.getAccountSummaries().add(getSavingsAccountSummary(customerID)); 52 report.getAccountSummaries().add(getStockAccountSummary(customerID)); 53 return report; 54 } 55 56 private AccountSummary getCheckAccountSummary(String customerID) { 57 CheckingAccount checking = accountDataService.getCheckingAccount(customerID); 58 AccountSummary summary = new AccountSummary(); 59 summary.setAccountNumber(checking.getAccountNumber()); 60 summary.setAccountType("Checking"); 61 summary.setBalance(checking.getBalance()); 62 return summary; 63 } 64 65 private AccountSummary getSavingsAccountSummary(String customerID) { 66 SavingsAccount savings = accountDataService.getSavingsAccount(customerID); 67 AccountSummary summary = new AccountSummary(); 68 summary.setAccountNumber(savings.getAccountNumber()); 69 summary.setAccountType("Savings"); 70 summary.setBalance(savings.getBalance()); 71 return summary; 72 } 73 74 private AccountSummary getStockAccountSummary(String customerID) { 75 StockAccount stock = accountDataService.getStockAccount(customerID); 76 AccountSummary summary = new AccountSummary(); 77 summary.setAccountNumber(stock.getAccountNumber()); 78 summary.setAccountType("Stock"); 79 float quote = getQuote(stock.getSymbol()); 80 summary.setBalance(quote * stock.getQuantity()); 81 return summary; 82 } 83 84 private float getQuote(String symbol) { 85 StockQuoteRequest req = new StockQuoteRequest(); 86 req.setSymbol(symbol); 87 StockQuoteResponse rep = stockQuoteService.getQuote(req); 88 return rep.getResult(); 89 } 90 91 } 92 | Popular Tags |