if (vias.size() > 0 && !infobjFlight.getFTYP().equals("D")) {
// no matter msg action type is insert or update for via, will always be update
_msgActionType = ACTIONTYPE.U;
StringBuilder vial = new StringBuilder();
for (Iterator<FlightEvent> it = vias.iterator(); it.hasNext();) {
FlightEvent viaFlightEvent = it.next();
vial.append(createVia(viaFlightEvent, infobjFlight.getADID(), ufisCalendar));
}
//TODO check if the following is correct
//Check the VIAN from LegNum (is this correct ?)
//infobjFlight.setVIAN(flightId.getLegNum().toString());
infobjFlight.setVIAN(Integer.toString(vias.size()));
infobjFlight.setVIAL(vial.toString());
if (ADID.A.equals(infobjFlight.getADID())) {
LOG.info("VIA Found {} {} {} {}", new Object[]{infobjFlight.getADID(), vial.toString(), flightEvent.getFlightId().getDepStn(), flightEvent.getFlightId().getArrStn()});
} else {
LOG.info("VIA Found {} {} {} {}", new Object[]{infobjFlight.getADID(), flightEvent.getFlightId().getDepStn(), flightEvent.getFlightId().getArrStn(), vial.toString()});
}
}
//infobjFlight.setREMP(flightStatus);
infobjFlight.setREM1(flightStatus);
infobjFlight.setDEPN(event.getDepNum().toString());
List<FlightEvent.Events.SiRemark> siRemarks = event.getSiRemark();
StringBuilder siRemarkBuild = new StringBuilder();
for (Iterator<FlightEvent.Events.SiRemark> it = siRemarks.iterator(); it.hasNext();) {
FlightEvent.Events.SiRemark siRemark = it.next();
//TODO Check about if the Type is needed
siRemarkBuild.append(siRemark.getValue());
}
infobjFlight.setREM2(siRemarkBuild.toString());
// 2013-04-18 updated by JGO - change fevtab to fevtab list
// TODO check where to put the flag and remark
//Door Flag
//infojfevtab.setSTFL(event.getDorFlag());
//infojfevtab.setSTRM(event.getDorRemark());
//Cabin /Cargo doors times
/*if (event.getCABINDOORCLOSURE() != null) {
INFOJFEVTAB cabinDoor = new INFOJFEVTAB();
ufisCalendar.setTime(event.getCABINDOORCLOSURE().getValue());
cabinDoor.setSTNM("CABIN DOOR CLOSURE");
cabinDoor.setSTTM(ufisCalendar.getCedaString());
cabinDoor.setSTFL("");
cabinDoor.setSTRM("");
infojfevtablist.getINFOJFEVTAB().add(cabinDoor);
}
if (event.getCARGODOORCLOSURE() != null) {
INFOJFEVTAB cargoDoor = new INFOJFEVTAB();
ufisCalendar.setTime(event.getCARGODOORCLOSURE().getValue());
cargoDoor.setSTNM("CARGO DOOR CLOSURE");
cargoDoor.setSTTM(ufisCalendar.getCedaString());
cargoDoor.setSTFL("");
cargoDoor.setSTRM("");
infojfevtablist.getINFOJFEVTAB().add(cargoDoor);
}*/
//Flight Duration
infobjFlight.setFDUR(event.getFltTime().getValue().toString());
//Schedule/Actual Block Time (min)
infobjFlight.setSOOB(event.getBlkTimeOrig().getValue().toString());
infobjFlight.setAOOB(event.getBlkTimeAct().getValue().toString());
// Units to measurement for the fuel
List<FlightEvent.Events.Fuel> fuels = event.getFuel();
// if (fuels.size() > 1) {
// LOG.info("FlightEvent with Fuel size > 1");
// }
//TODO for the moment CEDA can Habdle only one Fuel Record
for (Iterator<FlightEvent.Events.Fuel> it = fuels.iterator(); it.hasNext();) {
FlightEvent.Events.Fuel fuel = it.next();
infojxaftab.setFUEU(fuel.getUnits());
infojxaftab.setFUET(fuel.getType());
}
//Get Delays
List<FlightEvent.Delays.Delay> delays = flightEvent.getDelays().getDelay();
for (Iterator<FlightEvent.Delays.Delay> it = delays.iterator(); it.hasNext();) {
FlightEvent.Delays.Delay delay = it.next();
INFOJDCFTAB infojdcftab = new INFOJDCFTAB();
ufisCalendar.setTime(delay.getPostedOn());
infojdcftab.setCDAT(ufisCalendar.getCedaString());
infojdcftab.setDECA(delay.getCode());
//TODO Check why Type is not needed
//infojdcftab.setDURA(delay.getType());
//Format to 0000
infojdcftab.setDURA(String.format("%04d", delay.getAmount()));
infojdcftablist.getINFOJDCFTAB().add(infojdcftab);
}
//Get Operational Times
List<FlightEvent.Events.MvtDateTime> mvtDateTimes = event.getMvtDateTime();
/*
Actual Take Off Time (Airline) ATON ,AirborneAct – Actual Aiborne time
Estimated Landing Time (Airline) ELDN,LandedEst – Estimated landing time
Actual Landing Time (Airline) ALDN,LandedAct – Actual landing time
Estimated In-block Time (Airline) EIBN,OnBlocksAct – Actual on block time
Actual In-block Time (Airline) AIBN,OnBlocksEst – Estimated on block time
Estimated Off-block Time (Airline) EOBN,OffBlocksEst – Estimated off block time
Actual Off-block Time (Airline) AOBN,OffBlocksAct – Actual off block time
Estimated Take Off Time (Airline) ETON,AirborneEst – Estimated Airborne time
Actual Start Of Taxi Time (Airline) ASTN,StartTaxiAct – Actual time of start taxing
NXTI , NextInformation – Time at which next information for the flight shall be made available
*
*/
for (Iterator<FlightEvent.Events.MvtDateTime> it = mvtDateTimes.iterator(); it.hasNext();) {
FlightEvent.Events.MvtDateTime mvtDateTime = it.next();
String mvtType = mvtDateTime.getType();
ufisCalendar.setTime(mvtDateTime.getValue());
String cedaTime = ufisCalendar.getCedaString();
//LOG.info("MvtType {} ceda time {}", new Object[]{mvtType, afttab.getADID().toString()}, ufisCalendar.getCedaString());
switch (mvtType) {
case "AirborneAct":
infobjFlight.setATON(cedaTime);
break;
case "LandedEst":
infobjFlight.setELDN(cedaTime);
break;
case "LandedAct":
infobjFlight.setALDN(cedaTime);
break;
case "OnBlocksAct":
infobjFlight.setEIBN(cedaTime);
break;
case "OnBlocksEst":
infobjFlight.setAIBN(cedaTime);
break;
case "OffBlocksEst":
infobjFlight.setEOBN(cedaTime);
break;
case "OffBlocksAct":
infobjFlight.setAOBN(cedaTime);
break;
case "AirborneEst":
infobjFlight.setETON(cedaTime);
break;
case "StartTaxiAct":
infobjFlight.setASTN(cedaTime);
break;
case "NextInformation":
infobjFlight.setNXTI(cedaTime);
infojxaftab.setNEXI(cedaTime);
break;
}
}
} else {
LOG.info("FlightEven (event) size empty or > 1");
}
/* TODO
* if delete msg doesnt contain hopo, change action type to update and update via(maybe org and dest)
* if delete msg contains hopo, consider as flight delete?
*
*/
// Delete set infojflight
if (ACTIONTYPE.D == _msgActionType && aftFlight != null) {
//Airline
if (flightId.getCxCd().length() == 2) {
infobjFlight.setALC2(flightId.getCxCd());
} else {
infobjFlight.setALC3(flightId.getCxCd());
}
infobjFlight.setFLTN(HpUfisUtils.formatCedaFltn(flightId.getFltNum()));
//Suffix
if (HpUfisUtils.isNotEmptyStr(flightId.getFltSuffix())) {
infobjFlight.setFLNS(flightId.getFltSuffix());
}
// depNum
infobjFlight.setDEPN(String.valueOf(flightId.getDepNum()));
// adid
infobjFlight.setADID(ADID.fromValue(aftFlight.getAdid().toString()));
//Schedule Date / time
if (ADID.A.equals(infobjFlight.getADID())) {
infobjFlight.setSTOA(aftFlight.getStoa());
}
if (ADID.D.equals(infobjFlight.getADID())) {
infobjFlight.setSTOD(aftFlight.getStod());
}
/* TODO What we should for Return Flight ? */
if (ADID.B.equals(infobjFlight.getADID())) {
infobjFlight.setSTOD(aftFlight.getStoa());
infobjFlight.setSTOA(aftFlight.getStod());
}
infobjFlight.setFLDA(aftFlight.getFlda());
// if delete msg contains hopo, flight delete, otherwise update via
if (HOPO.equalsIgnoreCase(flightId.getDepStn()) && HOPO.equalsIgnoreCase(flightId.getArrStn())) {
//Return Flight /TAxi
infobjFlight.setADID(ADID.B);
infobjFlight.setORG3(flightId.getDepStn());
infobjFlight.setDES3(flightId.getDepStn());
} else if (HOPO.equalsIgnoreCase(flightId.getArrStn())) {
//Arival
infobjFlight.setADID(ADID.A);
infobjFlight.setORG3(flightId.getDepStn());
infobjFlight.setDES3(flightId.getArrStn());
} else if (HOPO.equalsIgnoreCase(flightId.getDepStn())) {
//Departure
infobjFlight.setADID(ADID.D);
infobjFlight.setORG3(flightId.getDepStn());
infobjFlight.setDES3(flightId.getArrStn());
} else {
// via delete message (change action type to update)
_msgActionType = ACTIONTYPE.U;
// remove from cache
removeFlight(flightId);
// get all flighs msg relate to this flight from cache
List<FlightEvent> flights = findFlight(flightEvent);
if (flights != null && flights.size() > 0) {
// no matter msg action type is insert or update for via, will always be update
_msgActionType = ACTIONTYPE.U;
StringBuilder vial = new StringBuilder();
Iterator<FlightEvent> it = flights.iterator();
boolean isFirst = true;
while (it.hasNext()) {
FlightEvent flight = it.next();
// first record
if (isFirst) {
infobjFlight.setORG3(flight.getFlightId().getDepStn());
isFirst = false;
}
// last record
if (!it.hasNext()) {
infobjFlight.setDES3(flight.getFlightId().getArrStn());
break;
}
// update vias
vial.append(createVia(flight, infobjFlight.getADID(), ufisCalendar));
}