* <p>{@inheritDoc}
*/
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Exchange answer = oldExchange == null ? newExchange : oldExchange;
FlightTripRequestInfo flightTripRequestInfo;
Object payload = answer.getIn().getBody();
if (payload instanceof FlightTripRequestInfo) {
flightTripRequestInfo = FlightTripRequestInfo.class.cast(payload);
} else {
flightTripRequestInfo = new FlightTripRequestInfo();
}
String to = newExchange.getProperty(Exchange.TO_ENDPOINT, String.class);
if (LOG.isDebugEnabled()) {
LOG.debug("To endpoint = {}", to);
}
if (to.contains("FlightConnectionInfo")) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding Flight Connection Info to exchange.");
}
flightTripRequestInfo.setFlightConnectionInfo(newExchange.getIn().getBody(FlightConnectionInfo.class));
} else if (to.contains("FlightCustomerInfo")){
if (LOG.isDebugEnabled()) {
LOG.debug("Adding Flight Customer Info to exchange.");
}
flightTripRequestInfo.setFlightCustomerInfo(newExchange.getIn().getBody(FlightCustomerInfo.class));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding Passenger Info to exchange.");
}
flightTripRequestInfo.setPassengerInfo(newExchange.getIn().getBody(PassengerInfo.class));
}
answer.getIn().setBody(flightTripRequestInfo);
return answer;
}