Package com.ufis_as.ufisapp.lib.time

Examples of com.ufis_as.ufisapp.lib.time.HpUfisCalendar


          }
          irmNextUrno += 1;
          isAllocated = false;
        }

        HpUfisCalendar ufisCal = new HpUfisCalendar(new Date());
        ufisCal.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC,
            EnumTimeInterval.Hours);
        utcCdat = ufisCal.getTime();

        EntDbIrmtab irmEntity = new EntDbIrmtab();
        // composite pkey
        irmEntity.setId(new EntDbIrmCompositeId(irmNextUrno, dtfl));
View Full Code Here


          }
          irmNextUrno += 1;
          isAllocated = false;
        }

        HpUfisCalendar ufisCal = new HpUfisCalendar(new Date());
        ufisCal.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC,
            EnumTimeInterval.Hours);
        utcCdat = ufisCal.getTime();

        EntDbIrmtab irmEntity = new EntDbIrmtab();
        // composite pkey
        irmEntity.setId(new EntDbIrmCompositeId(irmNextUrno, dtfl));
View Full Code Here

          }
          irmNextUrno += 1;
          isAllocated = false;
        }

        HpUfisCalendar ufisCal = new HpUfisCalendar(new Date());
        ufisCal.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC, EnumTimeInterval.Hours);
        utcCdat = ufisCal.getTime();

        EntDbIrmtab irmEntity = new EntDbIrmtab();
        // composite pkey
        irmEntity.setId(new EntDbIrmCompositeId(irmNextUrno, dtfl));
View Full Code Here

 
  public long getMinPaxUrno() {
    long urno = 0;
    try {
      // current date in UTC
      HpUfisCalendar ufisCalendar = new HpUfisCalendar();
      ufisCalendar.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC, EnumTimeInterval.Hours);
     
      // query
      StringBuilder sb = new StringBuilder();
      sb.append("SELECT MAX(e.id.urno) FROM EntDbIrmtab e ")
          .append(" WHERE e.id.dtfl = :dtfl ")
          .append(" AND to_char(e.cdat, 'yyyyMMdd') = :currentDate")
          .append(" AND e.stat <> :stat")
          .append(" ORDER BY e.cdat");
      Query paxUrnoQuery = em.createQuery(sb.toString());
      paxUrnoQuery.setParameter("dtfl", "PAX-TMP");
      paxUrnoQuery.setParameter("currentDate", ufisCalendar.getCedaDateString());
      paxUrnoQuery.setParameter("stat", "P");
     
//      List testList = paxUrnoQuery;
//      if (testList.size() > 0){
//        long s;
View Full Code Here

          }
          irmNextUrno += 1;
          isAllocated = false;
        }

        HpUfisCalendar ufisCal = new HpUfisCalendar(new Date());
        ufisCal.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC,
            EnumTimeInterval.Hours);
        utcCdat = ufisCal.getTime();

        EntDbIrmtab irmEntity = new EntDbIrmtab();
       
        ReUrno = irmNextUrno;  //  added by 2014-01-22
        // composite pkey
View Full Code Here

          }
          irmNextUrno += 1;
          isAllocated = false;
        }

        HpUfisCalendar ufisCal = new HpUfisCalendar(new Date());
        ufisCal.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC, EnumTimeInterval.Hours);
        utcCdat = ufisCal.getTime();

        EntDbIrmtab irmEntity = new EntDbIrmtab();
        // composite pkey
        irmEntity.setId(new EntDbIrmCompositeId(irmNextUrno, dtfl));
View Full Code Here

 
  public long getMinPaxUrno() {
    long urno = 0;
    try {
      // current date in UTC
      HpUfisCalendar ufisCalendar = new HpUfisCalendar();
      ufisCalendar.DateAdd(HpUfisAppConstants.OFFSET_LOCAL_UTC, EnumTimeInterval.Hours);
     
      // query
      StringBuilder sb = new StringBuilder();
      sb.append("SELECT MAX(e.id.urno) FROM EntDbIrmtab e ")
          .append(" WHERE e.id.dtfl = :dtfl ")
          .append(" AND to_char(e.cdat, 'yyyyMMdd') = :currentDate")
          .append(" AND e.stat <> :stat")
          .append(" ORDER BY e.cdat");
      Query paxUrnoQuery = em.createQuery(sb.toString());
      paxUrnoQuery.setParameter("dtfl", "PAX-TMP");
      paxUrnoQuery.setParameter("currentDate", ufisCalendar.getCedaDateString());
      paxUrnoQuery.setParameter("stat", "P");
     
//      List testList = paxUrnoQuery;
//      if (testList.size() > 0){
//        long s;
View Full Code Here

//  }

  public boolean tranformFlight(EGDSMSG flightEvent, EntDbAfttab aftFlight) {
    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
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;
View Full Code Here

  }

  private boolean tranformFlight(EGDSMSG message) {
    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;
        }
        break;
       
      case LOADACC:
        // aft
        //infobjFlight.setELDN(message.getEGDSBODY().getLOADSHEET());
        // xaf
        infojxaftab.setLSHT(message.getEGDSBODY().getLOADSHEET());
        infojxaftab.setZFWT(message.getEGDSBODY().getZFW());
        infojxaftab.setTOWT(message.getEGDSBODY().getTOW());
        // 2013-11-22 updated by JGO - Save LADT
        if (HpUfisUtils.isNotEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
          ufisCalendar.setTime(message.getEGDSHEADER().getTIMESTAMP(), ufisCalendar.getCustomFormat());
          infojxaftab.setLADT(ufisCalendar.getCedaString());
        }
        xafFound = true;
        break;
       
      case ROUTE:
        // confirm message from pilot that crew is on board
        //infobjgeneric.setALC2("EK");
        if (HpUfisUtils.isNotEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
          ufisCalendar.setTime(message.getEGDSHEADER().getTIMESTAMP(), ufisCalendar.getCustomFormat());
          INFOJFEVTAB route = new INFOJFEVTAB();
          route.setSTNM("Route Request");
          route.setSTRM(regn);
          route.setSTTM(ufisCalendar.getCedaString());
          infojfevtablist.getINFOJFEVTAB().add(route);
          fevFound = true;
        }
        break;
       
      case FUEL:
        oldData = fltFuelStatusBean.findByIdFlight(uaft);
        if (oldData == null) {
          data = new EntDbFlightFuelStatus();
          // msg send date
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSHEADER().getTIMESTAMP())) {
            ufisCalendar.setTime(message.getEGDSHEADER().getTIMESTAMP(), ufisCalendar.getCustomFormat());
            data.setMsgSendDate(ufisCalendar.getTime());
          }
          // 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);
         
          // trip fuel
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getTripFuel())) {
            data.setTripFuel(Float.parseFloat(message.getEGDSBODY().getTripFuel()));
          }
          // taxi fuel
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getTaxiFuel())) {
            data.setTaxiFuel(Float.parseFloat(message.getEGDSBODY().getTaxiFuel()));
          }
          // ramp fuel
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getRampFuel())) {
            data.setRampFuel(Float.parseFloat(message.getEGDSBODY().getRampFuel()));
          }
//          // onboard fuel
//          //if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getFOB())) {
//          if (message.getEGDSBODY().getFOB() != null) {
//            //fuelStatus.setOnboardFuel(Float.parseFloat(message.getEGDSBODY().getFOB()));
//            String fob = message.getEGDSBODY().getFOB().isEmpty() ? "0"
//                : message.getEGDSBODY().getFOB();
//            float onBoardFuel = Float.parseFloat(fob);
//            if (onBoardFuel != fuelStatus.getOnboardFuel()) {
//              fuelStatus.setOnboardFuel(onBoardFuel);
//              isNofified = true;
//            }
//          }
          data.setTrm(message.getEGDSBODY().getTRM());
          data.setDen(message.getEGDSBODY().getDEN());
          data.setRtw(message.getEGDSBODY().getRTW());
          data.setCreatedUser(MSGIF);
          data.setDataSource(MSGIF);
          fltFuelStatusBean.persist(data);
          LOG.info("EGDS FUEL: created flight fuel record={} for flight={}", data.getId(), uaft);
          cmd = UfisASCommands.IRT;
        }
       
        if (UfisASCommands.URT == cmd) {
          data = EntDbFlightFuelStatus.valueOf(oldData);
          // trip fuel
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getTripFuel())) {
            data.setTripFuel(Float.parseFloat(message.getEGDSBODY().getTripFuel()));
          }
          // taxi fuel
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getTaxiFuel())) {
            data.setTaxiFuel(Float.parseFloat(message.getEGDSBODY().getTaxiFuel()));
          }
          // ramp fuel
          if (HpUfisUtils.isNotEmptyStr(message.getEGDSBODY().getRampFuel())) {
            data.setRampFuel(Float.parseFloat(message.getEGDSBODY().getRampFuel()));
          }
          data.setTrm(message.getEGDSBODY().getTRM());
          data.setDen(message.getEGDSBODY().getDEN());
          data.setRtw(message.getEGDSBODY().getRTW());

          // 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 FUEL: updated flight fuel record={} for flight={}", data.getId(), uaft);
View Full Code Here

TOP

Related Classes of com.ufis_as.ufisapp.lib.time.HpUfisCalendar

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.