Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add days out of country to loader and rule runner. #2030

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public void setPassenger(Passenger passenger) {

@Column(name = "hours_before_takeoff")
private Integer hoursBeforeTakeOff;

@Column(name = "days_out_of_country")
private Double daysOutOfCountry;

@Transient
private String totalBagWeight;
Expand Down Expand Up @@ -249,4 +252,12 @@ public Integer getCoTravelerCount() {
public void setCoTravelerCount(Integer coTravelerCount) {
this.coTravelerCount = coTravelerCount;
}

public Double getDaysOutOfCountry() {
return daysOutOfCountry;
}

public void setDaysOutOfCountry(Double daysOutOfCountry) {
this.daysOutOfCountry = daysOutOfCountry;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public enum PassengerDetailsMapping implements IEntityMapping {
RESIDENCY_COUNTRY("residencyCountry", "Residency Country", TypeEnum.STRING.getType()),

PASSENGER_TYPE("passengerType", "Type", TypeEnum.STRING.getType()),

DAYS_OUT_OF_COUNTRY("daysOutOfCountry", "Days out of Country", TypeEnum.DOUBLE.getType()),

TRAVEL_FREQUENCY("travelFrequency", "Travel Frequency", TypeEnum.STRING.getType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public enum PassengerMapping implements IEntityMapping {
SEAT("seat", "Seat", TypeEnum.STRING.getType()),

PASSENGER_TYPE("passengerDetails.passengerType", "Type", TypeEnum.STRING.getType()),

DAYS_OUT_OF_COUNTRY("passengerTripDetails.daysOutOfCountry", "Days out of Country", TypeEnum.DOUBLE.getType()),

TRAVEL_FREQUENCY("passengerTripDetails.travelFrequency", "Travel Frequency", TypeEnum.STRING.getType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public MessageInformation load(MessageDto msgDto) {
pnr.setPassengerCount(pnr.getPassengers().size());
TripTypeEnum tripType = loaderRepo.calculateTripType(pnr.getFlightLegs(), pnr.getDwellTimes());
pnr.setTripType(tripType.toString());
calculateTimeOutOfCountry(pnr, primeFlight);
if (tamrEnabled) {
List<TamrPassenger> tamrPassengers = tamrAdapter
.convertPassengers(pnr.getFlights().iterator().next(), pnr.getPassengers());
Expand Down Expand Up @@ -218,6 +219,91 @@ public MessageInformation load(MessageDto msgDto) {
return messageInformation;
}

private void calculateTimeOutOfCountry(Pnr pnr, Flight primeFlight) {

List<FlightLeg> flistFlightLegs = pnr.getFlightLegs();
if (pnr.getFlightLegs().size() < 2) {
return;
}
// All following logic to determine time out of country depends on the flight legs being in order.
flistFlightLegs.sort(Comparator.comparing(FlightLeg::getLegNumber));
// find index of prime flight.
int flightIndex = -1;
for (int i = 0; i < flistFlightLegs.size(); i++) {
if (flistFlightLegs.get(i).getFlight() != null) {
flightIndex = i;
break;
}
}
// Set the time out of country using different logic if flight is in-bound or out-bound.
Double timeOutOfCountryInDays = null;
String homeCountry = lookupRepo.getAppConfigOption(AppConfigurationRepository.HOME_COUNTRY);

if ("I".equalsIgnoreCase(primeFlight.getDirection())) {
// This will take the first booking in-bound to the home country after an out-bound prime flight
timeOutOfCountryInDays = getInboundTimeOutOfCountry(primeFlight, flistFlightLegs, flightIndex, homeCountry);
} else if ("O".equalsIgnoreCase(primeFlight.getDirection())) {
// This will take the first flight in-bound to the home country after an out-bound booking detail
timeOutOfCountryInDays = getOutboundTimeOutOfCountry(primeFlight, flistFlightLegs, flightIndex, homeCountry);
}
// If a time was able to be calculated update the passenger trip details to reflect how many days a
// traveler is out of the country
if (timeOutOfCountryInDays != null) {
for (Passenger p : pnr.getPassengers()) {
PassengerTripDetails ptd = p.getPassengerTripDetails();
ptd.setDaysOutOfCountry(timeOutOfCountryInDays);
}
}
}

// Iterate through flight legs starting at the first flight leaving the home country
// and ending with the incoming prime flight to see if a time out of country can be determined
private Double getOutboundTimeOutOfCountry(Flight primeFlight, List<FlightLeg> flistFlightLegs, int flightIndex, String homeCountry) {
Double timeOutOfCountryInDays = null;

for (int i = flightIndex; i < flistFlightLegs.size(); i++) {
BookingDetail bd = flistFlightLegs.get(i).getBookingDetail();

if (flistFlightLegs.get(i).getFlight() == null
&& bd != null
&& homeCountry.equalsIgnoreCase(bd.getDestinationCountry())) {
Date entryDate = bd.getEta();
Date exitDate = primeFlight.getMutableFlightDetails().getEtd();
timeOutOfCountryInDays = differenceInDays(exitDate, entryDate);
break;
}
}
return timeOutOfCountryInDays;
}

// Iterate through flight legs starting at the first booking detail leaving the home country
// and ending with the incoming prime flight to see if a time out of country can be determined
private Double getInboundTimeOutOfCountry(Flight primeFlight, List<FlightLeg> flistFlightLegs, int flightIndex, String homeCountry) {
Double timeOutOfCountryInDays = null;

for (int i = 0; i < flightIndex; i++) {
BookingDetail bd = flistFlightLegs.get(i).getBookingDetail();
if (flistFlightLegs.get(i).getFlight() == null
&& bd != null
&& homeCountry.equalsIgnoreCase(bd.getOriginCountry())) {
Date entryDate = primeFlight.getMutableFlightDetails().getEta();
Date exitDate = bd.getEtd();
timeOutOfCountryInDays = differenceInDays(entryDate, exitDate);
}
}
return timeOutOfCountryInDays;
}


private Double differenceInDays(Date firstDate, Date secondDate) {
double timeOutOfCountryInDays;
long diff = secondDate.getTime() - firstDate.getTime();
int hours = (int) TimeUnit.HOURS.convert(diff, TimeUnit.MILLISECONDS);
DecimalFormat df = new DecimalFormat("#.##");
timeOutOfCountryInDays = Double.valueOf(df.format((double) hours / 24));
return timeOutOfCountryInDays;
}

private void addSegments(Pnr pnr, PnrVo vo) {
for (SavedSegmentVo ssVo : vo.getSavedSegments() ) {
String segmentName = ssVo.getSegmentName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class RuleTemplateConstants {
passengerTripDetailsMap.put("PASSENGERTRIPDETAILS.DEBARKCOUNTRY", "debarkCountry");
passengerTripDetailsMap.put("PASSENGERTRIPDETAILS.COTRAVELERCOUNT", "coTravelerCount");
passengerTripDetailsMap.put("PASSENGERTRIPDETAILS.HOURSBEFORETAKEOFF", "hoursBeforeTakeOff");
passengerTripDetailsMap.put("PASSENGERTRIPDETAILS.DAYSOUTOFCOUNTRY", "daysOutOfCountry");
passTripDetailsMap = Collections.unmodifiableMap(passengerTripDetailsMap);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table passenger_trip_details drop column `days_out_of_country`;
3 changes: 3 additions & 0 deletions gtas-parent/scripts/db/2.0/passenger_trip_detail_update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table passenger_trip_details
add column `days_out_of_country` double DEFAULT NULL;