formatting

This commit is contained in:
Mark Fisher
2010-05-08 20:57:49 +00:00
parent 293f599770
commit 4388226bdc
8 changed files with 94 additions and 53 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker;
import java.util.Map;
@@ -36,39 +37,42 @@ import org.springframework.integration.core.Message;
* channels if customer's credit score (retrieved from message header 'CREDIT_SCORE') is above 780.
*
* @author Oleg Zhurakousky
*
*/
public class BanksChannelSelector {
private static Logger logger = Logger.getLogger(BanksChannelSelector.class);
private Map<String, String> bankChannelPool;
private String routingExpression;
/**
*
* @param bankChannelPool
*/
public BanksChannelSelector(Map<String, String> bankChannelPool){
public BanksChannelSelector(Map<String, String> bankChannelPool) {
this.bankChannelPool = bankChannelPool;
}
/**
*
* @param message
* @return
*/
@SuppressWarnings("unchecked")
public Set<String> selectBankChannels(Message<?> message) {
EvaluationContext context = new StandardEvaluationContext(message);
context.setVariable("banks", bankChannelPool);
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression(routingExpression);
Set<String> bankChannels = (Set<String>) expression.getValue(context);
logger.debug("Selected bank channels: " + bankChannels);
return bankChannels;
}
/**
* @param routingExpression
*/
public void setRoutingExpression(String routingExpression) {
this.routingExpression = routingExpression;
}
/**
* @param message
* @return
*/
@SuppressWarnings("unchecked")
public Set<String> selectBankChannels(Message<?> message) {
EvaluationContext context = new StandardEvaluationContext(message);
context.setVariable("banks", bankChannelPool);
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression(routingExpression);
Set<String> bankChannels = (Set<String>) expression.getValue(context);
logger.debug("selected bank channels: " + bankChannels);
return bankChannels;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker;
import java.util.ArrayList;
@@ -24,22 +25,22 @@ import org.springframework.integration.loanbroker.domain.LoanQuote;
/**
* Will aggregate {@link LoanQuote}s based on the value of the 'RESPONSE_TYPE' message header.
* The value of 'RESPONSE_TYPE' header is set by 'header-enricher' and is based on the type of
* The value of 'RESPONSE_TYPE' header is set by the 'gateway' and is based on the type of
* {@link LoanBrokerGateway} method that was invoked by the client.
* Will return the best {@link LoanQuote} if 'RESPONSE_TYPE' header value is 'BEST' else it will return
* all quotes.
* <p>
* Will return the best {@link LoanQuote} if 'RESPONSE_TYPE' header value is 'BEST' else it will
* return all quotes.
*
* @author Oleg Zhurakousky
*
*/
public class LoanQuoteAggregator {
/**
* @param messages
* @return
*/
@SuppressWarnings({ "unused", "unchecked" })
private Object aggregateQuotes(List<Message<LoanQuote>> messages) {
ArrayList payloads = new ArrayList(messages.size());
for (Message<?> message : messages) {
payloads.add(message.getPayload());
@@ -47,9 +48,11 @@ public class LoanQuoteAggregator {
String responceType = (String) messages.get(0).getHeaders().get("RESPONSE_TYPE");
if (responceType.equals("ALL")) {
return payloads;
} else {
}
else {
Collections.sort(payloads);
return payloads.get(0);
}
}
}

View File

@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker;
import org.springframework.integration.loanbroker.domain.LoanQuote;
/**
* @author Gary Russell
*
*/
public class Transformer {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,39 +13,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker.domain;
/**
* @author Oleg Zhurakousky
*
*/
public class Address {
private String street;
private String zip;
private String city;
private String state;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,12 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker.domain;
/**
* @author Oleg Zhurakousky
*
*/
public class CreditScore {
private final int score;
private String creditHistory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,35 +13,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker.domain;
package org.springframework.integration.loanbroker.domain;
/**
* @author Oleg Zhurakousky
*
*/
public class Customer {
private String fname;
private String lname;
private String firstName;
private String lastName;
private Address address;
public String getFname() {
return fname;
public String getFirstName() {
return firstName;
}
public void setFname(String fname) {
this.fname = fname;
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLname() {
return lname;
public String getLastName() {
return lastName;
}
public void setLname(String lname) {
this.lname = lname;
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker.domain;
import java.text.DecimalFormat;
@@ -20,7 +21,6 @@ import java.util.Date;
/**
* @author Oleg Zhurakousky
*
*/
public class LoanQuote implements Comparable<LoanQuote>{
@@ -34,36 +34,47 @@ public class LoanQuote implements Comparable<LoanQuote>{
public String getLender() {
return lender;
}
public void setLender(String lender) {
this.lender = lender;
}
public Date getQuoteDate() {
return quoteDate;
}
public void setQuoteDate(Date quoteDate) {
this.quoteDate = quoteDate;
}
public Date getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(Date expirationDate) {
this.expirationDate = expirationDate;
}
public double getLoanAmount() {
return loanAmount;
}
public void setLoanAmount(double loanAmount) {
this.loanAmount = loanAmount;
}
public int getLoanTerm() {
return loanTerm;
}
public void setLoanTerm(int loanTerm) {
this.loanTerm = loanTerm;
}
public float getRate() {
return rate;
}
public void setRate(float rate) {
this.rate = rate;
}
@@ -81,11 +92,13 @@ public class LoanQuote implements Comparable<LoanQuote>{
}
public int compareTo(LoanQuote loanQuote) {
if (loanQuote.rate > this.rate){
if (loanQuote.rate > this.rate) {
return 1;
} else if (loanQuote.rate < this.rate){
}
else if (loanQuote.rate < this.rate) {
return -1;
}
return 0;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,27 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.loanbroker.domain;
package org.springframework.integration.loanbroker.domain;
/**
* @author Oleg Zhurakousky
*
*/
public class LoanRequest {
private Customer customer;
private float loanAmount;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public float getLoanAmount() {
return loanAmount;
}
public void setLoanAmount(float loanAmount) {
this.loanAmount = loanAmount;
}
}