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

com.github.debugthug.validators.CreateBookingValidator Maven / Gradle / Ivy

package com.github.debugthug.validators;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.github.debugthug.exceptions.IncorrectRequestException;
import com.github.debugthug.xo.Envelope;
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.PaxInfo;
import com.github.debugthug.xo.booking.SegmentInfo;

public class CreateBookingValidator implements RequestValidator{

	public void validate(Envelope envelopeRQ) throws IncorrectRequestException {

		try
		{
			CreateBookingRQ createBookingRQ=envelopeRQ.getBody().getCreateBooking().getStrInput().getCreateBookingRQ();
			PaxInfo paxInfo=createBookingRQ.getPaxInfo();
			List paxList=paxInfo.getPaxList();
			SegmentInfo segmentInfo=createBookingRQ.getSegmentInfo();
			List segmentList=segmentInfo.getSegmentList();
			
			if(paxList.size()==0)
				throw new IncorrectRequestException("No Pax Specified.");
			
			for(Pax pax : paxInfo.getPaxList())
			{
				if(StringUtils.isEmpty(pax.getTitle()))
					throw new IncorrectRequestException("Title of pax not Specified.");
				if(StringUtils.isEmpty(pax.getLastName()))
					throw new IncorrectRequestException("Last Name of pax not Specified.");
				if(StringUtils.isEmpty(pax.getFirstName()))
					throw new IncorrectRequestException("First Name of pax not Specified.");
				if(StringUtils.isEmpty(pax.getPaxTypeName()))
					throw new IncorrectRequestException("PaxType not Specified.");
			}
			
			if(segmentList.size()==0)
				throw new IncorrectRequestException("Segment(s) not specified.");
			
			for(Segment segment : segmentInfo.getSegmentList())
			{
				if(StringUtils.isEmpty(segment.getHoldID()))
					throw new IncorrectRequestException("HoldID not specified to hold the segment.");
				
				if(StringUtils.isEmpty(segment.getFlightConnectionGroup()))
					throw new IncorrectRequestException("FlightConnectionGroup not specified.");
			}
			
		}
		catch (IncorrectRequestException ire) {
			throw ire;
		} catch (Exception e) {
			throw new IncorrectRequestException(e);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy