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

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

Go to download

Simple library having an App to test the XML requests and responses of TruJet.

The newest version!
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.exceptions.FlightInfoException;
import com.github.debugthug.exceptions.IncorrectRequestException;
import com.github.debugthug.xo.Authenticate;
import com.github.debugthug.xo.Body;
import com.github.debugthug.xo.Envelope;
import com.github.debugthug.xo.flightInfo.FlightInformationRQ;
import com.github.debugthug.xo.flightInfo.FlightInformationRS;
import com.github.debugthug.xo.flightInfo.GetFlightInfo;
import com.github.debugthug.xo.flightInfo.GetFlightInfoResponse;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;

public class FlightInfoTransformer {

	public String transformRequest(Envelope envelopeFlightInfoRQ) throws FlightInfoException {
		final Logger logger = Logger.getLogger(FlightInfoTransformer.class);
		try {

			DateConverter dateconverter = new DateConverter("yyyyMMdd", new String[] {},TimeZone.getDefault());

			Body bodyFlightInfo = envelopeFlightInfoRQ.getBody();
			GetFlightInfo getFlightInfo = bodyFlightInfo.getGetFlightInfo();
			FlightInformationRQ flightInformationRQ = getFlightInfo.getStrInput().getFlightInformationRQ();
			Authenticate authenticateFlightInfoRQ = flightInformationRQ.getAunthenticate();

			StringBuilder sb = new StringBuilder();
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append(flightInformationRQ.getFlightNumber());
			sb.append("");
			sb.append("");
			sb.append(dateconverter.toString(flightInformationRQ.getFlightDate()));
			sb.append("");
			sb.append("");
			sb.append(flightInformationRQ.getOrigin());
			sb.append("");
			sb.append("");
			sb.append(flightInformationRQ.getDestination());
			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 FlightInfoException(ire.getMessage(), ire);
		} catch (Exception e) {
			throw new FlightInfoException(e);
		}

	}

	public Envelope transformResponse(String flightInfoResponse) throws FlightInfoException {

		Envelope envelopeFlightInfoRS = null;

		try {

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

			// date converter::
			xstream.registerLocalConverter(FlightInformationRQ.class, "flightDate", new DateConverterTest());

			envelopeFlightInfoRS = (Envelope) xstream.fromXML(flightInfoResponse);

			GetFlightInfoResponse getFlightInfoResponse = envelopeFlightInfoRS.getBody().getGetFlightInfoResponse();
			FlightInformationRS flightInformationRS = getFlightInfoResponse.getGetFlightInfoResult()
					.getFlightInformationRS();
			String status = flightInformationRS.getErrors().getStatus();
			String errorDescription = flightInformationRS.getErrors().getError().getDescription();
			if (StringUtils.equalsIgnoreCase("TRUE", status) || !(StringUtils.isEmpty(errorDescription)))
				throw new Exception(errorDescription);

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

		return envelopeFlightInfoRS;

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy