INFOBJGENERIC infobjgeneric = new INFOBJGENERIC();
INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
INFOJXAFTAB infojxaftab = new INFOJXAFTAB();
INFOJDCFTABLIST infojdcftablist = new INFOJDCFTABLIST();
INFOJFEVTABLIST infojfevtablist = new INFOJFEVTABLIST();
INFOBJFLTDAILYLIST infobjfltdailylist = new INFOBJFLTDAILYLIST();
boolean isXafFound = false;
// Check the message type and action type
_messageType = flightEvent.getMessageType();
_actionType = flightEvent.getActionType();
if (_actionType == null) {
LOG.debug("ActionType cannot be null or empty.");
LOG.debug("Message details: \n{}", _flightXml);
addExptInfo(EnumExceptionCodes.EMAND.name(),
"Action type cannot be null or empty");
return false;
}
if ("INSERT".equalsIgnoreCase(_actionType)) {
_msgActionType = ACTIONTYPE.I;
} else if ("UPDATE".equalsIgnoreCase(_actionType)) {
// _msgActionType = ACTIONTYPE.U;
_msgActionType = null;
} else {
_msgActionType = ACTIONTYPE.D;
}
// Check Flight id
if (flightId == null) {
LOG.debug("FlightId Cannot be null, message dropped.");
LOG.debug("Message details: \n{}", _flightXml);
addExptInfo(EnumExceptionCodes.EMAND.name(),
"FlightId Cannot be null");
return false;
}
// Mandatory fields in FlightId check
if (HpUfisUtils.isNullOrEmptyStr(flightId.getCxCd())
|| HpUfisUtils.isNullOrEmptyStr(flightId.getFltNum())
|| HpUfisUtils.isNullOrEmptyStr(flightId.getArrStn())
|| HpUfisUtils.isNullOrEmptyStr(flightId.getDepStn())
|| flightId.getDepNum() == null
|| flightId.getLegNum() == null
|| flightId.getFltDate() == null
|| flightId.getFltDate().getValue() == null) {
LOG.debug("Mandatory fields in FlightId Cannot be null or empty. ");
LOG.debug("Message dropped: \n{}", _flightXml);
addExptInfo(EnumExceptionCodes.EMAND.name(),
"Mandatory fields not found in FlightId");
return false;
}
// message events check
FlightEvent.Events event = null;
if (!CONST_DELETE.equalsIgnoreCase(_actionType)) {
if (!flightEvent.getEvents().isEmpty()
&& flightEvent.getEvents().size() == 1) {
event = flightEvent.getEvents().get(0);
} else {
LOG.debug("Events Cannot be empty or more than 1. ");
LOG.debug("Message dropped: \n{}", _flightXml);
addExptInfo(EnumExceptionCodes.EWVAL.name(),
"Non-Delete CORE messge: Flight Event is required and one only");
return false;
}
// Mandatory fields in events
if (HpUfisUtils.isNullOrEmptyStr(event.getCxCd())
|| HpUfisUtils.isNullOrEmptyStr(event.getFltNum())
|| HpUfisUtils.isNullOrEmptyStr(event.getArrStn())
|| HpUfisUtils.isNullOrEmptyStr(event.getDepStn())
|| event.getDepNum() == null
|| event.getLegNum() == null
|| event.getFltDate() == null
|| event.getFltDate().getValue() == null) {
LOG.debug("Mandatory fields in Events Cannot be null or empty. ");
LOG.debug("Message dropped: \n{}", _flightXml);
addExptInfo(EnumExceptionCodes.EMAND.name(),
"Mandatory field in FlightId cannot be null or empty in flight event as well");
return false;
}
}
// temp entity and temp return flight entity
EntDbCoreTmp tempMsg = null;
EntDbCoreTmp returnMsg = null;
// fltDate in FlightId default as UTC
String fldaUtc = "";
ufisCalendar.setTime(flightId.getFltDate().getValue());
fldaUtc = ufisCalendar.getCedaDateString();
// hop schedule time
String stoa = "";
String stod = "";
String fldaFromStoa = "";
String fldaFromStod = "";
if (!CONST_DELETE.equalsIgnoreCase(_actionType)) {
List<SchdDateTime> schedules = event.getSchdDateTime();
for (SchdDateTime schedule : schedules) {
ufisCalendar.setTime(schedule.getValue());
if ("Arrival".equalsIgnoreCase(schedule.getType())) {
fldaFromStoa = ufisCalendar.getCedaDateString();
stoa = df.format(ufisCalendar.getTime());
} else if ("Departure".equalsIgnoreCase(schedule.getType())) {
fldaFromStod = ufisCalendar.getCedaDateString();
stod = df.format(ufisCalendar.getTime());
}
}
}
/**
* Maintain the flight message chains in the temp table
* CxCd
* FltNum
* FltSuffix
* FltDate
* DepStn
* ArrStn
*/
List<EntDbCoreTmp> tempMessages = coreTmpBean.getMsgById(flightId);
// ======================================================================
// if message not found in temp tale, process by actionType/FltStatus
// ======================================================================
if (tempMessages == null || tempMessages.size() == 0) {
// According to actionType/FltStatus, process msg
// if (CONST_DELETE.equalsIgnoreCase(_actionType) || CONST_CANCEL.equalsIgnoreCase(event.getFltStatus())) {
if (CONST_DELETE.equalsIgnoreCase(_actionType)) {
// Drop this delete message due to the target is not existed
LOG.debug("Delete(actionType)/Cancel(FltStatus) message received, but target is not existed in temp table");
LOG.debug("Message details: \n{}", _flightXml);
addExptInfo(EnumExceptionCodes.ENREC.name(),
"No record found in DB to delete");
return false;
} else {
// insert message base on flightId
tempMsg = new EntDbCoreTmp();
tempMsg.setCxcd(flightId.getCxCd());
tempMsg.setFltNum(flightId.getFltNum());
tempMsg.setFltSuffix(flightId.getFltSuffix());
tempMsg.setFltDate(fldaUtc);
tempMsg.setDepStn(flightId.getDepStn());
tempMsg.setArrStn(flightId.getArrStn());
tempMsg.setLegNum(flightId.getLegNum().intValue());
tempMsg.setDepNum(flightId.getDepNum().intValue());
tempMsg.setSchArr(stoa);
tempMsg.setSchDep(stod);
tempMsg.setRecStatus(CONST_STAT_DEF);
coreTmpBean.create(tempMsg);
// check contian return info or not
// if id.arrStn != id.depStn and event.arrStn == event.depStn == HOPO
if (HpEKConstants.HOPO.equals(event.getArrStn())
&& HpEKConstants.HOPO.equals(event.getDepStn())
&& !flightId.getArrStn().equals(flightId.getDepStn())) {
returnMsg = new EntDbCoreTmp();
returnMsg.setCxcd(flightId.getCxCd());
returnMsg.setFltNum(flightId.getFltNum());
returnMsg.setFltSuffix(flightId.getFltSuffix());
returnMsg.setFltDate(fldaUtc);
returnMsg.setDepStn(event.getDepStn());
returnMsg.setArrStn(event.getArrStn());
returnMsg.setLegNum(flightId.getLegNum().intValue());
returnMsg.setDepNum(flightId.getDepNum().intValue());
returnMsg.setSchArr(stoa);
returnMsg.setSchDep(stod);
returnMsg.setRecStatus(CONST_STAT_DEF);
coreTmpBean.create(returnMsg);
}
}
} else {
// ===================================================================================
// if message found in temp tale, and according to actionType/FltStatus, process msg
// ===================================================================================
// delete or cancel
if (CONST_DELETE.equalsIgnoreCase(_actionType)
|| (event != null && CONST_CANCEL.equalsIgnoreCase(event.getFltStatus()))) {
// do update(for undo delete new generated leg message)
if (CONST_DELETE.equalsIgnoreCase(_actionType)
&& (flightId.getDepNum().intValue() != 1)
&& (HpEKConstants.HOPO.equals(flightId.getArrStn())
|| HpEKConstants.HOPO.equals(flightId.getDepStn()))) {
// update temp table info
int dNum = flightId.getDepNum().intValue();
int lNum = flightId.getLegNum().intValue();
for (EntDbCoreTmp item : tempMessages) {
if (item.getDepNum() == dNum && item.getLegNum() == lNum) {
//dNum = flightId.getDepNum().subtract(new BigInteger("1")).intValue();
//lNum = flightId.getLegNum().subtract(new BigInteger("1")).intValue();
dNum -= 1;
lNum -= 1;
item.setDepNum(dNum);
item.setLegNum(lNum);
coreTmpBean.edit(item);
}
}
// prepare update message for depNum decrement(undo for return)
_msgActionType = ACTIONTYPE.U;
infobjFlight.setDEPN(String.valueOf(dNum));
} else if (!flightId.getArrStn().equals(flightId.getDepStn())
&& (HpEKConstants.HOPO.equals(flightId.getArrStn())
|| HpEKConstants.HOPO.equals(flightId.getDepStn()))) {
// mark the whole chains as deleted
// rec_status: X-Delete; I-Invalid; blank-Valid
coreTmpBean.updMsgStatus(flightId, true, CONST_STAT_DEL);
} else {
// mark specific message as deleted
coreTmpBean.updMsgStatus(flightId, false, CONST_STAT_DEL);
}
} else {
// if return message, update/insert
if (HpEKConstants.HOPO.equals(event.getArrStn())
&& HpEKConstants.HOPO.equals(event.getDepStn())) {
// if flightId is return flight
if (HpEKConstants.HOPO.equals(flightId.getArrStn())
&& HpEKConstants.HOPO.equals(flightId.getDepStn())) {
// loop to check return flight existing or not
boolean isExisting = false;
for (EntDbCoreTmp item : tempMessages) {
if (item.getDepNum() == flightId.getDepNum().intValue()) {
//coreTmpBean.edit(item);
isExisting = true;
break;
}
}
// if no record to update, create new return record
if (!isExisting) {
returnMsg = new EntDbCoreTmp();
returnMsg.setCxcd(flightId.getCxCd());
returnMsg.setFltNum(flightId.getFltNum());
returnMsg.setFltSuffix(flightId.getFltSuffix());
returnMsg.setFltDate(fldaUtc);
returnMsg.setDepStn(event.getDepStn());
returnMsg.setArrStn(event.getArrStn());
returnMsg.setLegNum(flightId.getLegNum().intValue());
returnMsg.setDepNum(flightId.getDepNum().intValue());
returnMsg.setSchArr(stoa);
returnMsg.setSchDep(stod);
returnMsg.setRecStatus(CONST_STAT_DEF);
coreTmpBean.create(returnMsg);
}
}
} else if (!flightId.getArrStn().equals(event.getArrStn())
|| !flightId.getDepStn().equals(event.getDepStn())) {
// if the station changed, mark old record as X
EntDbCoreTmp msgRecord = tempMessages.get(0);
msgRecord.setRecStatus(CONST_STAT_DEL);
coreTmpBean.edit(msgRecord);
// return flight change to normal flight message
if (HpEKConstants.HOPO.equals(flightId.getArrStn())
&& HpEKConstants.HOPO.equals(flightId.getDepStn())) {
// need to send a delete message to ceda to delete return record
_msgActionType = ACTIONTYPE.D;
_actionType = CONST_DELETE;
}
// create new changed station record into temp table
/*tempMsg = new EntDbCoreTmp();
tempMsg.setCxcd(flightId.getCxCd());
tempMsg.setFltNum(flightId.getFltNum());
tempMsg.setFltSuffix(flightId.getFltSuffix());
tempMsg.setFltDate(fldaUtc);
tempMsg.setDepStn(event.getDepStn());
tempMsg.setArrStn(event.getArrStn());
tempMsg.setLegNum(flightId.getLegNum().intValue());
tempMsg.setDepNum(flightId.getDepNum().intValue());
tempMsg.setSchArr(stoa);
tempMsg.setSchDep(stod);
tempMsg.setRecStatus(' ');
coreTmpBean.create(tempMsg);*/
} else {
// update record (if header changed in body, take body value)
EntDbCoreTmp msgRecord = tempMessages.get(0);
boolean isChanged = false;
// update carrier
if (!msgRecord.getCxcd().equals(event.getCxCd())) {
msgRecord.setCxcd(event.getCxCd());
isChanged = true;
}
// update flight number
if (!msgRecord.getFltNum().equals(event.getFltNum())) {
msgRecord.setFltNum(event.getFltNum());
isChanged = true;
}
// update flight suffix
if (event.getFltSuffix() != null
&& !event.getFltSuffix().equals(msgRecord.getFltSuffix())) {
msgRecord.setFltSuffix(event.getFltSuffix());
isChanged = true;
}
// update flight date
if (!msgRecord.getFltDate().equals(fldaUtc)) {
msgRecord.setFltDate(fldaUtc);
isChanged = true;
}
// update arrStn
if (!msgRecord.getArrStn().equals(event.getArrStn())) {
msgRecord.setArrStn(event.getArrStn());
isChanged = true;
}
// update depStn
if (!msgRecord.getDepStn().equals(event.getDepStn())) {
msgRecord.setDepStn(event.getDepStn());
isChanged = true;
}
// update legNum
if (msgRecord.getLegNum() != event.getLegNum().intValue()) {
msgRecord.setLegNum(event.getLegNum());
isChanged = true;
}
// update depNum
if (msgRecord.getDepNum() != event.getDepNum().intValue()) {
msgRecord.setDepNum(event.getDepNum().intValue());
isChanged = true;
}
// schedule arr/dep
msgRecord.setSchArr(stoa);
msgRecord.setSchDep(stod);
if (isChanged || msgRecord.getRecStatus() == CONST_STAT_DEL) {
msgRecord.setRecStatus(CONST_STAT_DEF);
coreTmpBean.edit(msgRecord);
}
}
}
}
/**
* Info Populate
* =======================================================================
* According to action type and status
* Process and format message and send back to Ceda:
* Only when actionType is delete and contains HOPO will perform delete
* When body.org3 = body.des3, regarding header, handle as return flight
* Via message, will only pass via info (all rest exclude)
* Only contains HOPO message, will give full info
* ========================================================================
*/
// ==========================================================
// infobjgeneric - main for flight search
// ==========================================================
// Airline
String carrier = "";
if (flightId.getCxCd().length() == 2 || flightId.getCxCd().length() == 3) {
carrier = flightId.getCxCd();
}
// Flight number in Ceda format
String fltn = HpUfisUtils.formatCedaFltn(flightId.getFltNum());
if (carrier.length() == 3) {
infobjgeneric.setFLNO(carrier + fltn);
} else {
infobjgeneric.setFLNO(carrier + " " + fltn);
}
// Suffix
if (HpUfisUtils.isNotEmptyStr(flightId.getFltSuffix())) {
infobjgeneric.setFLNS(flightId.getFltSuffix());
// 2013-08-19 updated by JGO - adding suffix info to flno as well
// FLNO format: airline code(3) + flight number(5) + suffix(1)
if (fltn.length() == 5) {
infobjgeneric.setFLNO(infobjgeneric.getFLNO() + flightId.getFltSuffix());
} else if (fltn.length() == 4) {
infobjgeneric.setFLNO(infobjgeneric.getFLNO() + " " + flightId.getFltSuffix());
} else if (fltn.length() == 3) {
infobjgeneric.setFLNO(infobjgeneric.getFLNO() + " " + " " + flightId.getFltSuffix());
}
}
// FLDA(local) -> FLUT(utc)
//ufisCalendar.setTime(flightId.getFltDate().getValue());
//infobjgeneric.setFLDA(ufisCalendar.getCedaDateString());
infobjgeneric.setFLUT(fldaUtc);
// ADID
if (HpEKConstants.HOPO.equalsIgnoreCase(flightId.getDepStn())
&& HpEKConstants.HOPO.equalsIgnoreCase(flightId.getArrStn())) {
//Return Flight /TAxi
infobjgeneric.setADID(ADID.B);
infobjgeneric.setORG3(HpEKConstants.HOPO);
infobjgeneric.setDES3(HpEKConstants.HOPO);
// depNum
infobjgeneric.setDEPN(String.valueOf(flightId.getDepNum()));
} else if (HpEKConstants.HOPO.equalsIgnoreCase(flightId.getArrStn())) {
//Arival
infobjgeneric.setADID(ADID.A);
infobjgeneric.setDES3(HpEKConstants.HOPO);
// depNum
infobjgeneric.setDEPN(String.valueOf(flightId.getDepNum()));
} else if (HpEKConstants.HOPO.equalsIgnoreCase(flightId.getDepStn())) {
//Departure
infobjgeneric.setADID(ADID.D);
infobjgeneric.setORG3(HpEKConstants.HOPO);
// depNum
infobjgeneric.setDEPN(String.valueOf(flightId.getDepNum()));
}
// if it is via delete message, change ceda actionType to null (ceda decides what to do)
if (infobjgeneric.getADID() == null && CONST_DELETE.equalsIgnoreCase(_actionType) ) {
_msgActionType = null;
}
/**
* Find the flight chains in temp table(exclude return flight)
* CxCd
* FltNum
* FltSuffix
* FltDate
* DepStn != HOPO
* ArrStn != HOPO
*/
List<EntDbCoreTmp> msgChains = coreTmpBean.getMsgChainById(flightId);
/**
* If incoming message does not contain HOPO info
* Then check HOPO flight existing in db or not to get ADID, ORG3 or DES3
*/
// if via message coming first than HOPO, skip
//if (infobjgeneric.getADID() == null && msgChains != null && msgChains.size() > 0) {
if (msgChains != null && msgChains.size() > 0) {
// boolean isHopoFound = false;
boolean isHopoFoundInDepStn = false;
boolean isHopoFoundInArrStn = false;
for (EntDbCoreTmp item : msgChains) {
if (HpEKConstants.HOPO.equals(item.getArrStn())) {
infobjgeneric.setADID(ADID.A);
infobjgeneric.setDES3(HpEKConstants.HOPO);
// depNum
infobjgeneric.setDEPN(String.valueOf(item.getDepNum()));
// isHopoFound = true;
isHopoFoundInArrStn = true;
} else if (HpEKConstants.HOPO.equals(item.getDepStn())) {
infobjgeneric.setADID(ADID.D);
infobjgeneric.setORG3(HpEKConstants.HOPO);
// depNum
infobjgeneric.setDEPN(String.valueOf(item.getDepNum()));
// isHopoFound = true;
isHopoFoundInDepStn = true;
}
}
// if (!isHopoFound) {
if (!(isHopoFoundInDepStn || isHopoFoundInArrStn)) {
LOG.debug("Message Skipped due to Via message coming first than HOPO message.");
//LOG.debug("Message details: \n{}", _flightXml);
return false;
}
// 2013-09-13 updated by JGO - handle circular flight
// ====================================================
// if ulmate compressing of VIAs resulted in DXB - DXB
// if last leg > 1 then
// conclude is circular
// ====================================================
if (HpEKConstants.HOPO.equals(infobjgeneric.getORG3())
&& HpEKConstants.HOPO.equals(infobjgeneric.getDES3())) {
// treat as arrival flight
if (!HpEKConstants.HOPO.equals(flightId.getArrStn())) {
// remove the last leg of the Chains
msgChains.remove(msgChains.size() - 1);
infobjgeneric.setADID(ADID.D);
infobjgeneric.setDES3(null);
} else {
// treat as departure flight
if (flightId.getLegNum().intValue() > 1) {
// remove to keep only current message
msgChains = null;
infobjgeneric.setADID(ADID.A);
infobjgeneric.setORG3(null);
}
}
}
}
/**
* 2013-12-23 updated by JGO - Store all station info into flt_daily
*
*/
String headFlno = "";
String eventFlno = "";
String eventFlut = "";
// CEDA format flno from message header(FlightId)
headFlno = HpUfisUtils.formatCedaFlno(flightId.getCxCd(),
HpUfisUtils.formatCedaFltn(flightId.getFltNum()),
flightId.getFltSuffix());
if (!CONST_DELETE.equalsIgnoreCase(_actionType)) {
// CEDA format flno from message event
eventFlno = HpUfisUtils.formatCedaFlno(event.getCxCd(),
HpUfisUtils.formatCedaFltn(event.getFltNum()),
event.getFltSuffix());
// flut
ufisCalendar.setTime(event.getFltDate().getValue());
eventFlut = ufisCalendar.getCedaDateString();
}
// build flight daily query critiera (query by flightId)
EntFlightDailyDTO dto = new EntFlightDailyDTO();
dto.setFlightNumber(headFlno);
dto.setFltOrg3(flightId.getDepStn());
dto.setFltDes3(flightId.getArrStn());
dto.setLegNum(String.valueOf(flightId.getLegNum()));
dto.setFlut(fldaUtc);
// query from flt_daily table to insert/update record (data store by event)
EntDbFlightDaily fltDaily = fltDailyBean.getFltDaily(dto);
if (fltDaily == null) {
fltDaily = new EntDbFlightDaily();
fltDaily.setCreatedUser(dtfl);
fltDailyBean.persist(fltDaily);
}
// fill the via info
String nexi = "";
boolean isViaXafFound = false;
if (!CONST_DELETE.equalsIgnoreCase(_actionType)) {
fltDaily.setFltNumber(eventFlno);
fltDaily.setFltOrigin3(event.getDepStn());
fltDaily.setFltDest3(event.getArrStn());
fltDaily.setDepNum(String.valueOf(event.getDepNum()));
fltDaily.setLegNum(String.valueOf(event.getLegNum()));
fltDaily.setFlut(eventFlut);
fltDaily.setAct3(event.getAcSubType());
fltDaily.setFltServiceType(event.getServiceType());
fltDaily.setIsta(event.getFltStatus());
fltDaily.setRecStatus(" ");
// registration
if (event.getTailNo() != null && event.getTailNo().getValue() != null) {
if (event.getTailNo().getValue().matches(PATTERN_REGN)) {
fltDaily.setFltRegn("");
} else {
fltDaily.setFltRegn(event.getTailNo().getValue());
}
} else {
fltDaily.setFltRegn("");
}
// flda
if (event.getFltDateLocal() != null) {
ufisCalendar.setTime(event.getFltDateLocal().getValue());
fltDaily.setFlda(ufisCalendar.getCedaDateString());
} else {
// if ADID is D, refer from STOD, others STOA (yyyyMMdd)
if (ADID.D == infobjgeneric.getADID()) {
if (HpUfisUtils.isNotEmptyStr(fldaFromStod)) {
fltDaily.setFlda(fldaFromStod);
}
} else {
if (HpUfisUtils.isNotEmptyStr(fldaFromStoa)) {
fltDaily.setFlda(fldaFromStoa);
}
}
}
// flight duration (Duration from airborne to landing in minutes)
if (event.getFltTime() != null && event.getFltTime().getValue() != null) {
fltDaily.setFltDuration(new BigDecimal(event.getFltTime()
.getValue()));
}
// schedule block time (off block to on block in minutes)
if (event.getBlkTimeOrig() != null && event.getBlkTimeOrig().getValue() != null) {
fltDaily.setScheOffOnblockDuration(new BigDecimal(event
.getBlkTimeOrig().getValue()));
}
// actual block time (off block to on block in minutes)
if (event.getBlkTimeAct() != null && event.getBlkTimeAct().getValue() != null) {
fltDaily.setActualOffOnblockDuration(new BigDecimal(event
.getBlkTimeAct().getValue()));
}
// TaxiOut/TaxiIn
if (event.getTaxiOut() != null) {
fltDaily.setExot(new BigDecimal(event.getTaxiOut().getValue()));
}
if (event.getTaxiIn() != null) {
fltDaily.setExit(new BigDecimal(event.getTaxiIn().getValue()));
}
// flight remark
StringBuilder viaRemark = new StringBuilder();
for (FlightEvent.Events.Remark r : event.getRemark()) {
viaRemark.append(r.getValue());
viaRemark.append(" ");
}
fltDaily.setFltRemarks(viaRemark.toString());
// supplement remark
StringBuilder viaSiRemarkBuild = new StringBuilder();
for (FlightEvent.Events.SiRemark remark : event.getSiRemark()) {
viaSiRemarkBuild.append(remark.getValue());
viaSiRemarkBuild.append(" ");
}
fltDaily.setFltSupplementRemarks(viaSiRemarkBuild.toString());
// schedule block timing
for (SchdDateTime schedule : event.getSchdDateTime()) {
ufisCalendar.setTime(schedule.getValue());
if ("Arrival".equalsIgnoreCase(schedule.getType())) {
fltDaily.setSibtLoc(ufisCalendar.getTime());
// Convert to UTC datetime
// ufisCalendar.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC,
// EnumTimeInterval.Hours);
// fltDaily.setSibt(ufisCalendar.getTime());
try {
fltDaily.setSibt(df1.parse(df.format(ufisCalendar.getTime())));
} catch (ParseException e) {
LOG.warn("Cannot parse datetime: {}", e.getMessage());
}
} else if ("Departure".equalsIgnoreCase(schedule.getType())) {
fltDaily.setSobtLoc(ufisCalendar.getTime());
// Convert to UTC datetime
// ufisCalendar.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC,
// EnumTimeInterval.Hours);
// fltDaily.setSobt(ufisCalendar.getTime());
try {
fltDaily.setSobt(df1.parse(df.format(ufisCalendar.getTime())));
} catch (ParseException e) {
LOG.warn("Cannot parse datetime: {}", e.getMessage());
}
}
}
// mvtDatetime
for (FlightEvent.Events.MvtDateTime mvtDateTime : event.getMvtDateTime()) {
String mvtType = mvtDateTime.getType();
if (HpUfisUtils.isNullOrEmptyStr(mvtType)) {
continue;
}
Date tempDate = null;
if (mvtDateTime.getValue() != null) {
ufisCalendar.setTime(mvtDateTime.getValue());
// Convert to UTC datetime
// ufisCalendar.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC,
// EnumTimeInterval.Hours);
// tempDate = ufisCalendar.getTime();
try {
tempDate = df1.parse(df.format(ufisCalendar.getTime()));
} catch (ParseException e) {
LOG.warn("Cannot parse datetime: {}", e.getMessage());
}
}
switch (mvtType) {
case "AirborneEst":
// estimate airborne
fltDaily.setEtotLoc(ufisCalendar.getTime());
fltDaily.setEtot(tempDate);
break;
case "AirborneAct":
// actual airborne
fltDaily.setAtotLoc(ufisCalendar.getTime());
fltDaily.setAtot(tempDate);
break;
case "LandedEst":
// estimate landing
fltDaily.setEldtLoc(ufisCalendar.getTime());
fltDaily.setEldt(tempDate);
break;
case "LandedAct":
// actual landing
fltDaily.setAldtLoc(ufisCalendar.getTime());
fltDaily.setAldt(tempDate);
break;
case "OnBlocksEst":
// estimate in block
fltDaily.setEibtLoc(ufisCalendar.getTime());
fltDaily.setEibt(tempDate);
break;
case "OnBlocksAct":
// actual in block
fltDaily.setAibtLoc(ufisCalendar.getTime());
fltDaily.setAibt(tempDate);
break;
case "OffBlocksEst":
// estimate off block
fltDaily.setEobtLoc(ufisCalendar.getTime());
fltDaily.setEobt(tempDate);
break;
case "OffBlocksAct":
// actual off block
fltDaily.setAobtLoc(ufisCalendar.getTime());
fltDaily.setAobt(tempDate);
break;
case "StartTaxiAct":
// actual time of starting taxing
fltDaily.setAsttLoc(ufisCalendar.getTime());
fltDaily.setAstt(tempDate);
break;
case "NextInformation":
nexi = df.format(ufisCalendar.getTime());
isXafFound = true;
break;
}
}
} else {
fltDaily.setFltNumber(headFlno);
fltDaily.setFltOrigin3(flightId.getDepStn());
fltDaily.setFltDest3(flightId.getArrStn());
fltDaily.setDepNum(String.valueOf(flightId.getDepNum()));
fltDaily.setLegNum(String.valueOf(flightId.getLegNum()));
fltDaily.setFlut(fldaUtc);
fltDaily.setRecStatus("X");
}
fltDaily.setUpdatedUser(dtfl);
fltDailyBean.update(fltDaily);
// Event, Extension and DelayCode related table only store for non-Hopo by interface
if (!HpEKConstants.HOPO.equalsIgnoreCase(flightId.getDepStn())
&& !HpEKConstants.HOPO.equalsIgnoreCase(flightId.getArrStn())) {
if (!CONST_DELETE.equalsIgnoreCase(_actionType)) {
// XAFTAB related info
// AcOwner
String acow = "";
String acex = "";
if (event.getAcOwner() != null) {
acow = event.getAcOwner();
isViaXafFound = true;
}
// AcVersion
if (event.getAcVersion() != null) {
acex = event.getAcVersion();
isViaXafFound = true;
}
if (isViaXafFound) {
// find via related xaftab info
EntDbXaftab xaftab = xaftabBean.findByFltDailyId(fltDaily.getId());
if (xaftab == null) {
xaftab = new EntDbXaftab();
xaftab.setIdfd(fltDaily.getId());
xaftabBean.persist(xaftab);
}
xaftab.setIdfd(fltDaily.getId());
xaftab.setAcow(acow);
xaftab.setAcex(acex);
xaftab.setNexi(nexi);
xaftabBean.update(xaftab);
}
// DCFTAB related info
// Get Delays
if (flightEvent.getDelays() != null) {
for (FlightEvent.Delays.Delay delay : flightEvent.getDelays().getDelay()) {
EntDbDcftab dcftab = dcftabBean.findByFltDailyIdAndDelayCode(fltDaily.getId(), delay.getCode());
if (dcftab == null) {
dcftab = new EntDbDcftab();
dcftab.setUsec(dtfl);
dcftabBean.persist(dcftab);
}
dcftab.setIdfd(fltDaily.getId());
ufisCalendar.setTime(delay.getPostedOn());
dcftab.setCdat(ufisCalendar.getCedaString());
dcftab.setDeca(delay.getCode());
dcftab.setDura(String.format(FMT_DURA, delay.getAmount()));
dcftab.setUseu(dtfl);
dcftabBean.update(dcftab);
}
}
// FEVTAB related info
// RTG
if (event.getRtg() != null) {
EntDbFevtab fevtab = fevtabBean.findByFltDailyId(fltDaily.getId());
if (fevtab == null) {
fevtab = new EntDbFevtab();
fevtab.setUSEC(dtfl);
fevtabBean.persist(fevtab);
}
if (event.getRtg().getLastDoorCl() != null) {
ufisCalendar.setTime(event.getRtg().getLastDoorCl());
fevtab.setSTTM(df.format(ufisCalendar.getTime()));
}
fevtab.setSTNM("Ready to Go");
fevtab.setSTFL(event.getRtg().getValue());
fevtab.setSTRM("");
fevtab.setUSEU(dtfl);
fevtabBean.update(fevtab);
}
}
}
/**
* 2013-12-26 updated by JGO - Adding fltDaily id to CEDA message
*/
List<String> fltDailyIds = fltDailyBean.getFltDailyIds(dto);
if (fltDailyIds != null && fltDailyIds.size() > 0) {
for (String id : fltDailyIds) {
INFOBJFLTDAILY infobjfltdaily = new INFOBJFLTDAILY();
infobjfltdaily.setID(id);
infobjfltdailylist.getINFOBJFLTDAILY().add(infobjfltdaily);
}
}
// ============= infobjFlight ===============================
// infobjFlight - flight info update