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

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

package com.github.debugthug.transformers;

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.IncorrectRequestException;
import com.github.debugthug.exceptions.SearchAvailabilityException;
import com.github.debugthug.validators.SearchAvailabilityValidator;
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.StrInput;
import com.github.debugthug.xo.Tax;
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.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;

public class SearchAvailabilityTransformer {

	public String transformRequest(Envelope envelopeSearchRQ) throws SearchAvailabilityException {
		final Logger logger = Logger.getLogger(SearchAvailabilityTransformer.class);

		try {
			DateConverter dateconverter = new DateConverter("yyyyMMdd", new String[] {},TimeZone.getDefault());
			
			SearchAvailabilityValidator searchAvailabilityValidator = new SearchAvailabilityValidator();
			searchAvailabilityValidator.validate(envelopeSearchRQ);
			
			Body bodyAvailRQ = envelopeSearchRQ.getBody();
			SearchAvailability searchAvailability = bodyAvailRQ.getSearchAvailability();
			StrInput strInputAvailRQ = searchAvailability.getStrInput();
			OnlineAvailabilityRQ onlineAvailabilityRQ = strInputAvailRQ.getOnlineAvailabilityRQ();
			Authenticate authenticateAvailRQ = onlineAvailabilityRQ.getAuthenticate();
			Flight flightAvailRQ = onlineAvailabilityRQ.getFlight();
			Pax pax = onlineAvailabilityRQ.getPax();
			ReturnFlight returnFlight = onlineAvailabilityRQ.getReturnFlight();
			Others others=onlineAvailabilityRQ.getOthers();
			

			StringBuilder sb = new StringBuilder();
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append("");
			if(null!=returnFlight.getReturnDate())
				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 SearchAvailabilityException(ire.getMessage(), ire);
		} catch (Exception e) {
			throw new SearchAvailabilityException(e);
		}

	}

	public Envelope transformResponse(String searchResponse) throws SearchAvailabilityException {

		Envelope envelopeAvailabilityRS = null;

		try {

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

			xstream.registerLocalConverter(Flights.class, "origin", new StringNullConverter());
			xstream.registerLocalConverter(Flights.class, "destination", new StringNullConverter());
			xstream.registerLocalConverter(Flights.class, "originName", new StringNullConverter());
			xstream.registerLocalConverter(Flights.class, "destinationName", new StringNullConverter());
			xstream.registerLocalConverter(Flights.class, "cabinName", new StringNullConverter());
			xstream.registerLocalConverter(Flights.class, "returnAvailability", new IntConverterTest());

			xstream.registerLocalConverter(Flight.class, "orderNo", new IntConverterTest());
			xstream.registerLocalConverter(Flight.class, "flightNo", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "flightDate", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "origin", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "destination", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "originName", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "destinationName", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "originCityName", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "destinationCityName", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "departureTerminal", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "arrivalTerminal", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "dayChange", new IntConverterTest());
			xstream.registerLocalConverter(Flight.class, "flightDuration", new IntConverterTest());
			xstream.registerLocalConverter(Flight.class, "rBD", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "lapDuration", new IntConverterTest());
			xstream.registerLocalConverter(Flight.class, "stopsCount", new IntConverterTest());
			xstream.registerLocalConverter(Flight.class, "stopDuration", new IntConverterTest());
			xstream.registerLocalConverter(Flight.class, "departureTime", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "arrivalTime", new StringNullConverter());
			xstream.registerLocalConverter(Flight.class, "segmentStatus", 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, "rOE", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "equivalentFare", new DoubleConverterTest());
			xstream.registerLocalConverter(Fare.class, "equivalentCurrencyCode", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "paxType", 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, "cancellation_Allowed", new StringNullConverter());
			xstream.registerLocalConverter(Fare.class, "rebooking_Allowed", new StringNullConverter());

			xstream.registerLocalConverter(Tax.class, "taxNature", new StringNullConverter());
			xstream.registerLocalConverter(Tax.class, "currency", new StringNullConverter());
			xstream.registerLocalConverter(Tax.class, "amount", new DoubleConverterTest());
			xstream.registerLocalConverter(Tax.class, "surcharge", new IntConverterTest());
			
			//date converter::
			xstream.registerLocalConverter(Flight.class, "flightDate", new DateConverterTest());
			xstream.registerLocalConverter(Fare.class, "validFrom", new DateConverterTest());
			xstream.registerLocalConverter(Fare.class, "validTill", new DateConverterTest());

			envelopeAvailabilityRS = (Envelope) xstream.fromXML(searchResponse);
			
			SearchAvailabilityResponse searchAvailabilityResponse=envelopeAvailabilityRS.getBody().getSearchAvailabilityResponse();
			OnlineAvailabilityRS onlineAvailabilityRS=searchAvailabilityResponse.getSearchAvailabilityResult().getOnlineAvailabilityRS();
			String status=null;
			String errorDescription=null;
			if(null!=onlineAvailabilityRS)
			{
				status=onlineAvailabilityRS.getErrors().getStatus();
				errorDescription=onlineAvailabilityRS.getErrors().getError().getDescription();
				if(StringUtils.equalsIgnoreCase("TRUE", status) || !(StringUtils.isEmpty(errorDescription)))
					throw new Exception(errorDescription);
			}
			else
			{
				//if infant is more than adults,then in response  is there in place of 
				//and then error description is given
				OnlineAvailabilityRQ onlineAvailabilityRQ=searchAvailabilityResponse.getSearchAvailabilityResult().getOnlineAvailabilityRQ();
				status=onlineAvailabilityRQ.getErrors().getStatus();
				errorDescription=onlineAvailabilityRQ.getErrors().getError().getDescription();
				if(StringUtils.equalsIgnoreCase("TRUE", status))
					throw new Exception(errorDescription);
			}
			
		} catch (Exception e) {
			throw new SearchAvailabilityException(e.getMessage(), e);
		}

		return envelopeAvailabilityRS;

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy