try {
// Critical and Short count for main flight
int shortCount = 0;
int criticalCount = 0;
for (Object obj : idConxFlights) {
FltConnectionDTO dto = (FltConnectionDTO) obj;
LOG.debug("Main Flt : {}, Conx Flt : {}", mainFlt.getUrno(), dto.getIdConxFlight());
if(mainFlt.getUrno().equals(dto.getIdConxFlight())) {
LOG.error("ID_FLIGHT[{}] and ID_CONX_FLIGHT[{}] must not be the same. Otherwise the process will not be performed.", mainFlt.getUrno(), dto.getIdConxFlight());
return;
}
if (dto.getIdConxFlight().intValue() != 0) {
EntDbAfttab conxFlight = afttabBean.findFlightForConx(dto.getIdConxFlight());
if (conxFlight != null) {
// Main flight and conx flight must be either arrival or departure flight
if (ADID_ARRIVAL != mainFlt.getAdid() && ADID_DEPARTURE != mainFlt.getAdid()) {
LOG.warn("Main flight must be arrival or departure flight");
LOG.warn("ADID={} for main flight={}", mainFlt.getAdid(), mainFlt.getUrno());
continue;
}
if (ADID_ARRIVAL != conxFlight.getAdid() && ADID_DEPARTURE != conxFlight.getAdid()) {
LOG.warn("Conx flight must be arrival or departure flight");
LOG.warn("ADID={} for conx flight={}", conxFlight.getAdid(), conxFlight.getUrno());
continue;
}
// Calculate the time span between main and connect flight
BigDecimal idArrFlight = null;
BigDecimal idDepFlight = null;
HpUfisCalendar tifa = null;
HpUfisCalendar tifd = null;
char tga1 = ' ';
char tgd1 = ' ';
if (ADID_ARRIVAL == mainFlt.getAdid()) {
tifa = new HpUfisCalendar(mainFlt.getTifa());
tifd = new HpUfisCalendar(conxFlight.getTifd());
idArrFlight = mainFlt.getUrno();
idDepFlight = conxFlight.getUrno();
tga1 = mainFlt.getTga1();
tgd1 = conxFlight.getTgd1();
} else {
tifa = new HpUfisCalendar(conxFlight.getTifa());
tifd = new HpUfisCalendar(mainFlt.getTifd());
idArrFlight = conxFlight.getUrno();
idDepFlight = mainFlt.getUrno();
tga1 = conxFlight.getTgd1();
tgd1 = mainFlt.getTga1();
}
int timeDiff = (int) tifa.timeDiff(tifd, EnumTimeInterval.Minutes, false);
LOG.debug("Time Difference between main flight and conx flight: {} mins", timeDiff);
// check bag/pax/uld number for transfer
int transferNum = 0;
switch (tab) {
case HpUfisAppConstants.CON_LOAD_BAG_SUMMARY:
transferNum = dto.getBagPcs();
break;
case HpUfisAppConstants.CON_LOAD_PAX_SUMMARY:
transferNum = dto.getTotalPax();
break;
case HpUfisAppConstants.CON_LOAD_ULD_SUMMARY:
transferNum = dto.getUldPcs();
break;
default:
break;
}
// Connection status (no transfer subject or pax, no connection)
String status = null;
if (transferNum > 0 || tab.equals(HpUfisAppConstants.CON_AFTTAB)) {
long shortTime = 0;
long criticalTime = 0;
if (tga1 != ' ' && tga1 == tgd1) {
shortTime = HpEKConstants.CONX_ST_SHORT;
criticalTime = HpEKConstants.CONX_ST_CRITICAL;
} else {
shortTime = HpEKConstants.CONX_DT_SHORT;
criticalTime = HpEKConstants.CONX_DT_CRITICAL;
}
LOG.debug("TGA1: {} - TGD1: {}", tga1, tgd1);
LOG.debug("Short: {}", shortTime);
LOG.debug("Critical: {}", criticalTime);
if (timeDiff <= criticalTime) {
// Critical
status = HpUfisAppConstants.CONX_STAT_CRITICAL;
criticalCount += 1;
} else if (timeDiff > criticalTime && timeDiff <= shortTime) {
// Short
status = HpUfisAppConstants.CONX_STAT_SHORT;
shortCount += 1;
} else if (timeDiff > shortTime) {
// Normal
status = HpUfisAppConstants.CONX_STAT_NOMRAL;
} else {
// No Connection
status = HpUfisAppConstants.CONX_STAT_NOCONNX;
}
} else {
// No Connection
status = HpUfisAppConstants.CONX_STAT_NOCONNX;
}
// Find FLT_CONNECT_SUMMARY by id_arr_flight and id_dep_flight
UfisASCommands cmd = UfisASCommands.URT;
EntDbFltConnectSummary data = null;
EntDbFltConnectSummary fltConx = fltConnectSummaryBean.findExisting(idArrFlight, idDepFlight);
if (fltConx == null) {
data = new EntDbFltConnectSummary();
cmd = UfisASCommands.IRT;
data = new EntDbFltConnectSummary();
data.setIdArrFlight(idArrFlight);
data.setIdDepFlight(idDepFlight);
data.setCreatedDate(HpUfisCalendar.getCurrentUTCTime());
data.setCreatedUser(HpEKConstants.FLT_CONX_SOURCE);
// 2013-11-05 added by JGO - Default connection status
data.setConxStatPax(HpUfisAppConstants.CONX_STAT_NOCONNX);
data.setConxStatBag(HpUfisAppConstants.CONX_STAT_NOCONNX);
data.setConxStatUld(HpUfisAppConstants.CONX_STAT_NOCONNX);
// 2013-11-04 added by JGO - default decision
data.setConxDecBag(HpUfisAppConstants.CONX_DEC_NODC);
data.setConxDecPax(HpUfisAppConstants.CONX_DEC_NODC);
data.setConxDecUld(HpUfisAppConstants.CONX_DEC_NODC);
data.setRecStatus(" ");
fltConnectSummaryBean.persist(data);
} else {
data = EntDbFltConnectSummary.valueOf(fltConx);
}
//evaluatePaxJourneyTime
switch(tab) {
case HpUfisAppConstants.CON_AFTTAB:
case HpUfisAppConstants.CON_LOAD_PAX_SUMMARY:
evaluatePaxJourneyTime(tab, mainFlt, conxFlight, data, timeDiff);
break;
default:
break;
}
switch (tab) {
case HpUfisAppConstants.CON_AFTTAB:
data.setConxStatBag(status);
data.setConxStatPax(status);
data.setConxStatUld(status);
break;
case HpUfisAppConstants.CON_LOAD_BAG_SUMMARY:
data.setConxStatBag(status);
break;
case HpUfisAppConstants.CON_LOAD_PAX_SUMMARY:
data.setConxStatPax(status);
break;
case HpUfisAppConstants.CON_LOAD_ULD_SUMMARY:
data.setConxStatUld(status);
break;
default:
break;
}
data.setUpdatedDate(HpUfisCalendar.getCurrentUTCTime());
data.setUpdatedUser(HpEKConstants.FLT_CONX_SOURCE);
//set tifa/tifd
data.setTifa(tifa.getTime());
data.setTifd(tifd.getTime());
data = fltConnectSummaryBean.merge(data);
LOG.debug("Flt_Connect_Summary record has been created/update for idArrFlight={} and idDepFlight={}",
data.getIdArrFlight(),
data.getIdDepFlight());
// notification for flt_connect_summary
long start = System.currentTimeMillis();
if (HpCommonConfig.notifyTopic != null) {
ufisTopicProducer.sendNotification(
true,
cmd,
String.valueOf(mainFlt.getUrno()),
fltConx,
data);
} else {
ufisQueueProducer.sendNotification(
true,
cmd,
String.valueOf(mainFlt.getUrno()),
fltConx,
data);
}
LOG.debug("Send Notification msg used: {}", (System.currentTimeMillis() - start));
} else {
LOG.warn("No conx flight found with urno: {} in afttab for flight: {}",
dto.getIdConxFlight(),
mainFlt.getUrno());
}
} else {
LOG.warn("Conx flight urno cannot be 0");
}