com.github.debugthug.App Maven / Gradle / Ivy
package com.github.debugthug;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import org.apache.log4j.Logger;
import com.github.debugthug.xo.Authenticate;
import com.github.debugthug.xo.Body;
import com.github.debugthug.xo.Envelope;
import com.github.debugthug.xo.Fare;
import com.github.debugthug.xo.Flight;
import com.github.debugthug.xo.Pax;
import com.github.debugthug.xo.Segment;
import com.github.debugthug.xo.StrInput;
import com.github.debugthug.xo.availability.FlightDetails;
import com.github.debugthug.xo.availability.Flights;
import com.github.debugthug.xo.availability.OnlineAvailabilityRQ;
import com.github.debugthug.xo.availability.OnlineAvailabilityRS;
import com.github.debugthug.xo.availability.Others;
import com.github.debugthug.xo.availability.ReturnFlight;
import com.github.debugthug.xo.availability.SearchAvailability;
import com.github.debugthug.xo.availability.SearchAvailabilityResponse;
import com.github.debugthug.xo.availability.SearchAvailabilityResult;
import com.github.debugthug.xo.booking.CreateBooking;
import com.github.debugthug.xo.booking.CreateBookingRQ;
import com.github.debugthug.xo.booking.PaxInfo;
import com.github.debugthug.xo.booking.Payment;
import com.github.debugthug.xo.booking.PaymentInfo;
import com.github.debugthug.xo.booking.SegmentInfo;
import com.github.debugthug.xo.booking.Transaction;
import com.github.debugthug.xo.fareRules.FareRulesAndRestrictions;
import com.github.debugthug.xo.fareRules.FareRulesRQ;
import com.github.debugthug.xo.flightInfo.FlightInformationRQ;
import com.github.debugthug.xo.flightInfo.GetFlightInfo;
import com.github.debugthug.xo.holdInventory.Hold;
import com.github.debugthug.xo.holdInventory.HoldInventory;
import com.github.debugthug.xo.holdInventory.HoldInventoryRQ;
import com.github.debugthug.xo.holdInventory.HoldInventoryRS;
import com.github.debugthug.xo.holdInventory.HoldInventoryResult;;
public class App {
private static final Logger logger = Logger.getLogger(App.class);
@SuppressWarnings("unused")
public static void main(String[] args) throws Exception {
String userId = "*********";
String password = "*********";
String officeId = "*********";
String origin = "HYD";
String destination = "TIR";
Date flightDate = null;
Date returnDate = null;
int adults = 1;
int child = 0;
int infants = 0;
int inboundFlightChoice = 0;
int outboundFlightChoice = 0;
final boolean isRoundTrip = true;
int i = 0;
Calendar cal = Calendar.getInstance();
cal.set(2016, 9, 28);
flightDate = cal.getTime();
cal.set(2016, 9, 29);
if (isRoundTrip)
returnDate = cal.getTime();
Scanner scanner = new Scanner(System.in);
// *************************SearchAvailability*************************
// setting request parameters:
Envelope envelopeAvailRQ = new Envelope();
Body bodyAvailRQ = new Body();
envelopeAvailRQ.setBody(bodyAvailRQ);
SearchAvailability searchAvailability = new SearchAvailability();
bodyAvailRQ.setSearchAvailability(searchAvailability);
StrInput strInputAvailRQ = new StrInput();
searchAvailability.setStrInput(strInputAvailRQ);
OnlineAvailabilityRQ onlineAvailabilityRQ = new OnlineAvailabilityRQ();
strInputAvailRQ.setOnlineAvailabilityRQ(onlineAvailabilityRQ);
Authenticate authenticateAvailRQ = new Authenticate();
authenticateAvailRQ.setUserLogin(userId);
authenticateAvailRQ.setPassword(password);
authenticateAvailRQ.setOfficeId(officeId);
onlineAvailabilityRQ.setAunthenticate(authenticateAvailRQ);
Flight flightAvailRQ = new Flight();
flightAvailRQ.setOrigin(origin);
flightAvailRQ.setDestination(destination);
flightAvailRQ.setFlightDate(flightDate);
onlineAvailabilityRQ.setFlight(flightAvailRQ);
Pax paxAvailRQ = new Pax();
paxAvailRQ.setAdultCount(adults);
paxAvailRQ.setChildCount(child);
paxAvailRQ.setInfantCount(infants);
onlineAvailabilityRQ.setPax(paxAvailRQ);
ReturnFlight returnFlight = new ReturnFlight();
onlineAvailabilityRQ.setReturnFlight(returnFlight);
returnFlight.setReturnDate(returnDate);
Others others = new Others();
others.setCabinCode("Y");
others.setNationality("IN");
onlineAvailabilityRQ.setOthers(others);
// sending searchAvailability request:
Envelope envelopeAvailRS = TrujetXmlService.searchAvailability(envelopeAvailRQ);
logger.debug(envelopeAvailRS);
// retrieving values from availability response::::
SearchAvailabilityResponse searchAvailabilityResponse = envelopeAvailRS.getBody()
.getSearchAvailabilityResponse();
SearchAvailabilityResult searchAvailabilityResult = searchAvailabilityResponse.getSearchAvailabilityResult();
OnlineAvailabilityRS onlineAvailabilityRS = searchAvailabilityResult.getOnlineAvailabilityRS();
List flightsList = onlineAvailabilityRS.getFlightsList();
double outboundBaseFare = 0;
double outboundTaxes = 0;
double outboundSurcharge = 0;
double outboundAmountToPay = 0;
double inboundBaseFare = 0;
double inboundTaxes = 0;
double inboundSurcharge = 0;
double inboundAmountToPay = 0;
double totalAmountToPay = 0;
int outboundSegments = 0;
int inboundSegments = 0;
HoldInventoryRQ holdInventoryRQ = new HoldInventoryRQ();
Hold hold = null;
logger.debug("results for outbound:");
Flights outboundFlights = flightsList.get(0);
for (FlightDetails flightOtion : outboundFlights.getFlightDetails()) {
logger.debug("Option " + i + ":");
for (Flight flight : flightOtion.getFlightList()) {
logger.debug("Flight Segments:");
logger.debug("flight no':" + flight.getFlightNo() + " booking class:" + flight.getrBD() + " order no':"
+ flight.getOrderNo());
i++;
}
logger.debug("Fare charges for adult,child & infant::");
for (Fare fare : flightOtion.getFareList())
logger.debug("base fare:" + fare.getBaseFare() + " taxes:" + fare.getTaxes());
}
logger.debug("enter choice for outbound flight::");
outboundFlightChoice = scanner.nextInt();
FlightDetails flightSelectedOutbound = null;
List fareList = null;
flightSelectedOutbound = flightsList.get(0).getFlightDetails().get(outboundFlightChoice);
fareList = flightSelectedOutbound.getFareList();
i = 0;
if (adults > 0) {
outboundBaseFare = outboundBaseFare + adults * fareList.get(i).getBaseFare();
outboundTaxes = outboundTaxes + adults * fareList.get(i).getTaxes();
outboundSurcharge = outboundSurcharge + adults * fareList.get(i).getSurcharge();
i++;
}
if (child > 0) {
outboundBaseFare = outboundBaseFare + child * fareList.get(i).getBaseFare();
outboundTaxes = outboundTaxes + child * fareList.get(i).getTaxes();
outboundSurcharge = outboundSurcharge + adults * fareList.get(i).getSurcharge();
i++;
}
if (infants > 0) {
outboundBaseFare = outboundBaseFare + infants * fareList.get(i).getBaseFare();
outboundTaxes = outboundTaxes + infants * fareList.get(i).getTaxes();
outboundSurcharge = outboundSurcharge + adults * fareList.get(i).getSurcharge();
}
outboundAmountToPay = outboundBaseFare + outboundTaxes + outboundSurcharge;
logger.debug("fare for outbound:" + outboundAmountToPay);
// setting the flight no's of the segments available in out-bound for
// hold inventory request
outboundSegments = flightSelectedOutbound.getFlightList().size();
List outboundFlightNo = new ArrayList();
for (i = 0; i < outboundSegments; i++) {
outboundFlightNo.add(flightSelectedOutbound.getFlightList().get(i).getFlightNo());
hold = new Hold();
hold.setOrderNo(flightSelectedOutbound.getFlightList().get(i).getOrderNo());
hold.setFlightNo(flightSelectedOutbound.getFlightList().get(i).getFlightNo());
hold.setOrigin(flightSelectedOutbound.getFlightList().get(i).getOrigin());
hold.setDestination(flightSelectedOutbound.getFlightList().get(i).getDestination());
hold.setFlightDate(flightSelectedOutbound.getFlightList().get(i).getFlightDate());
hold.setrBD(flightSelectedOutbound.getFlightList().get(i).getrBD());
hold.setSeatCount(adults + child);
holdInventoryRQ.addHoldList(hold);
}
logger.debug(outboundFlightNo + "selected for outbound");
// if round-trip , and if in-bound flights available::
i = 0;
FlightDetails flightSelectedInbound = null;
if (isRoundTrip) {
logger.debug("results for inbound:");
for (FlightDetails flightOtion : flightsList.get(1).getFlightDetails()) {
logger.debug("Option " + i + ":");
for (Flight flight : flightOtion.getFlightList()) {
logger.debug("Flight Segments:");
logger.debug(i + "." + "flight no':" + flight.getFlightNo() + " booking class:" + flight.getrBD()
+ " order no':" + flight.getOrderNo());
i++;
}
logger.debug("Fare charges for adult,child & infant::");
for (Fare fare : flightOtion.getFareList()) {
logger.debug("base fare:" + fare.getBaseFare());
logger.debug("taxes:" + fare.getTaxes());
}
}
logger.debug("enter choice for inbound flight::");
inboundFlightChoice = scanner.nextInt();
flightSelectedInbound = flightsList.get(1).getFlightDetails().get(inboundFlightChoice);
fareList = flightSelectedInbound.getFareList();
i = 0;
if (adults > 0) {
inboundBaseFare = inboundBaseFare + adults * fareList.get(i).getBaseFare();
inboundTaxes = inboundTaxes + adults * fareList.get(i).getTaxes();
inboundSurcharge = inboundSurcharge + adults * fareList.get(i).getSurcharge();
i++;
}
if (child > 0) {
inboundBaseFare = inboundBaseFare + child * fareList.get(i).getBaseFare();
inboundTaxes = inboundTaxes + child * fareList.get(i).getTaxes();
inboundSurcharge = inboundSurcharge + adults * fareList.get(i).getSurcharge();
i++;
}
if (infants > 0) {
inboundBaseFare = inboundBaseFare + infants * fareList.get(i).getBaseFare();
inboundTaxes = inboundTaxes + infants * fareList.get(i).getTaxes();
inboundSurcharge = inboundSurcharge + adults * fareList.get(i).getSurcharge();
}
inboundAmountToPay = inboundBaseFare + inboundTaxes + inboundSurcharge;
logger.debug("fare for inbound:" + inboundAmountToPay);
// setting the flight no's of the segments available in in-bound for
// hold inventory request
inboundSegments = flightSelectedInbound.getFlightList().size();
List inboundFlightNo = new ArrayList();
for (i = 0; i < inboundSegments; i++) {
inboundFlightNo.add(flightSelectedInbound.getFlightList().get(i).getFlightNo());
hold = new Hold();
hold.setOrderNo(flightSelectedInbound.getFlightList().get(i).getOrderNo());
hold.setFlightNo(flightSelectedInbound.getFlightList().get(i).getFlightNo());
hold.setOrigin(flightSelectedInbound.getFlightList().get(i).getOrigin());
hold.setDestination(flightSelectedInbound.getFlightList().get(i).getDestination());
hold.setFlightDate(flightSelectedInbound.getFlightList().get(i).getFlightDate());
hold.setrBD(flightSelectedInbound.getFlightList().get(i).getrBD());
hold.setSeatCount(adults + child);
holdInventoryRQ.addHoldList(hold);
}
logger.debug(inboundFlightNo + "selected for inbound");
}
String fareBasisCodeOutBound = flightSelectedOutbound.getFareList().get(0).getFareBasisCode();
String fareBasisCodeInBound = null;
if (isRoundTrip)
fareBasisCodeInBound = flightSelectedInbound.getFareList().get(0).getFareBasisCode();
// *************************FareRulesAndRestrictions*************************
Envelope envelopeFareRulesRQ = new Envelope();
Body bodyFareRulesRQ = new Body();
envelopeFareRulesRQ.setBody(bodyFareRulesRQ);
FareRulesAndRestrictions fareRulesAndRestrictions = new FareRulesAndRestrictions();
bodyFareRulesRQ.setFareRulesAndRestrictions(fareRulesAndRestrictions);
StrInput strInputFareRulesRQ = new StrInput();
fareRulesAndRestrictions.setStrInput(strInputFareRulesRQ);
FareRulesRQ fareRulesRQ = new FareRulesRQ();
fareRulesRQ.setFareBasisCode(fareBasisCodeOutBound);
strInputFareRulesRQ.setFareRulesRQ(fareRulesRQ);
Authenticate authenticateFareRulesRQ = new Authenticate();
authenticateFareRulesRQ.setUserLogin(userId);
authenticateFareRulesRQ.setPassword(password);
authenticateFareRulesRQ.setOfficeId(officeId);
fareRulesRQ.setAuthenticate(authenticateFareRulesRQ);
// sending fareRulesAndRestrictions request::
Envelope envelopeFareRulesRS = TrujetXmlService.getFareRules(envelopeFareRulesRQ);
logger.debug(envelopeFareRulesRS);
// ****************************FlightInfo************************************
Envelope envelopeFlightInfoRQ = new Envelope();
Body bodyFlightInfoRQ = new Body();
envelopeFlightInfoRQ.setBody(bodyFlightInfoRQ);
GetFlightInfo getFlightInfo = new GetFlightInfo();
bodyFlightInfoRQ.setGetFlightInfo(getFlightInfo);
StrInput strInputFlightInfoRQ = new StrInput();
getFlightInfo.setStrInput(strInputFlightInfoRQ);
FlightInformationRQ flightInformationRQ = new FlightInformationRQ();
strInputFlightInfoRQ.setFlightInformationRQ(flightInformationRQ);
Authenticate authenticateFlightInfoRQ = new Authenticate();
authenticateFlightInfoRQ.setUserLogin(userId);
authenticateFlightInfoRQ.setPassword(password);
authenticateFlightInfoRQ.setOfficeId(officeId);
flightInformationRQ.setAunthenticate(authenticateFlightInfoRQ);
flightInformationRQ.setOrigin(origin);
flightInformationRQ.setDestination(destination);
flightInformationRQ.setFlightDate(flightDate);
flightInformationRQ.setFlightNumber(outboundFlightNo.get(0));
// sending flightInfo request::
Envelope envelopeFlightInfoRS = TrujetXmlService.getFlightInformation(envelopeFlightInfoRQ);
logger.debug(envelopeFlightInfoRS);
// ******************************HoldInventory**********************************
// setting request values for HoldInventory::
Envelope envelopeHoldInventoryRQ = new Envelope();
Body bodyHoldInventoryRQ = new Body();
envelopeHoldInventoryRQ.setBody(bodyHoldInventoryRQ);
HoldInventory holdInventory = new HoldInventory();
bodyHoldInventoryRQ.setHoldInventory(holdInventory);
StrInput strInputHoldInventoryRQ = new StrInput();
holdInventory.setStrInput(strInputHoldInventoryRQ);
strInputHoldInventoryRQ.setHoldInventoryRQ(holdInventoryRQ);
Authenticate authenticateHoldInventoryRQ = new Authenticate();
authenticateHoldInventoryRQ.setUserLogin(userId);
authenticateHoldInventoryRQ.setPassword(password);
authenticateHoldInventoryRQ.setOfficeId(officeId);
holdInventoryRQ.setAunthenticate(authenticateHoldInventoryRQ);
// sending hold inventory request::
Envelope envelopeHoldInventoryRS = TrujetXmlService.holdInventory(envelopeHoldInventoryRQ);
logger.debug(envelopeHoldInventoryRS);
// retrieving hold inventory response values::
Body bodyHoldInventoryRS = envelopeHoldInventoryRS.getBody();
HoldInventoryResult holdInventoryResult = bodyHoldInventoryRS.getHoldInventoryResponse()
.getHoldInventoryResult();
HoldInventoryRS holdInventoryRS = holdInventoryResult.getHoldInventoryRS();
List holdList = holdInventoryRS.getHoldList();
int holdListSize = holdList.size();
List holdedIds = new ArrayList();
logger.debug("holded ids are:");
for (i = 0; i < holdListSize; i++) {
holdedIds.add(holdList.get(i).getHoldID());
logger.debug(holdedIds.get(i));
}
// *******************************CreateBooking************************
totalAmountToPay = outboundAmountToPay + inboundAmountToPay;
Envelope envelopeCreateBookingRQ = new Envelope();
Body bodyCreateBooking = new Body();
envelopeCreateBookingRQ.setBody(bodyCreateBooking);
CreateBooking createBooking = new CreateBooking();
bodyCreateBooking.setCreateBooking(createBooking);
StrInput strInputBooking = new StrInput();
createBooking.setStrInput(strInputBooking);
CreateBookingRQ createBookingRQ = new CreateBookingRQ();
strInputBooking.setCreateBookingRQ(createBookingRQ);
Authenticate authenticateBooking = new Authenticate();
authenticateBooking.setUserLogin(userId);
authenticateBooking.setPassword(password);
authenticateBooking.setOfficeId(officeId);
createBookingRQ.setAuthenticate(authenticateBooking);
PaxInfo paxInfo = new PaxInfo();
List paxList = paxInfo.getPaxList();
Pax paxBookingRQ = null;
int totalPax = adults + child + infants;
for (i = 0; i < adults; i++) {
paxBookingRQ = new Pax();
logger.debug("Enter details of passenger " + i + ":");
logger.debug("First Name:");
String firstName = scanner.next();
logger.debug("Last Name:");
String lastName = scanner.next();
paxBookingRQ.setTitle("MR");
paxBookingRQ.setFirstName(firstName);
paxBookingRQ.setLastName(lastName);
paxBookingRQ.setPaxTypeName("Adult");
cal.set(1994, 03, 20);
paxBookingRQ.setDob(cal.getTime());
paxList.add(paxBookingRQ);
}
for (i = adults; i < totalPax - infants; i++) {
paxBookingRQ = new Pax();
logger.debug("Enter details of passenger " + i + ":");
logger.debug("First Name:");
String firstName = scanner.next();
logger.debug("Last Name:");
String lastName = scanner.next();
paxBookingRQ.setTitle("MSTR");
paxBookingRQ.setFirstName(firstName);
paxBookingRQ.setLastName(lastName);
paxBookingRQ.setPaxTypeName("Child");
cal.set(1999, 05, 28);
paxBookingRQ.setDob(cal.getTime());
paxList.add(paxBookingRQ);
}
for (i = adults + child; i < totalPax; i++) {
paxBookingRQ = new Pax();
logger.debug("Enter details of passenger " + i + ":");
logger.debug("First Name:");
String firstName = scanner.next();
logger.debug("Last Name:");
String lastName = scanner.next();
paxBookingRQ.setTitle("INF");
paxBookingRQ.setFirstName(firstName);
paxBookingRQ.setLastName(lastName);
paxBookingRQ.setPaxTypeName("Infant");
cal.set(2015, 01, 10);
paxBookingRQ.setDob(cal.getTime());
paxList.add(paxBookingRQ);
}
createBookingRQ.setPaxInfo(paxInfo);
SegmentInfo segmentInfo = new SegmentInfo();
Segment segmentCreateBookingRQ = null;
for (i = 0; i < holdListSize; i++) {
segmentCreateBookingRQ = new Segment();
segmentCreateBookingRQ.setHoldID(holdedIds.get(i));
if (i < outboundSegments)
segmentCreateBookingRQ.setFlightConnectionGroup("0");
else
segmentCreateBookingRQ.setFlightConnectionGroup("1");
segmentCreateBookingRQ.setSeats(String.valueOf(adults + child));
segmentInfo.addSegment(segmentCreateBookingRQ);
}
createBookingRQ.setSegmentInfo(segmentInfo);
PaymentInfo paymentInfo = new PaymentInfo();
createBookingRQ.setPaymentInfo(paymentInfo);
Payment payment = new Payment();
payment.setAmountPaid(totalAmountToPay);
payment.setPaymentType("CreditLimit");
paymentInfo.setPayment(payment);
Transaction transaction=new Transaction();
transaction.setAddress("");
transaction.setCity("");
transaction.setPincode("");
transaction.setMobile("9876543210");
transaction.setEmail("[email protected]");
transaction.setCountry("IN");
createBookingRQ.setTransaction(transaction);
Envelope envelopeCreateBookingRS = TrujetXmlService.createBooking(envelopeCreateBookingRQ);
logger.debug(envelopeCreateBookingRS);
com.github.debugthug.xo.booking.CreateBookingResult CreateBookingResult = envelopeCreateBookingRS.getBody().getCreateBookingResponse()
.getCreateBookingResult();
com.github.debugthug.xo.booking.Reservation reservation = CreateBookingResult.getCreateBookingRS().getReservation();
logger.debug("PNR No':: " + reservation.getpNRNo());
logger.debug("TicketNo'::"+CreateBookingResult.getCreateBookingRS().getPaxInfo().getPaxList().get(0).getTicketNo());
scanner.close();
}
}