Package com.ufis_as.exco

Examples of com.ufis_as.exco.INFOBJFLIGHT


    boolean isTransferred = false;
    try {
      HpUfisCalendar ufisCalendar = new HpUfisCalendar();
      ufisCalendar.setCustomFormat(HpEKConstants.EDGS_TIME_FORMAT);
 
      INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
      MSGOBJECTS msgobjects = new MSGOBJECTS();
      INFOBJGENERIC infobjgeneric = new INFOBJGENERIC();
      INFOJXAFTAB infojxaftab = new INFOJXAFTAB();
      INFOBJFUELSTATUS infofuelstatus = new INFOBJFUELSTATUS();
      INFOJFEVTABLIST  infojfevtablist = new INFOJFEVTABLIST();
      Boolean xafFound = false;
      Boolean fevFound = false;
     
      /*
       * REGN Java program has to trim the hyphen char '-'
       */
      infobjFlight.setREGN(aftFlight.getRegn());
     
      /*
       * Change to number for both in order to compare when use to search
       * flight
       */
      //infobjFlight.setFLTN(flightEvent.getEGDSBODY().getFNR());
      infobjFlight.setALC2(aftFlight.getAlc2());
      infobjFlight.setALC3(aftFlight.getAlc3());
      infobjFlight.setFLDA(aftFlight.getFlda());
 
      infobjFlight.setFLTN(aftFlight.getFltn());
      infobjFlight.setORG3(flightEvent.getEGDSBODY().getDEP());
      if ("DXB".equals(flightEvent.getEGDSBODY().getDEP()) && "DXB".equals(flightEvent.getEGDSBODY().getARR())) {
        infobjFlight.setADID(ADID.B);
      } else if ("DXB".equals(flightEvent.getEGDSBODY().getDEP())) {
        infobjFlight.setADID(ADID.D);
      } else {
        infobjFlight.setADID(ADID.fromValue(aftFlight.getAdid().toString()));
      }
 
      // according to type settle down return message
      if (flightEvent.getEGDSBODY().getTYPE() != null) {
        switch (flightEvent.getEGDSBODY().getTYPE()) {
        case MVT:
          /* 
           * OUT -> AOBN
           * OFF -> ATON
           * ON  -> ALDN
           * IN  -> AIBN
           */
          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getTRIGEVT())) {
            String trigevt = flightEvent.getEGDSBODY().getTRIGEVT();
            if (trigevt.contains("OUT")) {
              infobjFlight.setAOBN(flightEvent.getEGDSBODY().getATA());
            } else if (trigevt.contains("OFF")) {
              infobjFlight.setATON(flightEvent.getEGDSBODY().getATA());
            } else if (trigevt.contains("ON")) {
              infobjFlight.setALDN(flightEvent.getEGDSBODY().getATA());
            } else if (trigevt.contains("IN")) {
              infobjFlight.setAIBN(flightEvent.getEGDSBODY().getATA());
            }
          }
         
          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getFOB())) {
            infojxaftab.setFUOB(flightEvent.getEGDSBODY().getFOB());
            xafFound = true;
          }
         
          // Cargo Door closed and Cabin Door closed
          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getCARD())) {
            ufisCalendar.setTime(flightEvent.getEGDSBODY().getCARD(), ufisCalendar.getCustomFormat());
            INFOJFEVTAB cargoDoor = new INFOJFEVTAB();
            cargoDoor.setSTNM("CARGO DOOR CLOSED");
            cargoDoor.setSTTM(ufisCalendar.getCedaString());
            infojfevtablist.getINFOJFEVTAB().add(cargoDoor);
            fevFound = true;
          }
          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getCABD())) {
            ufisCalendar.setTime(flightEvent.getEGDSBODY().getCABD(), ufisCalendar.getCustomFormat());
            INFOJFEVTAB cabinDoor = new INFOJFEVTAB();
            cabinDoor.setSTNM("CABIN DOOR CLOSED");
            cabinDoor.setSTTM(ufisCalendar.getCedaString());
            infojfevtablist.getINFOJFEVTAB().add(cabinDoor);
            fevFound = true;
          }
          break;
         
        case PROGRESSREPORT:
//          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getETA())) {
//            infobjFlight.setELDN(flightEvent.getEGDSBODY().getETA());
//          }
          infobjFlight.setEIBN(flightEvent.getEGDSBODY().getETA());
          break;
         
        case LOADACC:
          infojxaftab.setLSHT(flightEvent.getEGDSBODY().getLOADSHEET());
//          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getZFW())) {
//            infojxaftab.setZFWT(flightEvent.getEGDSBODY().getZFW());
//            xafFound = true;
//          }
//          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSBODY().getTOW())) {
//            infojxaftab.setTOWT(flightEvent.getEGDSBODY().getTOW());
//            xafFound = true;
//          }
          break;
         
        case ROUTE:
          // confirm message from pilot that crew is on board
          // due to if NON-EK need to ignore whole message
          infobjgeneric.setALC2("EK");
          if (HpUfisUtils.isNotEmptyStr(flightEvent.getEGDSHEADER().getTIMESTAMP())) {
            ufisCalendar.setTime(flightEvent.getEGDSHEADER().getTIMESTAMP(), ufisCalendar.getCustomFormat());
            INFOJFEVTAB route = new INFOJFEVTAB();
            route.setSTNM("Route Request");
            route.setSTRM("<ACR>");
            route.setSTTM(ufisCalendar.getCedaString());
            infojfevtablist.getINFOJFEVTAB().add(route);
            fevFound = true;
          }
          break;
         
        case FUEL:
          // message send datetime
          ufisCalendar.setTime(flightEvent.getEGDSHEADER().getTIMESTAMP(), ufisCalendar.getCustomFormat());
          infofuelstatus.setMSGSENDDATE(ufisCalendar.getCedaString());
          // regn
          infofuelstatus.setFLTREGN(aftFlight.getRegn());
          // alc2
          infofuelstatus.setAIRLINECODE2(aftFlight.getAlc2());
          // org3
          infofuelstatus.setFLTORIGIN3(aftFlight.getOrg3());
          // des3
          infofuelstatus.setFLTDEST3(aftFlight.getDes3());
          // trip_fuel
          infofuelstatus.setTRIPFUEL(flightEvent.getEGDSBODY().getTripFuel());
          // taxi_fuel
          infofuelstatus.setTAXIFUEL(flightEvent.getEGDSBODY().getTaxiFuel());
          // ramp_fuel
          infofuelstatus.setRAMPFUEL(flightEvent.getEGDSBODY().getRampFuel());
          // trm
          infofuelstatus.setTRM(flightEvent.getEGDSBODY().getTRM());
          // den
          infofuelstatus.setDEN(flightEvent.getEGDSBODY().getDEN());
          // rtw
          infofuelstatus.setRTW(flightEvent.getEGDSBODY().getRTW());
          break;
        }
      }
 
      /*
       * Set the fields that uniquely identify a flight the rest are done in
       * the UfisMarshal
       */
      infobjgeneric.setDEPN(infobjFlight.getDEPN());
      infobjgeneric.setREGN(infobjFlight.getREGN());
      msgobjects.setINFOBJFLIGHT(infobjFlight);
      if (xafFound) {
        msgobjects.setINFOJXAFTAB(infojxaftab);
      }
      if (fevFound) {
View Full Code Here


        return _msgActionType;
    }

    public boolean tranformFlight(FlightEvent flightEvent, EntDbAfttab aftFlight) {
        HpUfisCalendar ufisCalendar = new HpUfisCalendar();
        INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
        INFOJXAFTAB infojxaftab = new INFOJXAFTAB();
        INFOJDCFTABLIST infojdcftablist = new INFOJDCFTABLIST();
        //INFOJFEVTAB infojfevtab = new INFOJFEVTAB();
        //INFOJFEVTABLIST infojfevtablist = new INFOJFEVTABLIST();
        FlightEvent.FlightId flightId = flightEvent.getFlightId();
        if (flightId != null) {
            //Event Actuall Flight Data
            if (!flightEvent.getEvents().isEmpty() && flightEvent.getEvents().size() == 1) {
                FlightEvent.Events event = flightEvent.getEvents().get(0);
                //Service Type
                infobjFlight.setSTYP(event.getServiceType());
                //AC Type
                //IATA aircraft subtype as per SSIM
                infobjFlight.setACT3(event.getAcSubType());
                //afttab.setAct5(event.getAcVersion());
                // Registration
                //Action event.getTailNo().getActionType() ??
                //ActionType : Assigned
                // 2013-05-14 updated by JGO - if 4 digits regn, ignored
                if (event.getTailNo() != null && event.getTailNo().getValue() != null) {
                  if (event.getTailNo().getValue().length() == 4) {
                    infobjFlight.setREGN("");
                  } else {
                    infobjFlight.setREGN(event.getTailNo().getValue());
                  }
                }
                //A/C Owner
                infojxaftab.setACOW(event.getAcOwner());
                //A/C Version
                infojxaftab.setACEX(event.getAcVersion());
                //
                //TaxiOut / IN
                if (event.getTaxiOut() != null) {
                    infobjFlight.setEXOT(event.getTaxiOut().getValue().toString());
                }
                if (event.getTaxiIn() != null) {
                    infobjFlight.setEXIT(event.getTaxiIn().getValue().toString());
                }
                //Flight Status
                /*
                 *
                 CODE STATUS_DESCRIPTION
                 1 RTNG RETURNED, IN FLIGHT
                 2 DVTG DIVERTED, IN FLIGHT
                 3 PDEP NOT YET DEPARTED
                 4 OFBL TAXIING FOR TAKEOFF
                 5 ENRT IN FLIGHT
                 6 LAND LANDED AND TAXIING
                 7 ARVD ARRIVED
                 8 CNLD CANCELLED
                 9 DVTD ARRIVED DIVERSION AIRPORT
                 10 DNLD TAXIING DIVERSION AIRPORT
                 11 RROF REROUTED, TAXIING
                 12 RRTG REROUTED, IN FLIGHT
                 13 RRTD REROUTED, LANDED
                 14 RTDR RETURNED TO STAND
                 15 RTND RETURNED DEPARTURE AIRPORT
                 16 DLND DIVERTED
                 17 RRLD REROUTED AND LANDING
                 */
                String flightStatus = event.getFltStatus();
                //TODO how will identify Schedule from Operational
                infobjFlight.setFTYP("S");
                switch (flightStatus) {
                    case "RTNG":
                    case "PRF":
                    case "RRTG":
                    case "RRTD":
                    case "RTND":
                    case "RRLD":
                        infobjFlight.setADID(ADID.B);
                        infobjFlight.setFTYP("Z");
                        break;
                    case "CNLD":
                        infobjFlight.setFTYP("X");
                        break;
                    case "DVTG":
                    case "DVTD":
                    case "DNLD":
                        infobjFlight.setFTYP("D");
                        break;
                }
                //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());
                }
                //Arrival , Departure , Orig, Des
                if (flightId.getDepStn().equalsIgnoreCase(HOPO) && flightId.getArrStn().equalsIgnoreCase(HOPO)) {
                    //Return Flight /TAxi
                    infobjFlight.setADID(ADID.B);
                    infobjFlight.setORG3(flightId.getDepStn());
                    infobjFlight.setDES3(flightId.getDepStn());
                } else if (flightId.getArrStn().equalsIgnoreCase(HOPO)) {
                    //Arival
                    infobjFlight.setADID(ADID.A);
                    infobjFlight.setORG3(flightId.getDepStn());
                    infobjFlight.setDES3(flightId.getArrStn());
                } else if (flightId.getDepStn().equalsIgnoreCase(HOPO)) {
                    //Departure
                    infobjFlight.setADID(ADID.D);
                    infobjFlight.setORG3(flightId.getDepStn());
                    infobjFlight.setDES3(flightId.getArrStn());
                } else {
                    // Check if this is VIA  or RETURN ?
                    //In case of a Return we would have set ADID just before
                    //if (infobjFlight.getADID() == null) {
                        //LOG.info("Flight which a part of a VIA detected {}", flightStatus);
                  if (aftFlight != null) {
                    infobjFlight.setADID(ADID.fromValue(aftFlight.getAdid().toString()));
                  } else {
                        infobjFlight.setADID(ADID.D);
                  }
                        //return true;
                    //}
                }
                //Schedule Date / time
                ufisCalendar.setTime(event.getSchdDateTime().get(0).getValue());
                if (infobjFlight.getADID() != null) {
                  if (ADID.A.equals(infobjFlight.getADID())) {
                      infobjFlight.setSTOA(ufisCalendar.getCedaString());
                  }
                  if (ADID.D.equals(infobjFlight.getADID())) {
                      infobjFlight.setSTOD(ufisCalendar.getCedaString());
                  }
                  /* TODO What we should for Return Flight ? */
                  if (ADID.B.equals(infobjFlight.getADID())) {
                      infobjFlight.setSTOD(ufisCalendar.getCedaString());
                      infobjFlight.setSTOA(ufisCalendar.getCedaString());
                  }
                }
                ufisCalendar.setTime(event.getFltDate().getValue());
                infobjFlight.setFLDA(ufisCalendar.getCedaDateString());
               
                //Get The Vias from cache
                List<FlightEvent> vias = findFlightEventVia(flightEvent, infobjFlight.getADID());
                //TODO in UFIS we Store ORG /  DES  so
                //So we must get the First Leg from the Arrival VIA's in order to find original ORG
                //and the Last Leg from the Destination in order to find the Final DES
                //This should be for the times also
                //Do we need really this feature for this Application ?
                //In case of a DIV flight we should (CXX the middle VIA)
                //Being an EK flight, it would still have the final destination being DXB. Airlines
                //do not get traffic rights between none home airports,
                //unless the flight has ORG/DES ad the home airport.
                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));
                        }
                        //TODO check if the following is correct
                        //Check the VIAN from LegNum (is this correct ?)
                        //infobjFlight.setVIAN(flightId.getLegNum().toString());
                      infobjFlight.setVIAN(Integer.toString(flights.size() -1));
                        infobjFlight.setVIAL(vial.toString());
                        if (infobjFlight.getADID().equals(ADID.A)) {
                            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()});
                        }
                    }
                }
            }
           
            MSGOBJECTS msgobjects = new MSGOBJECTS();
            INFOBJGENERIC infobjgeneric = new INFOBJGENERIC();
            /* Set the fields that uniquely identify a flight
             * the rest are done in the UfisMarshal
             */
            infobjgeneric.setDEPN(infobjFlight.getDEPN());
            msgobjects.setINFOBJFLIGHT(infobjFlight);
            //msgobjects.setINFOJFEVTAB(infojfevtab);
            //msgobjects.setINFOJFEVTABLIST(infojfevtablist);
            msgobjects.setINFOJXAFTAB(infojxaftab);
            msgobjects.setINFOJDCFTABLIST(infojdcftablist);
View Full Code Here

    boolean isTransferred = false;
    try {
      HpUfisCalendar ufisCalendar = new HpUfisCalendar();
      ufisCalendar.setCustomFormat(HpEKConstants.EDGS_TIME_FORMAT);
 
      INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
      MSGOBJECTS msgobjects = new MSGOBJECTS();
      INFOBJGENERIC infobjgeneric = new INFOBJGENERIC();
      INFOJXAFTAB infojxaftab = new INFOJXAFTAB();
      //INFOBJFUELSTATUS infofuelstatus = new INFOBJFUELSTATUS();
      INFOJFEVTABLIST  infojfevtablist = new INFOJFEVTABLIST();
      Boolean xafFound = false;
      Boolean fevFound = false;
     
      boolean isValid = true;
      // Header and body are mandatory
      if (message.getEGDSHEADER() == null || message.getEGDSBODY() == null) {
        LOG.error("EGDS header and body are mandatory, cannot be null");
        //LOG.error("Message Dropped: \n{}", _flightXml);
        isValid = false;
      }
     
      // if non-EK flight, drop
        if (!HpEKConstants.EK_ALC3.equals(message.getEGDSBODY().getCRR())
            && !HpEKConstants.EK_ALC2.equals(message.getEGDSBODY().getCRR())) {
          LOG.debug("EGDS message dropped due to it's non-EK flight message");
          //LOG.error("Message Dropped: \n{}", _flightXml);
          isValid = false;
        }
       
        // timestamp
        if (HpUfisUtils.isNullOrEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
          LOG.debug("EGDS message dropped due to timestamp(header) is null or empty");
          //LOG.error("Message Dropped: \n{}", _flightXml);
          isValid = false;
        }
       
        // egds message type
        MSGTYPE type = message.getEGDSBODY().getTYPE();
        if (type == null) {
          LOG.debug("EGDS message dropped due to type field is null");
          //LOG.error("Message Dropped: \n{}", _flightXml);
          isValid = false;
        }
       
        // flight number and registration number
        String fltn = HpUfisUtils.formatCedaFltn(message.getEGDSBODY().getFNR());
        String regn = message.getEGDSBODY().getACR().replaceAll("-", "");
        // regn should be less than 6 digits
        if (HpUfisUtils.isNullOrEmptyStr(regn) || regn.length() > 6) {
          LOG.debug("EGDS message dropped due to regn is either empty(or null), or length greater than 6 digits");
          //LOG.error("Message Dropped: \n{}", _flightXml);
          isValid = false;
        }
       
        if (!isValid) {
          addExptInfo(EnumExceptionCodes.EMAND.name(), EnumExceptionCodes.EMAND.toString());
          return false;
        }
       
        // org3
        String org3 = message.getEGDSBODY().getDEP();
       
        // des3
        String des3 = message.getEGDSBODY().getARR();
       
        // adid
        ADID adid = null;
        if (HOPO.equals(message.getEGDSBODY().getDEP()) && HOPO.equals(message.getEGDSBODY().getARR())) {
          adid = ADID.B;
      } else if (HOPO.equals(message.getEGDSBODY().getDEP())) {
        adid = ADID.D;
      } else if (HOPO.equals(message.getEGDSBODY().getARR())) {
        adid = ADID.A;
      }
     
        /*
         * 2013-07-02 updated by JGO - departure and arrival station changed to non-mandatory in ICD
         * else {
        if (MSGTYPE.ROUTE != type) {
          LOG.debug("EGDS message dropped due to cannot identify flight adid by ARR tag and DEP tag");
          LOG.error("Message Dropped: \n{}", _flightXml);
              return false;
        }
      }
      */
       
        // According to type, build afttab flight search criteria and parameters
        EntDbAfttab criteriaParams = new EntDbAfttab();
        criteriaParams.setFltn(fltn);
        criteriaParams.setRegn(regn);
       
        // get the configurable time range offset
        int from = 0;
        int to = 0;
        if (MSGTYPE.MVT == type) {
          from = HpEgdsConfig.getEgdsMvtFromOffset();
          to = HpEgdsConfig.getEgdsMvtToOffset();
        } else {
          from = HpEgdsConfig.getEgdsDefFromOffset();
          to = HpEgdsConfig.getEgdsDefToOffset();
        }
       
        // find flight from afttab
      //BigDecimal uaft = aftBean.getUrnoByCriteriaQuery(criteriaParams, type, adid);
        long start = System.currentTimeMillis();
      Tuple tuple = aftBean.getUrnoByCriteriaQuery(criteriaParams, type, adid, from, to);
      LOG.debug("EGDS search flight from afttab cost: {}ms", (System.currentTimeMillis() - start));
      if (tuple == null) {
          // drop message
          LOG.debug("EGDS message dropped due to cannot find flight from afttab");
          //LOG.error("Message Dropped: \n{}", _flightXml);
          addExptInfo(EnumExceptionCodes.ENOFL.name(), EnumExceptionCodes.ENOFL.toString());
            return false;
          }
         
          // uaft
          BigDecimal uaft = tuple.get("urno", BigDecimal.class);
         
          // tifa
          String tifa = tuple.get("tifa", String.class);
         
          // tifd
          String tifd = tuple.get("tifd", String.class);
         
          // adid
          Character aftAdid = tuple.get("adid", Character.class);
          if (adid == null && aftAdid != null) {
            adid = ADID.fromValue(aftAdid.toString());
          }
         
          // flag: continue to process message or not
          boolean isContinue = true;
         
          // flt fuel info
          EntDbFlightFuelStatus oldData = null;
          EntDbFlightFuelStatus data = null;
         
          start = System.currentTimeMillis();
          // according to type settle down return message
          UfisASCommands cmd = UfisASCommands.URT;
      switch (type) {
      case MVT:
        /* 
         * OUT -> AOBN
         * OFF -> ATON
         * ON  -> ALDN
         * IN  -> AIBN
         */
        String trigevt = message.getEGDSBODY().getTRIGEVT();
        String ata = message.getEGDSBODY().getATA();
        if (HpUfisUtils.isNotEmptyStr(trigevt) && ata != null) {
          if (ata.matches(TIME_PATTERN)) {
           
            // HHmm or HH:mm -> HHMM
            ata = String.format(TIME_FORMATTER, Integer.parseInt(ata.replaceAll(SYMB_COLON, "")));
            if (ADID.A == adid) {
              ata = HpUfisUtils.guessTheDate(tifa, ata);
            } else {
              ata = HpUfisUtils.guessTheDate(tifd, ata);
            }
           
            if (trigevt.contains("OUT")) {
              infobjFlight.setAOBN(ata);
            } else if (trigevt.contains("OFF")) {
              infobjFlight.setATON(ata);
            } else if (trigevt.contains("ON")) {
              infobjFlight.setALDN(ata);
            } else if (trigevt.contains("IN")) {
              infobjFlight.setAIBN(ata);
            }
          } else {
            LOG.debug("EGDS: ATA<{}> format is not match with HH:MM or HHMM", ata);
          }
         
          // onboard fuel
          //if (trigevt.contains("IN") && (message.getEGDSBODY().getFOB() != null)) {
          if (message.getEGDSBODY().getFOB() != null) {
            infojxaftab.setFUOB(message.getEGDSBODY().getFOB());
            xafFound = true;
          }
        } else {
          LOG.debug("EGDS: cannot process ATA due to TRIGEVT<{}> or ATA<{}> is null or empty", trigevt, ata);
        }
       
        // Cargo Door closed and Cabin Door closed
        if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getCARD())) {
          ufisCalendar.setTime(message.getEGDSBODY().getCARD(), ufisCalendar.getCustomFormat());
          INFOJFEVTAB cargoDoor = new INFOJFEVTAB();
          cargoDoor.setSTNM("CARGO DOOR CLOSED");
          cargoDoor.setSTTM(ufisCalendar.getCedaString());
          infojfevtablist.getINFOJFEVTAB().add(cargoDoor);
          fevFound = true;
        }
        if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getCABD())) {
          ufisCalendar.setTime(message.getEGDSBODY().getCABD(), ufisCalendar.getCustomFormat());
          INFOJFEVTAB cabinDoor = new INFOJFEVTAB();
          cabinDoor.setSTNM("CABIN DOOR CLOSED");
          cabinDoor.setSTTM(ufisCalendar.getCedaString());
          infojfevtablist.getINFOJFEVTAB().add(cabinDoor);
          fevFound = true;
        }
       
        // if contains FOB
        if (xafFound) {
          try {
            oldData = fltFuelStatusBean.findByIdFlight(uaft);
            if (oldData == null) {
              // Prepare notification data (dat)
              data = new EntDbFlightFuelStatus();
              // id flight
              data.setIdFlight(uaft);
              // flight number
              data.setFlightNumber(fltn);
              // flight date
              //fuelStatus.setFltDate(aftFlight.getFlda());
              // regn
              data.setFltRegn(regn);
              // alc2
              data.setAirlineCode2(HpEKConstants.EK_ALC2);
              // org3
              data.setFltOrigin3(org3);
              // dep3
              data.setFltDest3(des3);
              data.setCreatedUser(MSGIF);
              data.setDataSource(MSGIF);
              // msg send date
              if (HpUfisUtils.isNotEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
                ufisCalendar.setTime(message.getEGDSHEADER().getTIMESTAMP(), ufisCalendar.getCustomFormat());
                data.setMsgSendDate(ufisCalendar.getTime());
              }
              fltFuelStatusBean.persist(data);
              LOG.info("EGDS MVT: created flight fuel record={} for flight={}", data.getId(), uaft);
              cmd = UfisASCommands.IRT;
            }

           
            if (UfisASCommands.URT == cmd) {
              data = EntDbFlightFuelStatus.valueOf(oldData);
              String fob = message.getEGDSBODY().getFOB().isEmpty() ?
                  "0" : message.getEGDSBODY().getFOB();
              float onBoardFuel = Float.parseFloat(fob);
              // new value
              data.setOnboardFuel(onBoardFuel);

              // msg send date
              if (HpUfisUtils.isNotEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
                ufisCalendar.setTime(message.getEGDSHEADER().getTIMESTAMP(),
                    ufisCalendar.getCustomFormat());
                data.setMsgSendDate(ufisCalendar.getTime());
              }
              data.setRecStatus(' ');
              data.setUpdatedUser(MSGIF);
              fltFuelStatusBean.update(data);
              LOG.info("EGDS MVT: updated flight fuel record={} for flight={}", data.getId(), uaft);
            }
           
            if (HpUfisUtils.isNotEmptyStr(HpCommonConfig.notifyTopic)) {
              // send notification message to topic
              ufisTopicProducer.sendNotification(true, cmd, String.valueOf(uaft), oldData, data);
            } else {
              // if topic not defined, send notification to queue
              ufisQueueProducer.sendNotification(true, cmd, String.valueOf(uaft), oldData, data);
            }
           
            // onboard fuel
            /*Float oldOnBoardFuel = 0f;
            if (message.getEGDSBODY().getFOB() != null) {
              String fob = message.getEGDSBODY().getFOB().isEmpty() ?
                  "0" : message.getEGDSBODY().getFOB();
              float onBoardFuel = Float.parseFloat(fob);
              // if fuel changed, update and notify
              if (onBoardFuel != fuelStatus.getOnboardFuel()) {
                // old value
                oldOnBoardFuel = fuelStatus.getOnboardFuel();
                // new value
                fuelStatus.setOnboardFuel(onBoardFuel);

                // msg send date
                if (HpUfisUtils.isNotEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
                  ufisCalendar.setTime(message.getEGDSHEADER().getTIMESTAMP(),
                      ufisCalendar.getCustomFormat());
                  fuelStatus.setMsgSendDate(ufisCalendar.getTime());
                }
                fuelStatus.setRecStatus(' ');
                fuelStatus.setUpdatedUser(MSGIF);
                fltFuelStatusBean.update(fuelStatus);

                // notify flag
                isNofified = true;
              }
            }*/
           
            // notify change or not
            /*if (isNofified) {
              EntUfisMsgDTO msgObj = new EntUfisMsgDTO();
              // Header: id flight
              notifyHeader.getIdFlight().clear();
              notifyHeader.getIdFlight().add(String.valueOf(uaft));
              notifyHeader.setReqt(HpUfisCalendar.getCurrentUTCTimeString());
              msgObj.setHead(notifyHeader);
             
              // Body
              EntUfisMsgBody notifyBody = new EntUfisMsgBody();
              EntUfisMsgACT act = new EntUfisMsgACT();
              if (isInsert) {
                act.setCmd(HpUfisAppConstants.UfisASCommands.IRT.toString());
              } else {
                act.setCmd(HpUfisAppConstants.UfisASCommands.URT.toString());
              }
              act.setTab(TAB);
              act.getFld().add(NOTIFY_FOB);
              act.getData().add(message.getEGDSBODY().getFOB());
              act.getOdat().add(oldOnBoardFuel.toString());
              act.getId().add(fuelStatus.getId());
              act.setSel("WHERE id = " + "\"" + fuelStatus.getId() + "\"");
              notifyBody.getActs().add(act);
              msgObj.setBody(notifyBody);
             
              // json message
              String jsonNotifyMsg = mapper.writeValueAsString(msgObj);
              //bcMessaging.sendBroadcastMessage(jsonNotifyMsg);
              ufisTopicProducer.sendMessage(jsonNotifyMsg);
              LOG.debug("EGDS notification for changes: \n{}", jsonNotifyMsg);
            }*/
          } catch (Exception e) {
            LOG.error("Cannot transform egds message: {}", e.getMessage());
            //LOG.error("Message Dropped: \n{}", _flightXml);
          }
        }
        break;
       
      case PROGRESSREPORT:
        String eta = message.getEGDSBODY().getETA();
        if (HpUfisUtils.isNullOrEmptyStr(eta)) {
          // 2013-12-02 updated by JGO - ETA is optional in latest ICD
          // drop message
          /*LOG.debug("EGDS message dropped due to eta is null or empty");
            //LOG.error("Message Dropped: \n{}", _flightXml);
            addExptInfo(EnumExceptionCodes.EMAND.name(), EnumExceptionCodes.EMAND.toString());*/
            isContinue = false;
        }

        if (eta.matches(TIME_PATTERN)) {
          eta = String.format(TIME_FORMATTER, Integer.parseInt(eta.replaceAll(SYMB_COLON, "")));
          eta = HpUfisUtils.guessTheDate(tifa, eta);
          infobjFlight.setEIBN(eta);
        } else {
          LOG.debug("EGDS: ETA<{}> format is not match with HH:MM or HHMM", eta);
          addExptInfo(EnumExceptionCodes.EWVAL.name(), "ETA format not match with HH:MM or HHMM");
          isContinue = false;
        }
View Full Code Here

      infobjgeneric.setTIMEID(TIMEID.UTC);
      infobjgeneric.setTIMESTAMP(ufisCalendar.getCedaString());

      // BODY
      MSGOBJECTS msgObjects = new MSGOBJECTS();
      INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
      String cxCount = Integer.toString(criticalCount);
      String sxCount = Integer.toString(shortCount);
      //infobjFlight.setCXPX(cxpx);
      if (HpUfisAppConstants.CON_LOAD_BAG_SUMMARY.equalsIgnoreCase(tab)) {
        infobjFlight.setCXBG(cxCount);
        infobjFlight.setSXBG(sxCount);
      } else if (HpUfisAppConstants.CON_LOAD_PAX_SUMMARY.equalsIgnoreCase(tab)) {
        infobjFlight.setCXPX(cxCount);
        infobjFlight.setSXPX(sxCount);
      } else if (HpUfisAppConstants.CON_LOAD_ULD_SUMMARY.equalsIgnoreCase(tab)) {
        infobjFlight.setCXUD(cxCount);
        infobjFlight.setSXUD(sxCount);
      }
      msgObjects.setINFOBJFLIGHT(infobjFlight);

      // set HEADER and BODY to MSG
      msgstream_in.setINFOBJGENERIC(infobjgeneric);
View Full Code Here

       
        HpUfisCalendar ufisCalendar = new HpUfisCalendar();
        //ufisCalendar.setCustomFormat(HpEKConstants.DMIS_TIME_FORMAT);

        INFOBJGENERIC infobjgeneric = new INFOBJGENERIC();
        INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
        INFOJXAFTAB infojxaftab = new INFOJXAFTAB();

        FlightInfo flightInfo = null;
        String adid = "";
        String patkingT = "";
        String dubaiOrigin = "N";

        String viaRoutes = "";
        String arrivalStation = "";
        String departureStation = "";

        boolean isXafFound = false;
        if (flightEvent.getFlightInfo() != null) {
            flightInfo = flightEvent.getFlightInfo();
            // Format the flno as ufis format
            String alc2 = "";
            String fltn = "";
            String flns = "";
            String flno = "";
            if (flightInfo.getFlightNumber() != null && flightInfo.getFlightNumber().length() > 5) {
              alc2 = flightInfo.getFlightNumber().substring(0, 2);
              fltn = flightInfo.getFlightNumber().substring(2, 6);
              fltn = HpUfisUtils.formatCedaFltn(fltn);
              if ("".equals(fltn)) {
          LOG.debug("FlightNumber should follow format as IATA airline code + 4 digits number + 1 digit suffix(optional) ");
                //LOG.debug("Message dropped: \n{}", _flightXml);
            addExptInfo(EnumExceptionCodes.EWFMT.name(),
                "FlightNumber should follow format as IATA airline code + 4 digits number + 1 digit suffix(optional)");
                return false;
              }
             
              // flns
              if (flightInfo.getFlightNumber().length() == 7) {
                flns = flightInfo.getFlightNumber().substring(6);
              }
            } else {
              LOG.error("Wrong format of flight number");
              addExptInfo(EnumExceptionCodes.EWVAL.name(),
              "FlightNumber should follow format as IATA airline code + 4 digits number + 1 digit suffix(optional)");
                return false;
            }
            infobjFlight.setALC2(alc2);
            infobjFlight.setFLTN(fltn);
            flno = HpUfisUtils.formatCedaFlno(alc2, fltn, flns);
            infobjFlight.setFLNO(flno);
            infobjgeneric.setFLNO(flno);
           
            //Get the Suffix
            if (flightInfo.getFlightNumber() != null && flightInfo.getFlightNumber().length() > 6) {
                infobjFlight.setFLNS(flightInfo.getFlightNumber().substring(6));
            }
           
            // adid
            adid = flightInfo.getArrivalDepartureFlag();
           
            // schedule date in UTC from message
            //if (flightInfo.getScheduledDate() != null) {
            if (HpUfisUtils.isNotEmptyStr(flightInfo.getScheduledDate())) {
              if (flightInfo.getScheduledDate().matches(DT_LOC_SS)) {
                try {
            xmlGregCal = DatatypeFactory.newInstance()
                .newXMLGregorianCalendar(flightInfo.getScheduledDate());
           
            //ufisCalendar.setTime(flightInfo.getScheduledDate(), ufisCalendar.getCustomFormat());
                  ufisCalendar.setTime(xmlGregCal);
                     
                  // flda in utc
                      //infobjFlight.setFLUT(ufisCalendar.getCedaDateString());
                  infobjFlight.setFLUT(DF_CEDADATE.format(ufisCalendar.getTime()));
                     
                      // STDT
                      //infobjgeneric.setSTDT(ufisCalendar.getCedaString());
                  infobjgeneric.setSTDT(DF_CEDA.format(ufisCalendar.getTime()));
                     
                      // flda in local
                      ufisCalendar.DateAdd(HpUfisAppConstants.OFFSET_UTC_LOCAL, EnumTimeInterval.Hours);
                      //infobjFlight.setFLDA(ufisCalendar.getCedaDateString());
                      infobjFlight.setFLDA(DF_CEDADATE.format(ufisCalendar.getTime()));
          } catch (DatatypeConfigurationException e) {
            LOG.error("DatatypeConfigurationException: {}", e);
            //LOG.debug("Dropped Message details: \n{}", _flightXml);
              addExptInfo(EnumExceptionCodes.EWVAL.name(),
                  EnumExceptionCodes.EWVAL.toString());
                      return false;
          }
              } else {
                LOG.error("ScheduledDate format not matched with patten={}", DT_LOC_SS);
                LOG.error("ScheduledDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                    //LOG.debug("Dropped Message details: \n{}", _flightXml);
            addExptInfo(EnumExceptionCodes.EWFMT.name(),
                EnumExceptionCodes.EWFMT.toString());
                    return false;
              }
            } else {
                LOG.error("ScheduledDate with wrong format or NULL");
                //LOG.debug("Dropped Message details: \n{}", _flightXml);
          addExptInfo(EnumExceptionCodes.EWFMT.name(),
              EnumExceptionCodes.EWFMT.toString());
                return false;
            }
           
            // For aircraft type processing, igore data from aircraftype tag
            // intead of using aircraft type include in regn (handle by Ceda)
           
            // if not EK or QF flight, then drop
            /*if (!"EK".equalsIgnoreCase(alc2) && !"QF".equalsIgnoreCase(alc2)) {
              LOG.debug("DMIS Flight message has been dropped due to non-EK and non-QF flights");
              //LOG.debug("Dropped Message details: \n{}", _flightXml);
          addExptInfo(EnumExceptionCodes.EWALC.name(),
              "Non EK or QF flight found");
              return false;
            } else*/
            if ("EK".equalsIgnoreCase(alc2)) {
              // ===========================
              // EK flights
              // ===========================
             
              // action type
              _msgActionType = ACTIONTYPE.U;
              // schedule date
              //ufisCalendar.setTime(flightInfo.getScheduledDate(), ufisCalendar.getCustomFormat());
              infobjFlight.setFLNO(null);
              infobjFlight.setALC2(null);
              infobjFlight.setFLTN(null);
              infobjFlight.setFLDA(null);
              infobjFlight.setFLUT(null);
              switch (adid) {
                case "A":
                  //infobjFlight.setSTOA(ufisCalendar.getCedaString());
                    //infobjFlight.setADID(ADID.A);
                  infobjgeneric.setADID(ADID.A);
                    if (flightInfo.getBayNumber() != null && flightInfo.getBayNumber().getValue() != null) {
                        infobjFlight.setPSTA(flightInfo.getBayNumber().getValue());
                    }
                    if (flightInfo.getGateNumber() != null && flightInfo.getGateNumber().getValue() != null) {
                        infobjFlight.setGTA1(flightInfo.getGateNumber().getValue());
                    }
                    break;
                case "D":
                  //infobjFlight.setSTOD(ufisCalendar.getCedaString());
                    //infobjFlight.setADID(ADID.D);
                  infobjgeneric.setADID(ADID.D);
                    if (flightInfo.getBayNumber() != null && flightInfo.getBayNumber().getValue() != null) {
                        infobjFlight.setPSTD(flightInfo.getBayNumber().getValue());
                    }
                    if (flightInfo.getGateNumber() != null && flightInfo.getGateNumber().getValue() != null) {
                        infobjFlight.setGTD1(flightInfo.getGateNumber().getValue());
                    }
                    break;
              }
              // short final date
              if (HpUfisUtils.isNotEmptyStr(flightInfo.getShortFinalDate())) {
                    //ufisCalendar.setTime(flightInfo.getShortFinalDate(), ufisCalendar.getCustomFormat());
                    //infobjFlight.setSFIN(ufisCalendar.getCedaString());
                if (flightInfo.getShortFinalDate().matches(DT_LOC_SS)) {
                  try {
              xmlGregCal = DatatypeFactory.newInstance()
                  .newXMLGregorianCalendar(flightInfo.getShortFinalDate());
              ufisCalendar.setTime(xmlGregCal);
                    infobjFlight.setSFIN(DF_CEDA.format(ufisCalendar.getTime()));
            } catch (DatatypeConfigurationException e) {
              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
            }
                } else {
                  LOG.error("ShortFinalDate format not matched with patten={}", DT_LOC_SS);
                    LOG.error("ShortFinalDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                }
              }
             
            } else {
              // ===========================
              // QF flights
              // ===========================
                if (flightInfo.getParkingTerminal() != null && flightInfo.getParkingTerminal().getValue() != null) {
                    patkingT = flightInfo.getParkingTerminal().getValue().toString();
                }

                if (flightInfo.getDubaiOrigin() != null && flightInfo.getDubaiOrigin().getValue() != null) {
                    dubaiOrigin = flightInfo.getDubaiOrigin().getValue().toString();
                }
                LOG.info("DubaiOrigin {}", dubaiOrigin);

                //Manipulate arrivalStation / DepartureStation
                //Split by /
                viaRoutes = flightInfo.getViaRoutes();
                // 2013-12-27 updated by JGO - adding ROUT(AFTTAB) to store the routes info
                infobjFlight.setROUT(viaRoutes.replaceAll("/", "|"));
                arrivalStation = flightInfo.getArrivalStation();
                departureStation = flightInfo.getDepartureStation();
               
                switch (adid) {
                    case "A":
                      //infobjFlight.setSTOA(ufisCalendar.getCedaString());
                      infobjFlight.setSTOA(infobjgeneric.getSTDT());
                        infobjFlight.setADID(ADID.A);
                        infobjFlight.setTRMA(patkingT);
                        infobjFlight.setDES3(HpEKConstants.HOPO);

                        if (flightInfo.getEstimatedDate() != null
                            && HpUfisUtils.isNotEmptyStr(flightInfo.getEstimatedDate().getValue())) {
                            //ufisCalendar.setTime(flightInfo.getEstimatedDate().getValue(), ufisCalendar.getCustomFormat());
                            //infobjFlight.setEIBR(ufisCalendar.getCedaString());
                          if (flightInfo.getEstimatedDate().getValue().matches(DT_LOC_SS)) {
                            try {
                              xmlGregCal = DatatypeFactory.newInstance()
                                  .newXMLGregorianCalendar(flightInfo.getEstimatedDate().getValue());
                              ufisCalendar.setTime(xmlGregCal);
                              infobjFlight.setEIBD(DF_CEDA.format(ufisCalendar.getTime()));
                            } catch (DatatypeConfigurationException e) {
                              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                            }
                          } else {
                            LOG.error("EstimatedDate format not matched with patten={}", DT_LOC_SS);
                            LOG.error("EstimatedDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                          }
                        }

                        if (flightInfo.getLatestDate() != null
                            && HpUfisUtils.isNotEmptyStr(flightInfo.getLatestDate().getValue())) {
                            //ufisCalendar.setTime(flightInfo.getLatestDate().getValue(), ufisCalendar.getCustomFormat());
                            //infobjFlight.setTLDR(ufisCalendar.getCedaString());
                          if (flightInfo.getLatestDate().getValue().matches(DT_LOC_SS)) {
                            try {
                              xmlGregCal = DatatypeFactory.newInstance()
                                  .newXMLGregorianCalendar(flightInfo.getLatestDate().getValue());
                              ufisCalendar.setTime(xmlGregCal);
                              infobjFlight.setTLDD(DF_CEDA.format(ufisCalendar.getTime()));
                            } catch (DatatypeConfigurationException e) {
                              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                            }
                          } else {
                            LOG.error("LatestDate format not matched with patten={}", DT_LOC_SS);
                            LOG.error("LatestDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                          }
                        }
                       
                        /*if (HpUfisUtils.isNotEmptyStr(flightInfo.getActualDate().getValue())) {
                            ufisCalendar.setTime(flightInfo.getActualDate().getValue(), ufisCalendar.getCustomFormat());
                            //ufisCalendar.setTime(flightInfo.getTouchdownAirborneDate().getValue());
                        }*/
                       
                        if (HpUfisUtils.isNotEmptyStr(flightInfo.getTouchdownAirborneDate())) {
                          //ufisCalendar.setTime(flightInfo.getTouchdownAirborneDate(), ufisCalendar.getCustomFormat());
                            //infobjFlight.setALDR(ufisCalendar.getCedaString());
                          if (flightInfo.getTouchdownAirborneDate().matches(DT_LOC_SS)) {
                            try {
                              xmlGregCal = DatatypeFactory.newInstance()
                                  .newXMLGregorianCalendar(flightInfo.getTouchdownAirborneDate());
                              ufisCalendar.setTime(xmlGregCal);
                              infobjFlight.setALDD(DF_CEDA.format(ufisCalendar.getTime()));
                            } catch (DatatypeConfigurationException e) {
                              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                            }
                          } else {
                            LOG.error("TouchdownAirborneDate format not matched with patten={}", DT_LOC_SS);
                            LOG.error("TouchdownAirborneDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                          }
                        }

                        if (flightInfo.getBayNumber() != null && flightInfo.getBayNumber().getValue() != null) {
                            infobjFlight.setPSTA(flightInfo.getBayNumber().getValue());
                        }
                        if (flightInfo.getGateNumber() != null && flightInfo.getGateNumber().getValue() != null) {
                            infobjFlight.setGTA1(flightInfo.getGateNumber().getValue());
                        }
                        if (flightInfo.getBaggageBeltNumber() !=
                            null && flightInfo.getBaggageBeltNumber().getValue() != null) {
                            infobjFlight.setBLT1(flightInfo.getBaggageBeltNumber().getValue());
                        }
                        //Set ORG3 base on depStation
                        //Split with /
                        if (viaRoutes != null && viaRoutes.contains("/")) {
                            String[] splitviaRoutes = viaRoutes.split("/");
                            for (int i = 0; i < splitviaRoutes.length; i++) {
                                if (i == 0) {
                                    infobjFlight.setORG3(splitviaRoutes[i]);
                                }
                                if (i == 1) {
                                    //infobjFlight.setVIA3(splitviaRoutes[i]);
                                  if (HpUfisUtils.isNotEmptyStr(splitviaRoutes[i])) {
                                    infobjFlight.setVIAN("1");
                                    infobjFlight.setVIAL(formatVial(splitviaRoutes[i]));
                                  }
                                }
                            }
                        } else {
                            infobjFlight.setORG3(departureStation);
                        }


                        break;
                    case "D":
                      //infobjFlight.setSTOD(ufisCalendar.getCedaString());
                      infobjFlight.setSTOD(infobjgeneric.getSTDT());
                        infobjFlight.setADID(ADID.D);
                        infobjFlight.setTRMD(patkingT);
                        infobjFlight.setORG3(HpEKConstants.HOPO);

                        if (flightInfo.getEstimatedDate() != null
                            && HpUfisUtils.isNotEmptyStr(flightInfo.getEstimatedDate().getValue())) {
                            //ufisCalendar.setTime(flightInfo.getEstimatedDate().getValue(), ufisCalendar.getCustomFormat());
                            //infobjFlight.setEOBR(ufisCalendar.getCedaString());
                          if (flightInfo.getEstimatedDate().getValue().matches(DT_LOC_SS)) {
                            try {
                              xmlGregCal = DatatypeFactory.newInstance()
                                  .newXMLGregorianCalendar(flightInfo.getEstimatedDate().getValue());
                              ufisCalendar.setTime(xmlGregCal);
                              infobjFlight.setEOBD(DF_CEDA.format(ufisCalendar.getTime()));
                            } catch (DatatypeConfigurationException e) {
                              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                            }
                          } else {
                            LOG.error("EstimatedDate format not matched with patten={}", DT_LOC_SS);
                            LOG.error("EstimatedDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                          }
                        }

                        if (flightInfo.getLatestDate() != null
                            && HpUfisUtils.isNotEmptyStr(flightInfo.getLatestDate().getValue())) {
                            //ufisCalendar.setTime(flightInfo.getLatestDate().getValue(), ufisCalendar.getCustomFormat());
                            //infobjFlight.setTLDR(ufisCalendar.getCedaString());
                          if (flightInfo.getLatestDate().getValue().matches(DT_LOC_SS)) {
                            try {
                              xmlGregCal = DatatypeFactory.newInstance()
                                  .newXMLGregorianCalendar(flightInfo.getLatestDate().getValue());
                              ufisCalendar.setTime(xmlGregCal);
                              infobjFlight.setTLDD(DF_CEDA.format(ufisCalendar.getTime()));
                            } catch (DatatypeConfigurationException e) {
                              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                            }
                          } else {
                            LOG.error("LatestDate format not matched with patten={}", DT_LOC_SS);
                            LOG.error("LatestDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                          }
                        }

                        /*if (HpUfisUtils.isNotEmptyStr(flightInfo.getActualDate().getValue())) {
                            ufisCalendar.setTime(flightInfo.getActualDate().getValue(), ufisCalendar.getCustomFormat());
                            //ufisCalendar.setTime(flightInfo.getTouchdownAirborneDate().getValue());
                        }*/
                       
                        if (HpUfisUtils.isNotEmptyStr(flightInfo.getTouchdownAirborneDate())) {
                          //ufisCalendar.setTime(flightInfo.getTouchdownAirborneDate(), ufisCalendar.getCustomFormat());
                            //infobjFlight.setATOR(ufisCalendar.getCedaString());
                          if (flightInfo.getTouchdownAirborneDate().matches(DT_LOC_SS)) {
                            try {
                              xmlGregCal = DatatypeFactory.newInstance()
                                  .newXMLGregorianCalendar(flightInfo.getTouchdownAirborneDate());
                              ufisCalendar.setTime(xmlGregCal);
                              infobjFlight.setATOD(DF_CEDA.format(ufisCalendar.getTime()));
                            } catch (DatatypeConfigurationException e) {
                              LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                            }
                          } else {
                            LOG.error("TouchdownAirborneDate format not matched with patten={}", DT_LOC_SS);
                            LOG.error("TouchdownAirborneDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                          }
                        }

                        if (flightInfo.getBayNumber() != null && flightInfo.getBayNumber().getValue() != null) {
                            infobjFlight.setPSTD(flightInfo.getBayNumber().getValue());
                        }
                        if (flightInfo.getGateNumber() != null && flightInfo.getGateNumber().getValue() != null) {
                            infobjFlight.setGTD1(flightInfo.getGateNumber().getValue());
                        }

                        //Set DES3 base on arrivalStation
                        if (viaRoutes != null && viaRoutes.contains("/")) {
                            String[] splitviaRoutes = viaRoutes.split("/");
                            for (int i = 0; i < splitviaRoutes.length; i++) {
                                if (i == 0) {
                                    //infobjFlight.setVIA3(splitviaRoutes[i]);
                                  if (HpUfisUtils.isNotEmptyStr(splitviaRoutes[i])) {
                                    infobjFlight.setVIAN("1");
                                      infobjFlight.setVIAL(formatVial(splitviaRoutes[i]));
                                  }
                                }
                                if (i == splitviaRoutes.length - 1) {
                                    infobjFlight.setDES3(splitviaRoutes[i]);
                                }
                            }
                        } else {
                            infobjFlight.setDES3(arrivalStation);
                        }
                        break;
                }
                //Aircraft Type Code Eg. A330200
                //Need to format and break into 2 fields
                if (flightInfo.getAircraftType() != null
                    && flightInfo.getAircraftType().getValue() != null) {
                    infobjFlight.setACT3(flightInfo.getAircraftType().getValue().substring(0, 3));
                    infobjFlight.setACT5(flightInfo.getAircraftType().getValue().substring(3));
                }
                if (flightInfo.getRegistrationNumber() != null
                    && flightInfo.getRegistrationNumber().getValue() != null) {
                    infobjFlight.setREGN(flightInfo.getRegistrationNumber().getValue());
                }
                //Airline
                if (flightInfo.getAirlineCode() != null
                    && flightInfo.getAirlineCode().getValue() != null) {
                    if (flightInfo.getAirlineCode().getValue().length() == 2) {
                        infobjFlight.setALC2(flightInfo.getAirlineCode().getValue());
                    } else if (flightInfo.getAirlineCode().getValue().length() == 3) {
                        infobjFlight.setALC3(flightInfo.getAirlineCode().getValue());
                    }
                }
                //Handling Terminal
                if (flightInfo.getHandlingTerminal() != null
                    && flightInfo.getHandlingTerminal().getValue() != null) {
                  String stev = flightInfo.getHandlingTerminal().getValue().toString();
                  Matcher m = p.matcher(stev);
                  stev = m.replaceAll("");
                    infobjFlight.setSTEV(stev);
                }
                //Code Share fixed len
                //A3 1808  LG 1561  SK 3215  TP 7962  UA 9524
                StringBuilder codeShareBuilder = new StringBuilder();
                int codeShareCount = 0;
                boolean codeShareEnable = false;
                if (codeShareEnable == true) {
                    if (flightInfo.getCodeshareFlight1() != null
                        && flightInfo.getCodeshareFlight1().getValue() != null
                            && flightInfo.getCodeshareFlight1().getValue().length() > 1) {
                        codeShareBuilder.append(String.format("%-" + CODESHARESPACE + "s", flightInfo.getCodeshareFlight1().getValue()));
                        codeShareCount++;
                    }
                    if (flightInfo.getCodeshareFlight2() != null
                            && flightInfo.getCodeshareFlight2().length() > 1) {
                        codeShareBuilder.append(String.format("%-" + CODESHARESPACE + "s", flightInfo.getCodeshareFlight2()));
                        codeShareCount++;
                    }
                    if (flightInfo.getCodeshareFlight3() != null
                            && flightInfo.getCodeshareFlight3().length() > 1) {
                        codeShareBuilder.append(String.format("%-" + CODESHARESPACE + "s", flightInfo.getCodeshareFlight3()));
                        codeShareCount++;
                    }
                    if (flightInfo.getCodeshareFlight4() != null
                            && flightInfo.getCodeshareFlight4().length() > 1) {
                        codeShareBuilder.append(String.format("%-" + CODESHARESPACE + "s", flightInfo.getCodeshareFlight4()));
                        codeShareCount++;
                    }
                    if (flightInfo.getCodeshareFlight5() != null
                            && flightInfo.getCodeshareFlight5().length() > 1) {
                        codeShareBuilder.append(String.format("%-" + CODESHARESPACE + "s", flightInfo.getCodeshareFlight5()));
                        codeShareCount++;
                    }
                    if (codeShareCount > 0) {
                        infobjFlight.setJFNO(codeShareBuilder.toString());
                        infobjFlight.setJCNT(Integer.toString(codeShareCount));
                    }
                }
                // short final date
                if (HpUfisUtils.isNotEmptyStr(flightInfo.getShortFinalDate())) {
                  //ufisCalendar.setTime(flightInfo.getShortFinalDate(), ufisCalendar.getCustomFormat());
                  //infobjFlight.setSFIN(ufisCalendar.getCedaString());
                  if (flightInfo.getShortFinalDate().matches(DT_LOC_SS)) {
                    try {
                      xmlGregCal = DatatypeFactory.newInstance()
                          .newXMLGregorianCalendar(flightInfo.getShortFinalDate());
                      ufisCalendar.setTime(xmlGregCal);
                      infobjFlight.setSFIN(DF_CEDA.format(ufisCalendar.getTime()));
                    } catch (DatatypeConfigurationException e) {
                      LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                    }
                  } else {
                    LOG.error("ShortFinalDate format not matched with patten={}", DT_LOC_SS);
                    LOG.error("ShortFinalDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                  }
                 
                }
                // choksOn
                if (HpUfisUtils.isNotEmptyStr(flightInfo.getChoksOnDate())) {
                  if (flightInfo.getChoksOnDate().matches(DT_LOC_SS)) {
                    try {
                      xmlGregCal = DatatypeFactory.newInstance()
                          .newXMLGregorianCalendar(flightInfo.getChoksOnDate());
                      ufisCalendar.setTime(xmlGregCal);
                      infobjFlight.setAIBD(DF_CEDA.format(ufisCalendar.getTime()));
                    } catch (DatatypeConfigurationException e) {
                      LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                    }
                  } else {
                    LOG.error("ChoksOnDate format not matched with patten={}", DT_LOC_SS);
                    LOG.error("ChoksOnDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                  }
                }
                // choksOff
                if (HpUfisUtils.isNotEmptyStr(flightInfo.getChoksOffDate())) {
                  if (flightInfo.getChoksOffDate().matches(DT_LOC_SS)) {
                    try {
                      xmlGregCal = DatatypeFactory.newInstance()
                          .newXMLGregorianCalendar(flightInfo.getChoksOffDate());
                      ufisCalendar.setTime(xmlGregCal);
                      infobjFlight.setAOBD(DF_CEDA.format(ufisCalendar.getTime()));
                    } catch (DatatypeConfigurationException e) {
                      LOG.error("DatatypeConfigurationException: {}", e.getMessage());
                    }
                  } else {
                    LOG.error("ChoksOnDate format not matched with patten={}", DT_LOC_SS);
                    LOG.error("ChoksOnDate correct format should like: yyyy-MM-ddTHH:mm:ss[+-]hh:mm");
                  }
                }
                // uld charge and airline charge code -> XAFTAB
                if (flightInfo.getUldCharges() != null && flightInfo.getUldCharges().getValue() != null) {
                    infojxaftab.setULDC(flightInfo.getUldCharges().getValue());
                    isXafFound = true;
                }
                if (flightInfo.getChargedAirlineCode() != null
                    && flightInfo.getChargedAirlineCode().getValue() != null) {
                    infojxaftab.setCHAL(flightInfo.getChargedAirlineCode().getValue());
                    isXafFound = true;
                }
                if (flightInfo.getFlightCombiType() != null
                    && flightInfo.getFlightCombiType().getValue() != null) {
                    String flightCombiType = flightInfo.getFlightCombiType().getValue();
                    switch (flightCombiType) {
                        case "P":
                            infobjFlight.setSTYP("G");
                            break;
                        case "C":
                            infobjFlight.setSTYP("F");
                            break;
                        case "M":
                            infobjFlight.setSTYP("Q");
                            break;
                    }
                }

                if (flightInfo.getFlightStatus() != null
                    && flightInfo.getFlightStatus().getValue() != null) {
                    String flightStatus = flightInfo.getFlightStatus().getValue();
                    // put org flightStatus to rem1(new change to ISTA)
                    // infobjFlight.setREM1(flightStatus);
                    infobjFlight.setISTA(flightStatus);
            switch (flightStatus) {
            case "X":
              // Flight Deleted ?
              //_msgActionType = ACTIONTYPE.D;
              infobjFlight.setFTYP("X");
              break;
            case "C":
              // Flight CXX
              infobjFlight.setFTYP("X");
              break;
            // case "M":
            // case "A":
            // //Flight Diverted
            // infobjFlight.setFTYP("D");
            // break;
            // case "R":
            // infobjFlight.setFTYP("Z");
            // infobjFlight.setADID(ADID.B);
            // break;
            default:
              infobjFlight.setFTYP("O");
              break;
            }
                }
               
                if (flightInfo.getFlightRemarks() != null) {
                    //infobjFlight.setREM2(flightInfo.getFlightRemarks());
                  infobjFlight.setRRMK(flightInfo.getFlightRemarks());
                }
            }
        }
        MSGOBJECTS msgobjects = new MSGOBJECTS();
        /* Set the fields that uniquely identify a flight
View Full Code Here

      infobjgeneric.setTIMEID(TIMEID.UTC);
      infobjgeneric.setTIMESTAMP(ufisCalendar.getCedaString());

      // BODY
      MSGOBJECTS msgObjects = new MSGOBJECTS();
      INFOBJFLIGHT infobjFlight = new INFOBJFLIGHT();
      String count = Integer.toString(criticalCount);
      //infobjFlight.setCXPX(cxpx);
      if (HpUfisAppConstants.CON_LOAD_BAG_SUMMARY.equalsIgnoreCase(tab)) {
        infobjFlight.setCXBG(count);
      } else if (HpUfisAppConstants.CON_LOAD_PAX_SUMMARY.equalsIgnoreCase(tab)) {
        infobjFlight.setCXPX(count);
      } else if (HpUfisAppConstants.CON_LOAD_ULD_SUMMARY.equalsIgnoreCase(tab)) {
        infobjFlight.setCXUD(count);
      }
      msgObjects.setINFOBJFLIGHT(infobjFlight);

      // set HEADER and BODY to MSG
      msgstream_in.setINFOBJGENERIC(infobjgeneric);
View Full Code Here

    HpUfisCalendar ufisCalendar = new HpUfisCalendar();
        FlightEvent.FlightId flightId = flightEvent.getFlightId();
       
        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
        // ============= infobjFlight ===============================
        if (!CONST_DELETE.equalsIgnoreCase(_actionType)) {
          // Airline
          String airline = event.getCxCd();
            if (airline.length() == 2) {
                infobjFlight.setALC2(airline);
            } else {
                infobjFlight.setALC3(airline);
            }
            // Flight number in Ceda format
            infobjFlight.setFLTN(HpUfisUtils.formatCedaFltn(event.getFltNum()));
            if (airline.length() == 3) {
              infobjFlight.setFLNO(airline + infobjFlight.getFLTN());
            } else {
              infobjFlight.setFLNO(airline + " " + infobjFlight.getFLTN());
            }
            // Suffix
            if (HpUfisUtils.isNotEmptyStr(event.getFltSuffix())) {
                infobjFlight.setFLNS(event.getFltSuffix());
                // 2013-08-19 updated by JGO - adding suffix info to flno as well
                if (fltn.length() == 5) {
                  infobjFlight.setFLNO(infobjFlight.getFLNO() + event.getFltSuffix());
              } else if (fltn.length() == 4) {
                infobjFlight.setFLNO(infobjFlight.getFLNO() + " " + event.getFltSuffix());
              } else if (fltn.length() == 3) {
                infobjFlight.setFLNO(infobjFlight.getFLNO() + " " + " " + event.getFltSuffix());
              }
            }

            /*// FLUT - Flight date in utc
            infobjFlight.setFLUT(fldaUtc);
            // FLDA(local) - if cannot find from tag, getting from schedule time
            if (event.getFltDateLocal() != null) {
              ufisCalendar.setTime(event.getFltDateLocal().getValue());
              infobjFlight.setFLDA(ufisCalendar.getCedaDateString());
            } else {
              // if ADID is D, refer from STOD, others STOA (yyyyMMdd)
              if (ADID.D == infobjgeneric.getADID()) {
                if (HpUfisUtils.isNotEmptyStr(fldaFromStoa)) {
                  infobjFlight.setFLDA(fldaFromStoa);
                }
                if (HpUfisUtils.isNotEmptyStr(fldaFromStod)) {
                  infobjFlight.setFLDA(fldaFromStod);
                }
              } else {
                if (HpUfisUtils.isNotEmptyStr(fldaFromStod)) {
                  infobjFlight.setFLDA(fldaFromStod);
                }
                if (HpUfisUtils.isNotEmptyStr(fldaFromStoa)) {
                  infobjFlight.setFLDA(fldaFromStoa);
                }
              }
            }*/
           
            // ADID
            if (HpEKConstants.HOPO.equalsIgnoreCase(event.getDepStn())
                && HpEKConstants.HOPO.equalsIgnoreCase(event.getArrStn())) {
                //Return Flight /TAxi
                infobjFlight.setADID(ADID.B);
                infobjFlight.setORG3(HpEKConstants.HOPO);
                infobjFlight.setDES3(HpEKConstants.HOPO);
                infobjFlight.setDEPN(String.valueOf(event.getDepNum()));

                // when body is return flight info, update to header
                infobjgeneric.setADID(ADID.B);
                infobjgeneric.setORG3(HpEKConstants.HOPO);
              infobjgeneric.setDES3(HpEKConstants.HOPO);
              // depNum
            } else if (HpEKConstants.HOPO.equalsIgnoreCase(event.getArrStn())) {
                //Arival
                infobjFlight.setADID(ADID.A);
                infobjFlight.setORG3(event.getDepStn());
                infobjFlight.setDES3(HpEKConstants.HOPO);
                // depNum
                infobjFlight.setDEPN(String.valueOf(event.getDepNum()));
            } else if (HpEKConstants.HOPO.equalsIgnoreCase(event.getDepStn())) {
                //Departure
                infobjFlight.setADID(ADID.D);
                infobjFlight.setORG3(HpEKConstants.HOPO);
                infobjFlight.setDES3(event.getArrStn());
                // depNum
                infobjFlight.setDEPN(String.valueOf(event.getDepNum()));
            }
           
          // only HOPO message will pass full info
          if (HpEKConstants.HOPO.equals(event.getArrStn())
            || HpEKConstants.HOPO.equals(event.getDepStn())) {
           
            // 2013-11-27 updated by JGO - flda and flut in infobj_flight only when hopo message
            // FLUT - Flight date in utc
                infobjFlight.setFLUT(fldaUtc);
               
                // FLDA(local) - if cannot find from tag, getting from schedule time
                if (event.getFltDateLocal() != null) {
                  ufisCalendar.setTime(event.getFltDateLocal().getValue());
                  infobjFlight.setFLDA(ufisCalendar.getCedaDateString());
                } else {
                  // if ADID is D, refer from STOD, others STOA (yyyyMMdd)
                  if (ADID.D == infobjgeneric.getADID()) {
                    /*if (HpUfisUtils.isNotEmptyStr(fldaFromStoa)) {
                      infobjFlight.setFLDA(fldaFromStoa);
                    }*/
                    if (HpUfisUtils.isNotEmptyStr(fldaFromStod)) {
                      infobjFlight.setFLDA(fldaFromStod);
                    }
                  } else {
                    /*if (HpUfisUtils.isNotEmptyStr(fldaFromStod)) {
                      infobjFlight.setFLDA(fldaFromStod);
                    }*/
                    if (HpUfisUtils.isNotEmptyStr(fldaFromStoa)) {
                      infobjFlight.setFLDA(fldaFromStoa);
                    }
                  }
                }
           
            // Service Type
                infobjFlight.setSTYP(event.getServiceType());
               
                // AcType
                // IATA aircraft subtype as per SSIM
                infobjFlight.setACT3(event.getAcSubType());
               
                // Registration
                // 2013-05-14 updated by JGO - if 4 digits regn, ignored
                // 2013-05-31 updated by JGO - if 4 digits or less, and all numeric regn, ignored
                if (event.getTailNo() != null && event.getTailNo().getValue() != null) {
                  //if (event.getTailNo().getValue().length() <= 4) {
                  if (event.getTailNo().getValue().matches(PATTERN_REGN)) {
                    infobjFlight.setREGN("");
                  } else {
                    infobjFlight.setREGN(event.getTailNo().getValue());
                  }
                } else {
                  // regn is null, clear value
                  //infobjFlight.setREGN("");
                }
               
                // schedule datetime
                infobjFlight.setSTOA(stoa);
                infobjFlight.setSTOD(stod);
               
                // TaxiOut/TaxiIn
                if (event.getTaxiOut() != null) {
                    infobjFlight.setEXOT(event.getTaxiOut().getValue().toString());
                }
                if (event.getTaxiIn() != null) {
                    infobjFlight.setEXIT(event.getTaxiIn().getValue().toString());
                }
               
                /**
                 * Flight Status(From CORE)
                 * CODE STATUS_DESCRIPTION
                 * 1 RTNG RETURNED, IN FLIGHT
                 * 2 DVTG DIVERTED, IN FLIGHT
                 * 3 PDEP NOT YET DEPARTED
                 * 4 OFBL TAXIING FOR TAKEOFF
                 * 5 ENRT IN FLIGHT
                 * 6 LAND LANDED AND TAXIING
                 * 7 ARVD ARRIVED
                 * 8 CNLD CANCELLED
                 * 9 DVTD ARRIVED DIVERSION AIRPORT
                 * 10 DNLD TAXIING DIVERSION AIRPORT
                 * 11 RROF REROUTED, TAXIING
                 * 12 RRTG REROUTED, IN FLIGHT
                 * 13 RRTD REROUTED, LANDED
                 * 14 RTDR RETURNED TO STAND
                 * 15 RTND RETURNED DEPARTURE AIRPORT
                 * 16 DLND DIVERTED
                 * 17 RRLD REROUTED AND LANDING
                 */
                String flightStatus = event.getFltStatus();
                infobjFlight.setISTA(flightStatus);
                infobjFlight.setFTYP(CONST_FTYP_O);
          switch (flightStatus) {
          case CONST_CANCEL:
            infobjFlight.setFTYP(CONST_FTYP_X);
            break;
          }
         
                // SiRemarks
                List<FlightEvent.Events.SiRemark> siRemarks = event.getSiRemark();
                StringBuilder siRemarkBuild = new StringBuilder();
                if (siRemarks != null) {
                  for (FlightEvent.Events.SiRemark remark : siRemarks) {
                    siRemarkBuild.append(remark.getValue());
                    siRemarkBuild.append(" ");
                  }
                }
                infobjFlight.setREM2(siRemarkBuild.toString());
               
                // 2013-11-22 updated by JGO - Adding Remark
                StringBuilder remarkBuild = new StringBuilder();
                for (FlightEvent.Events.Remark r : event.getRemark()) {
                  remarkBuild.append(r.getValue());
                  remarkBuild.append(" ");
                }
                //infobjFlight.setREM1(remarkBuild.toString());
                infobjFlight.setRRMK(remarkBuild.toString());
               
                // Cabin door and Cargo door events (clarify dorFlag and remark is for which field)
                // 2013-04-18 updated by JGO - change fevtab to fevtab list
                // 2013-05-15 updated by JGO - Remove these info
                /*
        if (event.getCABINDOORCLOSURE() != null) {
          INFOJFEVTAB cabinDoor = new INFOJFEVTAB();
          ufisCalendar.setTime(event.getCABINDOORCLOSURE().getValue());
          cabinDoor.setSTNM("CABIN DOOR CLOSURE");
          cabinDoor.setSTTM(ufisCalendar.getCedaString());
          cabinDoor.setSTFL(event.getDorFlag());
          cabinDoor.setSTRM(event.getDorRemark());
          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(event.getDorFlag());
          cargoDoor.setSTRM(event.getDorRemark());
          infojfevtablist.getINFOJFEVTAB().add(cargoDoor);
        }
                */
               
                // Flight duration
                if (event.getFltTime() != null && event.getFltTime().getValue() != null) {
                  infobjFlight.setFDUR(event.getFltTime().getValue().toString());
                }
                // Schedule/Actual Block Time (min)
                if (event.getBlkTimeOrig() != null && event.getBlkTimeOrig().getValue() != null) {
                  infobjFlight.setSOOB(event.getBlkTimeOrig().getValue().toString());
                }
                if (event.getBlkTimeAct() != null && event.getBlkTimeAct().getValue() != null) {
                  infobjFlight.setAOOB(event.getBlkTimeAct().getValue().toString());
                }
               
                /**
                 *  <Fuel units="" type="" >xxxx</Fuel>
                 *  units not required
                 *  type required
                 *  value
                 * 
                 *  Design documents:
                 *  units -> FUEU
                 *  type  -> FUET
                 */
                // 2013-06-19 updated by JGO - Move fuel related into FLT_FUEL_STATUS
                /* 2013-06-23 updated by JGO - As discussed with Ritu(DTP),
                 *                  fuel info will get from EGDS, no Core fuel info will be used
                // find flt_fuel_status by flight info
                EntDbFlightFuelStatus fltFuelStatus = fltFuelStatusBean.findByFlight(
                    carrier,
                    fltn,
                    infobjgeneric.getFLNS(),
                    infobjgeneric.getFLDA());
                if (fltFuelStatus == null) {
                  fltFuelStatus = new EntDbFlightFuelStatus();
                  fltFuelStatus.setAirlineCode2(carrier);
                  fltFuelStatus.setFlightNumber(fltn);
                  if (HpUfisUtils.isNotEmptyStr(infobjgeneric.getFLNS())) {
                    fltFuelStatus.setFltSuffix(infobjgeneric.getFLNS().charAt(0));
                  }
                  fltFuelStatus.setFltDate(infobjgeneric.getFLDA());
                  fltFuelStatus.setDataSource(MSGIF);
                  fltFuelStatus.setRecStatus(' ');
                  fltFuelStatusBean.persist(fltFuelStatus);
                }
                // TODO check the default units
                // Units to measurement for the fuel
                List<FlightEvent.Events.Fuel> fuels = event.getFuel();
                boolean isFuelInfoIncluded = false;
              for (FlightEvent.Events.Fuel fuel : fuels) {
                    //infojxaftab.setFUEU(fuel.getUnits());
                    //infojxaftab.setFUET(fuel.getType());
                isFuelInfoIncluded = true;
          if (fuel.getType() != null) {
            float value = fuel.getValue().floatValue();
            // fuel units - need to convert to kg
                  if (HpUfisUtils.isNotEmptyStr(fuel.getUnits())) {
                    // convert to kg
                  }
                  // fule types
            switch (fuel.getType()) {
            case FUEL_TYPE_TOW:
              // take off weight
                    infojxaftab.setTOWT(String.valueOf(value));
              break;
            case FUEL_TYPE_ZFW:
              // zero fuel weight
                    infojxaftab.setZFWT(String.valueOf(value));
              break;
            case FUEL_TYPE_TOF:
              fltFuelStatus.setTakeoffFuel(value);
              break;
            case FUEL_TYPE_FOA:
              fltFuelStatus.setArrivalFuel(value);
              break;
            default:
              LOG.debug("Unexpected fuel type: {}", fuel.getType());
              break;
            }
          }
                }
             
              if (isFuelInfoIncluded) {
                fltFuelStatusBean.update(fltFuelStatus);
              }
                */
               
                // XAFTAB related info
                // AcOwner
                if (event.getAcOwner() != null) {
                  infojxaftab.setACOW(event.getAcOwner());
                  isXafFound = true;
                }
               
                // AcVersion
                if (event.getAcVersion() != null) {
                  infojxaftab.setACEX(event.getAcVersion());
                  isXafFound = true;
                }
               
                // MvtDatetimes - Local
                List<FlightEvent.Events.MvtDateTime> mvtDateTimes = event.getMvtDateTime();
                /**
                 * AirborneEst (Estimated Airborne time)      - ETON
                 * AirborneAct (Actual Aiborne time)          - ATON
                 * LandedEst (Estimated landing time)         - ELDN
                 * LandedAct (Actual landing time)            - ALDN
                 * OnBlocksEst (Estimated on block time)      - EIBN
                 * OnBlocksAct (Actual on block time)        - AIBN
                 * OffBlocksEst (Estimated off block time)     - EOBN
                 * OffBlocksAct (Actual off block time)       - AOBN
                 * StartTaxiAct (Actual time of start taxing) - ASTN
                 * NextInformation:                           - NEXI(XAFTAB)
                 *  (Time at which next information for the flight shall be made available)
                 *
                 */
                for (FlightEvent.Events.MvtDateTime mvtDateTime : mvtDateTimes) {
                    String mvtType = mvtDateTime.getType() == null ? "" : mvtDateTime.getType();
                    String cedaTime = "";
                    if (mvtDateTime.getValue() != null) {
                      ufisCalendar.setTime(mvtDateTime.getValue());
                      //cedaTime = ufisCalendar.getCedaString();
                      cedaTime = df.format(ufisCalendar.getTime());
                    }
                    switch (mvtType) {
                        case "AirborneAct":
                            infobjFlight.setATON(cedaTime);
                            break;
                        case "LandedEst":
                            infobjFlight.setELDN(cedaTime);
                            break;
                        case "LandedAct":
                            infobjFlight.setALDN(cedaTime);
                            break;
                        case "OnBlocksAct":
                          infobjFlight.setAIBN(cedaTime);
                            break;
                        case "OnBlocksEst":
                          infobjFlight.setEIBN(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);
                            isXafFound = true;
                            break;
                    }
                }
               
                // RTG
                FlightEvent.Events.Rtg rtg = event.getRtg();
                if (rtg != null) {
                  INFOJFEVTAB fev = new INFOJFEVTAB();
                  if (rtg.getLastDoorCl() != null) {
                    ufisCalendar.setTime(rtg.getLastDoorCl());
                    //fev.setSTTM(ufisCalendar.getCedaString());
                    fev.setSTTM(df.format(ufisCalendar.getTime()));
                  }
                    fev.setSTNM("Ready to Go");
                    fev.setSTFL(rtg.getValue());
                    fev.setSTRM("");
                    // flight daily id
                    fev.setIDFD(fltDaily.getId());
                    infojfevtablist.getINFOJFEVTAB().add(fev);
                }
               
                // Get Delays
                if (flightEvent.getDelays() != null) {
                  List<FlightEvent.Delays.Delay> delays = flightEvent.getDelays().getDelay();
                  for (FlightEvent.Delays.Delay delay : delays) {
                        INFOJDCFTAB infojdcftab = new INFOJDCFTAB();
                        ufisCalendar.setTime(delay.getPostedOn());
                        infojdcftab.setCDAT(ufisCalendar.getCedaString());
                        infojdcftab.setDECA(delay.getCode());
                        infojdcftab.setDURA(String.format(FMT_DURA, delay.getAmount()));
                        // flight daily id
                        infojdcftab.setIDFD(fltDaily.getId());
                        infojdcftablist.getINFOJDCFTAB().add(infojdcftab);
                    }
//                } else {
//                  // if tags are null, clear all delay info from dcftab
//                  INFOJDCFTAB infojdcftab = new INFOJDCFTAB();
//                  infojdcftablist.getINFOJDCFTAB().add(infojdcftab);
                }
          }
        }
       
        if (ACTIONTYPE.D != _msgActionType) {
          // Handle Via for non-return flights
          StringBuilder vial = new StringBuilder();
          boolean isFirstMsg = true;
          if (msgChains != null && ADID.B != infobjgeneric.getADID()) {
            // Let Ceda decide insert or update
            _msgActionType = null;
           
              Iterator<EntDbCoreTmp> iter = msgChains.iterator();
              while (iter.hasNext()) {
                EntDbCoreTmp temp = iter.next();
                if (isFirstMsg) {
                  infobjFlight.setORG3(temp.getDepStn());
                  // 2013-12-30 updated by JGO - Set stoa as orign
                  infobjFlight.setSTOD(temp.getSchDep());
                    isFirstMsg = false;
                  }
                  // last record
                  if (!iter.hasNext()) {
                  infobjFlight.setDES3(temp.getArrStn());
                  // 2013-12-30 updated by JGO - Set stod as destination
                  infobjFlight.setSTOA(temp.getSchArr());
                    break;
                  }
                  // update vias
                    vial.append(createVia(temp, infobjgeneric.getADID(), ufisCalendar));
              }
              infobjFlight.setVIAN(Integer.toString(msgChains.size() -1));
              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() });
                }
          }
        }
       
        // transUserId and transDatetime
        if (flightEvent.getAudit() != null) {
          infobjFlight.setUSEU(flightEvent.getAudit().getTransUserId());
          if (flightEvent.getAudit().getTransDateTime() != null) {
            ufisCalendar.setTime(flightEvent.getAudit().getTransDateTime());
            infobjFlight.setLSTU(df.format(ufisCalendar.getTime()));
          }
        }
       
        MSGOBJECTS msgobjects = new MSGOBJECTS();
        msgobjects.setINFOBJFLIGHT(infobjFlight);
View Full Code Here

TOP

Related Classes of com.ufis_as.exco.INFOBJFLIGHT

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.