com.github.debugthug.validators.SearchAvailabilityValidator Maven / Gradle / Ivy
package com.github.debugthug.validators;
import org.apache.commons.lang.StringUtils;
import com.github.debugthug.exceptions.IncorrectRequestException;
import com.github.debugthug.xo.Envelope;
import com.github.debugthug.xo.availability.OnlineAvailabilityRQ;
public class SearchAvailabilityValidator implements RequestValidator {
public void validate(Envelope envelopeRQ) throws IncorrectRequestException {
try {
OnlineAvailabilityRQ onlineAvailabilityRQ = envelopeRQ.getBody().getSearchAvailability().getStrInput()
.getOnlineAvailabilityRQ();
int adults = onlineAvailabilityRQ.getPax().getAdultCount();
int child = onlineAvailabilityRQ.getPax().getChildCount();
int infants = onlineAvailabilityRQ.getPax().getInfantCount();
String origin = onlineAvailabilityRQ.getFlight().getOrigin();
if (infants > adults)
throw new IncorrectRequestException(
"Invalid Infant Count : Infants count can't be greater than adults count.");
if (adults + child > 9)
throw new IncorrectRequestException(
"Number of guest should not be more than 9 : Sum of adult and child count can't be more than 9.");
if (adults == 0)
throw new IncorrectRequestException("No Adult Pax specified. Adult count can't be zero");
if (StringUtils.isEmpty(origin))
throw new IncorrectRequestException("No Origin specified");
} catch (IncorrectRequestException ire) {
throw ire;
} catch (Exception e) {
throw new IncorrectRequestException(e);
}
}
}