strong typing in aggregator, only using a header for 'BEST' ('ALL' is the default)

This commit is contained in:
Mark Fisher
2010-06-17 23:14:51 +00:00
parent 2bb02b13ae
commit 799afe484c
2 changed files with 11 additions and 19 deletions

View File

@@ -25,7 +25,7 @@ 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 the 'gateway' and is based on the type of
* The value of the 'RESPONSE_TYPE' header is set by the 'gateway' and is based on the type of
* {@link LoanBrokerGateway} method that was invoked by the client.
* <p>
* Will return the best {@link LoanQuote} if 'RESPONSE_TYPE' header value is 'BEST' else it will
@@ -35,24 +35,19 @@ import org.springframework.integration.loanbroker.domain.LoanQuote;
*/
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) {
public Object aggregateQuotes(List<Message<LoanQuote>> messages) {
ArrayList<LoanQuote> payloads = new ArrayList<LoanQuote>(messages.size());
for (Message<LoanQuote> message : messages) {
payloads.add(message.getPayload());
}
String responceType = (String) messages.get(0).getHeaders().get("RESPONSE_TYPE");
if (responceType.equals("ALL")) {
return payloads;
}
else {
String responseType = messages.get(0).getHeaders().get("RESPONSE_TYPE", String.class);
if ("BEST".equals(responseType)) {
Collections.sort(payloads);
return payloads.get(0);
}
else {
return payloads;
}
}
}

View File

@@ -16,9 +16,6 @@
<method name="getLoanQuote">
<header name="RESPONSE_TYPE" value="BEST"/>
</method>
<method name="getAllLoanQuotes">
<header name="RESPONSE_TYPE" value="ALL"/>
</method>
</gateway>
<chain input-channel="loanBrokerPreProcessingChannel">
@@ -26,8 +23,8 @@
<header name="CREDIT_SCORE" ref="creditBureau" method="getCreditScore"/>
</header-enricher>
<router expression="headers['CREDIT_SCORE'].score > 780
? @banks.?[value.equals('premier')].keySet()
: @banks.?[value.equals('secondary')].keySet()"
? @banks.?[value.equals('premier')].keySet()
: @banks.?[value.equals('secondary')].keySet()"
apply-sequence="true"/>
</chain>