All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.debugthug.transformers.CreateBookingTransformer Maven / Gradle / Ivy

package com.github.debugthug.transformers;

import java.util.List;
import java.util.TimeZone;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.github.debugthug.scCryptography;
import com.github.debugthug.converters.DateConverterTest;
import com.github.debugthug.converters.DoubleConverterTest;
import com.github.debugthug.converters.IntConverterTest;
import com.github.debugthug.converters.StringNullConverter;
import com.github.debugthug.exceptions.CreateBookingException;
import com.github.debugthug.exceptions.IncorrectRequestException;
import com.github.debugthug.validators.CreateBookingValidator;
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.Pax;
import com.github.debugthug.xo.Segment;
import com.github.debugthug.xo.booking.CreateBookingRQ;
import com.github.debugthug.xo.booking.CreateBookingRS;
import com.github.debugthug.xo.booking.CreateBookingResponse;
import com.github.debugthug.xo.booking.FareRules;
import com.github.debugthug.xo.booking.Payment;
import com.github.debugthug.xo.booking.PaymentInfo;
import com.github.debugthug.xo.booking.Reservation;
import com.github.debugthug.xo.booking.Seat;
import com.github.debugthug.xo.booking.Transaction;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;

public class CreateBookingTransformer {

	public String transformRequest(Envelope envelopeCreateBookingRQ) throws CreateBookingException {
		final Logger logger = Logger.getLogger(CreateBookingTransformer.class);
		try {
			DateConverter dateconverter = new DateConverter("yyyyMMdd", new String[] {},TimeZone.getDefault());

			CreateBookingValidator createBookingValidator = new CreateBookingValidator();
			createBookingValidator.validate(envelopeCreateBookingRQ);

			Body body = envelopeCreateBookingRQ.getBody();
			CreateBookingRQ createBookingRQ = body.getCreateBooking().getStrInput().getCreateBookingRQ();
			Authenticate authenticateBooking = createBookingRQ.getAuthenticate();

			List paxList = createBookingRQ.getPaxInfo().getPaxList();
			List segmentList = createBookingRQ.getSegmentInfo().getSegmentList();

			PaymentInfo paymentInfo = createBookingRQ.getPaymentInfo();
			Payment payment = paymentInfo.getPayment();
			
			Transaction transaction=createBookingRQ.getTransaction();
			int i = 0;
			
			StringBuilder sb = new StringBuilder();
			sb.append("");
			sb.append("");
			sb.append("IN");
			sb.append("");
			for (i = 0; i < paxList.size(); i++) {
				sb.append("");
			}
			sb.append("");
			sb.append("");

			for (i = 0; i < segmentList.size(); i++) {
				sb.append("");
			}

			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			
			logger.debug("request created::" + sb.toString());
			String request = null;
			scCryptography sc = new scCryptography();
			request = sc.Encrypt(sb.toString());

			StringBuilder builder = new StringBuilder(
					"");
			builder.append("");
			builder.append("");
			builder.append("");
			builder.append(request);
			builder.append("");
			builder.append("");
			builder.append("");
			builder.append("");

			return builder.toString();
		} catch (IncorrectRequestException ire) {
			throw new CreateBookingException(ire.getMessage(), ire);
		} catch (Exception e) {
			throw new CreateBookingException(e);
		}

	}

	public Envelope transformResponse(String bookingResponse) throws CreateBookingException {

		Envelope envelopeBookingRS = null;

		try {

			XStream xstream = new XStream();
			xstream.processAnnotations(Envelope.class);

			// CONVERTER::
			xstream.registerLocalConverter(Reservation.class, "pNRNo", new StringNullConverter());
			xstream.registerLocalConverter(Reservation.class, "dateOfIssue", new StringNullConverter());
			xstream.registerLocalConverter(Reservation.class, "placeOfIssue1", new StringNullConverter());
			xstream.registerLocalConverter(Reservation.class, "placeOfIssue2", new StringNullConverter());
			xstream.registerLocalConverter(Reservation.class, "placeOfIssue3", new StringNullConverter());
			xstream.registerLocalConverter(Reservation.class, "ticketTimeLimit", new StringNullConverter());

			xstream.registerLocalConverter(Transaction.class, "totalBaseFare", new DoubleConverterTest());
			xstream.registerLocalConverter(Transaction.class, "totalTaxes", new DoubleConverterTest());
			xstream.registerLocalConverter(Transaction.class, "totalSurcharge", new DoubleConverterTest());
			xstream.registerLocalConverter(Transaction.class, "transactionCharge", new DoubleConverterTest());
			xstream.registerLocalConverter(Transaction.class, "paymentCharge", new DoubleConverterTest());
			xstream.registerLocalConverter(Transaction.class, "commission", new DoubleConverterTest());
			xstream.registerLocalConverter(Transaction.class, "discount", new DoubleConverterTest());

			xstream.registerLocalConverter(Payment.class, "paymentType", new StringNullConverter());
			xstream.registerLocalConverter(Payment.class, "paymentCharges", new StringNullConverter());
			xstream.registerLocalConverter(Payment.class, "amountPaid", new DoubleConverterTest());

			xstream.registerLocalConverter(Pax.class, "title", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "lastName", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "firstName", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "paxTypeName", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "dob", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "FFPNo", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "identity_Type", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "identity_Detail", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "ticketNo", new StringNullConverter());
			xstream.registerLocalConverter(Pax.class, "paxConvenienceCharges", new DoubleConverterTest());

			xstream.registerLocalConverter(Segment.class, "segID", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "seats", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "flightNo", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "flightDate", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "origin", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "destination", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "flightArriaval", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "flightDeparture", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "segmentStatusName", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "flightConnectionGroup", new StringNullConverter());
			xstream.registerLocalConverter(Segment.class, "returnFlightGroup", new StringNullConverter());

			xstream.registerLocalConverter(FareRules.class, "flightConnectionGroup", new StringNullConverter());

			xstream.registerLocalConverter(Fare.class, "fareBasisCode", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "baseFare", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "taxes", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "surcharge", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "currency", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "paxTypeName", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "rOE", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "equivalentFare", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "equivalentCurrency", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "baggageAllowed", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "validFrom", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "validTill", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "paxCount", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "segIDList", new IntConverterTest());

			xstream.registerLocalConverter(Seat.class, "seatNumber", new StringNullConverter());
			xstream.registerLocalConverter(Seat.class, "paxID", new IntConverterTest());
			xstream.registerLocalConverter(Seat.class, "segID", new IntConverterTest());
			xstream.registerLocalConverter(Seat.class, "boardingPointCode", new StringNullConverter());
			xstream.registerLocalConverter(Seat.class, "boardingPointName", new StringNullConverter());

			// date converter::
			xstream.registerLocalConverter(Pax.class, "dob", new DateConverterTest());
			xstream.registerLocalConverter(Reservation.class, "dateOfIssue", new DateConverterTest());
			xstream.registerLocalConverter(Segment.class, "flightDate", new DateConverterTest());
			xstream.registerLocalConverter(Fare.class, "validFrom", new DateConverterTest());
			xstream.registerLocalConverter(Fare.class, "validTill", new DateConverterTest());

			envelopeBookingRS = (Envelope) xstream.fromXML(bookingResponse);

			CreateBookingResponse createBookingResponse = envelopeBookingRS.getBody().getCreateBookingResponse();
			CreateBookingRS createBookingRS = createBookingResponse.getCreateBookingResult().getCreateBookingRS();
			String status = createBookingRS.getErrors().getStatus();
			String errorDescription = createBookingRS.getErrors().getError().getDesc();
			if (StringUtils.equalsIgnoreCase("TRUE", status) || !(StringUtils.isEmpty(errorDescription)))
				throw new Exception(errorDescription);

		} catch (Exception e) {
			throw new CreateBookingException(e.getMessage(), e);
		}

		return envelopeBookingRS;

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy