use of org.fusesource.camel.component.sap.model.rfc.Structure in project quickstarts by jboss-switchyard.
the class GetFlightConnectionDetailMessageComposer method decompose.
@Override
public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
CamelBindingData response = super.decompose(exchange, target);
// Get BAPI_FLCONN_GETLIST SAP Response object.
Structure flightConnectionGetListResponse = exchange.getMessage().getContent(Structure.class);
if (flightConnectionGetListResponse == null) {
throw new Exception("No Flight Connection Get List Response.");
}
// Get the list of matching flight connections in response object.
@SuppressWarnings("unchecked") Table<? extends Structure> connectionList = flightConnectionGetListResponse.get("FLIGHT_CONNECTION_LIST", Table.class);
if (connectionList == null || connectionList.size() == 0) {
throw new Exception("No Flight Connections");
}
// Select the first connection.
Structure connection = connectionList.get(0);
// Create SAP Request object from target endpoint.
SapSynchronousRfcDestinationEndpoint endpoint = response.getMessage().getExchange().getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLCONN_GETDETAIL", SapSynchronousRfcDestinationEndpoint.class);
Structure request = endpoint.createRequest();
// Copy connection number of matching connection into request.
String connectionNumber = connection.get("FLIGHTCONN", String.class);
if (connectionNumber != null) {
request.put("CONNECTIONNUMBER", connectionNumber);
if (LOG.isDebugEnabled()) {
LOG.debug("Added CONNECTIONNUMBER = '{}' to request", connectionNumber);
}
} else {
throw new Exception("No Flight Connection Number");
}
// Copy agency number of matching connection into request.
String travelAgencyNumber = connection.get("AGENCYNUM", String.class);
if (travelAgencyNumber != null) {
request.put("TRAVELAGENCYNUMBER", travelAgencyNumber);
if (LOG.isDebugEnabled()) {
LOG.debug("Added TRAVELAGENCYNUMBER = '{}' to request", travelAgencyNumber);
}
} else {
throw new Exception("No Agency Number");
}
// Copy flight date of matching connection into request.
Date flightDate = connection.get("FLIGHTDATE", Date.class);
if (flightDate != null) {
request.put("FLIGHTDATE", flightDate);
if (LOG.isDebugEnabled()) {
LOG.debug("Added FLIGHTDATE = '{}' to request", flightDate);
}
} else {
throw new Exception("No Flight Date");
}
// Include availability data in RFC response.
request.put("NO_AVAILIBILITY", "");
// Put request object into body of exchange message.
response.getMessage().setBody(request);
return response;
}
use of org.fusesource.camel.component.sap.model.rfc.Structure in project quickstarts by jboss-switchyard.
the class CreateFlightTripMessageComposer method compose.
@Override
public Message compose(CamelBindingData source, Exchange exchange) throws Exception {
Message response = exchange.createMessage();
// map context properties
getContextMapper().mapFrom(source, exchange.getContext(response));
Set<String> attachements = source.getMessage().getAttachmentNames();
if (!attachements.isEmpty()) {
for (Entry<String, DataHandler> entry : source.getMessage().getAttachments().entrySet()) {
response.addAttachment(entry.getKey(), entry.getValue().getDataSource());
}
}
// Retrieve flight connection and passenger info from exchange context property.
FlightTripRequestInfo flightTripRequestInfo = (FlightTripRequestInfo) exchange.getContext().getProperty(FLIGHT_TRIP_REQUEST_INFO).getValue();
FlightConnectionInfo flightConnectionInfo = flightTripRequestInfo.getFlightConnectionInfo();
PassengerInfo passengerInfo = flightTripRequestInfo.getPassengerInfo();
// Retrieve SAP response object from body of exchange message.
Structure flightTripCreateResponse = source.getMessage().getBody(Structure.class);
if (flightTripCreateResponse == null) {
throw new Exception("No Flight Trip Create Response");
}
// Check BAPI return parameter for errors
@SuppressWarnings("unchecked") Table<Structure> bapiReturn = flightTripCreateResponse.get("RETURN", Table.class);
Structure bapiReturnEntry = bapiReturn.get(0);
if (!bapiReturnEntry.get("TYPE", String.class).equals("S")) {
String message = bapiReturnEntry.get("MESSAGE", String.class);
throw new Exception("BAPI call failed: " + message);
}
// Create bean to hold Flight Booking data.
BookFlightResponse bookFlightResponse = new BookFlightResponse();
// Trip Number
String tripNumber = flightTripCreateResponse.get("TRIPNUMBER", String.class);
if (tripNumber != null) {
bookFlightResponse.setTripNumber(tripNumber);
if (LOG.isDebugEnabled()) {
LOG.debug("Added TRIPNUMBER = '{}' to request", tripNumber);
}
} else {
throw new Exception("No Flight Booking Trip Number");
}
// Pricing Info
Structure ticketPrice = flightTripCreateResponse.get("TICKET_PRICE", Structure.class);
if (ticketPrice != null) {
// Ticket Price
BigDecimal tripPrice = ticketPrice.get("TRIPPRICE", BigDecimal.class);
bookFlightResponse.setTicketPrice(tripPrice);
if (LOG.isDebugEnabled()) {
LOG.debug("Added TICKET_PRICE = '{}' to request", tripPrice);
}
// Ticket Tax
BigDecimal tripTax = ticketPrice.get("TRIPTAX", BigDecimal.class);
bookFlightResponse.setTicketTax(tripTax);
if (LOG.isDebugEnabled()) {
LOG.debug("Added TICKET_TAX = '{}' to request", tripTax);
}
// Currency
String currency = ticketPrice.get("CURR", String.class);
bookFlightResponse.setCurrency(currency);
if (LOG.isDebugEnabled()) {
LOG.debug("Added CURRENCY = '{}' to request", currency);
}
} else {
throw new Exception("No Flight Booking Ticket Price");
}
// Passenger Info
// Form
bookFlightResponse.setPassengerFormOfAddress(passengerInfo.getFormOfAddress());
// Name
bookFlightResponse.setPassengerName(passengerInfo.getName());
// DOB
bookFlightResponse.setPassengerDateOfBirth(passengerInfo.getDateOfBirth());
// Flight Info
FlightInfo flightInfo = new FlightInfo();
// Flight Time
flightInfo.setFlightTime(flightConnectionInfo.getFlightTime());
// Departure City
flightInfo.setCityFrom(flightConnectionInfo.getDepartureCity());
// Departure Date
flightInfo.setDepartureDate(flightConnectionInfo.getDepartureDate());
// Departure Time
flightInfo.setDepartureTime(flightConnectionInfo.getDepartureTime());
// Arrival City
flightInfo.setCityTo(flightConnectionInfo.getArrivalCity());
// Arrival Date
flightInfo.setArrivalDate(flightConnectionInfo.getArrivalDate());
// Arrival Time
flightInfo.setArrivalTime(flightConnectionInfo.getArrivalTime());
bookFlightResponse.setFlightInfo(flightInfo);
ConnectionInfoTable connectionInfoTable = new ConnectionInfoTable();
List<ConnectionInfo> rows = new ArrayList<ConnectionInfo>();
for (FlightHop flightHop : flightConnectionInfo.getFlightHopList()) {
// Connection Info
ConnectionInfo connection = new ConnectionInfo();
// Connection ID
connection.setConnectionId(flightHop.getHopNumber());
// Airline
connection.setAirline(flightHop.getAirlineName());
// Plane Type
connection.setPlaneType(flightHop.getAircraftType());
// Departure City
connection.setCityFrom(flightHop.getDepatureCity());
// Departure Date
connection.setDepartureDate(flightHop.getDepatureDate());
// Departure Time
connection.setDepartureTime(flightHop.getDepatureTime());
// Arrival City
connection.setCityTo(flightHop.getArrivalCity());
// Arrival Date
connection.setArrivalDate(flightHop.getArrivalDate());
// Arrival Time
connection.setArrivalTime(flightHop.getArrivalTime());
rows.add(connection);
}
connectionInfoTable.setRows(rows);
bookFlightResponse.setConnectionInfo(connectionInfoTable);
response.setContent(bookFlightResponse);
return response;
}
use of org.fusesource.camel.component.sap.model.rfc.Structure in project quickstarts by jboss-switchyard.
the class CreateFlightTripMessageComposer method decompose.
@Override
public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
CamelBindingData response = super.decompose(exchange, target);
// Get flight connection info, flight customer info and passenger info bean objects
FlightTripRequestInfo flightTripRequestInfo = exchange.getMessage().getContent(FlightTripRequestInfo.class);
FlightConnectionInfo flightConnectionInfo = flightTripRequestInfo.getFlightConnectionInfo();
FlightCustomerInfo flightCustomerInfo = flightTripRequestInfo.getFlightCustomerInfo();
PassengerInfo passengerInfo = flightTripRequestInfo.getPassengerInfo();
exchange.getContext().setProperty(FLIGHT_TRIP_REQUEST_INFO, flightTripRequestInfo, Scope.EXCHANGE);
// Create SAP Request object from target endpoint.
SapSynchronousRfcDestinationEndpoint endpoint = response.getMessage().getExchange().getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLTRIP_CREATE", SapSynchronousRfcDestinationEndpoint.class);
Structure request = endpoint.createRequest();
//
// Add Flight Trip Data to request object.
//
Structure flightTripData = request.get("FLIGHT_TRIP_DATA", Structure.class);
// Add Travel Agency Number to request if set
String travelAgencyNumber = flightConnectionInfo.getTravelAgencyNumber();
if (travelAgencyNumber != null && travelAgencyNumber.length() != 0) {
flightTripData.put("AGENCYNUM", travelAgencyNumber);
if (LOG.isDebugEnabled()) {
LOG.debug("Added AGENCYNUM = '{}' to FLIGHT_TRIP_DATA", travelAgencyNumber);
}
}
// Add Customer ID to request if set
String flightCustomerNumber = flightCustomerInfo.getCustomerNumber();
if (flightCustomerNumber != null && flightCustomerNumber.length() != 0) {
flightTripData.put("CUSTOMERID", flightCustomerNumber);
if (LOG.isDebugEnabled()) {
LOG.debug("Added CUSTOMERID = '{}' to FLIGHT_TRIP_DATA", flightCustomerNumber);
}
}
// Add Flight Connection Number to request if set
String flightConnectionNumber = flightConnectionInfo.getFlightConnectionNumber();
if (flightConnectionNumber != null && flightConnectionNumber.length() != 0) {
flightTripData.put("FLCONN1", flightConnectionNumber);
if (LOG.isDebugEnabled()) {
LOG.debug("Added FLCONN1 = '{}' to FLIGHT_TRIP_DATA", flightConnectionNumber);
}
}
// Add Departure Date to request if set
Date flightConnectionDepartureData = flightConnectionInfo.getDepartureDate();
if (flightConnectionDepartureData != null) {
flightTripData.put("FLDATE1", flightConnectionDepartureData);
if (LOG.isDebugEnabled()) {
LOG.debug("Added FLDATE1 = '{}' to FLIGHT_TRIP_DATA", flightConnectionDepartureData);
}
}
// Add Flight Connection Class to request.
// C : Business Class
// Y : Economy Class
// F : First Class
String flightConnectionClass = "Y";
if (flightConnectionClass != null && flightConnectionClass.length() != 0) {
flightTripData.put("CLASS", flightConnectionClass);
if (LOG.isDebugEnabled()) {
LOG.debug("Added CLASS = '{}' to FLIGHT_TRIP_DATA", flightConnectionClass);
}
}
//
// Add Passenger List Data to request object.
//
@SuppressWarnings("unchecked") Table<Structure> passengerList = request.get("PASSENGER_LIST", Table.class);
Structure passengerListEntry = passengerList.add();
// Add Passenger Form of Address to request if set
String passengerFormOfAddress = passengerInfo.getFormOfAddress();
if (passengerFormOfAddress != null && passengerFormOfAddress.length() != 0) {
passengerListEntry.put("PASSFORM", passengerFormOfAddress);
if (LOG.isDebugEnabled()) {
LOG.debug("Added PASSFORM = '{}' to PASSENGER_LIST", passengerFormOfAddress);
}
}
// Add Passenger Name to request if set
String passengerName = passengerInfo.getName();
if (passengerName != null && passengerName.length() != 0) {
passengerListEntry.put("PASSNAME", passengerName);
if (LOG.isDebugEnabled()) {
LOG.debug("Added PASSNAME = '{}' to PASSENGER_LIST", passengerName);
}
}
// Add Passenger Data of Birth to request if set
Date passengerDateOfBirth = passengerInfo.getDateOfBirth();
if (passengerDateOfBirth != null) {
passengerListEntry.put("PASSBIRTH", passengerDateOfBirth);
if (LOG.isDebugEnabled()) {
LOG.debug("Added PASSBIRTH = '{}' to PASSENGER_LIST", passengerDateOfBirth);
}
}
// Put request object into body of exchange message.
response.getMessage().setBody(request);
return response;
}
use of org.fusesource.camel.component.sap.model.rfc.Structure in project quickstarts by jboss-switchyard.
the class FlightCustomerInfoMessageComposer method decompose.
@Override
public CamelBindingData decompose(Exchange exchange, CamelBindingData target) throws Exception {
CamelBindingData response = super.decompose(exchange, target);
// Get BOOK_FLIGHT Request JAXB Bean object.
BookFlightRequest bookFlightRequest = exchange.getMessage().getContent(BookFlightRequest.class);
// Create SAP Request object from target endpoint.
SapSynchronousRfcDestinationEndpoint endpoint = target.getMessage().getExchange().getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLCUST_GETLIST", SapSynchronousRfcDestinationEndpoint.class);
Structure request = endpoint.createRequest();
// Add Customer Name to request if set
if (bookFlightRequest.getCustomerName() != null && bookFlightRequest.getCustomerName().length() > 0) {
request.put("CUSTOMER_NAME", bookFlightRequest.getCustomerName());
if (LOG.isDebugEnabled()) {
LOG.debug("Added CUSTOMER_NAME = '{}' to request", bookFlightRequest.getCustomerName());
}
} else {
throw new Exception("No Customer Name");
}
// Put request object into body of exchange message.
response.getMessage().setBody(request);
return response;
}
use of org.fusesource.camel.component.sap.model.rfc.Structure in project quickstarts by jboss-switchyard.
the class FlightCustomerInfoMessageComposer method compose.
@Override
public Message compose(CamelBindingData source, Exchange exchange) throws Exception {
Message response = exchange.createMessage();
// map context properties
getContextMapper().mapFrom(source, exchange.getContext(response));
Set<String> attachements = source.getMessage().getAttachmentNames();
if (!attachements.isEmpty()) {
for (Entry<String, DataHandler> entry : source.getMessage().getAttachments().entrySet()) {
response.addAttachment(entry.getKey(), entry.getValue().getDataSource());
}
}
// Retrieve SAP response object from body of exchange message.
Structure flightCustomerGetListResponse = source.getMessage().getBody(Structure.class);
if (flightCustomerGetListResponse == null) {
throw new Exception("No Flight Customer Get List Response");
}
// Check BAPI return parameter for errors
@SuppressWarnings("unchecked") Table<Structure> bapiReturn = flightCustomerGetListResponse.get("RETURN", Table.class);
Structure bapiReturnEntry = bapiReturn.get(0);
if (!bapiReturnEntry.get("TYPE", String.class).equals("S")) {
String message = bapiReturnEntry.get("MESSAGE", String.class);
throw new Exception("BAPI call failed: " + message);
}
// Get customer list table from response object.
@SuppressWarnings("unchecked") Table<? extends Structure> customerList = flightCustomerGetListResponse.get("CUSTOMER_LIST", Table.class);
if (customerList == null || customerList.size() == 0) {
throw new Exception("No Customer Info.");
}
// Get Flight Customer data from first row of table.
Structure customer = customerList.get(0);
// Create bean to hold Flight Customer data.
FlightCustomerInfo flightCustomerInfo = new FlightCustomerInfo();
// Get customer id from Flight Customer data and add to bean.
String customerId = customer.get("CUSTOMERID", String.class);
if (customerId != null) {
flightCustomerInfo.setCustomerNumber(customerId);
if (LOG.isDebugEnabled()) {
LOG.debug("Set customer number = '{}' in flight customer info", customerId);
}
}
// Get customer name from Flight Customer data and add to bean.
String customerName = customer.get("CUSTNAME", String.class);
if (customerName != null) {
flightCustomerInfo.setName(customerName);
if (LOG.isDebugEnabled()) {
LOG.debug("Set customer name = '{}' in flight customer info", customerName);
}
}
// Get customer form of address from Flight Customer data and add to bean.
String formOfAddress = customer.get("FORM", String.class);
if (formOfAddress != null) {
flightCustomerInfo.setFormOfAddress(formOfAddress);
if (LOG.isDebugEnabled()) {
LOG.debug("Set form of address = '{}' in flight customer info", formOfAddress);
}
}
// Get customer street name from Flight Customer data and add to bean.
String street = customer.get("STREET", String.class);
if (street != null) {
flightCustomerInfo.setStreet(street);
if (LOG.isDebugEnabled()) {
LOG.debug("Set street = '{}' in flight customer info", street);
}
}
// Get customer PO box from Flight Customer data and add to bean.
String poBox = customer.get("POBOX", String.class);
if (poBox != null) {
flightCustomerInfo.setPoBox(poBox);
if (LOG.isDebugEnabled()) {
LOG.debug("Set PO box = '{}' in flight customer info", poBox);
}
}
// Get customer postal code from Flight Customer data and add to bean.
String postalCode = customer.get("POSTCODE", String.class);
if (postalCode != null) {
flightCustomerInfo.setPostalCode(postalCode);
if (LOG.isDebugEnabled()) {
LOG.debug("Set postal code = '{}' in flight customer info", postalCode);
}
}
// Get customer city name from Flight Customer data and add to bean.
String city = customer.get("CITY", String.class);
if (city != null) {
flightCustomerInfo.setCity(city);
if (LOG.isDebugEnabled()) {
LOG.debug("Set city = '{}' in flight customer info", city);
}
}
// Get customer country name from Flight Customer data and add to bean.
String country = customer.get("COUNTR", String.class);
if (country != null) {
flightCustomerInfo.setCountry(country);
if (LOG.isDebugEnabled()) {
LOG.debug("Set country = '{}' in flight customer info", country);
}
}
// Get customer country ISO code from Flight Customer data and add to bean.
String countryIso = customer.get("COUNTR_ISO", String.class);
if (countryIso != null) {
flightCustomerInfo.setCountryIso(countryIso);
if (LOG.isDebugEnabled()) {
LOG.debug("Set iso country code = '{}' in flight customer info", countryIso);
}
}
// Get customer region name from Flight Customer data and add to bean.
String region = customer.get("REGION", String.class);
if (region != null) {
flightCustomerInfo.setRegion(region);
if (LOG.isDebugEnabled()) {
LOG.debug("Set region = '{}' in flight customer info", region);
}
}
// Get customer phone number from Flight Customer data and add to bean.
String phone = customer.get("PHONE", String.class);
if (phone != null) {
flightCustomerInfo.setPhone(phone);
if (LOG.isDebugEnabled()) {
LOG.debug("Set phone = '{}' in flight customer info", phone);
}
}
// Get customer email from Flight Customer data and add to bean.
String email = customer.get("EMAIL", String.class);
if (email != null) {
flightCustomerInfo.setEmail(email);
if (LOG.isDebugEnabled()) {
LOG.debug("Set email = '{}' in flight customer info", email);
}
}
// Put flight customer info bean
response.setContent(flightCustomerInfo);
return response;
}
Aggregations