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

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

package com.github.debugthug.transformers;

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

import com.github.debugthug.scCryptography;
import com.github.debugthug.exceptions.FareRulesNotAvailableException;
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.fareRules.FareRulesAndRestrictionsResponse;
import com.github.debugthug.xo.fareRules.FareRulesRQ;
import com.github.debugthug.xo.fareRules.FareRulesRS;
import com.thoughtworks.xstream.XStream;

public class FareRulesAndRestrictionsTransformer {
	final Logger logger = Logger.getLogger(FareRulesAndRestrictionsTransformer.class);
	public String transformRequest(Envelope envelopeFareRulesRQ) throws FareRulesNotAvailableException {

		try {
			
			Body body = envelopeFareRulesRQ.getBody();
			FareRulesRQ fareRulesRQ = body.getFareRulesAndRestrictions().getStrInput().getFareRulesRQ();
			Authenticate authenticateBooking = fareRulesRQ.getAuthenticate();

			StringBuilder sb = new StringBuilder();
			sb.append("");
			sb.append("");
			sb.append("");
			sb.append(fareRulesRQ.getFareBasisCode());
			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 FareRulesNotAvailableException(ire.getMessage(), ire);
		} catch (Exception e) {
			throw new FareRulesNotAvailableException(e);
		}

	}

	public Envelope transformResponse(String fareRulesResponse) throws FareRulesNotAvailableException {

		Envelope envelopeFareRulesRS = null;

		try {

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

			envelopeFareRulesRS = (Envelope) xstream.fromXML(fareRulesResponse);
			
			FareRulesAndRestrictionsResponse fareRulesAndRestrictionsResponse=envelopeFareRulesRS.getBody().getFareRulesAndRestrictionsResponse();
			FareRulesRS fareRulesRS=fareRulesAndRestrictionsResponse.getFareRulesAndRestrictionsResult().getFareRulesRS();
			String status=fareRulesRS.getErrors().getStatus();
			String errorDescription=fareRulesRS.getErrors().getError().getDesc();
			if(StringUtils.equalsIgnoreCase("TRUE", status) || !(StringUtils.isEmpty(errorDescription)))
				throw new Exception(errorDescription);

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

		return envelopeFareRulesRS;

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy