Search in sources :

Example 1 with SapSynchronousRfcDestinationEndpoint

use of org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint 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;
}
Also used : Structure(org.fusesource.camel.component.sap.model.rfc.Structure) SapSynchronousRfcDestinationEndpoint(org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint) CamelBindingData(org.switchyard.component.camel.common.composer.CamelBindingData) Date(java.util.Date)

Example 2 with SapSynchronousRfcDestinationEndpoint

use of org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint 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;
}
Also used : FlightConnectionInfo(org.switchyard.quickstarts.camel.sap.binding.bean.FlightConnectionInfo) PassengerInfo(org.switchyard.quickstarts.camel.sap.binding.bean.PassengerInfo) FlightTripRequestInfo(org.switchyard.quickstarts.camel.sap.binding.bean.FlightTripRequestInfo) SapSynchronousRfcDestinationEndpoint(org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint) Structure(org.fusesource.camel.component.sap.model.rfc.Structure) CamelBindingData(org.switchyard.component.camel.common.composer.CamelBindingData) FlightCustomerInfo(org.switchyard.quickstarts.camel.sap.binding.bean.FlightCustomerInfo) Date(java.util.Date)

Example 3 with SapSynchronousRfcDestinationEndpoint

use of org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint 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;
}
Also used : BookFlightRequest(org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest) SapSynchronousRfcDestinationEndpoint(org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint) Structure(org.fusesource.camel.component.sap.model.rfc.Structure) CamelBindingData(org.switchyard.component.camel.common.composer.CamelBindingData)

Example 4 with SapSynchronousRfcDestinationEndpoint

use of org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint in project quickstarts by jboss-switchyard.

the class GetFlightConnectionListMessageComposer 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 = response.getMessage().getExchange().getContext().getEndpoint("sap-srfc-destination:nplDest:BAPI_FLCONN_GETLIST", SapSynchronousRfcDestinationEndpoint.class);
    Structure request = endpoint.createRequest();
    // Add Travel Agency Number to request if set
    if (bookFlightRequest.getTravelAgencyNumber() != null && bookFlightRequest.getTravelAgencyNumber().length() > 0) {
        request.put("TRAVELAGENCY", bookFlightRequest.getTravelAgencyNumber());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Added TRAVELAGENCY = '{}' to request", bookFlightRequest.getTravelAgencyNumber());
        }
    } else {
        throw new Exception("No Travel Agency Number");
    }
    // Add Flight Date to request if set
    if (bookFlightRequest.getFlightDate() != null) {
        @SuppressWarnings("unchecked") Table<Structure> table = request.get("DATE_RANGE", Table.class);
        Structure date_range = table.add();
        date_range.put("SIGN", "I");
        date_range.put("OPTION", "EQ");
        Date date = bookFlightRequest.getFlightDate();
        date_range.put("LOW", date);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Added DATE_RANGE = '{}' to request", RfcUtil.marshal(table));
        }
    } else {
        throw new Exception("No Flight Date");
    }
    // Add Start Destination if set
    if (bookFlightRequest.getStartAirportCode() != null && bookFlightRequest.getStartAirportCode().length() > 0) {
        Structure destination_from = request.get("DESTINATION_FROM", Structure.class);
        destination_from.put("AIRPORTID", bookFlightRequest.getStartAirportCode());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Added DESTINATION_FROM = '{}' to request", RfcUtil.marshal(destination_from));
        }
    } else {
        throw new Exception("No Start Destination");
    }
    // Add End Destination if set
    if (bookFlightRequest.getEndAirportCode() != null && bookFlightRequest.getEndAirportCode().length() > 0) {
        Structure destination_to = request.get("DESTINATION_TO", Structure.class);
        destination_to.put("AIRPORTID", bookFlightRequest.getEndAirportCode());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Added DESTINATION_TO = '{}' to request", RfcUtil.marshal(destination_to));
        }
    } else {
        throw new Exception("No End Destination");
    }
    // Put request object into body of exchange message.
    response.getMessage().setBody(request);
    return response;
}
Also used : BookFlightRequest(org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest) SapSynchronousRfcDestinationEndpoint(org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint) Structure(org.fusesource.camel.component.sap.model.rfc.Structure) CamelBindingData(org.switchyard.component.camel.common.composer.CamelBindingData) Date(java.util.Date)

Aggregations

SapSynchronousRfcDestinationEndpoint (org.fusesource.camel.component.sap.SapSynchronousRfcDestinationEndpoint)4 Structure (org.fusesource.camel.component.sap.model.rfc.Structure)4 CamelBindingData (org.switchyard.component.camel.common.composer.CamelBindingData)4 Date (java.util.Date)3 BookFlightRequest (org.switchyard.quickstarts.camel.sap.binding.jaxb.BookFlightRequest)2 FlightConnectionInfo (org.switchyard.quickstarts.camel.sap.binding.bean.FlightConnectionInfo)1 FlightCustomerInfo (org.switchyard.quickstarts.camel.sap.binding.bean.FlightCustomerInfo)1 FlightTripRequestInfo (org.switchyard.quickstarts.camel.sap.binding.bean.FlightTripRequestInfo)1 PassengerInfo (org.switchyard.quickstarts.camel.sap.binding.bean.PassengerInfo)1