in serverless-workflow-examples/serverless-workflow-loanbroker-showcase/aggregator/src/main/java/org/acme/serverless/loanbroker/aggregator/QuotesAggregationStrategy.java [35:54]
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
final BankQuote quote = (BankQuote) newExchange.getIn().getBody();
if (quote.getBankId() == null || quote.getBankId().isEmpty()) {
return null;
}
if (oldExchange == null) {
final List<BankQuote> quotes = new ArrayList<>();
quotes.add(quote);
newExchange.getIn().setBody(quotes);
newExchange.getIn().setHeader(HEADER_QUOTES_COUNT, quotes.size());
return newExchange;
}
final List<BankQuote> quotes = (List<BankQuote>) oldExchange.getIn().getBody();
quotes.add(quote);
oldExchange.getIn().setBody(quotes);
oldExchange.getIn().setHeader(HEADER_QUOTES_COUNT, quotes.size());
return oldExchange;
}